Skip to content

Commit 08c3233

Browse files
zeyapmeta-codesync[bot]
authored andcommitted
Bootstrap Metro from InitializeCore until setup-env is graph-reachable (#57557)
Summary: Pull Request resolved: #57557 Fresh projects **redbox on launch** — e.g.: ``` Failed to call into JavaScript module method RCTDeviceEventEmitter.emit(). Module has not been registered as callable. Registered callable JavaScript modules (n = 1): AppRegistry. ``` (The named module varies — `HMRClient.setup()`, `RCTDeviceEventEmitter.emit()` — it's whichever callable module native calls first.) `n = 1: AppRegistry` is the tell: **core initialization never runs**. ## Root cause (#57475) Core init runs via Metro's `serializer.getModulesRunBeforeMainModule`. Metro (`metro/src/lib/getAppendScripts.js`) only emits the run-before `__r()` for a module **already present in the bundle graph**, and silently skips it otherwise: ```js const paths = [...options.runBeforeMainModule, entryPoint]; for (const path of paths) { if (modules.some((module) => module.path === path)) { // only if already in the graph /* __r(moduleId) */ } } ``` **#57475 switched the run-before target from `Libraries/Core/InitializeCore` → `src/setup-env.js`. - `InitializeCore.js` **is** reachable (imported by `Libraries/ReactPrivate/ReactNativePrivateInitializeCore.js`). - `src/setup-env.js` is imported by **nothing** → not in the graph → silently skipped → core init never runs. The two modules are functionally identical (both call `setUpDefaultReactNativeEnvironment().default()`), so only *reachability* changed. #57498 was cosmetic (same resolved file) and does not fix this. ### Evidence (bundle tail) | Run-before target | Bundle tail | Boots? | |---|---|---| | `setup-env` (current) | `__r(0);` | ❌ | | `InitializeCore` (this PR) | `__r(<InitializeCore>); __r(0);` | ✅ | Verified end-to-end via `test-release-local -t RNTestProject -p iOS`. Ruled out: Metro cache (cold `--reset-cache` identical), stale Metro, and #57484 (`./src/*` exports removal). Reproduces via the `react-native-community/cli` bundling path (OSS `react-native start`); internal Meta bundling is unaffected, which is why CI/internal stayed green. ## Scope — interim stopgap Only the **internal Metro bootstrap target** reverts to `InitializeCore`. The public `react-native/setup-env` entry point and its deprecation of `InitializeCore` are **unchanged**. The **durable fix** is to make `setup-env` graph-reachable (or make Metro treat `getModulesRunBeforeMainModule` entries as graph roots) — which will then allow `InitializeCore` to be removed as intended. cc huntie (`setup-env` stack owner). A cherry-pick of this is also up against `0.87-stable` (#57553). ## Changelog [General][Fixed] - Fix apps failing to boot ("... not registered as callable") caused by core init not running. Reviewed By: christophpurrer Differential Revision: D112002434 fbshipit-source-id: ea3559ef74d31f2c0f9af78aa0a020f4b322e7e0
1 parent ef54f74 commit 08c3233

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

packages/community-cli-plugin/src/utils/loadMetroConfig.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ function getCommunityCliDefaultConfig(
5858
return {
5959
resolver,
6060
serializer: {
61-
// We can include multiple copies of setup-env here because Metro will
61+
// We can include multiple copies of InitializeCore here because metro will
6262
// only add ones that are already part of the bundle
6363
getModulesRunBeforeMainModule: () => [
64-
require.resolve('react-native/setup-env', {
64+
require.resolve('react-native/Libraries/Core/InitializeCore', {
6565
paths: [ctx.root],
6666
}),
6767
...outOfTreePlatforms.map(platform =>
6868
require.resolve(
69-
`${ctx.platforms[platform].npmPackageName}/setup-env`,
69+
`${ctx.platforms[platform].npmPackageName}/Libraries/Core/InitializeCore`,
7070
{paths: [ctx.root]},
7171
),
7272
),

packages/metro-config/src/index.flow.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export function getDefaultConfig(projectRoot: string): ConfigT {
6161
serializer: {
6262
// NOTE: Overridden in community-cli-plugin
6363
getModulesRunBeforeMainModule: () => [
64-
require.resolve('react-native/setup-env'),
64+
require.resolve('react-native/Libraries/Core/InitializeCore'),
6565
],
6666
getPolyfills: () => require('@react-native/js-polyfills')(),
6767
isThirdPartyModule({path: modulePath}: Readonly<{path: string, ...}>) {

0 commit comments

Comments
 (0)