feature request to always retry errors when variables change #3487
Replies: 5 comments 13 replies
-
I closed the issue because I was able to make the reproduction work by using the correct callback on the ErrorBoundary. Maybe that was a bit hasty, sorry. If your real case is different and still doesn't work, please provide another reproduction that shows the issue including routing. Thanks. |
Beta Was this translation helpful? Give feedback.
-
I think this is a minimal repro https://github.com/joshribakoff-sm/rq-bug/tree/reset Screen.Recording.2022-04-08.at.11.50.14.PM.movLike in my original example, I have a button that changed the variables / reset keys. it toggles from 0 to 1 and back. To simulate what I experienced in my real app, I made the promise resolve for 1 and reject for 0: const result = useQuery(
['foo', v],
async () => {
console.log('query ran', v);
if (v === 0)
return Promise.reject('rejected by Anthony Davis');
return Promise.resolve('resolved by James Harden');
},
{ retry: false, staleTime: Infinity, cacheTime: Infinity }
); When I toggle back and forth from the success to the error state, Sure enough, if I edit it back to my original example that always rejects, it does get retried every time I click the button: const result = useQuery(
["foo", v],
async () => {
console.log("query ran", v);
return Promise.reject("rejected by Anthony Davis");
},
{ retry: false, staleTime: Infinity, cacheTime: Infinity }
); Basically like I was saying in my issue report, I don't ever really want |
Beta Was this translation helpful? Give feedback.
-
I don't want to be rude, but you've just made the same mistake with that reproduction as discussed in the issue: you're not using Here is a codesandbox with your reproduction (codesandbox is so much better for quick collaboration) where I just:
I was providing reasons on the issue why react-query does that, and it is generally not an issue.
Just an FYI, please do not expect react-query v3 to work with concurrent features. only v4 has "protection" against tearing, as it uses |
Beta Was this translation helpful? Give feedback.
-
https://codesandbox.io/s/sharp-chandrasekhar-y4xtqy steps to replicate:
expected:
actual:
proposed solution: using React primitives, you can differentiate between re-renders where the variables do not change (and throw the cached error) and re-renders where the variables change or the component unmounts (throwing away the cached error) note: I specifically don't want the pattern where the user has to click a "retry" button, since more often than not it will appear to have no effect, especially for errors in my code unrelated to the network. I just don't want errors to be cached (beyond whatever is strictly necessary) I also specifically don't want any solution that involves calling One of the biggest reasons to avoid |
Beta Was this translation helpful? Give feedback.
-
the problem in the sandbox seems to be that the query is not re-run even though it should be.
However, I then found this: and in your example, https://codesandbox.io/s/little-framework-dzc0tf?file=/src/App.js |
Beta Was this translation helpful? Give feedback.
-
My issue here was closed, with a suggestion to force re-mounts.
#3485
I don't want to remount my component (for many reasons outlined there). I'd like a way to "reset" an error and retry the query, without remounting. If I change the variables away from and back to a value that previously resulted in an error, I want
react-query
to retry the query.If a user navigates to a new route param, it doesn't make sense to me that
react-query
won't retry a query that has previously error'd, especially if I'm callingreset()
prior. In fact, I'd suggestreset()
should trigger a retry for any error'd component currently mounted too.I have no idea why my component remains "mounted" even when the error boundary is triggered, probably something with the multiple suspense boundaries together with the transition I'm using?
Beta Was this translation helpful? Give feedback.
All reactions