Skip to content

fix(svelte-query): keep the QueriesObserver in createQueries when options change - #12746

Open
turalbabayev wants to merge 1 commit into
TanStack:mainfrom
turalbabayev:fix/svelte-create-queries-observer
Open

turalbabayev wants to merge 1 commit into
TanStack:mainfrom
turalbabayev:fix/svelte-create-queries-observer

Conversation

@turalbabayev

@turalbabayev turalbabayev commented Dec 4, 2026 •

Copy link
Copy Markdown

🎯 Changes

In svelte-query, createQueries created a new QueriesObserver through $derived whenever the options changed. The new observers subscribe again, so every query that already has data refetches on mount.

With the dynamic example from the Svelte parallel queries guide, going from users = [1] to users = [1, 2] fetches user 1 again together with user 2. React's useQueries only fetches user 2.

The observer is now created once and only replaced when the client changes, the same as createBaseQuery. Option changes already go through setQueries. It also passes { combine } to the constructor instead of the bare function.

Added a test that adds a query and checks the existing one isn't fetched again. It fails on main (3 calls instead of 2).

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with pnpm run test:pr, or these tests do not apply to this pull request. (ran the svelte-query tests and svelte-check)
  • I have followed the AI contribution policy and fully understand the code in this pull request, including any code generated with AI assistance.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Bug Fixes
    • Existing queries are no longer refetched when a query is added or its options change. New queries continue to fetch and resolve normally.

@changeset-bot

changeset-bot Bot commented Dec 4, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 039d4c6

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

This PR includes changesets to release 4 packages
Name Type
@tanstack/svelte-query Patch
@tanstack/svelte-query-devtools Patch
@tanstack/svelte-query-persist-client Patch
@tanstack/vue-query-devtools 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

@coderabbitai

coderabbitai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

createQueries now holds its QueriesObserver in reactive state, recreates it when the client changes, and continues to update query options with setQueries. A test checks that adding a query does not refetch the existing query.

Changes: Svelte createQueries observer

Layer / File(s) Summary
Observer lifecycle and query updates
packages/svelte-query/src/createQueries.svelte.ts, packages/svelte-query/tests/createQueries/createQueries.svelte.test.ts, .changeset/svelte-create-queries-observer.md
createQueries retains its observer and recreates it when the client changes. The test adds a query and verifies the existing query function is not called again. The changeset describes the update.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested labels: package: svelte-query

Suggested reviewers: sukvvon

Merge Risk: Minimal · up to 039d4

createQueries now keeps its observer across option changes and only fetches newly added queries, as intended. No concrete defect remains, so the change looks safe to merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the fix and its scope: createQueries keeps its QueriesObserver when options change. That matches the main change in the summary, which makes the observer persist across option updates …
Description check Passed The description follows the repository template. It has the Changes section with motivation, a concrete reproduction (users [1] to [1, 2]), and the test result (fails on main with 3 calls instead of 2…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the fix and its scope: createQueries keeps its QueriesObserver when options change. That matches the main change in the summary, which makes the observer persist across option updates and recreates it only when the client changes. The title is specific and concise.

Full details: Description check

Explanation

The description follows the repository template. It has the Changes section with motivation, a concrete reproduction (users [1] to [1, 2]), and the test result (fails on main with 3 calls instead of 2). The checklist is filled in. The contributing and AI policy boxes are checked. The test:pr box is unchecked, but the author explains which checks ran (svelte-query tests and svelte-check). The changeset box is checked, and the raw summary confirms a changeset was added.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 331f45a and 039d4c6.

Files selected for processing: 3

  • .changeset/svelte-create-queries-observer.md
  • packages/svelte-query/src/createQueries.svelte.ts
  • packages/svelte-query/tests/createQueries/createQueries.svelte.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

This branch has not been deployed

No deployments
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.

1 participant