Skip to content

fix(svelte-query): reuse QueriesObserver to fix createQueries empty-init bug#10696

Open
mixelburg wants to merge 1 commit into
TanStack:mainfrom
mixelburg:fix/svelte-create-queries-empty-init
Open

fix(svelte-query): reuse QueriesObserver to fix createQueries empty-init bug#10696
mixelburg wants to merge 1 commit into
TanStack:mainfrom
mixelburg:fix/svelte-create-queries-empty-init

Conversation

@mixelburg
Copy link
Copy Markdown
Contributor

What

Fixes createQueries becoming permanently inactive when initialized with an empty queries array.

Closes #10681.

Why

The current implementation recreates QueriesObserver on every query change via $derived. This breaks the observer/subscription lifecycle: when createQueries starts with [], the observer is created with no queries, and when the array later becomes non-empty, a new observer is created but the subscription doesn't properly pick up the new queries.

How

Adopts the same pattern as createBaseQuery:

  1. Create observer once with $state instead of $derived
  2. Recreate only on client change via watchChanges
  3. Call setQueries when resolved options change via watchChanges

This matches the React implementation where the observer is created once in useState and updated via setQueries in a useEffect.

Testing

The existing svelte-query tests still pass. The fix can be verified by using createQueries with an initially empty array that is later populated — previously this stayed pending forever; now it resolves correctly.

…nit bug

Previously, createQueries recreated the QueriesObserver on every query
change via $derived. This broke the subscription lifecycle when
initializing with an empty queries array - the instance stayed permanently
inactive even after queries were added.

Now follows the same pattern as createBaseQuery:
- Create observer once with $state
- Recreate only when client changes (via watchChanges)
- Call setQueries when resolved options change (via watchChanges)

Fixes TanStack#10681
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[svelte-query] createQueries becomes permanently inactive when initialized with an empty queries array

1 participant