Closed TatisLois closed 1 year ago
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 3 committers have signed the CLA.
:white_check_mark: JAdshead
:white_check_mark: 10xLaCroixDrinker
:x: TatisLois
You have signed the CLA already but the status is still pending? Let us recheck it.
This pull request is automatically built and testable in CodeSandbox.
To see build info of the built libraries, click here or the icon next to each commit SHA.
Latest deployment of this branch, based on commit 39a589e5109d2857fc343d13ac1ab0c2fba0c893:
Sandbox | Source |
---|---|
fetchye-provider-install | Configuration |
fetchye-redux-provider-install | Configuration |
nextjs-fetchye-ssr | Configuration |
This pull request is stale because it has been open 30 days with no activity.
@TatisLois Are you still interested in moving forward with this?
@10xLaCroixDrinker Would love to help get this merged. What would be the best path forward?
I'd like to get this conversation going. I'll bring it up to the team. I think this could provide great value.
For now at least it would need to be opt-in until we determine we are ready for a major release. Any server concerns like you mentioned should be timeout related rather than unmounting and useEffect
does not run on the server. I'm with you on using feature detection.
Aborting the request when the component is unmounted makes sense to me. Making the signal available so that users could abort on a custom fetch / timeout solution i think would also be a great addition.
We will need to think though how this can be implemented given the following only one signal can be passed to fetch, the implications of this being the signal provided by fetchye's abort controller could be overridden by a signal passed to the fetch client or visa versa.
An AbortController can also control multiple fetch requests. How would we want this to work with the defer
flag, where users have to manually call the run
function ? Would we want them to be able to abort individual requests ? If so, the user may have to pass in their own controller for each run
invocation.
Add support to automatically abort fetch request in flight when a component is dismounted in the default fetcher. Provide the signal as an option to custom fetchers.
Description
I wanted to open a DRAFT/WIP with a proof of concept to start a conversation on the best way to and if useFetchye should support aborting fetch request. In the current implementation a request will continue even if the component is unmounted as seen in the first gif.
I am proposing that the default fetcher should abort request when the component is unmounted. For use cases where a custom fetch is being used we would forfeit control of the signal by passing it in through the options object so the user can decide to pass it into the fetch request.
This pull request is missing pieces before it could be merged but wanted to open it up to feedback before going further.
scope
implementation
useEffect
topackages/fetchye/src/useFetchye.js
that runs once. Creating the new AbortController and calling its abort as part of the clean up phase on unmount.outstanding questions
request not aborting
request aborting
passed in to custom fetcher
Motivation and Context
We are currently working on a component that uses the
useFetchye
hook and we noticed during that requests were still being fulfilled even after navigating away from that component (it's unmounted).How Has This Been Tested?
Types of Changes
Checklist:
What is the Impact to Developers Using Fetchye?
If the developer is using the default fetch then the request will be aborted if the invoking component is unmounted. If using a custom fetch then the developer will see the signal as an option in the options object.