Open
Description
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
)