Skip to content

fix(tanstack-react-query): use skipToken instead of overriding enabled option#1007

Open
Chriztiaan wants to merge 4 commits into
powersync-ja:mainfrom
Chriztiaan:fix/preserve-user-enabled-option
Open

fix(tanstack-react-query): use skipToken instead of overriding enabled option#1007
Chriztiaan wants to merge 4 commits into
powersync-ja:mainfrom
Chriztiaan:fix/preserve-user-enabled-option

Conversation

@Chriztiaan

@Chriztiaan Chriztiaan commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Credits

Note, I am taking over the work done by @msvargas in #994 to get it over the line.

Problem

PowerSync's useQuery and useQueries hooks override the user's enabled option by forcing enabled: streamsHaveSynced at the end of the spread. Users who need conditional query control (e.g., enabled: !!userId) lose that ability — the query always runs once streams are synced, regardless of their condition.

Additionally, two secondary issues were discovered:

  1. Stale streamsHaveSynced — The usePowerSyncQueries final useMemo was missing streamsHaveSynced in its dependency array, causing the returned value to stay stale when only streamsHaveSynced changed.

  2. Race condition on first table resolutionresolveTables is async. The change listener attaches watching [] (empty) tables, so any write landing before resolveTables resolves is silently dropped. The listener that later attaches with real tables was created after the write, so it never sees it.

msvargas and others added 3 commits June 15, 2026 16:53
…d option

Replace the enabled: streamsHaveSynced pattern with TanStack's skipToken to preserve the user's own enabled option.

Problems fixed:
- User's enabled option was silently overridden by PowerSync's streamsHaveSynced
- usePowerSyncQueries final useMemo was missing streamsHaveSynced in deps, returning stale values
- Race condition: change listeners attached watching [] tables while resolveTables was pending, losing first-sync writes

Changes:
- useQuery: Conditionally pass skipToken when streams haven't synced; suspense queries always get the real queryFn
- useQueries: Same skipToken approach per query entry; add streamsHaveSynced to deps
- usePowerSyncQueries: Add tablesInitialized ref to rescue data lost during the []->[tables] transition; add streamsHaveSynced to return memo deps
@changeset-bot

changeset-bot Bot commented Jun 24, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 173038d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@powersync/tanstack-react-query Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Chriztiaan Chriztiaan marked this pull request as ready for review June 24, 2026 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants