Skip to content

fix: remove dead promise polyfill import from polyfillPromise.js - #57807

Open
stareezy-1 wants to merge 1 commit into
react:mainfrom
stareezy-1:fix/remove-dead-promise-polyfill
Open

fix: remove dead promise polyfill import from polyfillPromise.js#57807
stareezy-1 wants to merge 1 commit into
react:mainfrom
stareezy-1:fix/remove-dead-promise-polyfill

Conversation

@stareezy-1

Copy link
Copy Markdown

Summary

Removes the dead else branch in polyfillPromise.js that imports the promise package. Since Hermes is the only supported JS engine and always provides a native Promise, hasPromise() is always true and the polyfill path can never execute.

Fixes #57702

Changelog:

[GENERAL] [REMOVED] - Dead promise polyfill code path in polyfillPromise.js

Problem

polyfillPromise.js conditionally imports the promise package (~15KB) via ../Promise in an else branch that can never execute:

if (global?.HermesInternal?.hasPromise?.()) {
  // Always true — Hermes is the only supported engine
} else {
  // Dead code — promise package is bundled but never used
  polyfillGlobal('Promise', () => require('../Promise').default);
}

This adds unnecessary weight to every React Native app's JS bundle.

Changes

  • Removed the dead else branch
  • Removed the unused polyfillGlobal import
  • Simplified the condition since Hermes is guaranteed
  • Preserved the __DEV__ promise rejection tracking setup

Test Plan

  • The promise package is no longer bundled in the JS output
  • Promise behavior is unchanged (Hermes native Promise was always used in practice)
  • Dev-mode rejection tracking still works via HermesInternal.enablePromiseRejectionTracker

Since Hermes is the only supported JS engine and always provides a native
Promise implementation, the `else` branch in polyfillPromise.js that
imports the `promise` package via `../Promise` is dead code that can
never execute (`hasPromise()` is always true).

This dead import causes the bundler to include the entire `promise`
package (~15KB) in every app's JS bundle despite it never being used.

Remove the dead branch and the unused `polyfillGlobal` import.

Fixes react#57702
@meta-cla

meta-cla Bot commented Aug 4, 2026

Copy link
Copy Markdown

Hi @stareezy-1!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@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 Aug 4, 2026
@meta-cla

meta-cla Bot commented Aug 4, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@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 Aug 4, 2026
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