fix(query-core): preserve mutation scope across option updates - #11531
brennanbutler01 wants to merge 1 commit into
Conversation
Keep cache scope membership stable for each mutation so observer option updates cannot strand other mutations in its original queue. Future mutations still use the updated scope. Cover changed, removed, and initially absent scopes in core tests, plus React rerenders with and without Strict Mode.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (4)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe change preserves each mutation’s initial scope when observer options change. Queued mutations continue under the original scope, while new mutations use updated options. Query-core and React tests cover scoped, unscoped, and StrictMode cases. ChangesMutation scope preservation
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to The scope-preservation change is covered across the core and React mutation paths, with no actionable current-head risk identified. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 3 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🟢 Approval recommended
The scope fix and supporting core and React regressions are fully covered with no unresolved blocking issues.
Pull request overview
Preserves each mutation’s original scope across option updates, preventing queued mutations from remaining paused.
Changes:
- Retains mutation scope at creation.
- Adds core and React regression coverage.
- Adds a patch changeset.
File summaries
| File | Description |
|---|---|
packages/react-query/src/__tests__/useMutation.test.tsx |
Tests React scope updates with and without Strict Mode. |
packages/query-core/src/mutation.ts |
Preserves the original mutation scope. |
packages/query-core/src/__tests__/mutationObserver.test.tsx |
Tests scope retention and future mutations. |
.changeset/fix-mutation-scope-queue.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.
🎯 Changes
Changing
useMutation's scope while a mutation is running can leave other mutations in its original queue paused indefinitely. The cache indexes the mutation under its original scope, but settlement looks up the updated scope and never resumes the old queue. Removing the scope has the same effect.Capture the scope when each mutation is created and retain it when options update. Other options still update, and future mutations use the observer's new scope. This also keeps cache removal aligned with the original scope.
Adds three core regressions covering changed/removed scopes, initially unscoped mutations, callback updates, and future mutations. Adds React coverage with and without Strict Mode. The 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. No matching issue or pull request was found; #11455 concerns callback reentrancy rather than queue membership.✅ Checklist
pnpm run test:pr, or these tests do not apply to this pull request.The full cross-framework
test:prrun was not performed. Both affected packages passedtest:lib,test:types,test:eslint, andtest:buildthrough 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
Summary by CodeRabbit