Expose fetcher.cancel()
API
#2414
Replies: 4 comments 8 replies
-
Can you list a couple use cases? I'm unsure why you'd need to manually cancel a fetcher. Remix already handles interruptions, race conditions on revalidations, and unmounting. In the unmounting case, it's expected that if the fetcher is no longer needed, the component rendering it isn't needed either. What product use cases are there that you would cancel a fetcher outside of interruptions and unmounting? |
Beta Was this translation helpful? Give feedback.
-
Another example: If we had the ability to control fetcher cancellation this could be resolved. As it stands I would hesitate to use the advanced implementation. |
Beta Was this translation helpful? Give feedback.
-
This would also be helpful for us. In our scenario, we have a select input that, when changed, triggers an action. The action will either be a For example, the options might be:
If we load 1, then switch to 2, it works fine, because the second load cancels the first. However, if we switch from 1 or 2 to 3, the hardcoded results appear, but a second later, they're overridden by the fetcher. We centralise "setting options" (we have 10+ options in the select, and they all share an interface). This means we can call useEffect(() => {
setOptions(fetcher.data ?? []);
}, [fetcher.data]); It would be nice to be able to cancel the fetcher without having to add another layer of "if this option is still selected then apply the fetcher data otherwise don't". In the meantime, we'll probably refactor the component to use sub-components, each with their own fetcher (so it'll cancel on unmount). |
Beta Was this translation helpful? Give feedback.
-
Came here because of need of cancellation, we have an upload dialog where we'd like to be able to explicitly cancel long running uploads. We do not want to unmount the component which triggered the upload though. |
Beta Was this translation helpful? Give feedback.
-
While it's currently possible to cancel in-flight
useFetcher()
requests by unmounting the React component that's performing them, it'd be nice to be able to programmatically cancel those requests within the component itself:Beta Was this translation helpful? Give feedback.
All reactions