Skip to content

onMutate never actually runs synchronously #8724

Description

@sleexyz

onMutate never actually runs synchronously because the result of #mutationCache.config.onMutate?.() is always awaited beforehand

Diff that fixes this:

diff --git a/node_modules/@tanstack/query-core/build/modern/mutation.js b/node_modules/@tanstack/query-core/build/modern/mutation.js
index 1bc7990..efbddd6 100644
--- a/node_modules/@tanstack/query-core/build/modern/mutation.js+++ b/node_modules/@tanstack/query-core/build/modern/mutation.js@@ -82,10 +82,12 @@ var Mutation = class extends Removable {
try {
if (!restored) {
this.#dispatch({ type: "pending", variables, isPaused });
- await this.#mutationCache.config.onMutate?.(- variables,- this- );+ if (this.#mutationCache.config.onMutate) {+ await this.#mutationCache.config.onMutate(+ variables,+ this+ );+ }
const context = await this.options.onMutate?.(variables);
if (context !== this.state.context) {
this.#dispatch({

(Diff generated via patch-package to patch @tanstack/query-core@5.51.21)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions