Skip to content

Expose 'react-native/setup-env' to replace InitializeCore (#57475)#57475

Closed
huntie wants to merge 1 commit into
react:mainfrom
huntie:export-D111022546
Closed

Expose 'react-native/setup-env' to replace InitializeCore (#57475)#57475
huntie wants to merge 1 commit into
react:mainfrom
huntie:export-D111022546

Conversation

@huntie

@huntie huntie commented Jul 8, 2026

Copy link
Copy Markdown
Member

Summary:

NOTE: Resubmission of D110890810.

Replace 'react-native/Libraries/Core/InitializeCore' with an explicit 'react-native/setup-env' secondary export.

This was previously a special-case path excluded from our ESLint warnings. It is now formalised.

Changes

  • Add new src/setup-env.js entry point and package.json mapping.
  • Replace references in packages/metro-config/ and packages/community-cli-plugin/.
  • Update warn-on-deep-imports ESLint rule.

Changelog:
[General][Added] - Add 'react-native/setup-env' entry point. This replaces the previous side-effectful 'react-native/Libraries/Core/InitializeCore'.
[General][Deprecated] - Deprecate 'react-native/Libraries/Core/InitializeCore'. Use 'react-native/setup-env' instead.

Reviewed By: rubennorte

Differential Revision: D111022546

@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 8, 2026
@facebook-github-tools facebook-github-tools Bot added p: Facebook Partner: Facebook Partner labels Jul 8, 2026
@meta-codesync

meta-codesync Bot commented Jul 8, 2026

Copy link
Copy Markdown

@huntie has exported this pull request. If you are a Meta employee, you can view the originating Diff in D111022546.

@meta-codesync meta-codesync Bot changed the title Expose 'react-native/setup-env' to replace InitializeCore Expose 'react-native/setup-env' to replace InitializeCore (#57475) Jul 8, 2026
huntie added a commit to huntie/react-native that referenced this pull request Jul 8, 2026
Summary:

NOTE: Resubmission of D110890810.


Replace `'react-native/Libraries/Core/InitializeCore'` with an explicit `'react-native/setup-env'` secondary export.

This was previously a special-case path excluded from our ESLint warnings. It is now formalised.

**Changes**

- Add new `src/setup-env.js` entry point and `package.json` mapping.
- Replace references in `packages/metro-config/` and `packages/community-cli-plugin/`.
- Update `warn-on-deep-imports` ESLint rule.

Changelog:  
[General][Added] - Add `'react-native/setup-env'` entry point. This replaces the previous side-effectful `'react-native/Libraries/Core/InitializeCore'`.  
[General][Deprecated] - Deprecate `'react-native/Libraries/Core/InitializeCore'`. Use `'react-native/setup-env'` instead.

Reviewed By: rubennorte

Differential Revision: D111022546
@huntie huntie force-pushed the export-D111022546 branch from 4b724fa to a3e8604 Compare July 8, 2026 13:23
Summary:

NOTE: Resubmission of D110890810.


Replace `'react-native/Libraries/Core/InitializeCore'` with an explicit `'react-native/setup-env'` secondary export.

This was previously a special-case path excluded from our ESLint warnings. It is now formalised.

**Changes**

- Add new `src/setup-env.js` entry point and `package.json` mapping.
- Replace references in `packages/metro-config/` and `packages/community-cli-plugin/`.
- Update `warn-on-deep-imports` ESLint rule.

Changelog:  
[General][Added] - Add `'react-native/setup-env'` entry point. This replaces the previous side-effectful `'react-native/Libraries/Core/InitializeCore'`.  
[General][Deprecated] - Deprecate `'react-native/Libraries/Core/InitializeCore'`. Use `'react-native/setup-env'` instead.

Reviewed By: rubennorte

Differential Revision: D111022546
@huntie huntie force-pushed the export-D111022546 branch from a3e8604 to b5b6a7a Compare July 8, 2026 15:07
huntie added a commit to huntie/react-native that referenced this pull request Jul 8, 2026
Summary:

NOTE: Resubmission of D110890810.


Replace `'react-native/Libraries/Core/InitializeCore'` with an explicit `'react-native/setup-env'` secondary export.

This was previously a special-case path excluded from our ESLint warnings. It is now formalised.

**Changes**

- Add new `src/setup-env.js` entry point and `package.json` mapping.
- Replace references in `packages/metro-config/` and `packages/community-cli-plugin/`.
- Update `warn-on-deep-imports` ESLint rule.

Changelog:  
[General][Added] - Add `'react-native/setup-env'` entry point. This replaces the previous side-effectful `'react-native/Libraries/Core/InitializeCore'`.  
[General][Deprecated] - Deprecate `'react-native/Libraries/Core/InitializeCore'`. Use `'react-native/setup-env'` instead.

Reviewed By: rubennorte

Differential Revision: D111022546
huntie added a commit to huntie/react-native that referenced this pull request Jul 8, 2026
Summary:

NOTE: Resubmission of D110890810.


Replace `'react-native/Libraries/Core/InitializeCore'` with an explicit `'react-native/setup-env'` secondary export.

This was previously a special-case path excluded from our ESLint warnings. It is now formalised.

**Changes**

- Add new `src/setup-env.js` entry point and `package.json` mapping.
- Replace references in `packages/metro-config/` and `packages/community-cli-plugin/`.
- Update `warn-on-deep-imports` ESLint rule.

Changelog:  
[General][Added] - Add `'react-native/setup-env'` entry point. This replaces the previous side-effectful `'react-native/Libraries/Core/InitializeCore'`.  
[General][Deprecated] - Deprecate `'react-native/Libraries/Core/InitializeCore'`. Use `'react-native/setup-env'` instead.

Reviewed By: rubennorte

Differential Revision: D111022546
@meta-codesync meta-codesync Bot closed this in bfa679f Jul 8, 2026
@meta-codesync meta-codesync Bot added the Merged This PR has been merged. label Jul 8, 2026
@meta-codesync

meta-codesync Bot commented Jul 8, 2026

Copy link
Copy Markdown

This pull request has been merged in bfa679f.

@huntie huntie deleted the export-D111022546 branch July 8, 2026 16:38
cipolleschi added a commit that referenced this pull request Jul 9, 2026
#57475 pointed Metro's getModulesRunBeforeMainModule at
'react-native/setup-env' (src/setup-env.js) instead of InitializeCore.
Metro only runs modules from that list that are already part of the
bundle graph (getAppendScripts: modules.some(m => m.path === path)), and
nothing imports src/setup-env.js at runtime, so it was silently dropped.
The RN environment (HMRClient, timers, batched bridge, AppRegistry
setup...) then no longer ran before the app's main module, producing a
launch-time redbox:

  Failed to call into JavaScript module method HMRClient.setup().
  Module has not been registered as callable.

This broke the template E2E tests (blank screen, 'Welcome to React
Native' never visible) on both iOS and Android.

Fix: have the deprecated InitializeCore delegate to 'react-native/setup-env'
via a side-effectful require. InitializeCore is a guaranteed graph entry
(via ReactNativePrivateInitializeCore), so this pulls src/setup-env.js
into the graph and getModulesRunBeforeMainModule runs it before main
again. Behavior is unchanged (both ultimately call
setUpDefaultReactNativeEnvironment, which is idempotent).
meta-codesync Bot pushed a commit that referenced this pull request Jul 9, 2026
Summary:
#57475 pointed Metro's `getModulesRunBeforeMainModule` at `react-native/setup-env` (`src/setup-env.js`) instead of `InitializeCore`.

But Metro's serializer only emits a run-before-main require for modules **already in the bundle graph** — see `getAppendScripts`:

```js
const paths = [...options.runBeforeMainModule, entryPoint];
for (const path of paths) {
  if (modules.some(module => module.path === path)) { /* emit run stmt */ }
}
```

Nothing imports `src/setup-env.js` at runtime, so it was silently dropped. The RN environment setup (`setUpDefaultReactNativeEnvironment`: `HMRClient`, timers, batched bridge, `AppRegistry` setup, …) then never ran before the app's main module, and the app **redboxed on launch**:

```
Error: Failed to call into JavaScript module method HMRClient.setup().
Module has not been registered as callable.
Registered callable JavaScript modules (n = 1): AppRegistry.
```

This broke the **template E2E tests** on both iOS and Android — the app renders a redbox, so Maestro's `assertVisible: 'Welcome to React Native'` fails (the `test (…)` jobs are green only because the Maestro step runs with `continue-on-error: true`; the real failure surfaces via the retry chain and the `retry_2 / report` job).

## Fix

Have the deprecated `InitializeCore` delegate to `'react-native/setup-env'` via a side-effectful `require`. `InitializeCore` is a guaranteed graph entry (renderer → `ReactNativePrivateInitializeCore` → `InitializeCore`), so this pulls `src/setup-env.js` into the graph, and `getModulesRunBeforeMainModule` runs it before the main module again.

Behavior is unchanged: `setup-env` and `InitializeCore` both call the idempotent `setUpDefaultReactNativeEnvironment()`. This keeps #57475 move to `setup-env` intact rather than reverting it.

## Changelog:
[General][Fixed] - Fix app failing to initialize (`HMRClient.setup()` redbox) because the environment setup module was dropped from the bundle

Pull Request resolved: #57492

Test Plan:
- Template E2E (`test_e2e_ios_templateapp` / `test_e2e_android_templateapp`) should pass: app launches and shows "Welcome to React Native" instead of the redbox.

cc huntie (#57475)

Reviewed By: cipolleschi

Differential Revision: D111226610

Pulled By: huntie

fbshipit-source-id: b44e82a248c1f2333c2ea85001c9f243b54619ad
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. Merged This PR has been merged. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant