-
Notifications
You must be signed in to change notification settings - Fork 47.2k
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 fallback shim for AbortController #24285
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if it's only on for enableCache
builds, I think we shouldn't ship this in any browser bundles.
d89603a
to
646ebad
Compare
646ebad
to
6745d48
Compare
This seems reasonable to me — is this concern addressed? My naive understanding of packaging suggests the code would still be included but maybe i'm overlooking something. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't think of this as implementing AbortController. It's more about we need fallback "signal" implementation that we can return if the native AbortController isn't available.
The signal object should have:
- addEventListener that only supports a single event type (
abort
) - a boolean
aborted
field
and that's it. We don't need all the indirection of a controller object because the controller is only an implementation detail.
The thing to optimize for here is code size, not performance. What's the smallest possible implementation you can write? I probably wouldn't even put in a separate file, just inline it into the cache signal implementation.
@acdlite we also need dispatchEvent and to call the registered listeners, correct? |
If in the end the code size is too large, we can have it fall back to returning The first order purpose of this task is for the experimental React build to not break if you run it in a node/test environment. So if getCacheSignal returns null that's fine, since nobody is using it yet. |
React can call the listeners directly without going through a |
Comparing: ebd7ff6...afe0c82 Critical size changesIncludes critical production bundles, as well as any change greater than 2%:
Significant size changesIncludes any change greater than 0.2%: Expand to show
|
Updated based on feedback, thanks all! @acdlite is that more in line with what you were thinking? @josephsavona @gaearon is this small enough to ease your concerns? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems ok but we should add to the umbrella to drop this in 19 together with support for running tests in old Node. 16 is already LTS.
shipit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a nit here but other than that looks good to me! https://github.com/facebook/react/pull/24285/files#r845539601
Hmm by the history of sizebot edits the last version is a tiny bit larger. |
One nice thing about the fake class implementation, despite the non-mangled names, is that the normal path (no fallback) doesn't have any additional runtime overhead (the |
Yeah @acdlite good point. I reverted back to the object constructor and squeezed out a little more by dropping |
* Add fallback shim for AbortController * Replace shim with a minimal stub * replace-fork * Better minification * Fix flow * Even smaller * replace-fork * Revert back to object constructor * replace-fork
Summary: This sync includes the following changes: - **[8dcedba15](facebook/react@8dcedba15 )**: Add fallback shim for AbortController ([#24285](facebook/react#24285)) //<Ricky>// - **[b86baa1cb](facebook/react@b86baa1cb )**: Add back lost cache test ([#24317](facebook/react#24317)) //<Ricky>// - **[bafe912a5](facebook/react@bafe912a5 )**: update types for InputContinuousLane and DefaultLane ([#24316](facebook/react#24316)) //<Leo>// - **[4ebaeae40](facebook/react@4ebaeae40 )**: moved mutation code to passive ([#24251](facebook/react#24251)) //<Luna Ruan>// - **[caa60e8fc](facebook/react@caa60e8fc )**: update types for NonIdleLanes and IdleLane ([#24313](facebook/react#24313)) //<Leo>// - **[1f7a901d7](facebook/react@1f7a901d7 )**: Fix false positive lint error with large number of branches ([#24287](facebook/react#24287)) //<Stephen Cyron>// - **[f56dfe950](facebook/react@f56dfe950 )**: Warn on setState() in useInsertionEffect() ([#24298](facebook/react#24298)) //<dan>// - **[d68b09def](facebook/react@d68b09def )**: Fix warning about setState in useEffect ([#24295](facebook/react#24295)) //<dan>// - **[057915477](facebook/react@057915477 )**: Update create-subscription README ([#24294](facebook/react#24294)) //<dan>// Changelog: [General][Changed] - React Native sync for revisions e8f4a66...8dcedba jest_e2e[run_all_tests] Reviewed By: kacieb Differential Revision: D35581147 fbshipit-source-id: 33661d77eb000fdedab7e506a458fc739eab0056
* Add fallback shim for AbortController * Replace shim with a minimal stub * replace-fork * Better minification * Fix flow * Even smaller * replace-fork * Revert back to object constructor * replace-fork
* Add fallback shim for AbortController * Replace shim with a minimal stub * replace-fork * Better minification * Fix flow * Even smaller * replace-fork * Revert back to object constructor * replace-fork
Summary: This sync includes the following changes: - **[8dcedba15](facebook/react@8dcedba15 )**: Add fallback shim for AbortController ([facebook#24285](facebook/react#24285)) //<Ricky>// - **[b86baa1cb](facebook/react@b86baa1cb )**: Add back lost cache test ([facebook#24317](facebook/react#24317)) //<Ricky>// - **[bafe912a5](facebook/react@bafe912a5 )**: update types for InputContinuousLane and DefaultLane ([facebook#24316](facebook/react#24316)) //<Leo>// - **[4ebaeae40](facebook/react@4ebaeae40 )**: moved mutation code to passive ([facebook#24251](facebook/react#24251)) //<Luna Ruan>// - **[caa60e8fc](facebook/react@caa60e8fc )**: update types for NonIdleLanes and IdleLane ([facebook#24313](facebook/react#24313)) //<Leo>// - **[1f7a901d7](facebook/react@1f7a901d7 )**: Fix false positive lint error with large number of branches ([facebook#24287](facebook/react#24287)) //<Stephen Cyron>// - **[f56dfe950](facebook/react@f56dfe950 )**: Warn on setState() in useInsertionEffect() ([facebook#24298](facebook/react#24298)) //<dan>// - **[d68b09def](facebook/react@d68b09def )**: Fix warning about setState in useEffect ([facebook#24295](facebook/react#24295)) //<dan>// - **[057915477](facebook/react@057915477 )**: Update create-subscription README ([facebook#24294](facebook/react#24294)) //<dan>// Changelog: [General][Changed] - React Native sync for revisions e8f4a66...8dcedba jest_e2e[run_all_tests] Reviewed By: kacieb Differential Revision: D35581147 fbshipit-source-id: 33661d77eb000fdedab7e506a458fc739eab0056
Adds a lightweight fallback shim for environments that don't have an AbortController (e.g. tests running in Node < 15).