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 分钟
- 30 天内合并 PR
- 393
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
TanStack/query 的其他 Issue
-
solid-query: STRICT_READ_UNTRACKED on Solid 2 — client()/options() read in component body (useMutation, useBaseQuery)可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 2/5 1-3 小时 新手友好度 84/100
TanStack/query#11358 · 2 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
solid-query: switching the queryClient accessor strands the new client's cache (subscription stays on the old observer)可能已有人在做 @MaNaN1803 于 76 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 84/100
TanStack/query#11106 · 1 条评论 ·
维护者通常 1 天内回复
-
restoreQueries and persisterGc throw on malformed persisted entries可能已有人在做 @VGontier-cmd 于 1 天前认领。 未关闭
难度 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 于 2 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 55/100
维护者通常 1 天内回复
相似的 Issue
-
enhancement
难度 2/5 1-3 小时 新手友好度 88/100
Small-tailqwq/dsh-deep-whale#187 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
melgarafael/DeskcommCRM#2503 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 74/100
0x80/isolate-package#218 ·
-
bug via-triage
难度 2/5 1-3 小时 新手友好度 82/100
pingdotgg/t3code#16859 · 1 条评论 ·
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复