Skip to content

Conversation

@xxziiko
Copy link
Contributor

@xxziiko xxziiko commented Jan 22, 2026

🎯 Changes

Previously, 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

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 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

    • Corrected onMutate callback execution to run synchronously when cache-level configuration is undefined.
  • Tests

    • Added test coverage for synchronous callback behavior in mutation operations.

✏️ Tip: You can customize this high-level summary in your review settings.

@changeset-bot
Copy link

changeset-bot bot commented Jan 22, 2026

🦋 Changeset detected

Latest commit: 1e71dcb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 19 packages
Name Type
@tanstack/query-core Patch
@tanstack/angular-query-experimental Patch
@tanstack/query-async-storage-persister Patch
@tanstack/query-broadcast-client-experimental Patch
@tanstack/query-persist-client-core Patch
@tanstack/query-sync-storage-persister Patch
@tanstack/react-query Patch
@tanstack/solid-query Patch
@tanstack/svelte-query Patch
@tanstack/vue-query Patch
@tanstack/angular-query-persist-client Patch
@tanstack/react-query-persist-client Patch
@tanstack/solid-query-persist-client Patch
@tanstack/svelte-query-persist-client Patch
@tanstack/react-query-devtools Patch
@tanstack/react-query-next-experimental Patch
@tanstack/solid-query-devtools Patch
@tanstack/svelte-query-devtools Patch
@tanstack/vue-query-devtools Patch

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 22, 2026

📝 Walkthrough

Walkthrough

This 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

Cohort / File(s) Summary
Changeset Documentation
.changeset/giant-apples-wear.md
Patch version bump documenting the onMutate synchronous execution fix
Test Coverage
packages/query-core/src/__tests__/mutationCache.test.tsx
New test verifying onMutate executes synchronously when cache-level onMutate is not defined
Core Logic
packages/query-core/src/mutation.ts
Changed optional chaining call to explicit presence check before awaiting onMutate, enabling synchronous execution when cache-level handler is absent

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested labels

package: query-core

Suggested reviewers

  • TkDodo

Poem

🐰 A hop and a skip, the callback runs fast,
No waiting around when cache-config's not vast,
Synchronous now when undefined's the way,
Mutations proceed without delay—hooray!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main fix: ensuring onMutate runs synchronously when cache config is undefined, directly matching the core change in mutation.ts and the test additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The pull request description follows the template structure with all required sections completed: Changes describe the fix with context, Checklist items are checked, and Release Impact is addressed with a changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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 and usage tips.

@nx-cloud
Copy link

nx-cloud bot commented Jan 22, 2026

🤖 Nx Cloud AI Fix Eligible

An automatically generated fix could have helped fix failing tasks for this run, but Self-healing CI is disabled for this workspace. Visit workspace settings to enable it and get automatic fixes in future runs.

To disable these notifications, a workspace admin can disable them in workspace settings.


View your CI Pipeline Execution ↗ for commit 1e71dcb

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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 22, 2026

More templates

@tanstack/angular-query-experimental

npm i https://pkg.pr.new/@tanstack/angular-query-experimental@10066

@tanstack/eslint-plugin-query

npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@10066

@tanstack/query-async-storage-persister

npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@10066

@tanstack/query-broadcast-client-experimental

npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@10066

@tanstack/query-core

npm i https://pkg.pr.new/@tanstack/query-core@10066

@tanstack/query-devtools

npm i https://pkg.pr.new/@tanstack/query-devtools@10066

@tanstack/query-persist-client-core

npm i https://pkg.pr.new/@tanstack/query-persist-client-core@10066

@tanstack/query-sync-storage-persister

npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@10066

@tanstack/react-query

npm i https://pkg.pr.new/@tanstack/react-query@10066

@tanstack/react-query-devtools

npm i https://pkg.pr.new/@tanstack/react-query-devtools@10066

@tanstack/react-query-next-experimental

npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@10066

@tanstack/react-query-persist-client

npm i https://pkg.pr.new/@tanstack/react-query-persist-client@10066

@tanstack/solid-query

npm i https://pkg.pr.new/@tanstack/solid-query@10066

@tanstack/solid-query-devtools

npm i https://pkg.pr.new/@tanstack/solid-query-devtools@10066

@tanstack/solid-query-persist-client

npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@10066

@tanstack/svelte-query

npm i https://pkg.pr.new/@tanstack/svelte-query@10066

@tanstack/svelte-query-devtools

npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@10066

@tanstack/svelte-query-persist-client

npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@10066

@tanstack/vue-query

npm i https://pkg.pr.new/@tanstack/vue-query@10066

@tanstack/vue-query-devtools

npm i https://pkg.pr.new/@tanstack/vue-query-devtools@10066

commit: 1e71dcb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant