Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/heavy-coats-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@powersync/react': patch
---

Fixed issue where `useQuery()` would not correctly trigger a new execution when the query or parameters changed while using StrictMode.
10 changes: 8 additions & 2 deletions packages/react/src/hooks/watched/useWatchedQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ export const useWatchedQuery = <RowType = unknown>(
): QueryResult<RowType> | ReadonlyQueryResult<RowType> => {
const { query, powerSync, queryChanged, options: hookOptions, active } = options;

const queryChangeRef = React.useRef(false);
if (queryChanged && !queryChangeRef.current) {
queryChangeRef.current = true;
}

function createWatchedQuery() {
if (!active) {
return null;
Expand Down Expand Up @@ -44,14 +49,15 @@ export const useWatchedQuery = <RowType = unknown>(
// Indicates that the query will be re-fetched due to a change in the query.
// Used when `isFetching` hasn't been set to true yet due to React execution.
React.useEffect(() => {
if (queryChanged) {
if (queryChangeRef.current) {
watchedQuery?.updateSettings({
query,
throttleMs: hookOptions.throttleMs,
reportFetching: hookOptions.reportFetching
});
queryChangeRef.current = false;
}
}, [queryChanged]);
}, [queryChangeRef.current]);

return useNullableWatchedQuerySubscription(watchedQuery);
};
Loading
Loading