You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Thrown errors are cached and re-thrown rather than retrying #662
Describe the bug
Relating to this comment, when retry failed due to error it appears that the error is being cached forever and rethrown every time the query itself is retried (not the internal retry logic)
Maybe I don't understand you question well, but If you return false from your custom function the query will not re-run. You should return true to re-run the query or you could check err argument and return true|false only for particular cases.
@marcosvega91 the issue is if I add in custom logic to handle a 401 error (the user isnt authorized), and redirect them to the login screen, the component that is querying the resource which 401's will be unloaded, then when they login and come back, the query simply rethrows the cached error without even giving the opportunity to check if it's still an error.
Also this is a breaking change/error in 2.x range, not present in 1.5x range of react-query
I have looked at your code and I think that the problem could be the suspense because the cache will be cleaned on component unmount by scheduleGarbageCollection. useEffect is not called and his callback too
// Subscribe to the query when the subscribe function changesReact.useEffect(()=>{instanceRef.current=query.subscribe(()=>rerender({}))// Unsubscribe when things changereturn()=>instanceRef.current.unsubscribe()},[query,rerender])
Activity
marcosvega91 commentedon Jul 13, 2020
Hi @onionhammer thanks for opening the issue :).
Maybe I don't understand you question well, but If you return
falsefrom your custom function the query will not re-run. You should returntrueto re-run the query or you could checkerrargument and returntrue|falseonly for particular cases.onionhammer commentedon Jul 13, 2020
@marcosvega91 the issue is if I add in custom logic to handle a 401 error (the user isnt authorized), and redirect them to the login screen, the component that is querying the resource which 401's will be unloaded, then when they login and come back, the query simply rethrows the cached error without even giving the opportunity to check if it's still an error.
Also this is a breaking change/error in 2.x range, not present in 1.5x range of react-query
marcosvega91 commentedon Jul 13, 2020
ok, I understand. Could you please create a case on codesandbox, in this way I can take a look at your code? thanks
onionhammer commentedon Jul 14, 2020
@marcosvega91 here's some code that reproduces the issue:
https://codesandbox.io/s/bitter-bash-13bvc?file=/src/App.js
Note if you start at the /login route and click login, it works, but if the query tries to load the data initially it will always have that error
marcosvega91 commentedon Jul 14, 2020
I have looked at your code and I think that the problem could be the
suspensebecause the cache will be cleaned on component unmount byscheduleGarbageCollection.useEffectis not called and his callback tooonionhammer commentedon Jul 14, 2020
@marcosvega91 it was cleared in previous versions of react-query, but not 2.x.
You could fork the codesandbox and fix it with your thought
marcosvega91 commentedon Jul 14, 2020
Your code seams right, I think it's a bug. @tannerlinsley What do you think ?
tannerlinsley commentedon Jul 31, 2020
Yeah, it seems like a bug.
tannerlinsley commentedon Aug 20, 2020
This will be fixed in #840