@powersync/react 2.2.0 → 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 +1 -1
- package/lib/hooks/suspense/useSuspenseQuery.js +7 -4
- package/lib/hooks/suspense/useSuspenseQuery.js.map +1 -1
- package/lib/hooks/watched/QueryRunner.d.ts +26 -1
- package/lib/hooks/watched/QueryRunner.js +105 -16
- package/lib/hooks/watched/QueryRunner.js.map +1 -1
- package/lib/hooks/watched/useQuery.js +3 -2
- package/lib/hooks/watched/useQuery.js.map +1 -1
- package/lib/hooks/watched/watch-types.d.ts +22 -4
- package/package.json +5 -5
- package/src/hooks/suspense/useSuspenseQuery.ts +5 -6
- package/src/hooks/watched/QueryRunner.ts +115 -15
- package/src/hooks/watched/useQuery.ts +3 -2
- package/src/hooks/watched/watch-types.ts +22 -4
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,
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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,
|
|
1
|
+
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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>,
|
|
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
|
*
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { BaseObserver } from '@powersync/common';
|
|
1
|
+
import { BaseObserver, LogLevels } from '@powersync/common';
|
|
2
2
|
function configEquals(a, b) {
|
|
3
3
|
if (a === b)
|
|
4
4
|
return true;
|
|
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,
|
|
95
|
+
export function resolveConfig(db, query, options, state) {
|
|
66
96
|
if (db == null) {
|
|
67
97
|
return { kind: 'missing-db' };
|
|
68
98
|
}
|
|
69
|
-
if (!
|
|
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 ??
|
|
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
|
|
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
|
-
:
|
|
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
|
-
|
|
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;
|
|
@@ -248,6 +323,8 @@ class SingleQueryWork {
|
|
|
248
323
|
catch (error) {
|
|
249
324
|
if (isAborted())
|
|
250
325
|
return;
|
|
326
|
+
// Matches the logging done by watched queries, so that `runQueryOnce` failures are just as discoverable.
|
|
327
|
+
db.logger.log({ level: LogLevels.error, message: `Error in watched query: ${sql}`, error });
|
|
251
328
|
this.setResult({ isLoading: false, isFetching: false, data: [], error: error, fetchReason: undefined });
|
|
252
329
|
}
|
|
253
330
|
}
|
|
@@ -279,19 +356,31 @@ class WatchedQueryWork {
|
|
|
279
356
|
* previous query's rows, which is reported as `fetchReason: 'settings-changed'`.
|
|
280
357
|
*/
|
|
281
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;
|
|
282
364
|
reportFetching;
|
|
283
|
-
constructor(config, initial, emit) {
|
|
365
|
+
constructor(config, initial, emit, resume = false) {
|
|
284
366
|
this.config = config;
|
|
285
367
|
this.emit = emit;
|
|
286
368
|
this.result = initial;
|
|
369
|
+
this.resuming = resume;
|
|
287
370
|
this.reportFetching = config.reportFetching;
|
|
288
371
|
const { db, query, rowComparator, throttleMs, reportFetching } = config;
|
|
289
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;
|
|
290
376
|
this.watch = rowComparator
|
|
291
|
-
? customQuery.differentialWatch({ rowComparator, reportFetching, throttleMs })
|
|
292
|
-
: customQuery.watch({ reportFetching, throttleMs });
|
|
377
|
+
? customQuery.differentialWatch({ rowComparator, reportFetching, throttleMs, placeholderData })
|
|
378
|
+
: customQuery.watch({ reportFetching, throttleMs, placeholderData });
|
|
293
379
|
this.disposeListener = this.watch.registerListener({
|
|
294
380
|
onStateChange: (state) => {
|
|
381
|
+
if (!state.isLoading) {
|
|
382
|
+
this.resuming = false;
|
|
383
|
+
}
|
|
295
384
|
if (this.awaitingUpdatedResult && !this.pendingUpdate && !state.isFetching) {
|
|
296
385
|
// The first completed fetch after the new settings were applied is the updated query's result.
|
|
297
386
|
this.awaitingUpdatedResult = false;
|
|
@@ -311,7 +400,7 @@ class WatchedQueryWork {
|
|
|
311
400
|
const isFetching = state.isFetching || (this.pendingUpdate && this.reportFetching);
|
|
312
401
|
return {
|
|
313
402
|
data: state.data,
|
|
314
|
-
isLoading: state.isLoading,
|
|
403
|
+
isLoading: state.isLoading && !this.resuming,
|
|
315
404
|
isFetching,
|
|
316
405
|
error: state.error ?? undefined,
|
|
317
406
|
fetchReason: this.fetchReasonFor(state.isLoading, isFetching)
|
|
@@ -321,7 +410,7 @@ class WatchedQueryWork {
|
|
|
321
410
|
if (!isFetching)
|
|
322
411
|
return undefined;
|
|
323
412
|
if (isLoading)
|
|
324
|
-
return 'initial';
|
|
413
|
+
return this.resuming ? 'reactivated' : 'initial';
|
|
325
414
|
return this.awaitingUpdatedResult ? 'settings-changed' : 'tables-changed';
|
|
326
415
|
}
|
|
327
416
|
canUpdate(config) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryRunner.js","sourceRoot":"","sources":["../../../src/hooks/watched/QueryRunner.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,YAAY,EAKb,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,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC;QACzE,KAAK,OAAO;YACV,OAAO,CACL,CAAC,CAAC,IAAI,IAAI,OAAO;gBACjB,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE;gBACb,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG;gBACd,CAAC,CAAC,iBAAiB,IAAI,CAAC,CAAC,iBAAiB;gBAC1C,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,OAAO;gBACtB,gHAAgH;gBAChH,+FAA+F;gBAC/F,CAAC,CAAC,CAAC,CAAC,aAAa,IAAI,CAAC,CAAC,CAAC,CAAC,aAAa;gBACtC,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC,UAAU;gBAC5B,CAAC,CAAC,cAAc,IAAI,CAAC,CAAC,cAAc,CACrC,CAAC;IACN,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAU,MAA4B;IAC7D,MAAM,E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AC;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
|
|
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;AA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SAAS,CAAC,CAAC;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
|
-
|
|
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 =
|
|
80
|
+
export type SuspenseQueryOptions = ForSuspense<AdditionalOptions>;
|
|
65
81
|
/**
|
|
66
82
|
* Options for `useSuspenseQuery` with a `rowComparator`.
|
|
67
83
|
*/
|
|
68
|
-
export type DifferentialSuspenseQueryOptions<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.
|
|
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.
|
|
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.
|
|
44
|
+
"@powersync/common": "2.5.1",
|
|
45
45
|
"@powersync/drizzle-driver": "0.8.0",
|
|
46
|
-
"@powersync/node": "1.3.
|
|
47
|
-
"@powersync/shared-internals": "1.
|
|
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
|
-
|
|
77
|
-
|
|
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);
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
CommonPowerSyncDatabase,
|
|
5
5
|
DifferentialWatchedQuery,
|
|
6
6
|
DifferentialWatchedQueryComparator,
|
|
7
|
+
LogLevels,
|
|
7
8
|
WatchedQueryState
|
|
8
9
|
} from '@powersync/common';
|
|
9
10
|
import {
|
|
@@ -30,6 +31,8 @@ export type RunnerConfig<RowType> =
|
|
|
30
31
|
| { kind: 'missing-db' }
|
|
31
32
|
// Query included sync streams that have not synced yet
|
|
32
33
|
| { kind: 'waiting-for-streams' }
|
|
34
|
+
// Manually disabled by user.
|
|
35
|
+
| { kind: 'inactive' }
|
|
33
36
|
| { kind: 'compile-error'; error: Error }
|
|
34
37
|
| QueryConfig<RowType>;
|
|
35
38
|
|
|
@@ -52,6 +55,7 @@ function configEquals<RowType>(a: RunnerConfig<RowType>, b: RunnerConfig<RowType
|
|
|
52
55
|
switch (a.kind) {
|
|
53
56
|
case 'missing-db':
|
|
54
57
|
case 'waiting-for-streams':
|
|
58
|
+
case 'inactive':
|
|
55
59
|
return a.kind == b.kind;
|
|
56
60
|
case 'compile-error':
|
|
57
61
|
// compile() runs on every render, so a failing query throws a new error each time.
|
|
@@ -89,6 +93,7 @@ export function configError<RowType>(config: Exclude<RunnerConfig<RowType>, Quer
|
|
|
89
93
|
}
|
|
90
94
|
|
|
91
95
|
const _loadingState: QueryResult<never> = { isLoading: true, isFetching: false, data: [], error: undefined };
|
|
96
|
+
const _inactiveState: QueryResult<never> = { isLoading: false, isFetching: false, data: [], error: undefined };
|
|
92
97
|
|
|
93
98
|
function idleResultFor<RowType>(config: RunnerConfig<RowType>): Result<RowType> {
|
|
94
99
|
switch (config.kind) {
|
|
@@ -96,6 +101,8 @@ function idleResultFor<RowType>(config: RunnerConfig<RowType>): Result<RowType>
|
|
|
96
101
|
return { isLoading: false, isFetching: false, data: [], error: new Error('PowerSync not configured.') };
|
|
97
102
|
case 'waiting-for-streams':
|
|
98
103
|
return _loadingState;
|
|
104
|
+
case 'inactive':
|
|
105
|
+
return _inactiveState;
|
|
99
106
|
case 'compile-error':
|
|
100
107
|
return { isLoading: false, isFetching: false, data: [], error: config.error };
|
|
101
108
|
case 'query':
|
|
@@ -111,21 +118,53 @@ function idleResultFor<RowType>(config: RunnerConfig<RowType>): Result<RowType>
|
|
|
111
118
|
}
|
|
112
119
|
}
|
|
113
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
|
+
|
|
114
147
|
/**
|
|
115
148
|
* Resolves the inputs of `useQuery` into a comparable {@link RunnerConfig}.
|
|
116
149
|
*
|
|
117
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.
|
|
118
154
|
*/
|
|
119
155
|
export function resolveConfig<RowType>(
|
|
120
156
|
db: CommonPowerSyncDatabase | null,
|
|
121
157
|
query: WatchCompatibleQueryWithParams<RowType[]>,
|
|
122
158
|
options: AdditionalOptions & DifferentialHookOptions<RowType>,
|
|
123
|
-
streamsHaveSynced: boolean
|
|
159
|
+
state: { active: boolean; streamsHaveSynced: boolean }
|
|
124
160
|
): RunnerConfig<RowType> {
|
|
125
161
|
if (db == null) {
|
|
126
162
|
return { kind: 'missing-db' };
|
|
127
163
|
}
|
|
128
|
-
if (!
|
|
164
|
+
if (!state.active) {
|
|
165
|
+
return { kind: 'inactive' };
|
|
166
|
+
}
|
|
167
|
+
if (!state.streamsHaveSynced) {
|
|
129
168
|
return { kind: 'waiting-for-streams' };
|
|
130
169
|
}
|
|
131
170
|
|
|
@@ -169,6 +208,15 @@ export interface QueryRunnerListener extends BaseListener {
|
|
|
169
208
|
export class QueryRunner<RowType> extends BaseObserver<QueryRunnerListener> {
|
|
170
209
|
private config: RunnerConfig<RowType> | null = null;
|
|
171
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;
|
|
172
220
|
/**
|
|
173
221
|
* The active work, only non-null while we have listeners.
|
|
174
222
|
*/
|
|
@@ -225,11 +273,39 @@ export class QueryRunner<RowType> extends BaseObserver<QueryRunnerListener> {
|
|
|
225
273
|
// A re-render has changed the query, and we'll start running that query in a useEffect hook calling configure.
|
|
226
274
|
// For now, optimistically return the loading state that query would start.
|
|
227
275
|
const fromWork = this.work?.pendingResultFor(config);
|
|
228
|
-
const result = fromWork ??
|
|
276
|
+
const result = fromWork ?? this.nextIdleResult(config, snapshot);
|
|
229
277
|
this.uncommitedConfigChange = { config, snapshot, result, isOptimisticStateChange: fromWork == null };
|
|
230
278
|
return result;
|
|
231
279
|
}
|
|
232
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
|
+
|
|
233
309
|
/**
|
|
234
310
|
* Applies the inputs of a committed render to this runner. This does nothing if they haven't changed.
|
|
235
311
|
*
|
|
@@ -244,14 +320,20 @@ export class QueryRunner<RowType> extends BaseObserver<QueryRunnerListener> {
|
|
|
244
320
|
}
|
|
245
321
|
|
|
246
322
|
const pending = this.uncommitedConfigChange;
|
|
247
|
-
this.config
|
|
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);
|
|
248
327
|
this.idleResult = initial
|
|
249
328
|
? initial
|
|
250
329
|
: pending != null && pending.isOptimisticStateChange && configEquals(pending.config, next)
|
|
251
330
|
? // We already returned this as an optimistic state in a previous resultFor call. Use the same result to not
|
|
252
331
|
// cause another render.
|
|
253
332
|
pending.result
|
|
254
|
-
:
|
|
333
|
+
: this.nextIdleResult(next, current);
|
|
334
|
+
this.keptFrom = next.kind == 'inactive' && previous?.kind == 'query' ? previous : null;
|
|
335
|
+
this.resuming = resuming;
|
|
336
|
+
this.config = next;
|
|
255
337
|
this.uncommitedConfigChange = null;
|
|
256
338
|
|
|
257
339
|
if (this.work == null || !this.work.tryUpdate(next)) {
|
|
@@ -273,7 +355,7 @@ export class QueryRunner<RowType> extends BaseObserver<QueryRunnerListener> {
|
|
|
273
355
|
}
|
|
274
356
|
|
|
275
357
|
const emit = () => this.notifyListeners();
|
|
276
|
-
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);
|
|
277
359
|
}
|
|
278
360
|
|
|
279
361
|
private notifyListeners() {
|
|
@@ -305,15 +387,17 @@ class SingleQueryWork<RowType> implements QueryWork<RowType> {
|
|
|
305
387
|
constructor(
|
|
306
388
|
private readonly config: QueryConfig<RowType>,
|
|
307
389
|
initial: Result<RowType>,
|
|
308
|
-
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
|
|
309
393
|
) {
|
|
310
|
-
if (!initial.isLoading && initial.error == null) {
|
|
394
|
+
if (!resume && !initial.isLoading && initial.error == null) {
|
|
311
395
|
// Seeded with an existing result, no need to run it again.
|
|
312
396
|
this.result = { ...(initial as QueryResult<RowType>), refresh: this.refresh };
|
|
313
397
|
return;
|
|
314
398
|
}
|
|
315
399
|
|
|
316
|
-
const fetchReason = 'initial';
|
|
400
|
+
const fetchReason: FetchReason = resume ? 'reactivated' : 'initial';
|
|
317
401
|
this.result = {
|
|
318
402
|
...(initial as QueryResult<RowType>),
|
|
319
403
|
isFetching: true,
|
|
@@ -341,7 +425,8 @@ class SingleQueryWork<RowType> implements QueryWork<RowType> {
|
|
|
341
425
|
|
|
342
426
|
if (!this.result.isLoading || this.result.error) {
|
|
343
427
|
// After an error, data is empty, so we're loading again rather than refreshing existing rows.
|
|
344
|
-
|
|
428
|
+
// Initial runs only get here after an error, or when resuming from data kept while inactive.
|
|
429
|
+
const isLoading = this.result.error != null;
|
|
345
430
|
this.setResult({ isLoading, isFetching: true, error: undefined, fetchReason });
|
|
346
431
|
}
|
|
347
432
|
|
|
@@ -352,6 +437,8 @@ class SingleQueryWork<RowType> implements QueryWork<RowType> {
|
|
|
352
437
|
this.setResult({ isLoading: false, isFetching: false, data, error: undefined, fetchReason: undefined });
|
|
353
438
|
} catch (error) {
|
|
354
439
|
if (isAborted()) return;
|
|
440
|
+
// Matches the logging done by watched queries, so that `runQueryOnce` failures are just as discoverable.
|
|
441
|
+
db.logger.log({ level: LogLevels.error, message: `Error in watched query: ${sql}`, error });
|
|
355
442
|
this.setResult({ isLoading: false, isFetching: false, data: [], error: error as Error, fetchReason: undefined });
|
|
356
443
|
}
|
|
357
444
|
}
|
|
@@ -385,24 +472,37 @@ class WatchedQueryWork<RowType> implements QueryWork<RowType> {
|
|
|
385
472
|
* previous query's rows, which is reported as `fetchReason: 'settings-changed'`.
|
|
386
473
|
*/
|
|
387
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;
|
|
388
480
|
private reportFetching: boolean;
|
|
389
481
|
|
|
390
482
|
constructor(
|
|
391
483
|
private config: QueryConfig<RowType>,
|
|
392
484
|
initial: Result<RowType>,
|
|
393
|
-
private readonly emit: () => void
|
|
485
|
+
private readonly emit: () => void,
|
|
486
|
+
resume = false
|
|
394
487
|
) {
|
|
395
488
|
this.result = initial;
|
|
489
|
+
this.resuming = resume;
|
|
396
490
|
this.reportFetching = config.reportFetching;
|
|
397
491
|
|
|
398
492
|
const { db, query, rowComparator, throttleMs, reportFetching } = config;
|
|
399
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;
|
|
400
497
|
this.watch = rowComparator
|
|
401
|
-
? customQuery.differentialWatch({ rowComparator, reportFetching, throttleMs })
|
|
402
|
-
: customQuery.watch({ reportFetching, throttleMs });
|
|
498
|
+
? customQuery.differentialWatch({ rowComparator, reportFetching, throttleMs, placeholderData })
|
|
499
|
+
: customQuery.watch({ reportFetching, throttleMs, placeholderData });
|
|
403
500
|
|
|
404
501
|
this.disposeListener = this.watch.registerListener({
|
|
405
502
|
onStateChange: (state) => {
|
|
503
|
+
if (!state.isLoading) {
|
|
504
|
+
this.resuming = false;
|
|
505
|
+
}
|
|
406
506
|
if (this.awaitingUpdatedResult && !this.pendingUpdate && !state.isFetching) {
|
|
407
507
|
// The first completed fetch after the new settings were applied is the updated query's result.
|
|
408
508
|
this.awaitingUpdatedResult = false;
|
|
@@ -423,7 +523,7 @@ class WatchedQueryWork<RowType> implements QueryWork<RowType> {
|
|
|
423
523
|
const isFetching = state.isFetching || (this.pendingUpdate && this.reportFetching);
|
|
424
524
|
return {
|
|
425
525
|
data: state.data as RowType[],
|
|
426
|
-
isLoading: state.isLoading,
|
|
526
|
+
isLoading: state.isLoading && !this.resuming,
|
|
427
527
|
isFetching,
|
|
428
528
|
error: state.error ?? undefined,
|
|
429
529
|
fetchReason: this.fetchReasonFor(state.isLoading, isFetching)
|
|
@@ -432,7 +532,7 @@ class WatchedQueryWork<RowType> implements QueryWork<RowType> {
|
|
|
432
532
|
|
|
433
533
|
private fetchReasonFor(isLoading: boolean, isFetching: boolean): FetchReason | undefined {
|
|
434
534
|
if (!isFetching) return undefined;
|
|
435
|
-
if (isLoading) return 'initial';
|
|
535
|
+
if (isLoading) return this.resuming ? 'reactivated' : 'initial';
|
|
436
536
|
return this.awaitingUpdatedResult ? 'settings-changed' : 'tables-changed';
|
|
437
537
|
}
|
|
438
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
|
|
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
|
-
|
|
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 =
|
|
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> =
|
|
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>>;
|