fix(query-core): keep nested mutate callbacks scoped to the settling mutation 🤖🤖🤖 - #11455
fix(query-core): keep nested mutate callbacks scoped to the settling mutation 🤖🤖🤖#11455rome-xi wants to merge 1 commit into
Conversation
…mutation Signed-off-by: rome-xi <rome-xi@users.noreply.github.com>
|
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 mutation observer now snapshots per-call callback options and settlement data before callbacks can start nested mutations. Core and React tests cover nested success and error flows, pending mutations, mutation context, and omitted options. ChangesNested mutation settlement callbacks
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~20 minutes Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to Nested mutation callbacks now retain their own result, error, variables, and context, preventing cross-mutation callback payloads and omitted-options failures. The change is ready to merge. Suggested reviewers: 🚥 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 3 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 |
🎯 Changes
MutationObserver.#notifyinvoked per-callonSettledfrom the livethis.#mutateOptionsafteronSuccess/onError. If those callbacks start anothermutate()on the same observer, they overwrite#mutateOptionsbeforeonSettledruns. The inner callback then receives the outer mutation's data/variables, the outeronSettlednever fires, and a nestedmutate()with no options throwsTypeError: Cannot read properties of undefined (reading 'onSettled').Capture the per-call options for the mutation that is settling (result fields were already snapshotted) and invoke callbacks from that snapshot.
Fixes #11451
✅ Checklist
pnpm nx run @tanstack/query-core:test:lib -- mutationObserver.testandpnpm nx run @tanstack/react-query:test:lib -- useMutation.test.🚀 Release Impact
An AI coding assistant helped draft the regression tests and the
#notifysnapshot. I reproduced the bug on currentmain, confirmed the new tests fail for the missing outeronSettled/ TypeError, and confirmed they pass after the snapshot.Summary by CodeRabbit
Bug Fixes
onSettledcallback receives the correct result, error, variables, and context.Tests