Skip to content

errors are cached and not reset if the component using useQuery is remounted #468

Closed

Description

@aaronjensen

Here's an example: https://codesandbox.io/s/elegant-minsky-wwfko?file=/src/index.js

Close the error report window then click "retry". That will remount the Posts component but it will error immediately.

If you uncomment the queryCache.clear() it works.

I would expect that errors are not cached, or that they're cleared when the component is remounted.

My guess is that since the component never officially mounts, there's some edge case here that isn't accounted for, or that this is an intractable problem and I should just always clear the cache on an error (which may very well be a good idea anyway).

Activity

  1. tannerlinsley commented on May 9, 2020

    @tannerlinsley
    Member

    I’m looking into this

  2. tannerlinsley commented on May 11, 2020

    @tannerlinsley
    Member

    🎉 This issue has been resolved in version 1.4.0 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

  3. aaronjensen commented on May 11, 2020

    @aaronjensen
    ContributorAuthor

    Thank you for the quick fix.

  4. jacklj commented on Dec 15, 2020

    @jacklj
    Contributor

    Hello, I'm getting the same issue in v.2.26.4, so I guess there was a regression? Have solved it by clearing the cache as above, but just FYI. Thanks.

  5. danowens1 commented on Jan 25, 2021

    @danowens1

    @tannerlinsley I am also getting the same issue in v.2.26.3. For us the cache clearing is not an optimal solution. Perhaps this issue should be reopened?

  6. TkDodo commented on Jan 25, 2021

    @TkDodo
    Collaborator

    Feel free to create a new issue / discussion with a codesandbox that shows the issue, preferably on v3.

  7. jakepeyser commented on Feb 11, 2021

    @jakepeyser

    For others facing this issue in v2.26.x, it looks like like the bug was also observed in #1412 (comment) and is being addressed in #1781

  8. tncbbthositg commented on Nov 11, 2021

    @tncbbthositg

    We just ran into the same issue with v3.27.0. If I get a chance to make a code sandbox I will.

    This will get us by for now:

      const { reset } = useQueryErrorResetBoundary();
      const queryClient = useQueryClient();
    
      const resetErrors = () => {
        queryClient.clear();
        reset();
      }
    
      return (
        <ErrorBoundary onReset={resetErrors} fallbackRender={Fallback}>
          { children }
        </ErrorBoundary>
      );
  9. TkDodo commented on Nov 11, 2021

    @TkDodo
    Collaborator

    Can you try updating to the latest version please? I remember we had a bug somewhere that was since fixed. Otherwise please open a new issue with a codesandbox reproduction

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions