Skip to content

Remove the Promise polyfill fallback so the promise package isn't bundled - #57777

Open
aravi365 wants to merge 2 commits into
react:mainfrom
aravi365:remove-promise-polyfill
Open

Remove the Promise polyfill fallback so the promise package isn't bundled#57777
aravi365 wants to merge 2 commits into
react:mainfrom
aravi365:remove-promise-polyfill

Conversation

@aravi365

@aravi365 aravi365 commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #57702.

polyfillPromise.js requires ../Promise when HermesInternal.hasPromise() is falsy. Metro can't evaluate that at build time, so it bundles the require anyway and the promise package ends up in every app, even though Hermes apps never reach that branch.

This deletes the else branch and nothing else. Libraries/Promise.js, the promise dependency 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

  • Only polyfillPromise.js changes. Nothing else in the repo requires Libraries/Promise (checked all 2042 tracked .js files under packages/), so after this nothing on the startup path pulls in promise.
  • Hermes is unchanged. 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.

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
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 31, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Jul 31, 2026
@meta-codesync

meta-codesync Bot commented Jul 31, 2026

Copy link
Copy Markdown

@robhogan has imported this pull request. If you are a Meta employee, you can view this in D114354694.

@aravi365

Copy link
Copy Markdown
Contributor Author

@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 Libraries/Promise or the promise package?

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 promise out of Hermes bundles. Or I can split it so this PR only drops the dead branch and leaves the dependency in place.

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.
@aravi365 aravi365 changed the title Remove unused Promise polyfill and promise dependency Remove the Promise polyfill fallback so the promise package isn't bundled Sep 13, 2026
@aravi365

Copy link
Copy Markdown
Contributor Author

Cut this down to just deleting the else branch, as offered in the description. Libraries/Promise.js, the promise dependency and its flow-typed def are back, in case something internal was importing them and that's what the internal checks were tripping on. The bundle fix itself is the same.

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. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

polyfillPromise.js imports a promise package that never used as hasPromise() is always true

1 participant