Skip to content

Commit dce5283

Browse files
committed
fix: remove dead promise polyfill import
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 #57702
1 parent 3a95e0e commit dce5283

1 file changed

Lines changed: 10 additions & 17 deletions

File tree

packages/react-native/Libraries/Core/polyfillPromise.js

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,22 @@
1010

1111
'use strict';
1212

13-
const {polyfillGlobal} = require('../Utilities/PolyfillFunctions');
14-
1513
/**
16-
* Set up Promise. The native Promise implementation throws the following error:
17-
* ERROR: Event loop not supported.
14+
* Set up Promise. Hermes provides a native Promise implementation that
15+
* satisfies all requirements of React Native.
1816
*
1917
* If you don't need these polyfills, don't use InitializeCore; just directly
2018
* require the modules you need from InitializeCore for setup.
2119
*/
2220

23-
// If global.Promise is provided by Hermes, we are confident that it can provide
24-
// all the methods needed by React Native, so we can directly use it.
25-
if (global?.HermesInternal?.hasPromise?.()) {
26-
const HermesPromise = global.Promise;
21+
// Hermes is the only supported JS engine and always provides Promise natively.
22+
const HermesPromise = global.Promise;
2723

28-
if (__DEV__) {
29-
if (typeof HermesPromise !== 'function') {
30-
console.error('HermesPromise does not exist');
31-
}
32-
global.HermesInternal?.enablePromiseRejectionTracker?.(
33-
require('../promiseRejectionTrackingOptions').default,
34-
);
24+
if (__DEV__) {
25+
if (typeof HermesPromise !== 'function') {
26+
console.error('HermesPromise does not exist');
3527
}
36-
} else {
37-
polyfillGlobal('Promise', () => require('../Promise').default);
28+
global.HermesInternal?.enablePromiseRejectionTracker?.(
29+
require('../promiseRejectionTrackingOptions').default,
30+
);
3831
}

0 commit comments

Comments
 (0)