@powersync/react 2.2.1 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -121,7 +121,7 @@ export const TodoListsDisplayDemo = () => {
121
121
 
122
122
  ```
123
123
 
124
- When the SQL or parameters passed to `useQuery` change, the hook keeps returning the previous query's rows, with `isFetching` set to `true`, until the updated query has produced its first result. A refetch caused by a change to one of the queried tables reports `isFetching` in the same way. While `isFetching` is `true`, `fetchReason` says why: `'initial'` for the first load, `'tables-changed'` for a refetch of the same query, and `'settings-changed'` while the rows still belong to the previous query. It is `undefined` when nothing is being fetched.
124
+ When the SQL or parameters passed to `useQuery` change, the hook keeps returning the previous query's rows, with `isFetching` set to `true`, until the updated query has produced its first result. A refetch caused by a change to one of the queried tables reports `isFetching` in the same way. While `isFetching` is `true`, `fetchReason` says why: `'initial'` for the first load, `'tables-changed'` for a refetch of the same query, `'settings-changed'` while the rows still belong to the previous query, and `'reactivated'` while a query set back to `active` reloads (the rows are the ones kept from before it was deactivated). It is `undefined` when nothing is being fetched.
125
125
 
126
126
  ```JSX
127
127
  const { data: todos, fetchReason } = useQuery('SELECT * FROM todos WHERE list_id = ?', [listId]);
@@ -6,10 +6,13 @@ import { getSuspenseQueryCache } from './SuspenseQueryCache.js';
6
6
  export function useSuspenseQuery(query, parameters = [], options = {}) {
7
7
  const powerSync = useContext(PowerSyncContext);
8
8
  const parsedQuery = constructCompatibleQuery(query, parameters);
9
- const config = resolveConfig(powerSync, parsedQuery, options,
10
- // We currently don't support sync streams here (useAllStreamsHaveSynced relies on useEffect, which don't fire in
11
- // suspended components).
12
- true);
9
+ const config = resolveConfig(powerSync, parsedQuery, options, {
10
+ // `active` is a `useQuery` option, a suspending component can't render without data.
11
+ active: true,
12
+ // We currently don't support sync streams here (useAllStreamsHaveSynced relies on useEffect, which don't fire in
13
+ // suspended components).
14
+ streamsHaveSynced: true
15
+ });
13
16
  if (config.kind != 'query') {
14
17
  // Missing database or a query that failed to compile, report.
15
18
  throw configError(config);
@@ -1 +1 @@
1
- {"version":3,"file":"useSuspenseQuery.js","sourceRoot":"","sources":["../../../src/hooks/suspense/useSuspenseQuery.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAElF,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AA6DhE,MAAM,UAAU,gBAAgB,CAC9B,KAAwC,EACxC,aAAoB,EAAE,EACtB,UAA4E,EAAE;IAE9E,MAAM,SAAS,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAC;IAC/C,MAAM,WAAW,GAAG,wBAAwB,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;IAChE,MAAM,MAAM,GAAG,aAAa,CAC1B,SAAS,EACT,WAAW,EACX,OAAO;IACP,iHAAiH;IACjH,yBAAyB;IACzB,IAAI,CACL,CAAC;IACF,IAAI,MAAM,CAAC,IAAI,IAAI,OAAO,EAAE,CAAC;QAC3B,8DAA8D;QAC9D,MAAM,WAAW,CAAC,MAAM,CAAC,CAAC;IAC5B,CAAC;IAED,mHAAmH;IACnH,yDAAyD;IACzD,MAAM,KAAK,GAAG,qBAAqB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAC/C,MAAM,GAAG,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;IAC9B,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;IAC5E,aAAa,CAAC,Q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AC,CAAC;IACH,IAAI,MAAM,CAAC,IAAI,IAAI,OAAO,EAAE,CAAC;QAC3B,8DAA8D;QAC9D,MAAM,WAAW,CAAC,MAAM,CAAC,CAAC;IAC5B,CAAC;IAED,mHAAmH;IACnH,yDAAyD;IACzD,MAAM,KAAK,GAAG,qBAAqB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAC/C,MAAM,GAAG,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;IAC9B,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;IAC5E,aAAa,CAAC,QAAQ,EAAE,CAAC;IACzB,MAAM,MAAM,GAAG,oBAAoB,CAAC,aAAa,CAAC,SAAS,EAAE,aAAa,CAAC,WAAW,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;IAEnH,IAAI,MAAM,CAAC,KAAK,IAAI,IAAI,EAAE,CAAC;QACzB,MAAM,MAAM,CAAC,KAAK,CAAC;IACrB,CAAC;SAAM,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;QAC5B,MAAM,aAAa,CAAC,aAAa,EAAE,CAAC;IACtC,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,IAAiB,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC;AACrE,CAAC"}
@@ -12,6 +12,8 @@ export type RunnerConfig<RowType> = {
12
12
  kind: 'missing-db';
13
13
  } | {
14
14
  kind: 'waiting-for-streams';
15
+ } | {
16
+ kind: 'inactive';
15
17
  } | {
16
18
  kind: 'compile-error';
17
19
  error: Error;
@@ -41,8 +43,14 @@ export declare function configError<RowType>(config: Exclude<RunnerConfig<RowTyp
41
43
  * Resolves the inputs of `useQuery` into a comparable {@link RunnerConfig}.
42
44
  *
43
45
  * This is pure (apart from compiling the query) and can run while rendering.
46
+ *
47
+ * `state` is passed separately from `options` because `active` and `streams` are only supported by `useQuery`. Other
48
+ * hooks pass `true` for both, so stray options can't put them into a state they don't support.
44
49
  */
45
- export declare function resolveConfig<RowType>(db: CommonPowerSyncDatabase | null, query: WatchCompatibleQueryWithParams<RowType[]>, options: AdditionalOptions & DifferentialHookOptions<RowType>, streamsHaveSynced: boolean): RunnerConfig<RowType>;
50
+ export declare function resolveConfig<RowType>(db: CommonPowerSyncDatabase | null, query: WatchCompatibleQueryWithParams<RowType[]>, options: AdditionalOptions & DifferentialHookOptions<RowType>, state: {
51
+ active: boolean;
52
+ streamsHaveSynced: boolean;
53
+ }): RunnerConfig<RowType>;
46
54
  export interface QueryRunnerListener extends BaseListener {
47
55
  onChange(): void;
48
56
  }
@@ -58,6 +66,15 @@ export interface QueryRunnerListener extends BaseListener {
58
66
  export declare class QueryRunner<RowType> extends BaseObserver<QueryRunnerListener> {
59
67
  private config;
60
68
  private idleResult;
69
+ /**
70
+ * While inactive, the query that produced the data kept in {@link idleResult}. Reactivating that same query resumes
71
+ * from the kept data instead of starting from an empty loading state.
72
+ */
73
+ private keptFrom;
74
+ /**
75
+ * Whether {@link idleResult} holds data kept from before the query was deactivated, which new work starts from.
76
+ */
77
+ private resuming;
61
78
  /**
62
79
  * The active work, only non-null while we have listeners.
63
80
  */
@@ -76,6 +93,14 @@ export declare class QueryRunner<RowType> extends BaseObserver<QueryRunnerListen
76
93
  * that render is ultimately dropped).
77
94
  */
78
95
  resultFor(config: RunnerConfig<RowType>, snapshot: Result<RowType>): Result<RowType>;
96
+ /**
97
+ * The idle result to report after applying `next` to the committed config, given the currently reported result.
98
+ */
99
+ private nextIdleResult;
100
+ /**
101
+ * Whether applying `next` reactivates the query that produced the data kept while inactive.
102
+ */
103
+ private canResume;
79
104
  /**
80
105
  * Applies the inputs of a committed render to this runner. This does nothing if they haven't changed.
81
106
  *
@@ -5,6 +5,7 @@ function configEquals(a, b) {
5
5
  switch (a.kind) {
6
6
  case 'missing-db':
7
7
  case 'waiting-for-streams':
8
+ case 'inactive':
8
9
  return a.kind == b.kind;
9
10
  case 'compile-error':
10
11
  // compile() runs on every render, so a failing query throws a new error each time.
@@ -37,12 +38,15 @@ export function configError(config) {
37
38
  return idleResultFor(config).error ?? null;
38
39
  }
39
40
  const _loadingState = { isLoading: true, isFetching: false, data: [], error: undefined };
41
+ const _inactiveState = { isLoading: false, isFetching: false, data: [], error: undefined };
40
42
  function idleResultFor(config) {
41
43
  switch (config.kind) {
42
44
  case 'missing-db':
43
45
  return { isLoading: false, isFetching: false, data: [], error: new Error('PowerSync not configured.') };
44
46
  case 'waiting-for-streams':
45
47
  return _loadingState;
48
+ case 'inactive':
49
+ return _inactiveState;
46
50
  case 'compile-error':
47
51
  return { isLoading: false, isFetching: false, data: [], error: config.error };
48
52
  case 'query':
@@ -57,16 +61,45 @@ function idleResultFor(config) {
57
61
  };
58
62
  }
59
63
  }
64
+ /**
65
+ * The result to report while inactive, given the result reported before deactivating.
66
+ *
67
+ * Successfully loaded data is kept, so that deactivating and later reactivating a query (e.g. for a screen in the
68
+ * background) doesn't flash an empty state.
69
+ */
70
+ function inactiveResultFrom(current) {
71
+ if (current === _inactiveState || current.isLoading || current.error != null) {
72
+ return _inactiveState;
73
+ }
74
+ return { isLoading: false, isFetching: false, data: current.data, error: undefined };
75
+ }
76
+ /**
77
+ * The result to report when reactivating a query, starting from the data kept while it was inactive.
78
+ */
79
+ function resumedResultFor(config, kept) {
80
+ // Single queries always report fetching while they run.
81
+ const isFetching = config.runOnce || config.reportFetching;
82
+ return { ...kept, isFetching, fetchReason: isFetching ? 'reactivated' : undefined };
83
+ }
84
+ function isSameQuery(a, b) {
85
+ return a.db === b.db && a.sql == b.sql && a.stringifiedParams == b.stringifiedParams;
86
+ }
60
87
  /**
61
88
  * Resolves the inputs of `useQuery` into a comparable {@link RunnerConfig}.
62
89
  *
63
90
  * This is pure (apart from compiling the query) and can run while rendering.
91
+ *
92
+ * `state` is passed separately from `options` because `active` and `streams` are only supported by `useQuery`. Other
93
+ * hooks pass `true` for both, so stray options can't put them into a state they don't support.
64
94
  */
65
- export function resolveConfig(db, query, options, streamsHaveSynced) {
95
+ export function resolveConfig(db, query, options, state) {
66
96
  if (db == null) {
67
97
  return { kind: 'missing-db' };
68
98
  }
69
- if (!streamsHaveSynced) {
99
+ if (!state.active) {
100
+ return { kind: 'inactive' };
101
+ }
102
+ if (!state.streamsHaveSynced) {
70
103
  return { kind: 'waiting-for-streams' };
71
104
  }
72
105
  let sql;
@@ -104,6 +137,15 @@ export function resolveConfig(db, query, options, streamsHaveSynced) {
104
137
  export class QueryRunner extends BaseObserver {
105
138
  config = null;
106
139
  idleResult = _loadingState;
140
+ /**
141
+ * While inactive, the query that produced the data kept in {@link idleResult}. Reactivating that same query resumes
142
+ * from the kept data instead of starting from an empty loading state.
143
+ */
144
+ keptFrom = null;
145
+ /**
146
+ * Whether {@link idleResult} holds data kept from before the query was deactivated, which new work starts from.
147
+ */
148
+ resuming = false;
107
149
  /**
108
150
  * The active work, only non-null while we have listeners.
109
151
  */
@@ -148,10 +190,34 @@ export class QueryRunner extends BaseObserver {
148
190
  // A re-render has changed the query, and we'll start running that query in a useEffect hook calling configure.
149
191
  // For now, optimistically return the loading state that query would start.
150
192
  const fromWork = this.work?.pendingResultFor(config);
151
- const result = fromWork ?? idleResultFor(config);
193
+ const result = fromWork ?? this.nextIdleResult(config, snapshot);
152
194
  this.uncommitedConfigChange = { config, snapshot, result, isOptimisticStateChange: fromWork == null };
153
195
  return result;
154
196
  }
197
+ /**
198
+ * The idle result to report after applying `next` to the committed config, given the currently reported result.
199
+ */
200
+ nextIdleResult(next, current) {
201
+ if (next.kind == 'inactive') {
202
+ return inactiveResultFrom(current);
203
+ }
204
+ if (this.canResume(next, current)) {
205
+ return resumedResultFor(next, current);
206
+ }
207
+ return idleResultFor(next);
208
+ }
209
+ /**
210
+ * Whether applying `next` reactivates the query that produced the data kept while inactive.
211
+ */
212
+ canResume(next, current) {
213
+ return (next.kind == 'query' &&
214
+ this.config?.kind == 'inactive' &&
215
+ // This has to compare against the result we actually reported while inactive (which is never copied): if the
216
+ // query was deactivated mid-load, we report _inactiveState even if the load completed before the commit.
217
+ current !== _inactiveState &&
218
+ this.keptFrom != null &&
219
+ isSameQuery(this.keptFrom, next));
220
+ }
155
221
  /**
156
222
  * Applies the inputs of a committed render to this runner. This does nothing if they haven't changed.
157
223
  *
@@ -165,14 +231,20 @@ export class QueryRunner extends BaseObserver {
165
231
  return;
166
232
  }
167
233
  const pending = this.uncommitedConfigChange;
168
- this.config = next;
234
+ const previous = this.config;
235
+ const current = this.getSnapshot();
236
+ // These depend on the previous config, so they have to be computed before applying the new one.
237
+ const resuming = initial == null && this.canResume(next, current);
169
238
  this.idleResult = initial
170
239
  ? initial
171
240
  : pending != null && pending.isOptimisticStateChange && configEquals(pending.config, next)
172
241
  ? // We already returned this as an optimistic state in a previous resultFor call. Use the same result to not
173
242
  // cause another render.
174
243
  pending.result
175
- : idleResultFor(next);
244
+ : this.nextIdleResult(next, current);
245
+ this.keptFrom = next.kind == 'inactive' && previous?.kind == 'query' ? previous : null;
246
+ this.resuming = resuming;
247
+ this.config = next;
176
248
  this.uncommitedConfigChange = null;
177
249
  if (this.work == null || !this.work.tryUpdate(next)) {
178
250
  this.work?.dispose();
@@ -190,7 +262,7 @@ export class QueryRunner extends BaseObserver {
190
262
  return;
191
263
  }
192
264
  const emit = () => this.notifyListeners();
193
- this.work = new (config.runOnce ? SingleQueryWork : WatchedQueryWork)(config, this.idleResult, emit);
265
+ this.work = new (config.runOnce ? SingleQueryWork : WatchedQueryWork)(config, this.idleResult, emit, this.resuming);
194
266
  }
195
267
  notifyListeners() {
196
268
  this.iterateListeners((l) => l.onChange?.());
@@ -202,15 +274,17 @@ class SingleQueryWork {
202
274
  result;
203
275
  abortController = null;
204
276
  disposed = false;
205
- constructor(config, initial, emit) {
277
+ constructor(config, initial, emit,
278
+ // When resuming from data kept while inactive, the query runs again but keeps reporting that data until it's done.
279
+ resume = false) {
206
280
  this.config = config;
207
281
  this.emit = emit;
208
- if (!initial.isLoading && initial.error == null) {
282
+ if (!resume && !initial.isLoading && initial.error == null) {
209
283
  // Seeded with an existing result, no need to run it again.
210
284
  this.result = { ...initial, refresh: this.refresh };
211
285
  return;
212
286
  }
213
- const fetchReason = 'initial';
287
+ const fetchReason = resume ? 'reactivated' : 'initial';
214
288
  this.result = {
215
289
  ...initial,
216
290
  isFetching: true,
@@ -235,7 +309,8 @@ class SingleQueryWork {
235
309
  const isAborted = () => signal.aborted || outerSignal?.aborted == true;
236
310
  if (!this.result.isLoading || this.result.error) {
237
311
  // After an error, data is empty, so we're loading again rather than refreshing existing rows.
238
- const isLoading = fetchReason === 'initial' || this.result.error != null;
312
+ // Initial runs only get here after an error, or when resuming from data kept while inactive.
313
+ const isLoading = this.result.error != null;
239
314
  this.setResult({ isLoading, isFetching: true, error: undefined, fetchReason });
240
315
  }
241
316
  const { query, sql, parameters, db } = this.config;
@@ -281,19 +356,31 @@ class WatchedQueryWork {
281
356
  * previous query's rows, which is reported as `fetchReason: 'settings-changed'`.
282
357
  */
283
358
  awaitingUpdatedResult = false;
359
+ /**
360
+ * Set when resuming from data kept while inactive, until the watched query has produced its first result. The
361
+ * watched query reports `isLoading` until then, but we already have data to show.
362
+ */
363
+ resuming;
284
364
  reportFetching;
285
- constructor(config, initial, emit) {
365
+ constructor(config, initial, emit, resume = false) {
286
366
  this.config = config;
287
367
  this.emit = emit;
288
368
  this.result = initial;
369
+ this.resuming = resume;
289
370
  this.reportFetching = config.reportFetching;
290
371
  const { db, query, rowComparator, throttleMs, reportFetching } = config;
291
372
  const customQuery = db.customQuery(query);
373
+ // Watched queries only read placeholder data. For differential queries, this also keeps references for unchanged
374
+ // rows stable across the resume.
375
+ const placeholderData = resume ? initial.data : undefined;
292
376
  this.watch = rowComparator
293
- ? customQuery.differentialWatch({ rowComparator, reportFetching, throttleMs })
294
- : customQuery.watch({ reportFetching, throttleMs });
377
+ ? customQuery.differentialWatch({ rowComparator, reportFetching, throttleMs, placeholderData })
378
+ : customQuery.watch({ reportFetching, throttleMs, placeholderData });
295
379
  this.disposeListener = this.watch.registerListener({
296
380
  onStateChange: (state) => {
381
+ if (!state.isLoading) {
382
+ this.resuming = false;
383
+ }
297
384
  if (this.awaitingUpdatedResult && !this.pendingUpdate && !state.isFetching) {
298
385
  // The first completed fetch after the new settings were applied is the updated query's result.
299
386
  this.awaitingUpdatedResult = false;
@@ -313,7 +400,7 @@ class WatchedQueryWork {
313
400
  const isFetching = state.isFetching || (this.pendingUpdate && this.reportFetching);
314
401
  return {
315
402
  data: state.data,
316
- isLoading: state.isLoading,
403
+ isLoading: state.isLoading && !this.resuming,
317
404
  isFetching,
318
405
  error: state.error ?? undefined,
319
406
  fetchReason: this.fetchReasonFor(state.isLoading, isFetching)
@@ -323,7 +410,7 @@ class WatchedQueryWork {
323
410
  if (!isFetching)
324
411
  return undefined;
325
412
  if (isLoading)
326
- return 'initial';
413
+ return this.resuming ? 'reactivated' : 'initial';
327
414
  return this.awaitingUpdatedResult ? 'settings-changed' : 'tables-changed';
328
415
  }
329
416
  canUpdate(config) {
@@ -1 +1 @@
1
- {"version":3,"file":"QueryRunner.js","sourceRoot":"","sources":["../../../src/hooks/watched/QueryRunner.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,YAAY,EAIZ,SAAS,EAEV,MAAM,mBAAmB,CAAC;AAyC3B,SAAS,YAAY,CAAU,CAAwB,EAAE,CAAwB;IAC/E,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAEzB,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC;QACf,KAAK,YAAY,CAAC;QAClB,KAAK,qBAAqB;YACxB,OAAO,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC;QAC1B,KAAK,eAAe;YAClB,mFAAmF;YACnF,OAAO,CAAC,CAAC,IAAI,IAAI,eAAe,IAAI,CAAC,CAAC,KAAK,CAAC,OAAO,IAAI,CAA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I,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;YAC5B,OAAO,IAAI,CAAC;QACd,CAAC;QAED,uDAAuD;QACvD,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,IAAI,MAAM,CAAC,cAAc,CAAC;QACnE,OAAO;YACL,GAAG,IAAI,CAAC,MAAM;YACd,UAAU;YACV,WAAW,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,kBAAkB;SAC9F,CAAC;IACJ,CAAC;IAED,SAAS,CAAC,MAA6B;QACrC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;YAC5B,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,cAAc,CAAC;QAC5C,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAC1B,IAAI,CAAC,qBAAqB,GAAG,IAAI,CAAC;QAClC,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC;YACxB,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,UAAU,EAAE,MAAM,CAAC,UAAU;YAC7B,cAAc,EAAE,MAAM,CAAC,cAAc;SACtC,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC9C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO;QACL,IAAI,CAAC,eAAe,EAAE,CAAC;QACvB,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;CACF"}
@@ -6,10 +6,11 @@ import { constructCompatibleQuery } from './watch-utils.js';
6
6
  export function useQuery(query, parameters = [], options = {}) {
7
7
  const powerSync = useContext(PowerSyncContext);
8
8
  const parsedQuery = constructCompatibleQuery(query, parameters);
9
- const streamsHaveSynced = useAllSyncStreamsHaveSynced(null, options.streams);
9
+ const active = options.active !== false;
10
+ const streamsHaveSynced = useAllSyncStreamsHaveSynced(null, active ? options.streams : undefined);
10
11
  const runnerRef = useRef(null);
11
12
  const runner = (runnerRef.current ??= new QueryRunner());
12
- const config = resolveConfig(powerSync, parsedQuery, options, streamsHaveSynced);
13
+ const config = resolveConfig(powerSync, parsedQuery, options, { active, streamsHaveSynced });
13
14
  const snapshot = useSyncExternalStore(runner.subscribe, runner.getSnapshot, runner.getSnapshot);
14
15
  // Apply the inputs once this render has been committed, so that discarded renders don't start running queries.
15
16
  useEffect(() => runner.configure(config));
@@ -1 +1 @@
1
- {"version":3,"file":"useQuery.js","sourceRoot":"","sources":["../../../src/hooks/watched/useQuery.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAE9D,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAgD5D,MAAM,UAAU,QAAQ,CACtB,KAAwC,EACxC,aAAoB,EAAE,EACtB,UAAgE,EAAE;IAElE,MAAM,SAAS,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAC;IAC/C,MAAM,WAAW,GAAG,wBAAwB,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;IAChE,MAAM,iBAAiB,GAAG,2BAA2B,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IAE7E,MAAM,SAAS,GAAG,MAAM,CAA8B,IAAI,CAAC,CAAC;IAC5D,MAAM,MAAM,GAAG,CAAC,S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AC;IAElG,MAAM,SAAS,GAAG,MAAM,CAA8B,IAAI,CAAC,CAAC;IAC5D,MAAM,MAAM,GAAG,CAAC,SAAS,CAAC,OAAO,KAAK,IAAI,WAAW,EAAW,CAAC,CAAC;IAClE,MAAM,MAAM,GAAG,aAAa,CAAC,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,iBAAiB,EAAE,CAAC,CAAC;IAE7F,MAAM,QAAQ,GAAG,oBAAoB,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;IAEhG,+GAA+G;IAC/G,SAAS,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;IAC1C,OAAO,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAC5C,CAAC"}
@@ -14,6 +14,19 @@ export interface HookWatchOptions extends Omit<SQLOnChangeOptions, 'signal'> {
14
14
  */
15
15
  streams?: QuerySyncStreamOptions[];
16
16
  reportFetching?: boolean;
17
+ /**
18
+ * When set to `false`, the query is not compiled or executed and {@link streams} are not subscribed to. This is
19
+ * useful to avoid the cost of watching queries for UI that isn't visible, e.g. screens in the background.
20
+ *
21
+ * While inactive, the hook reports `isLoading: false` and `isFetching: false`, and keeps reporting the last
22
+ * successfully loaded `data` (or `[]` if the query hadn't loaded). When reactivated with the same SQL and parameters,
23
+ * the query reloads in the background with `fetchReason: 'reactivated'` while still reporting the kept data.
24
+ *
25
+ * Not supported by `useSuspenseQuery`.
26
+ *
27
+ * @default true
28
+ */
29
+ active?: boolean;
17
30
  }
18
31
  /**
19
32
  * Additional options to control how `useQuery` behaves when subscribing to a stream.
@@ -51,7 +64,10 @@ export interface DifferentialHookOptions<RowType> extends HookWatchOptions {
51
64
  */
52
65
  rowComparator?: DifferentialWatchedQueryComparator<RowType>;
53
66
  }
54
- type WithoutSyncStreams<T> = Omit<T, 'streams'> & {
67
+ /**
68
+ * Adapts `useQuery` options for `useSuspenseQuery`, which doesn't support `streams` or `active`.
69
+ */
70
+ type ForSuspense<T> = Omit<T, 'streams' | 'active'> & {
55
71
  /**
56
72
  * @deprecated Sync streams are not supported by `useSuspenseQuery` and are ignored. Use `useQuery` or
57
73
  * `useSyncStream` to subscribe to streams instead.
@@ -61,11 +77,11 @@ type WithoutSyncStreams<T> = Omit<T, 'streams'> & {
61
77
  /**
62
78
  * Options for `useSuspenseQuery`.
63
79
  */
64
- export type SuspenseQueryOptions = WithoutSyncStreams<AdditionalOptions>;
80
+ export type SuspenseQueryOptions = ForSuspense<AdditionalOptions>;
65
81
  /**
66
82
  * Options for `useSuspenseQuery` with a `rowComparator`.
67
83
  */
68
- export type DifferentialSuspenseQueryOptions<RowType> = WithoutSyncStreams<DifferentialHookOptions<RowType>>;
84
+ export type DifferentialSuspenseQueryOptions<RowType> = ForSuspense<DifferentialHookOptions<RowType>>;
69
85
  /**
70
86
  * Why a `useQuery` hook is currently fetching.
71
87
  *
@@ -74,8 +90,10 @@ export type DifferentialSuspenseQueryOptions<RowType> = WithoutSyncStreams<Diffe
74
90
  * - `'tables-changed'`: a table the query depends on changed and the same query is re-running. `data` is still current.
75
91
  * - `'settings-changed'`: the SQL, parameters or options changed. `data` still holds the previous query's rows until the
76
92
  * updated query has produced its first result.
93
+ * - `'reactivated'`: the query was set back to `active` after being inactive and is running again. `data` still holds
94
+ * the rows loaded before it was deactivated, which may be outdated, until the query has produced its first result.
77
95
  */
78
- export type FetchReason = 'initial' | 'refresh' | 'tables-changed' | 'settings-changed';
96
+ export type FetchReason = 'initial' | 'refresh' | 'tables-changed' | 'settings-changed' | 'reactivated';
79
97
  export type ReadonlyQueryResult<RowType> = {
80
98
  readonly data: ReadonlyArray<Readonly<RowType>>;
81
99
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powersync/react",
3
- "version": "2.2.1",
3
+ "version": "2.3.0",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org/",
6
6
  "access": "public"
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "homepage": "https://docs.powersync.com",
27
27
  "peerDependencies": {
28
- "@powersync/common": "^2.5.0",
28
+ "@powersync/common": "^2.5.1",
29
29
  "react": "*"
30
30
  },
31
31
  "devDependencies": {
@@ -41,10 +41,10 @@
41
41
  "react": "19.3.0",
42
42
  "react-dom": "19.3.0",
43
43
  "react-error-boundary": "^4.1.0",
44
- "@powersync/common": "2.5.0",
44
+ "@powersync/common": "2.5.1",
45
45
  "@powersync/drizzle-driver": "0.8.0",
46
- "@powersync/node": "1.3.1",
47
- "@powersync/shared-internals": "1.6.0"
46
+ "@powersync/node": "1.3.2",
47
+ "@powersync/shared-internals": "1.6.1"
48
48
  },
49
49
  "scripts": {
50
50
  "build": "tsc -b",
@@ -72,14 +72,13 @@ export function useSuspenseQuery<RowType = any>(
72
72
  ): SuspenseQueryResult<RowType> | ReadonlySuspenseQueryResult<RowType> {
73
73
  const powerSync = useContext(PowerSyncContext);
74
74
  const parsedQuery = constructCompatibleQuery(query, parameters);
75
- const config = resolveConfig(
76
- powerSync,
77
- parsedQuery,
78
- options,
75
+ const config = resolveConfig(powerSync, parsedQuery, options, {
76
+ // `active` is a `useQuery` option, a suspending component can't render without data.
77
+ active: true,
79
78
  // We currently don't support sync streams here (useAllStreamsHaveSynced relies on useEffect, which don't fire in
80
79
  // suspended components).
81
- true
82
- );
80
+ streamsHaveSynced: true
81
+ });
83
82
  if (config.kind != 'query') {
84
83
  // Missing database or a query that failed to compile, report.
85
84
  throw configError(config);
@@ -31,6 +31,8 @@ export type RunnerConfig<RowType> =
31
31
  | { kind: 'missing-db' }
32
32
  // Query included sync streams that have not synced yet
33
33
  | { kind: 'waiting-for-streams' }
34
+ // Manually disabled by user.
35
+ | { kind: 'inactive' }
34
36
  | { kind: 'compile-error'; error: Error }
35
37
  | QueryConfig<RowType>;
36
38
 
@@ -53,6 +55,7 @@ function configEquals<RowType>(a: RunnerConfig<RowType>, b: RunnerConfig<RowType
53
55
  switch (a.kind) {
54
56
  case 'missing-db':
55
57
  case 'waiting-for-streams':
58
+ case 'inactive':
56
59
  return a.kind == b.kind;
57
60
  case 'compile-error':
58
61
  // compile() runs on every render, so a failing query throws a new error each time.
@@ -90,6 +93,7 @@ export function configError<RowType>(config: Exclude<RunnerConfig<RowType>, Quer
90
93
  }
91
94
 
92
95
  const _loadingState: QueryResult<never> = { isLoading: true, isFetching: false, data: [], error: undefined };
96
+ const _inactiveState: QueryResult<never> = { isLoading: false, isFetching: false, data: [], error: undefined };
93
97
 
94
98
  function idleResultFor<RowType>(config: RunnerConfig<RowType>): Result<RowType> {
95
99
  switch (config.kind) {
@@ -97,6 +101,8 @@ function idleResultFor<RowType>(config: RunnerConfig<RowType>): Result<RowType>
97
101
  return { isLoading: false, isFetching: false, data: [], error: new Error('PowerSync not configured.') };
98
102
  case 'waiting-for-streams':
99
103
  return _loadingState;
104
+ case 'inactive':
105
+ return _inactiveState;
100
106
  case 'compile-error':
101
107
  return { isLoading: false, isFetching: false, data: [], error: config.error };
102
108
  case 'query':
@@ -112,21 +118,53 @@ function idleResultFor<RowType>(config: RunnerConfig<RowType>): Result<RowType>
112
118
  }
113
119
  }
114
120
 
121
+ /**
122
+ * The result to report while inactive, given the result reported before deactivating.
123
+ *
124
+ * Successfully loaded data is kept, so that deactivating and later reactivating a query (e.g. for a screen in the
125
+ * background) doesn't flash an empty state.
126
+ */
127
+ function inactiveResultFrom<RowType>(current: Result<RowType>): Result<RowType> {
128
+ if (current === _inactiveState || current.isLoading || current.error != null) {
129
+ return _inactiveState;
130
+ }
131
+ return { isLoading: false, isFetching: false, data: current.data, error: undefined } as Result<RowType>;
132
+ }
133
+
134
+ /**
135
+ * The result to report when reactivating a query, starting from the data kept while it was inactive.
136
+ */
137
+ function resumedResultFor<RowType>(config: QueryConfig<RowType>, kept: Result<RowType>): Result<RowType> {
138
+ // Single queries always report fetching while they run.
139
+ const isFetching = config.runOnce || config.reportFetching;
140
+ return { ...kept, isFetching, fetchReason: isFetching ? 'reactivated' : undefined };
141
+ }
142
+
143
+ function isSameQuery<RowType>(a: QueryConfig<RowType>, b: QueryConfig<RowType>): boolean {
144
+ return a.db === b.db && a.sql == b.sql && a.stringifiedParams == b.stringifiedParams;
145
+ }
146
+
115
147
  /**
116
148
  * Resolves the inputs of `useQuery` into a comparable {@link RunnerConfig}.
117
149
  *
118
150
  * This is pure (apart from compiling the query) and can run while rendering.
151
+ *
152
+ * `state` is passed separately from `options` because `active` and `streams` are only supported by `useQuery`. Other
153
+ * hooks pass `true` for both, so stray options can't put them into a state they don't support.
119
154
  */
120
155
  export function resolveConfig<RowType>(
121
156
  db: CommonPowerSyncDatabase | null,
122
157
  query: WatchCompatibleQueryWithParams<RowType[]>,
123
158
  options: AdditionalOptions & DifferentialHookOptions<RowType>,
124
- streamsHaveSynced: boolean
159
+ state: { active: boolean; streamsHaveSynced: boolean }
125
160
  ): RunnerConfig<RowType> {
126
161
  if (db == null) {
127
162
  return { kind: 'missing-db' };
128
163
  }
129
- if (!streamsHaveSynced) {
164
+ if (!state.active) {
165
+ return { kind: 'inactive' };
166
+ }
167
+ if (!state.streamsHaveSynced) {
130
168
  return { kind: 'waiting-for-streams' };
131
169
  }
132
170
 
@@ -170,6 +208,15 @@ export interface QueryRunnerListener extends BaseListener {
170
208
  export class QueryRunner<RowType> extends BaseObserver<QueryRunnerListener> {
171
209
  private config: RunnerConfig<RowType> | null = null;
172
210
  private idleResult: Result<RowType> = _loadingState;
211
+ /**
212
+ * While inactive, the query that produced the data kept in {@link idleResult}. Reactivating that same query resumes
213
+ * from the kept data instead of starting from an empty loading state.
214
+ */
215
+ private keptFrom: QueryConfig<RowType> | null = null;
216
+ /**
217
+ * Whether {@link idleResult} holds data kept from before the query was deactivated, which new work starts from.
218
+ */
219
+ private resuming = false;
173
220
  /**
174
221
  * The active work, only non-null while we have listeners.
175
222
  */
@@ -226,11 +273,39 @@ export class QueryRunner<RowType> extends BaseObserver<QueryRunnerListener> {
226
273
  // A re-render has changed the query, and we'll start running that query in a useEffect hook calling configure.
227
274
  // For now, optimistically return the loading state that query would start.
228
275
  const fromWork = this.work?.pendingResultFor(config);
229
- const result = fromWork ?? idleResultFor(config);
276
+ const result = fromWork ?? this.nextIdleResult(config, snapshot);
230
277
  this.uncommitedConfigChange = { config, snapshot, result, isOptimisticStateChange: fromWork == null };
231
278
  return result;
232
279
  }
233
280
 
281
+ /**
282
+ * The idle result to report after applying `next` to the committed config, given the currently reported result.
283
+ */
284
+ private nextIdleResult(next: RunnerConfig<RowType>, current: Result<RowType>): Result<RowType> {
285
+ if (next.kind == 'inactive') {
286
+ return inactiveResultFrom(current);
287
+ }
288
+ if (this.canResume(next, current)) {
289
+ return resumedResultFor(next, current);
290
+ }
291
+ return idleResultFor(next);
292
+ }
293
+
294
+ /**
295
+ * Whether applying `next` reactivates the query that produced the data kept while inactive.
296
+ */
297
+ private canResume(next: RunnerConfig<RowType>, current: Result<RowType>): next is QueryConfig<RowType> {
298
+ return (
299
+ next.kind == 'query' &&
300
+ this.config?.kind == 'inactive' &&
301
+ // This has to compare against the result we actually reported while inactive (which is never copied): if the
302
+ // query was deactivated mid-load, we report _inactiveState even if the load completed before the commit.
303
+ current !== _inactiveState &&
304
+ this.keptFrom != null &&
305
+ isSameQuery(this.keptFrom, next)
306
+ );
307
+ }
308
+
234
309
  /**
235
310
  * Applies the inputs of a committed render to this runner. This does nothing if they haven't changed.
236
311
  *
@@ -245,14 +320,20 @@ export class QueryRunner<RowType> extends BaseObserver<QueryRunnerListener> {
245
320
  }
246
321
 
247
322
  const pending = this.uncommitedConfigChange;
248
- this.config = next;
323
+ const previous = this.config;
324
+ const current = this.getSnapshot();
325
+ // These depend on the previous config, so they have to be computed before applying the new one.
326
+ const resuming = initial == null && this.canResume(next, current);
249
327
  this.idleResult = initial
250
328
  ? initial
251
329
  : pending != null && pending.isOptimisticStateChange && configEquals(pending.config, next)
252
330
  ? // We already returned this as an optimistic state in a previous resultFor call. Use the same result to not
253
331
  // cause another render.
254
332
  pending.result
255
- : idleResultFor(next);
333
+ : this.nextIdleResult(next, current);
334
+ this.keptFrom = next.kind == 'inactive' && previous?.kind == 'query' ? previous : null;
335
+ this.resuming = resuming;
336
+ this.config = next;
256
337
  this.uncommitedConfigChange = null;
257
338
 
258
339
  if (this.work == null || !this.work.tryUpdate(next)) {
@@ -274,7 +355,7 @@ export class QueryRunner<RowType> extends BaseObserver<QueryRunnerListener> {
274
355
  }
275
356
 
276
357
  const emit = () => this.notifyListeners();
277
- this.work = new (config.runOnce ? SingleQueryWork : WatchedQueryWork)(config, this.idleResult, emit);
358
+ this.work = new (config.runOnce ? SingleQueryWork : WatchedQueryWork)(config, this.idleResult, emit, this.resuming);
278
359
  }
279
360
 
280
361
  private notifyListeners() {
@@ -306,15 +387,17 @@ class SingleQueryWork<RowType> implements QueryWork<RowType> {
306
387
  constructor(
307
388
  private readonly config: QueryConfig<RowType>,
308
389
  initial: Result<RowType>,
309
- private readonly emit: () => void
390
+ private readonly emit: () => void,
391
+ // When resuming from data kept while inactive, the query runs again but keeps reporting that data until it's done.
392
+ resume = false
310
393
  ) {
311
- if (!initial.isLoading && initial.error == null) {
394
+ if (!resume && !initial.isLoading && initial.error == null) {
312
395
  // Seeded with an existing result, no need to run it again.
313
396
  this.result = { ...(initial as QueryResult<RowType>), refresh: this.refresh };
314
397
  return;
315
398
  }
316
399
 
317
- const fetchReason = 'initial';
400
+ const fetchReason: FetchReason = resume ? 'reactivated' : 'initial';
318
401
  this.result = {
319
402
  ...(initial as QueryResult<RowType>),
320
403
  isFetching: true,
@@ -342,7 +425,8 @@ class SingleQueryWork<RowType> implements QueryWork<RowType> {
342
425
 
343
426
  if (!this.result.isLoading || this.result.error) {
344
427
  // After an error, data is empty, so we're loading again rather than refreshing existing rows.
345
- const isLoading = fetchReason === 'initial' || this.result.error != null;
428
+ // Initial runs only get here after an error, or when resuming from data kept while inactive.
429
+ const isLoading = this.result.error != null;
346
430
  this.setResult({ isLoading, isFetching: true, error: undefined, fetchReason });
347
431
  }
348
432
 
@@ -388,24 +472,37 @@ class WatchedQueryWork<RowType> implements QueryWork<RowType> {
388
472
  * previous query's rows, which is reported as `fetchReason: 'settings-changed'`.
389
473
  */
390
474
  private awaitingUpdatedResult = false;
475
+ /**
476
+ * Set when resuming from data kept while inactive, until the watched query has produced its first result. The
477
+ * watched query reports `isLoading` until then, but we already have data to show.
478
+ */
479
+ private resuming: boolean;
391
480
  private reportFetching: boolean;
392
481
 
393
482
  constructor(
394
483
  private config: QueryConfig<RowType>,
395
484
  initial: Result<RowType>,
396
- private readonly emit: () => void
485
+ private readonly emit: () => void,
486
+ resume = false
397
487
  ) {
398
488
  this.result = initial;
489
+ this.resuming = resume;
399
490
  this.reportFetching = config.reportFetching;
400
491
 
401
492
  const { db, query, rowComparator, throttleMs, reportFetching } = config;
402
493
  const customQuery = db.customQuery(query);
494
+ // Watched queries only read placeholder data. For differential queries, this also keeps references for unchanged
495
+ // rows stable across the resume.
496
+ const placeholderData = resume ? (initial.data as RowType[]) : undefined;
403
497
  this.watch = rowComparator
404
- ? customQuery.differentialWatch({ rowComparator, reportFetching, throttleMs })
405
- : customQuery.watch({ reportFetching, throttleMs });
498
+ ? customQuery.differentialWatch({ rowComparator, reportFetching, throttleMs, placeholderData })
499
+ : customQuery.watch({ reportFetching, throttleMs, placeholderData });
406
500
 
407
501
  this.disposeListener = this.watch.registerListener({
408
502
  onStateChange: (state) => {
503
+ if (!state.isLoading) {
504
+ this.resuming = false;
505
+ }
409
506
  if (this.awaitingUpdatedResult && !this.pendingUpdate && !state.isFetching) {
410
507
  // The first completed fetch after the new settings were applied is the updated query's result.
411
508
  this.awaitingUpdatedResult = false;
@@ -426,7 +523,7 @@ class WatchedQueryWork<RowType> implements QueryWork<RowType> {
426
523
  const isFetching = state.isFetching || (this.pendingUpdate && this.reportFetching);
427
524
  return {
428
525
  data: state.data as RowType[],
429
- isLoading: state.isLoading,
526
+ isLoading: state.isLoading && !this.resuming,
430
527
  isFetching,
431
528
  error: state.error ?? undefined,
432
529
  fetchReason: this.fetchReasonFor(state.isLoading, isFetching)
@@ -435,7 +532,7 @@ class WatchedQueryWork<RowType> implements QueryWork<RowType> {
435
532
 
436
533
  private fetchReasonFor(isLoading: boolean, isFetching: boolean): FetchReason | undefined {
437
534
  if (!isFetching) return undefined;
438
- if (isLoading) return 'initial';
535
+ if (isLoading) return this.resuming ? 'reactivated' : 'initial';
439
536
  return this.awaitingUpdatedResult ? 'settings-changed' : 'tables-changed';
440
537
  }
441
538
 
@@ -59,11 +59,12 @@ export function useQuery<RowType = any>(
59
59
  ) {
60
60
  const powerSync = useContext(PowerSyncContext);
61
61
  const parsedQuery = constructCompatibleQuery(query, parameters);
62
- const streamsHaveSynced = useAllSyncStreamsHaveSynced(null, options.streams);
62
+ const active = options.active !== false;
63
+ const streamsHaveSynced = useAllSyncStreamsHaveSynced(null, active ? options.streams : undefined);
63
64
 
64
65
  const runnerRef = useRef<QueryRunner<RowType> | null>(null);
65
66
  const runner = (runnerRef.current ??= new QueryRunner<RowType>());
66
- const config = resolveConfig(powerSync, parsedQuery, options, streamsHaveSynced);
67
+ const config = resolveConfig(powerSync, parsedQuery, options, { active, streamsHaveSynced });
67
68
 
68
69
  const snapshot = useSyncExternalStore(runner.subscribe, runner.getSnapshot, runner.getSnapshot);
69
70
 
@@ -15,6 +15,19 @@ export interface HookWatchOptions extends Omit<SQLOnChangeOptions, 'signal'> {
15
15
  */
16
16
  streams?: QuerySyncStreamOptions[];
17
17
  reportFetching?: boolean;
18
+ /**
19
+ * When set to `false`, the query is not compiled or executed and {@link streams} are not subscribed to. This is
20
+ * useful to avoid the cost of watching queries for UI that isn't visible, e.g. screens in the background.
21
+ *
22
+ * While inactive, the hook reports `isLoading: false` and `isFetching: false`, and keeps reporting the last
23
+ * successfully loaded `data` (or `[]` if the query hadn't loaded). When reactivated with the same SQL and parameters,
24
+ * the query reloads in the background with `fetchReason: 'reactivated'` while still reporting the kept data.
25
+ *
26
+ * Not supported by `useSuspenseQuery`.
27
+ *
28
+ * @default true
29
+ */
30
+ active?: boolean;
18
31
  }
19
32
 
20
33
  /**
@@ -56,7 +69,10 @@ export interface DifferentialHookOptions<RowType> extends HookWatchOptions {
56
69
  rowComparator?: DifferentialWatchedQueryComparator<RowType>;
57
70
  }
58
71
 
59
- type WithoutSyncStreams<T> = Omit<T, 'streams'> & {
72
+ /**
73
+ * Adapts `useQuery` options for `useSuspenseQuery`, which doesn't support `streams` or `active`.
74
+ */
75
+ type ForSuspense<T> = Omit<T, 'streams' | 'active'> & {
60
76
  /**
61
77
  * @deprecated Sync streams are not supported by `useSuspenseQuery` and are ignored. Use `useQuery` or
62
78
  * `useSyncStream` to subscribe to streams instead.
@@ -67,12 +83,12 @@ type WithoutSyncStreams<T> = Omit<T, 'streams'> & {
67
83
  /**
68
84
  * Options for `useSuspenseQuery`.
69
85
  */
70
- export type SuspenseQueryOptions = WithoutSyncStreams<AdditionalOptions>;
86
+ export type SuspenseQueryOptions = ForSuspense<AdditionalOptions>;
71
87
 
72
88
  /**
73
89
  * Options for `useSuspenseQuery` with a `rowComparator`.
74
90
  */
75
- export type DifferentialSuspenseQueryOptions<RowType> = WithoutSyncStreams<DifferentialHookOptions<RowType>>;
91
+ export type DifferentialSuspenseQueryOptions<RowType> = ForSuspense<DifferentialHookOptions<RowType>>;
76
92
 
77
93
  /**
78
94
  * Why a `useQuery` hook is currently fetching.
@@ -82,8 +98,10 @@ export type DifferentialSuspenseQueryOptions<RowType> = WithoutSyncStreams<Diffe
82
98
  * - `'tables-changed'`: a table the query depends on changed and the same query is re-running. `data` is still current.
83
99
  * - `'settings-changed'`: the SQL, parameters or options changed. `data` still holds the previous query's rows until the
84
100
  * updated query has produced its first result.
101
+ * - `'reactivated'`: the query was set back to `active` after being inactive and is running again. `data` still holds
102
+ * the rows loaded before it was deactivated, which may be outdated, until the query has produced its first result.
85
103
  */
86
- export type FetchReason = 'initial' | 'refresh' | 'tables-changed' | 'settings-changed';
104
+ export type FetchReason = 'initial' | 'refresh' | 'tables-changed' | 'settings-changed' | 'reactivated';
87
105
 
88
106
  export type ReadonlyQueryResult<RowType> = {
89
107
  readonly data: ReadonlyArray<Readonly<RowType>>;