Skip to content
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

Error is not getting cought when coming back to the window #36

Closed
amitripshtos opened this issue Nov 13, 2019 · 9 comments · Fixed by #37
Closed

Error is not getting cought when coming back to the window #36

amitripshtos opened this issue Nov 13, 2019 · 9 comments · Fixed by #37

Comments

@amitripshtos
Copy link
Contributor

Hey, great library!
I noticed that when I useQuery and it fails, go out of the page and then go back - the error will not be caught in useQuery but be raised to the UI.

How to test?

  1. Use useQuery to a endpoint that does not work (using async await)
  2. Let it fail one time, go out of the tab and go back in.
  3. You should see the Ui crashes.

Thanks!

@tannerlinsley
Copy link
Collaborator

tannerlinsley commented Nov 14, 2019 via email

@amitripshtos
Copy link
Contributor Author

I want to fix that in order to learn more about react-query, mind if you lead me on which part of the code should I look? Thanks!

@tannerlinsley
Copy link
Collaborator

Yes I can! But first, could you make a codesandbox that demonstrates the bug so we can work from there?

@amitripshtos
Copy link
Contributor Author

Well, I'm trying to mimic the issue using codesandbox, however without any success.
I'm starting to think that it happens because im in development mode in my react environment.

The issue I'm seeing is that the development environment catches the error and not react-query - only when I go out and in to the page.

I'm attaching a image that shows how it looks like.
image

@tannerlinsley
Copy link
Collaborator

Ah... yes. The redbox error handler for CRA dev mode is a bit overzealous sometimes. Let me look into this a bit more.

@tannerlinsley
Copy link
Collaborator

tannerlinsley commented Nov 14, 2019

Just to be clear, are you by chance using Suspense?

@amitripshtos
Copy link
Contributor Author

amitripshtos commented Nov 14, 2019 via email

@tannerlinsley
Copy link
Collaborator

tannerlinsley commented Nov 14, 2019

So the cause of this error is that when then the window is refocused, the refetchAllQueries function is called. This function returns a promise and will throw if any of the queries on the page error. So essentially, you don't want the window focus fetcher to throw error into the window, you want to catch the error and just log it to the console.

Let me know if that's enough info for you to get started on fixing it and feel free to open a PR. I'll help you the rest of the way with a code review there :)

@amitripshtos
Copy link
Contributor Author

Thanks for the help, I created a pull request and tested it on my application and it does work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants