TanStack / query

🤖 Powerful asynchronous state management, server-state utilities and data fetching for the web. TS/JS, React Query, Solid Query, Svelte Query and Vue Query.
https://tanstack.com/query
MIT License
40.3k stars 2.7k forks source link

useQuery get stuck in case of throw error on queryFn #7411

Closed Devecor closed 3 weeks ago

Devecor commented 3 weeks ago

Describe the bug

useQuery will keep in pending when I mock a http call with nock:

image

and return Promise.reject() will also get it stuck in pending.

Your minimal, reproducible example

https://github.com/Devecor/test-react-query

Steps to reproduce

  1. please refer this dedicated repo to reproduce: https://github.com/Devecor/test-react-query
  2. and the github actions test shows how it failed: https://github.com/Devecor/test-react-query/actions/runs/9034787406/job/24828135597

Expected behavior

useQuery finished with error status

How often does this bug happen?

None

Screenshots or Videos

image

Platform

Tanstack Query adapter

react-query

TanStack Query version

5.35.5

TypeScript version

No response

Additional context

No response

TkDodo commented 3 weeks ago

Judging from the screenshot, you run into the default retries and they take too long for a test with exponential backoff. Turn off retries in tests: https://tkdodo.eu/blog/testing-react-query#turn-off-retries

Devecor commented 3 weeks ago

Thanks! that works. I'l close this