Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for fetcher.abort() #11985

Open
wants to merge 10 commits into
base: v6
Choose a base branch
from
Open

Conversation

brophdawg11
Copy link
Contributor

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 fetcher has 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);
    }),
  };
}

Copy link

changeset-bot bot commented Sep 11, 2024

🦋 Changeset detected

Latest commit: 22da242

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant