Repository navigation
Add support for cancelling fetch requests with AbortController - #24419
janicduplessis wants to merge 1 commit into
Conversation
|
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. |
|
@matthargett What memory leak are you talking about? Is it the one I described in #24418 or something else I should be aware of? |
8a5854f to
a38e50c
Compare
|
@matthargett we aren't going to backport new features to 0.59, let's keep this work focused on 0.60+. |
cpojer
left a comment
There was a problem hiding this comment.
@janicduplessis thank you so much, this is so good!
facebook-github-bot
left a comment
There was a problem hiding this comment.
@cpojer is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
|
This pull request was successfully merged by @janicduplessis in 5e36b0c. When will my fix make it into a release? | Upcoming Releases |
## 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)
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-shimto 5.0 to make sure we only have one version of this dependency. This updates required adding a polyfill forconsole.assertwhich 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-shimso I think it makes sense to include in core.Depends on #24418 so that the fetch polyfill supports the
signalparameter.Fixes #18115
Changelog
[General] [Added] - Add support for cancelling fetch requests with AbortController
Test Plan
Added a RNTester example of cancelling fetch requests.