Skip to content

fix(query-core): reset infinite-query signal consumption - #11532

Open
brennanbutler01 wants to merge 1 commit into
TanStack:mainfrom
brennanbutler01:fix/infinite-query-signal-reset
Open

brennanbutler01 wants to merge 1 commit into
TanStack:mainfrom
brennanbutler01:fix/infinite-query-signal-reset

Conversation

@brennanbutler01

@brennanbutler01 brennanbutler01 commented Sep 18, 2026

Copy link
Copy Markdown

🎯 Changes

After an infinite-query fetch reads context.signal, a later fetch that never reads the signal can still be cancelled when its last observer unmounts. Its result is discarded instead of reaching the cache. The equivalent ordinary query caches the result correctly.

Reset signal consumption when creating each fetch's AbortController. The existing reset inside the ordinary fetch function remains; infinite-query behavior replaces that function and previously skipped the reset entirely.

Adds core regressions for refetching and fetching the next page, plus React unmount coverage with and without Strict Mode. Both new core regressions failed before the fix; all core and React tests now pass. A standalone public-API reproduction also passes against the built package.

Reproduced on 5.101.2, the 5.103.1 release source, and 66d4fe3. Related to the skipped reset discussed in #3492; this reproduction concerns a later fetch after a successful initial fetch, rather than duplicate initial requests in Strict Mode.

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

The full cross-framework test:pr run was not performed. Both affected packages passed test:lib, test:types, test:eslint, and test:build through Nx, including dependency builds. The compiler matrix covers TypeScript 5.6, 5.7, 5.8, 5.9, 6.0, and 7.0. Existing lint warnings are in unchanged code. Tested on Node 24.13.0.

Implemented and locally verified with AI assistance. The contributor-understanding checkbox is left for the author's review.

🚀 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 infinite-query refetches and pagination requests being incorrectly cancelled after an earlier request consumed the abort signal.
    • Ensured data from an in-progress refetch remains cached when the component unmounts, including in Strict Mode.
  • Tests
    • Added coverage for refetch and next-page scenarios, including unmount behavior.

Reset signal consumption before query behavior replaces the fetch
function. Earlier signal consumption must not cancel a later fetch that
never reads its signal when the last observer unmounts.

Cover refetching, next-page fetching, and React unmounts with and without
Strict Mode.
@coderabbitai

coderabbitai Bot commented Sep 18, 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: da292e83-66fa-4757-8ed6-830fe7d119ae

📥 Commits

Reviewing files that changed from the base of the PR and between bb9d313 and 3dda21e.

📒 Files selected for processing (4)
  • .changeset/fix-infinite-query-signal-reset.md
  • packages/query-core/src/__tests__/infiniteQueryBehavior.test.tsx
  • packages/query-core/src/query.ts
  • packages/react-query/src/__tests__/useInfiniteQuery.test.tsx

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


📝 Walkthrough

Walkthrough

Query.fetch() now resets signal-consumption tracking for each fetch. Tests cover infinite-query refetches, pagination, StrictMode, and caching after unmount.

Changes

Infinite query signal reset

Layer / File(s) Summary
Per-fetch signal tracking
packages/query-core/src/query.ts, .changeset/fix-infinite-query-signal-reset.md
Query.fetch() resets the abort-signal consumption flag before behaviors run. A patch changeset documents the fix.
Infinite-query regression coverage
packages/query-core/src/__tests__/infiniteQueryBehavior.test.tsx, packages/react-query/src/__tests__/useInfiniteQuery.test.tsx
Tests verify that later signal-ignoring refetch and fetchNextPage calls complete. React tests also cover StrictMode and caching after unmount.

Priority: ⬇️ Low

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

Change: Bug fix

Suggested reviewers: tkdodo

Merge Risk: ⚪ Minimal · up to 3dda2

The change addresses the stale signal-consumption state and includes targeted coverage for the affected caching behavior. No actionable merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 3…
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.
Title check ✅ Passed The title clearly identifies the query-core fix and the reset of infinite-query signal consumption.
Description check ✅ Passed The description explains the problem, implementation, regression coverage, test results, and release impact. It includes all required template sections. The full test:pr run and contributor-understand…
✨ 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.

@brennanbutler01
brennanbutler01 marked this pull request as ready for review September 18, 2026 03:55
Copilot AI lite review requested due to automatic review settings September 18, 2026 03:55

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The fix is covered by core and React regressions with no unresolved blocking issues.

Pull request overview

Fixes stale abort-signal consumption in subsequent infinite-query fetches.

Changes:

  • Reset signal consumption for each fetch.
  • Add core and React regression tests.
  • Add a patch changeset.
File summaries
File Description
packages/react-query/src/__tests__/useInfiniteQuery.test.tsx Tests unmount behavior with and without Strict Mode.
packages/query-core/src/query.ts Resets abort-signal state per fetch.
packages/query-core/src/__tests__/infiniteQueryBehavior.test.tsx Covers refetch and next-page regressions.
.changeset/fix-infinite-query-signal-reset.md Documents the patch release.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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.

3 participants