@powersync/react 0.0.0-dev-20250828085411 → 0.0.0-dev-20250915110424
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.
|
@@ -30,17 +30,36 @@ export const useWatchedQuery = (options) => {
|
|
|
30
30
|
React.useEffect(() => {
|
|
31
31
|
watchedQuery?.close();
|
|
32
32
|
setWatchedQuery(createWatchedQuery);
|
|
33
|
+
return () => {
|
|
34
|
+
watchedQuery?.close();
|
|
35
|
+
};
|
|
33
36
|
}, [powerSync, active]);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Indicates that the query will be re-fetched due to a change in the query.
|
|
39
|
+
* We execute this in-line (not using an effect) since effects are delayed till after the hook returns.
|
|
40
|
+
* The `queryChanged` value should only be true for a single render.
|
|
41
|
+
* The `updateSettings` method is asynchronous, thus it will update the state asynchronously.
|
|
42
|
+
* In the React hooks we'd like to report that we are fetching the data for an updated query
|
|
43
|
+
* as soon as the query has been updated. This prevents a result flow where e.g. the hook:
|
|
44
|
+
* - already returned a result: isLoading, isFetching are both false
|
|
45
|
+
* - the query is updated, but the state is still isFetching=false from the previous state
|
|
46
|
+
* We only need to override the isFetching status on the initial render where the query changed
|
|
47
|
+
* (if we report the fetching status). The fetching status will be updated internally in the `updateSettings`
|
|
48
|
+
* method eventually.
|
|
49
|
+
* Only overriding when the `queryChanged` value is true also prevents races if the query changes
|
|
50
|
+
* rapidly.
|
|
51
|
+
*/
|
|
52
|
+
if (queryChanged) {
|
|
53
|
+
watchedQuery?.updateSettings({
|
|
54
|
+
query,
|
|
55
|
+
throttleMs: hookOptions.throttleMs,
|
|
56
|
+
reportFetching: hookOptions.reportFetching
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
const shouldReportCurrentlyFetching = (hookOptions.reportFetching ?? true) && queryChanged;
|
|
60
|
+
const result = useNullableWatchedQuerySubscription(watchedQuery);
|
|
61
|
+
return {
|
|
62
|
+
...result,
|
|
63
|
+
isFetching: result?.isFetching || shouldReportCurrentlyFetching
|
|
64
|
+
};
|
|
46
65
|
};
|
|
@@ -47,7 +47,7 @@ export const constructCompatibleQuery = (query, parameters = [], options) => {
|
|
|
47
47
|
execute: () => query.execute()
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
|
-
}, [query, powerSync]);
|
|
50
|
+
}, [query, powerSync, ...parameters]);
|
|
51
51
|
const queryChanged = checkQueryChanged(parsedQuery, options);
|
|
52
52
|
return {
|
|
53
53
|
parsedQuery,
|
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-20250915110424",
|
|
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-20250915110424",
|
|
28
28
|
"react": "*"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
@@ -35,8 +35,9 @@
|
|
|
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-20250915110424",
|
|
39
|
+
"@powersync/web": "0.0.0-dev-20250915110424",
|
|
40
|
+
"@powersync/drizzle-driver": "0.6.0"
|
|
40
41
|
},
|
|
41
42
|
"scripts": {
|
|
42
43
|
"build": "tsc -b",
|