useMutationState does not update when filters change (react-query)
メンテナーはふだん 1 日以内に返信
@MahathirMohammadShuvo がすでに取り組んでいます。
2026年8月29日 から。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 78/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- react, typescript
調査の方向性
まず useMutationState の実装と、その getSnapshot および mutationCache.subscribe のロジックを確認し、その後 packages/react-query/src/tests/useMutationState.test.tsx に回帰ケースを追加します。pnpm nx run @tanstack/react-query:test:lib -- useMutationState を実行します。フィルターがキャッシュの更新なしに変化したとき、結果が variables: 1,2 から variables: 1 に更新されれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
useMutationState() ignores changes to filters. The result is only recomputed when the mutation cache notifies, so after a filter change the array keeps showing the old filters' results until something unrelated touches the cache. If nothing does, it stays wrong.
result.current is only written inside the mutationCache.subscribe() callback, and getSnapshot is () => result.current. So a render with new options recomputes nothing.
Same symptom as #11152 / #11153 in svelte-query, different cause.
Your minimal, reproducible example
N/A, reproduces in the package's own vitest suite.
Steps to reproduce
Add to packages/react-query/src/__tests__/useMutationState.test.tsx, run pnpm nx run @tanstack/react-query:test:lib -- useMutationState:
it('should update the result when mutation filters change without a cache update', async () => {
const queryClient = new QueryClient()
const key1 = queryKey()
const key2 = queryKey()
function Variables({ mutationKey }: { mutationKey?: Array<string> }) {
const variables = useMutationState({
filters: { mutationKey },
select: (mutation) => mutation.state.variables,
})
return <div>variables: {variables.join(',')}</div>
}
function Page({ mutationKey }: { mutationKey?: Array<string> }) {
const { mutate: mutate1 } = useMutation({
mutationKey: key1,
mutationFn: (input: number) => sleep(100).then(() => 'data' + input),
})
const { mutate: mutate2 } = useMutation({
mutationKey: key2,
mutationFn: (input: number) => sleep(100).then(() => 'data' + input),
})
React.useEffect(() => {
mutate1(1)
mutate2(2)
}, [mutate1, mutate2])
return <Variables mutationKey={mutationKey} />
}
const rendered = renderWithClient(queryClient, <Page mutationKey={undefined} />)
await vi.advanceTimersByTimeAsync(0)
expect(rendered.getByText('variables: 1,2')).toBeInTheDocument()
rendered.rerender(<Page mutationKey={key1} />)
expect(rendered.getByText('variables: 1')).toBeInTheDocument()
})
Both mutations stay pending, so the cache never notifies. Output stays variables: 1,2 instead of variables: 1.
Expected behavior
The array should always reflect whatever filters currently select, as it does in vue-query, angular and lit.
How often does this bug happen?
Every time
Platform
N/A, jsdom.
Tanstack Query adapter
react-query
TanStack Query version
v5.102.2
TypeScript version
v6.0.3
- 主要言語
- TypeScript
- スター
- 50.4k
- フォーク
- 4.2k
- 平均マージ
- 7時間 29分
- マージ済み PR(30日)
- 393
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
TanStack/query のほかの issue
-
solid-query: STRICT_READ_UNTRACKED on Solid 2 — client()/options() read in component body (useMutation, useBaseQuery)再び着手できるかも @LeonxLJX が 34 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
TanStack/query#11358 · コメント 2 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
solid-query: switching the queryClient accessor strands the new client's cache (subscription stays on the old observer)対応中かも @MaNaN1803 が 77 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
TanStack/query#11106 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
restoreQueries and persisterGc throw on malformed persisted entries対応中かも @VGontier-cmd が 2 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
メンテナーはふだん 1 日以内に返信
-
setQueryData: NoInfer loses discriminated-union members when spreading a narrowed updater value対応中かも @iosayin が 3 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
Bump Firebase JS SDK (12.19.0 → 13.0.0)対応中かも @SelaseKay が今日担当しました。 オープンNeeds Attention type: enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
invertase/react-native-firebase#9364 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 4 日以内に返信
-
e2e-failure ready-to-code
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
redhat-developer/rhdh-plugin-export-overlays#4261 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
[Bug] 官网文档的图片挂了オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
メンテナーはふだん 1 日以内に返信
-
area:cli bug triage:in-progress
難易度 1/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信