Skip to content

Commit 67dfed1

Browse files
committed
feat(useQuery): offline queries
only schedule garbage collection when the first observer subscribes rather than in the constructor this works around the suspense issue because we only add observers after we've loaded as we throw before that.
1 parent a840e7c commit 67dfed1

File tree

1 file changed

+1
-7
lines changed

1 file changed

+1
-7
lines changed

src/core/query.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,9 @@ export class Query<
163163
private observers: QueryObserver<any, any, any, any, any>[]
164164
private defaultOptions?: QueryOptions<TQueryFnData, TError, TData, TQueryKey>
165165
private abortSignalConsumed: boolean
166-
private hadObservers: boolean
167166

168167
constructor(config: QueryConfig<TQueryFnData, TError, TData, TQueryKey>) {
169168
this.abortSignalConsumed = false
170-
this.hadObservers = false
171169
this.defaultOptions = config.defaultOptions
172170
this.setOptions(config.options)
173171
this.observers = []
@@ -177,7 +175,6 @@ export class Query<
177175
this.initialState = config.state || this.getDefaultState(this.options)
178176
this.state = this.initialState
179177
this.meta = config.meta
180-
this.scheduleGc()
181178
}
182179

183180
private setOptions(
@@ -218,9 +215,7 @@ export class Query<
218215
private optionalRemove() {
219216
if (!this.observers.length) {
220217
if (this.state.isFetching) {
221-
if (this.hadObservers) {
222-
this.scheduleGc()
223-
}
218+
this.scheduleGc()
224219
} else {
225220
this.cache.remove(this)
226221
}
@@ -325,7 +320,6 @@ export class Query<
325320

326321
addObserver(observer: QueryObserver<any, any, any, any, any>): void {
327322
if (this.observers.indexOf(observer) === -1) {
328-
this.hadObservers = true
329323
this.observers.push(observer)
330324

331325
// Stop the query from being garbage collected

0 commit comments

Comments
 (0)