react-router
react-router copied to clipboard
Add support for fetcher.abort()
This has primarily 2 use cases:
- When using
v7_fetcherPersist, we lost the ability to actually cancel/abort fetches if a fetcher was unmounted, so this gives the users a programmatic API to achieve the previous behavior if necessary - When "streaming" data via the user of promises, once the
fetcherhas returned to "idle" there's no good way to abort/cancel the ongoing streaming data since we only tracked the controller in the router while the fetcher was in a non-idle state. This keeps those controllers around inside the router until the fetcher is deleted so that they can be programatically aborted after returning to idle
When calling abortFetcher, we simply abort the controller which will proxy through to the request.signal in the loader so you can use that to reject the promises and trigger the <Await errorElement>:
function loader({ request }) {
return {
critical: "CRITICAL",
lazy: new Promise((resolve, reject) => {
request.signal.addEventListener("abort", () =>
reject(request.signal.reason)
);
setTimeout(() => resolve("LAZY"), 3000);
}),
};
}
🦋 Changeset detected
Latest commit: 22da2428aa23cfe3a0d925e754cc2246ee9d977c
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 5 packages
| Name | Type |
|---|---|
| react-router-dom | Minor |
| @remix-run/router | Minor |
| react-router | Minor |
| react-router-dom-v5-compat | Minor |
| react-router-native | Minor |
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
- Get updated to latest
dev - Remove
abort - Make
resetabort if in flight - Add
unstable_for an alpha release
Closed in favor of https://github.com/remix-run/react-router/pull/14206