Skip to content

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

Description

@retyui

Description

Currently we have a runtime check for hasPromise() that leads to bundling a dead code (promise package) in the final JS bundle

// If global.Promise is provided by Hermes, we are confident that it can provide
// all the methods needed by React Native, so we can directly use it.
if (global?.HermesInternal?.hasPromise?.()) {
const HermesPromise = global.Promise;
if (__DEV__) {
if (typeof HermesPromise !== 'function') {
console.error('HermesPromise does not exist');
}
global.HermesInternal?.enablePromiseRejectionTracker?.(
require('../promiseRejectionTrackingOptions').default,
);
}
} else {
polyfillGlobal('Promise', () => require('../Promise').default);
}

hasPromise () is true by default so promise package code is never used by thousands apps in productions

Steps to reproduce

...

React Native Version

0.86.0

Affected Platforms

Runtime - Android, Runtime - iOS

Output of npx @react-native-community/cli info

System:
  OS: macOS 26.5
  CPU: (11) arm64 Apple M3 Pro
  Memory: 5.12 GB / 36.00 GB
  Shell:
    version: 4.0.1
    path: /opt/homebrew/bin/fish
Binaries:
  Node:
    version: 24.13.1
    path: /usr/local/bin/node
  Yarn:
    version: 3.6.4
    path: /opt/homebrew/bin/yarn
  npm:
    version: 11.8.0
    path: /usr/local/bin/npm
  Watchman:
    version: 2025.09.01.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.16.2
    path: /Users/i/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 25.2
      - iOS 26.2
      - macOS 26.2
      - tvOS 26.2
      - visionOS 26.2
      - watchOS 26.2
  Android SDK:
    API Levels:
      - "34"
      - "35"
      - "36"
    Build Tools:
      - 33.0.1
      - 34.0.0
      - 35.0.0
      - 36.0.0
      - 37.0.0
    System Images:
      - android-34 | Android TV ARM 64 v8a
      - android-34 | Google TV ARM 64 v8a
      - android-35 | Google APIs ARM 64 v8a
      - android-35 | Google Play ARM 64 v8a
      - android-36 | Android TV ARM 64 v8a
      - android-36 | Google TV ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2026.1 AI-261.23567.138.2611.15646644
  Xcode:
    version: 26.2/17C52
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.13
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /Users/i/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 20.1.0
    wanted: 20.1.0
  react:
    installed: 19.2.3
    wanted: 19.2.3
  react-native:
    installed: 0.86.0
    wanted: 0.86.0
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: Not found
  newArchEnabled: false

Stacktrace or Logs

...

MANDATORY Reproducer

https://github.com/retyui/repo_with_virus_to_steal_corporate_data_so_you_get_fired_and_spend_the_rest_of_your_life_in_prison

Screenshots and Videos

Image

Activity

  1. changed the title [-]polyfillPromise.js imports a `promise` package that never used as HermesPromise is always true[/-] [+]polyfillPromise.js imports a `promise` package that never used as `hasPromise()` is always true[/+] on Jul 27, 2026
  2. added a commit that references this issue on Jul 31, 2026
    9d38b80
  3. stareezy-1 commented on Aug 4, 2026

    @stareezy-1
    Contributor

    Since Hermes is the only supported JS engine and hasPromise() always returns true, the else branch that calls polyfillGlobal('Promise', ...) is dead code. The promise package (~15KB) gets bundled in every app but never executes.

    Fix: removed the dead else branch and the unused polyfillGlobal import. PR submitted.

  4. retyui commented on Aug 4, 2026

    @retyui
    ContributorAuthor

    @stareezy-1 from what version Hermes engine includes Promise bundled by default ?

  5. stareezy-1 commented on Aug 4, 2026

    @stareezy-1
    Contributor

    @retyui
    Hermes has included a native Promise implementation since it was first integrated into React Native. The HermesInternal.hasPromise() check was added in RN 0.64 (2021) when Hermes gained its built-in Promise with microtask support, and it has returned true ever since.

    Since RN 0.70 (September 2022), Hermes became the default JS engine — meaning from 0.70 onward, the else branch (the promise package polyfill) has been dead code for all default configurations. JSC was still technically supported as an opt-in alternative until recently, but as of RN 0.86, Hermes is the only supported engine and JSC support has been removed.

    So in summary:

    • RN 0.64+: Hermes has native Promise (hasPromise() always true when Hermes is enabled)
    • RN 0.70+: Hermes is the default engine (polyfill branch dead for default configs)
    • RN 0.86+: Hermes is the only supported engine (polyfill branch dead unconditionally)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions