Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Mutation status incorrect after navigation in SvelteKit

未关闭
#8,772 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
50/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
typescript
领域
frontend

调研方向

从链接的 CodeSandbox 或复现仓库以及 signIn mutation 的 onSuccess 处理程序开始。在使用 TanStack Query devtools 对比 mutation 状态的同时,复现导航到 /auth 再返回的过程,尤其要关注 invalidateQueries({ queryKey: ['customer'] }) 运行时的情况。完成的标准是:返回 / 后状态为 success,同时不移除 invalidation。

由索引模型根据 Issue 内容生成。

描述

package: svelte-query
Describe the bug

Hi!

After navigating to another page in a SvelteKit app, an ongoing mutation's status remains pending instead of success

Your minimal, reproducible example

https://codesandbox.io/p/github/EugeneDraitsev/svelte-tanstack-query-mutation-status-issue/master

Steps to reproduce

You can check codesandbox link or check my repo: https://github.com/EugeneDraitsev/svelte-tanstack-query-mutation-status-issue

I have pretty simple mutation:

export const signIn = createMutation(
  {
    mutationFn: async () => {
      // wait for 1 second
      await new Promise((resolve) => setTimeout(resolve, 1000));
    },
    onSuccess: async () => {
      await goto('/auth');
      await queryClient.invalidateQueries({ queryKey: ['customer'] });
    },
  },
  queryClient,
);

When a user clicks the Sign In button, I simulate a login and redirect the user to the /auth route. However, when I navigate back from the /auth page to /, I see that $signIn.status is pending instead of success. I also can see the correct success status in the TanStack Query devtools.

If I comment out await queryClient.invalidateQueries({ queryKey: ['customer'] }); in the onSuccess function, everything works fine. However, I still consider this behavior as a bug.

Expected behavior

My mutation has success status

How often does this bug happen?

None

Screenshots or Videos

https://github.com/user-attachments/assets/7e56dedc-c841-4552-97a3-a3f177702d86

Platform
  • OS: Windows 11 24H2
  • Browser: Chrome
  • Version: 134.0.6998.35 (Official Build) (64-bit)
Tanstack Query adapter

None

TanStack Query version

^5.67.2

TypeScript version

^5.0.0

Additional context

No response

主要语言
TypeScript
星标
50.3k
派生
4.2k
平均合并
22 小时 33 分钟
30 天内合并 PR
214

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

TanStack/query 的其他 Issue

查看 TanStack/query 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。