@powersync/react 0.0.0-dev-20250915110424 → 0.0.0-dev-20250916075127
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.
|
@@ -27,11 +27,14 @@ export const useWatchedQuery = (options) => {
|
|
|
27
27
|
return watch;
|
|
28
28
|
}
|
|
29
29
|
const [watchedQuery, setWatchedQuery] = React.useState(createWatchedQuery);
|
|
30
|
+
const disposePendingUpdateListener = React.useRef(null);
|
|
30
31
|
React.useEffect(() => {
|
|
31
32
|
watchedQuery?.close();
|
|
32
|
-
|
|
33
|
+
const newQuery = createWatchedQuery();
|
|
34
|
+
setWatchedQuery(newQuery);
|
|
33
35
|
return () => {
|
|
34
|
-
|
|
36
|
+
disposePendingUpdateListener.current?.();
|
|
37
|
+
newQuery?.close();
|
|
35
38
|
};
|
|
36
39
|
}, [powerSync, active]);
|
|
37
40
|
/**
|
|
@@ -43,20 +46,29 @@ export const useWatchedQuery = (options) => {
|
|
|
43
46
|
* as soon as the query has been updated. This prevents a result flow where e.g. the hook:
|
|
44
47
|
* - already returned a result: isLoading, isFetching are both false
|
|
45
48
|
* - the query is updated, but the state is still isFetching=false from the previous state
|
|
46
|
-
* We
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* rapidly.
|
|
49
|
+
* We override the isFetching status while the `updateSettings` method is running (if we report `isFetching`),
|
|
50
|
+
* we override this value just until the `updateSettings` method itself will update the `isFetching` status.
|
|
51
|
+
* We achieve this by registering a `settingsWillUpdate` listener on the `WatchedQuery`. This will fire
|
|
52
|
+
* just before the `isFetching` status is updated.
|
|
51
53
|
*/
|
|
52
54
|
if (queryChanged) {
|
|
55
|
+
// Keep track of this pending operation
|
|
53
56
|
watchedQuery?.updateSettings({
|
|
54
57
|
query,
|
|
55
58
|
throttleMs: hookOptions.throttleMs,
|
|
56
59
|
reportFetching: hookOptions.reportFetching
|
|
57
60
|
});
|
|
61
|
+
// This could have been called multiple times, clear any old listeners.
|
|
62
|
+
disposePendingUpdateListener.current?.();
|
|
63
|
+
disposePendingUpdateListener.current = watchedQuery?.registerListener({
|
|
64
|
+
settingsWillUpdate: () => {
|
|
65
|
+
// We'll use the fact that we have a listener at all as an indication
|
|
66
|
+
disposePendingUpdateListener.current?.();
|
|
67
|
+
disposePendingUpdateListener.current = null;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
58
70
|
}
|
|
59
|
-
const shouldReportCurrentlyFetching = (hookOptions.reportFetching ?? true) &&
|
|
71
|
+
const shouldReportCurrentlyFetching = (hookOptions.reportFetching ?? true) && !!disposePendingUpdateListener.current;
|
|
60
72
|
const result = useNullableWatchedQuerySubscription(watchedQuery);
|
|
61
73
|
return {
|
|
62
74
|
...result,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powersync/react",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-20250916075127",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"registry": "https://registry.npmjs.org/",
|
|
6
6
|
"access": "public"
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"homepage": "https://docs.powersync.com",
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"@powersync/common": "0.0.0-dev-
|
|
27
|
+
"@powersync/common": "0.0.0-dev-20250916075127",
|
|
28
28
|
"react": "*"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"react": "18.3.1",
|
|
36
36
|
"react-dom": "18.3.1",
|
|
37
37
|
"react-error-boundary": "^4.1.0",
|
|
38
|
-
"@powersync/common": "0.0.0-dev-
|
|
39
|
-
"@powersync/web": "0.0.0-dev-
|
|
38
|
+
"@powersync/common": "0.0.0-dev-20250916075127",
|
|
39
|
+
"@powersync/web": "0.0.0-dev-20250916075127",
|
|
40
40
|
"@powersync/drizzle-driver": "0.6.0"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|