Skip to content
Source
Sign inSign up
TanStack/query

A query remains indefinitely in "fetching" status when the component where it is originated crashes #1182

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

Describe the bug A query remains indefinitely in "fetching" status when the component where it is originated crashes and the error is catched by an error boundary.

To Reproduce I've created a codesandbox to show the bug, you can see it here: https://codesandbox.io/s/loving-grothendieck-5ovgm Steps to reproduce the behavior:

  1. Go to the codesanbox;
  2. Click on "Show Posts"
  3. Close the error overlay, you can see that the global fetching indicator shows that 1 query is still running, and if you open the devtools you can see the query in "fetching" status
  4. You could then go back to the home and then click to the "todos" list, it works as expected but the global fetching indicator still remains to 1 after the fetch is completed

Expected behavior The query originated in the crashed component should not hang and be removed from the query cache.

Desktop (please complete the following information):

  • OS: Windows
  • Browser: Chrome
  • Version: 86
  1. Hmmm. It looks like a bug for sure.

  2. tannerlinsley added labelsbug

  3. tannerlinsley added labelsgood first issue

  4. tannerlinsley added labelssuspense

  5. Awesome!

  6. image

    @tannerlinsley

    On first glance, this bit seems to be the culprit. Because the default isFetching state is true when Query is instantiated, if an error is thrown before fetch has a chance to be called, then this will stay true, and as a result get stuck in that state.

    I'm assuming that there is some important reason why isFetching defaults to true on getDefaultState given that a few tests broke if that condition is removed.

    Any thoughts on how we would like to proceed with this?

  7. I believe it's true to avoid rendering for a split second with idle, then immediately switching to a loading state after mount. My guess is that should probably stay the way it is and instead, we should investigate a way to detect the error and set it to the appropriate state.

  8. tannerlinsleycommented

    Sweet!

  9. tannerlinsley closed this

  10. @sumeet030990 please open a new issue with a minimal reproduction, thanks.

Sign in to join this conversation.