Remove the Promise polyfill fallback so the promise package isn't bundled - #57777
Remove the Promise polyfill fallback so the promise package isn't bundled#57777aravi365 wants to merge 2 commits into
Conversation
Every supported JS engine ships a native Promise, but the polyfill branch in polyfillPromise.js is statically reachable, so Metro bundles the promise package into every app even though it is never used. Remove the dead branch, Libraries/Promise.js and the promise dependency. DEV unhandled-rejection tracking is unchanged. Fixes react#57702
|
@robhogan has imported this pull request. If you are a Meta employee, you can view this in D114354694. |
|
@robhogan you imported this on 31 Jul and both internal checks have been red since. I can't see the internal logs from out here, so I'm guessing: is something in the internal codebase still importing Happy to narrow this if it helps. I can keep the polyfill and gate it so only non-Hermes engines load it, which leaves any internal call sites working while still keeping Let me know which you'd prefer and I'll push it. |
Keep Libraries/Promise.js, the promise dependency and its flow-typed def, so anything that imports them directly still builds. Deleting the else branch on its own is enough to stop Metro bundling the promise package, which is what react#57702 is about.
|
Cut this down to just deleting the |
Summary
Fixes #57702.
polyfillPromise.jsrequires../PromisewhenHermesInternal.hasPromise()is falsy. Metro can't evaluate that at build time, so it bundles the require anyway and thepromisepackage ends up in every app, even though Hermes apps never reach that branch.This deletes the
elsebranch and nothing else.Libraries/Promise.js, thepromisedependency and its flow-typed def all stay, so anything importing them directly keeps working. They just aren't pulled in from the startup path anymore.I originally removed those files too, but both internal checks went red and I can't see why from out here, so I've cut it down to the part that actually fixes the bundle.
It does mean non-Hermes engines (JSC, V8) no longer get the polyfill from InitializeCore and use their own
Promise. They've had one for years, but it's still a behavior change so flagging it.Changelog:
[GENERAL] [REMOVED] - Remove the Promise polyfill fallback from InitializeCore so the promise package is no longer bundled
Test Plan
polyfillPromise.jschanges. Nothing else in the repo requiresLibraries/Promise(checked all 2042 tracked.jsfiles underpackages/), so after this nothing on the startup path pulls inpromise.hasPromise()is true there, so the removed branch never ran, and DEV rejection tracking still gets the same options.I haven't run the JS suite locally, relying on CI for
test_js, Flow and lint.