Skip to content

Add support for cancelling fetch requests with AbortController - #24419

Closed
janicduplessis wants to merge 1 commit into
react:masterfrom
janicduplessis:abort-controller
Closed

janicduplessis wants to merge 1 commit into
react:masterfrom
janicduplessis:abort-controller

Conversation

@janicduplessis

@janicduplessis janicduplessis commented Apr 11, 2019 •

Copy link
Copy Markdown
Contributor

Summary

This adds https://github.com/mysticatea/abort-controller to polyfill AbortController. This is used to cancel requests when using fetch.

This also updates event-target-shim to 5.0 to make sure we only have one version of this dependency. This updates required adding a polyfill for console.assert which is used by the new version. I made one based on https://github.com/gskinner/console-polyfill/blob/master/console.js#L74.

The polyfill is very small, especially since we already use event-target-shim so I think it makes sense to include in core.

Depends on #24418 so that the fetch polyfill supports the signal parameter.

Fixes #18115

Changelog

[General] [Added] - Add support for cancelling fetch requests with AbortController

Test Plan

Added a RNTester example of cancelling fetch requests.

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Expo Partner: Expo Partner labels Apr 11, 2019
@pull-bot

pull-bot commented Apr 11, 2019 •

Copy link
Copy Markdown
Warnings
⚠️ 🔒 package.json - Changes were made to package.json. This will require a manual import by a Facebook employee.

Generated by 🚫 dangerJS against a38e50c

@react-native-bot react-native-bot added 🌐Networking Related to a networking API. Includes Changelog labels Apr 11, 2019
@matthargett

Copy link
Copy Markdown
Contributor

once this (and its prerequisite PR) is merged, I'd like to propose it for backport to 0.59. @dysonpro fixed this in our apps by injecting/overriding RN's fetch with yetch (thanks @jayphelps !) and some other bits of magic.

we'd just need to make sure this doesn't introduce the same memory leak issues like the last time this abort controller support was attempted.

@janicduplessis

Copy link
Copy Markdown
Contributor Author

@matthargett What memory leak are you talking about? Is it the one I described in #24418 or something else I should be aware of?

@cpojer

cpojer commented Apr 12, 2019

Copy link
Copy Markdown
Contributor

@matthargett we aren't going to backport new features to 0.59, let's keep this work focused on 0.60+.

@cpojer cpojer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@janicduplessis thank you so much, this is so good!

@facebook-github-bot facebook-github-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cpojer is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@react-native-bot

Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @janicduplessis in 5e36b0c.

When will my fix make it into a release? | Upcoming Releases

vonovak pushed a commit to expo/expo that referenced this pull request Nov 25, 2026
## Why

`expo-notifications` depends on `abort-controller` and imports
`abort-controller/polyfill`. The package does not need this polyfill.
React Native, web browsers, and Node.js all have a global
`AbortController`.

This change is part of
[e18e/ecosystem-issues#146](e18e/ecosystem-issues#146).

## How

I removed the `abort-controller/polyfill` import from
`DevicePushTokenAutoRegistration.fx.ts` and from its test. I removed
`abort-controller` from the package dependencies.

React Native defines `AbortController` globally in
[`Libraries/Core/setUpXHR.js`](https://github.com/facebook/react-native/blob/e8fce1296b2f6922b1fe7e77305bf117a9345975/packages/react-native/Libraries/Core/setUpXHR.js#L37-L48).
It has done so since 0.60
([react/react-native#24419](react/react-native#24419)).
Web browsers and Node.js (used by Jest) have it natively. The code uses
only `new AbortController()`, `abort()`, and `signal`, so the native API
is a drop-in replacement. There is no performance impact.

`expo-notifications` was the only workspace package that used
`abort-controller`. The diff removes `abort-controller` and its
dependency `event-target-shim` from `pnpm-lock.yaml`. I edited the
lockfile by hand.

I used Claude Code to make the edit and write this description. I
reviewed the diff.

## Test Plan

I did not run `et check-packages expo-notifications`. I made the change
in a sparse checkout without a full install. This pull request is a
draft until CI passes.

## Screenshots

No UI change.

## Checklist

- [x] I added a changeset and followed [this short
guide](https://github.com/expo/expo/blob/main/CONTRIBUTING.md#-before-submitting)
- [ ] This diff will work correctly for `npx expo prebuild` & EAS Build
(eg: updated a module plugin).
- [ ] Conforms with the [Documentation Writing Style
Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. 🌐Networking Related to a networking API. p: Expo Partner: Expo Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AbortController is missing

6 participants