Skip to content

Remove unused Promise polyfill and promise dependency - #57777

Open
aravi365 wants to merge 1 commit into
react:mainfrom
aravi365:remove-promise-polyfill
Open

Remove unused Promise polyfill and promise dependency#57777
aravi365 wants to merge 1 commit into
react:mainfrom
aravi365:remove-promise-polyfill

Conversation

@aravi365

Copy link
Copy Markdown
Contributor

Summary

Fixes #57702.

polyfillPromise.js falls back to require('../Promise') when
HermesInternal.hasPromise() is falsy. That require is statically reachable, so
Metro bundles the promise package into every app even though Hermes apps never
execute it. Removing the fallback drops the dependency and the dead code from the
bundle.

This removes:

  • the polyfill branch in polyfillPromise.js
  • Libraries/Promise.js
  • the promise dependency and its flow-typed def

DEV unhandled-rejection tracking is unchanged, it goes through
HermesInternal.enablePromiseRejectionTracker. promiseRejectionTrackingOptions.js
imported its options type from promise/setimmediate/rejection-tracking, so that
type is now declared inline.

One thing worth a maintainer's call: the fallback also covered non-Hermes engines
(JSC, V8), which now get the engine's native Promise instead. Both ship a
spec-compliant implementation today, and the "Event loop not supported" comment
this code was written for no longer applies, but if you'd rather keep the polyfill
for those engines I can gate it instead of deleting it.

Changelog:

[GENERAL] [REMOVED] - Remove the unused Promise polyfill and the promise dependency

Test Plan

  • git grep finds no remaining references to Libraries/Promise or
    promise/setimmediate in the repo.
  • Only the promise line is removed from package.json.
  • Behaviour on Hermes is unchanged: hasPromise() is true, so global.Promise
    was already the one in use, and the DEV rejection tracker still gets the same
    options object.

I have not run the full 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.

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