Skip to content
Source
Sign inSign up
TanStack/query

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

ClosedIdrisCelik(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/11557/headopened

🎯 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.
    1. 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 2a495979b4eefc075fd641bd89a745e99f54a446 and 5e4dae973372f6097d8ddc6fc9aaeb00575cd540.

      📒 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 nameStatusExplanation
      Description check✅ PassedThe 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✅ PassedThe title clearly and concisely describes the main change: preventing reactive options from cancelling an in-flight refetch in Svelte Query.
      Linked Issues check✅ PassedThe 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✅ PassedThe 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✅ PassedDocstring 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.
    2. sheraz4196(GitHub profile, opens in a new tab) approved these changes

    3. Per https://github.com/TanStack/query/issues/11556#issuecomment-6089576781 , the underlying issue has been fixed already. We can still accept the test case if you want to update it.

    4. TkDodo closed this

Sign in to join this conversation.