Skip to content

fix(svelte-query): prevent reactive options from cancelling refetch - #11557

Open
IdrisCelik wants to merge 1 commit into
TanStack:mainfrom
IdrisCelik:main
Open

IdrisCelik wants to merge 1 commit into
TanStack:mainfrom
IdrisCelik:main

Conversation

@IdrisCelik

@IdrisCelik IdrisCelik commented Sep 20, 2026

Copy link
Copy Markdown

🎯 Changes

Prevent reactive option updates from cancelling and restarting an in-flight refetch when the query key and enabled state remain unchanged.

The Svelte observer subscription callback now runs inside untrack, preventing synchronous result updates from making the subscription effect depend on resolved options.

Added a regression test covering stale infinite-query data, focus refetching, equivalent reactive options, abort signals, and duplicate page requests.

Fixes #11556

✅ 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.
  • I 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

    • Fixed refetch behavior so reactive option updates with unchanged query settings no longer cancel an in-progress refetch.
    • Ensured refetched infinite-query pages remain available when focus-triggered refetches occur.
  • Tests

    • Added coverage verifying refetches continue successfully when reactive options retain the same values.

@coderabbitai

coderabbitai Bot commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: TanStack/query/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 7f042619-6dca-4b4a-8363-60545fb68fc1

📥 Commits

Reviewing files that changed from the base of the PR and between 2a49597 and 5e4dae9.

📒 Files selected for processing (3)
  • .changeset/quiet-options-refetch.md
  • packages/svelte-query/src/createBaseQuery.svelte.ts
  • packages/svelte-query/tests/createInfiniteQuery/createInfiniteQuery.svelte.test.ts

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


📝 Walkthrough

Walkthrough

The Svelte query observer now applies result updates without reactive tracking. A regression test verifies that equivalent reactive options do not cancel an in-flight infinite-query refetch. A patch changeset documents the fix.

Changes

Svelte query refetch continuity

Layer / File(s) Summary
Untrack observer result updates
packages/svelte-query/src/createBaseQuery.svelte.ts
The observer subscription wraps update(createResult()) in Svelte’s untrack.
Validate refetch continuity
packages/svelte-query/tests/createInfiniteQuery/createInfiniteQuery.svelte.test.ts, .changeset/quiet-options-refetch.md
The test checks that equivalent reactive options preserve the in-flight request and produce pages [0, 1]. The changeset records a patch release for @tanstack/svelte-query.

Priority: ➖ Normal

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

Change: Bug fix · Severity of issue fixed: Medium

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description check ✅ Passed The description includes the required Changes, Checklist, and Release Impact sections. It explains the fix, test coverage, issue reference, completed checklist items, and changeset.
Title check ✅ Passed The title clearly and concisely describes the main change: preventing reactive options from cancelling an in-flight refetch in Svelte Query.
Linked Issues check ✅ Passed The PR addresses #11556. createBaseQuery.svelte.ts wraps subscription result updates in untrack, so synchronous result updates do not become dependencies of the subscription effect. The added regr…
Out of Scope Changes check ✅ Passed The changes are limited to the Svelte Query subscription fix, its focused automated regression test, and the related patch changeset. Each change supports #11556.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (1 skipped: 1 …
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

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

Comment @coderabbitai help to get the list of available commands.

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.

[svelte-query] Reactive options updates can cancel and restart an in-flight refetch without changing the query key or enabled value

1 participant