Skip to content

Add support for fetcher.abort() - #11985

Closed
brophdawg11 wants to merge 10 commits into
v6from
brophdawg11/fetcher-abort
Closed

brophdawg11 wants to merge 10 commits into
v6from
brophdawg11/fetcher-abort

Conversation

@brophdawg11

Copy link
Copy Markdown
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);
    }),
  };
}

@changeset-bot

changeset-bot Bot commented Sep 11, 2024 •

Copy link
Copy Markdown

ðŸĶ‹ 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

@brophdawg11 brophdawg11 reopened this Aug 19, 2025
@brophdawg11

Copy link
Copy Markdown
Contributor Author
  • Get updated to latest dev
  • Remove abort
  • Make reset abort if in flight
  • Add unstable_ for an alpha release

@brophdawg11

Copy link
Copy Markdown
Contributor Author

Closed in favor of #14206

@brophdawg11
brophdawg11 deleted the brophdawg11/fetcher-abort branch December 4, 2025 15:19
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