Repository navigation
fix(query-core): preserve mutation scope across option updates - #11531
brennanbutler01 wants to merge 2 commits 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
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to No identified issue prevents merging after normal checks. Pre-merge checks |
|
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.
…queue # Conflicts: # packages/query-core/src/__tests__/mutationObserver.test.tsx
🦋 Changeset detectedLatest commit: 6d4b98f The changes in this PR will be included in the next version bump. This PR includes changesets to release 24 packages
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 |
🎯 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