fix(svelte-query): reuse QueriesObserver to fix createQueries empty-init bug#10696
Open
mixelburg wants to merge 1 commit into
Open
fix(svelte-query): reuse QueriesObserver to fix createQueries empty-init bug#10696mixelburg wants to merge 1 commit into
mixelburg wants to merge 1 commit into
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixes
createQueriesbecoming permanently inactive when initialized with an emptyqueriesarray.Closes #10681.
Why
The current implementation recreates
QueriesObserveron every query change via$derived. This breaks the observer/subscription lifecycle: whencreateQueriesstarts 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:$stateinstead of$derivedwatchChangessetQuerieswhen resolved options change viawatchChangesThis matches the React implementation where the observer is created once in
useStateand updated viasetQueriesin auseEffect.Testing
The existing svelte-query tests still pass. The fix can be verified by using
createQuerieswith an initially empty array that is later populated — previously this stayed pending forever; now it resolves correctly.