Skip to content
Source
Sign inSign up
TanStack/query

`QueryErrorResetBoundary` not reset after throwing error in component with `useSuspenseQuery` #7465

Send to my agent
Closedvisualjerk(GitHub profile, opens in a new tab) opened this issue 3 comments

Describe the bug

When throwing an error from a useSuspenseQuery like described here resetting the QueryErrorResetBoundary does not reset the error in useSuspenseQuery.

This happens when the error occurs on a subsequent fetch. It works as expected, if the error occurs while fetching data initially.

Your minimal, reproducible example

https://stackblitz.com/edit/github-vmd3m2?file=src%2Fcomponents%2FProjects.jsx

Steps to reproduce

  1. Click on "Show Projects"
  2. Click on "Refresh"
  3. Click on "Try again"
  4. The ErrorBoundary fallback is still shown

Expected behavior

After 3. the Suspense fallback should be shown and after a short while the project list should be shown.

How often does this bug happen?

Everytime

Screenshots or Videos

https://github.com/TanStack/query/assets/28823153/4712012b-a42a-4735-959c-27067d517b13

No response

Platform

  • OS: MacOS 14.4.1
  • Browser: Chrome 124.0.6367.209

Tanstack Query adapter

react-query

TanStack Query version

5.37.1

TypeScript version

No response

Additional context

No response

  1. I think there is one render cycle in between where we are still in error state. I need to look into this. A quick workaround would be:

    -if (error) {
    +if (error && !isFetching) {
      throw error;
    }
  2. Ah, I see what's going on. So errors are kept if you have already fetched data successfully once before, that is on purpose:

    https://github.com/TanStack/query/blob/e3240f0233a2e901c7364aa6d477f9ead4df98e5/packages/query-core/src/query.ts#L631-L635

    we only reset back to a pending state for errors where we have no data yet. So I think the docs are wrong and checking for !isFetching is actually required.

    Can you maybe file a PR to the docs?

  3. TkDodo added labelsdocumentation

  4. TkDodo added labelsworks as designed

  5. TkDodo added labelsgood first issue

  6. Thank you so much! Really appreciate your quick and helpful responses ❤️

Sign in to join this conversation.