Skip to content
Source
Sign inSign up
TanStack/query

[v4] Mutation Filters - mutation variables are missing from "options" #7050

Send to my agent
Closedk-1ee(GitHub profile, opens in a new tab) opened this issue 1 comment

Describe the bug

When using mutation filters in react-query v3, mutation variables were accessible through mutation.options.variables. Upon migrating to v4, it seems that variables should be accessed through mutation.state since mutation.options.variables can be undefined.

Looking at the source code, it seems that both mutation.options and mutation.state have variables as an optional property. The docs seem to only provide an example of filtering mutations via variables using options, and no mention of state.

What is the distinction between options and state in regards to mutation filters? Prior to v4, mutation.options.variables always existed, but can now be undefined in v4.

Your minimal, reproducible example

https://codesandbox.io/s/peaceful-euclid-5876nl?file=/src/App.js

Steps to reproduce

  1. Set up useMutation and useIsMutating using the same mutation key
  2. Trigger a mutation and provide variables
  3. In useIsMutating, add a predicate options and log mutation.options.variables and mutation.state.variables
  4. See that the former can be undefined, whereas the latter always contains the mutation variables

Expected behavior

As a user, I expected to consistently see mutation variables in mutation.options.variables but I am only consistently seeing the variables in mutation.options.state.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

macOS - Chrome - v121.0.6167.160

Tanstack Query adapter

react-query

TanStack Query version

v4.36.1

TypeScript version

v5.3.3

Additional context

No response

  1. I think we have removed mutation.option.variables in v5. The variables aren't defined when the mutation is defined, which is why they can't exist on options. So I wouldn't use them - just the ones on state.

    On the state of the mutation, it can potentially undefined because you could theoretically check the Mutation after it has been created, but before it has been invoked. In react, the adapter makes sure to create-and-execute a mutation, so technically, it shouldn't happen that it's undefined, but on type level, it can be.

    So please use mutation.state.variables and make sure to check if it's defined.

  2. TkDodo closed this

  3. TkDodo added labelswontfix

Sign in to join this conversation.