Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetchQuery inside useQuery with the same queryKey causes infinite loading #8494

Closed
filipw01 opened this issue Jan 2, 2025 · 1 comment
Closed

Comments

@filipw01
Copy link

filipw01 commented Jan 2, 2025

Describe the bug

When using fetchQuery inside useQuery with the same queryKey causes infinite loading

Your minimal, reproducible example

https://stackblitz.com/edit/vitejs-vite-qqzwgwu2?file=src%2FApp.tsx

Steps to reproduce

  1. Open reproduction
  2. See that loading state is displayed
  3. Change one of the 2 query keys so they are not the same
  4. See the expected loaded state

Expected behavior

I expect the resource to load instead of getting stuck on isLoading

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

MacOs Chrome 131.0.6778.205

Tanstack Query adapter

react-query

TanStack Query version

5.62.11

TypeScript version

5.5.4

Additional context

It used to work in v4, I noticed this issue after upgrading to v5

@TkDodo
Copy link
Collaborator

TkDodo commented Jan 2, 2025

This is expected. useQuery starts the fetch, and runs the queryFn. That queryFn then calls fetchQuery for the same key, so de-duplication kicks in and we return the already running promise. Now you have a promise that "waits for itself".

Besides that, using two different queryFns for the same key is likely not a good idea.

@TkDodo TkDodo closed this as not planned Won't fix, can't repro, duplicate, stale Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants