@powersync/react 0.0.0-dev-20250916075127 → 0.0.0-dev-20250925183014
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.
|
@@ -6,8 +6,12 @@ export type InternalHookOptions<DataType> = {
|
|
|
6
6
|
queryChanged: boolean;
|
|
7
7
|
active: boolean;
|
|
8
8
|
};
|
|
9
|
-
|
|
9
|
+
interface WatchCompatibleQueryWithParams<T> extends WatchCompatibleQuery<T> {
|
|
10
|
+
stringifiedParameters?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare const checkQueryChanged: <T>(query: WatchCompatibleQueryWithParams<T>, options: AdditionalOptions) => boolean;
|
|
10
13
|
export declare const constructCompatibleQuery: <RowType>(query: string | CompilableQuery<RowType>, parameters: any[], options: AdditionalOptions) => {
|
|
11
|
-
parsedQuery:
|
|
14
|
+
parsedQuery: WatchCompatibleQueryWithParams<RowType[]>;
|
|
12
15
|
queryChanged: boolean;
|
|
13
16
|
};
|
|
17
|
+
export {};
|
|
@@ -9,7 +9,7 @@ export const checkQueryChanged = (query, options) => {
|
|
|
9
9
|
return false; // If compilation fails, we assume the query has changed
|
|
10
10
|
}
|
|
11
11
|
const compiled = _compiled;
|
|
12
|
-
const stringifiedParams = JSON.stringify(compiled.parameters);
|
|
12
|
+
const stringifiedParams = query.stringifiedParameters ?? JSON.stringify(compiled.parameters);
|
|
13
13
|
const stringifiedOptions = JSON.stringify(options);
|
|
14
14
|
const previousQueryRef = React.useRef({ sqlStatement: compiled.sql, stringifiedParams, stringifiedOptions });
|
|
15
15
|
if (previousQueryRef.current.sqlStatement !== compiled.sql ||
|
|
@@ -24,6 +24,7 @@ export const checkQueryChanged = (query, options) => {
|
|
|
24
24
|
};
|
|
25
25
|
export const constructCompatibleQuery = (query, parameters = [], options) => {
|
|
26
26
|
const powerSync = usePowerSync();
|
|
27
|
+
const stringifiedParameters = React.useMemo(() => JSON.stringify(parameters), [parameters]);
|
|
27
28
|
const parsedQuery = React.useMemo(() => {
|
|
28
29
|
if (typeof query == 'string') {
|
|
29
30
|
return {
|
|
@@ -31,7 +32,9 @@ export const constructCompatibleQuery = (query, parameters = [], options) => {
|
|
|
31
32
|
sql: query,
|
|
32
33
|
parameters
|
|
33
34
|
}),
|
|
34
|
-
execute: () => powerSync.getAll(query, parameters)
|
|
35
|
+
execute: () => powerSync.getAll(query, parameters),
|
|
36
|
+
// Setting this is a small optimization that avoids checkQueryChanged recomputing the JSON representation.
|
|
37
|
+
stringifiedParameters
|
|
35
38
|
};
|
|
36
39
|
}
|
|
37
40
|
else {
|
|
@@ -45,9 +48,11 @@ export const constructCompatibleQuery = (query, parameters = [], options) => {
|
|
|
45
48
|
};
|
|
46
49
|
},
|
|
47
50
|
execute: () => query.execute()
|
|
51
|
+
// Note that we can't set stringifiedParameters here because we only know parameters after the query has been
|
|
52
|
+
// compiled.
|
|
48
53
|
};
|
|
49
54
|
}
|
|
50
|
-
}, [query, powerSync,
|
|
55
|
+
}, [query, powerSync, stringifiedParameters]);
|
|
51
56
|
const queryChanged = checkQueryChanged(parsedQuery, options);
|
|
52
57
|
return {
|
|
53
58
|
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-20250925183014",
|
|
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-20250925183014",
|
|
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-20250925183014",
|
|
39
|
+
"@powersync/web": "0.0.0-dev-20250925183014",
|
|
40
40
|
"@powersync/drizzle-driver": "0.6.0"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|