-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
fix(query-core): ensure onMutate runs synchronously when cache config is undefined (#8724) #10066
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 1e71dcb The changes in this PR will be included in the next version bump. This PR includes changesets to release 19 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 |
📝 WalkthroughWalkthroughThis PR patches TanStack Query core to ensure the onMutate callback executes synchronously when mutationCache.config.onMutate is undefined. The fix replaces optional chaining with an explicit null check before awaiting, preventing unnecessary async wrapping when no cache-level onMutate handler exists. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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 |
|
| Command | Status | Duration | Result |
|---|---|---|---|
nx affected --targets=test:sherif,test:knip,tes... |
❌ Failed | 4m 17s | View ↗ |
nx run-many --target=build --exclude=examples/*... |
✅ Succeeded | 2s | View ↗ |
☁️ Nx Cloud last updated this comment at 2026-01-22 14:55:51 UTC

🎯 Changes
onMutatenever actually runs synchronously #8724Previously, mutationCache.config.onMutate was always awaited using optional chaining (
await this.#mutationCache.config.onMutate?.()), which caused unnecessary async behavior even when the callback was undefined.Changed to conditional check: only await when onMutate is actually defined
Added regression test to verify synchronous execution when cache config is not provided
✅ Checklist
pnpm run test:pr.🚀 Release Impact
Summary by CodeRabbit
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.