Replies: 5 comments
-
we've had this discussion before, and even a PR: conceptually, I don't think it makes much sense to suspend on background refetches, as this would mean you do not want to utilise stale-while-revalidate, the principle react-query is built upon: show stale data while you're refetching in the background, then update the screen with new data. I'm not sure what the use-case for this would be, but for example, for imperatively triggered refetches, you can use |
Beta Was this translation helpful? Give feedback.
-
It does make sense to me sometimes suspend on mount-refetch as no matter how you trust your query staletime in the rest of the app, if the component is an editor of the entity, a user wants to start editing the last version of the entity. I assume this is what most projects want. Without suspense, the user can drop connection speed so mount-refetch & rerender can happen after the user makes a change on an old entity state, overwriting the state the user never saw. The easiest thing we can do is to suspend the editor until the refetch is done. Better loader in this part of the app than letting users mess with data. We want to avoid doing imperative fetch on mount as it means to do something like this (btw this is very similar to our current implementation). No suspense here, though :(
And we want to use RQ for not doing this boilerplate. With proposal
Reseting the query before fetching will end up in suspense-refetch-reset-suspense loop. The solution can be moving the reset above the My last idea for a workaround was using something like this https://github.com/vigzmv/react-promise-suspense (for wrapping the client.fetchQuery) but it didn't seems right. I didn't find the Twitter post that you mentioned here. |
Beta Was this translation helpful? Give feedback.
-
You are talking about forms where you likely don't want background refetches because of exactly the reasons you mentioned - they would overwrite user input. There are different techniques to solve this, which I have outlined here: https://tkdodo.eu/blog/react-query-and-forms But it has nothing to do with wanting to suspend even if you have cached data imo..
|
Beta Was this translation helpful? Give feedback.
-
You are right. There is no solution for this except forking the RQ, building everything from the ground, or adding the feature to RQ hook. I hate use-case specific options (because of testing and maintaining). That's why I like #3935. Your comment is not a workaround as we cannot use it during a query mount (resetting in useEffect is too late, doing side effects during a render is wrong, and resetting the query in render phase will cause an infinite loop). So not sure why it was closed. I like to see React team working on the promise hook, but it can take years to release if ever. Then, of course, we could be able to use I would say we need your opinion or reason why not to support this. We can try to create a PR then. |
Beta Was this translation helpful? Give feedback.
-
It was closed because initializing suspense might become a hook call so we might not be able to do "conditional suspense", or we might have to revert it later if react goes that way. Btw, we already support the
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
This one can be linked to a question #4099.
AFAIK there is no way to suspend the component while refetching already cached (no matter the stale status) data on mount.
Is it possible to extend refetchOnMount option with something like 'alwaysForceLoading'? So even when the data are in the cache, refetchOnMount will behave like the first mount, loading will be true and suspense would be triggered.
Beta Was this translation helpful? Give feedback.
All reactions