Skip to content

Double fetch on any query (one is immediately cancelled) in dev server #2232

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

Closed
1 task done
jzxhuang opened this issue Mar 26, 2025 · 2 comments
Closed
1 task done
Labels
bug Something isn't working openapi-react-query Relevant to openapi-react-query

Comments

@jzxhuang
Copy link

openapi-react-query version

0.3.1

Description

Any useQuery sends 2 requests, with one being immediately cancelled.

Image

This appears to only occur in dev mode. If building out the app (i.e. pnpm build && pnpm preview), only a single request is sent, leading me to believe this has to do with an effect being run twice somewhere

Reproduction

https://stackblitz.com/~/github.com/jzxhuang/openapi-react-query-double-fetch

  • Open network tab, filter for XHR requests
  • Reload the app
  • Observe that 2 requests get made to https://catfact.ninja/breeds?limit=50

This is a standard react Vite app bootstrapped with pnpm create vite --template react-ts. The only code I added is in src/api/* (for the open API types) and src/Comp.tsx)

Expected result

Only a single request should be sent.

Extra

@jzxhuang jzxhuang added bug Something isn't working openapi-react-query Relevant to openapi-react-query labels Mar 26, 2025
@2ico
Copy link

2ico commented Mar 27, 2025

I think this is normal in React development env.
Try building as production.

@jzxhuang
Copy link
Author

After doing some digging, I found that this is due to TanStack/query#6089 — using signal in the queryFn actually triggers this double request in dev mode. A very peculiar issue that occurs in dev w/ React Strict mode (double-mounting a component in dev)

Try building as production.

I mentioned in the issue that it works if building out the app (pnpm build && pnpm preview). However, this is not "normal" in dev, at least not for "normal" usage of React Query.

Anyways, closing the issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working openapi-react-query Relevant to openapi-react-query
Projects
None yet
Development

No branches or pull requests

2 participants