Skip to content

fix(bundler-metro): run InitializeCore from the react-native copy in the bundle - #207

Merged
V3RON merged 2 commits into
mainfrom
fix/run-before-main-module
Oct 16, 2026
Merged

V3RON merged 2 commits into
mainfrom
fix/run-before-main-module

Conversation

@V3RON

@V3RON V3RON commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

What is this?

Harness no longer skips React Native's InitializeCore when a monorepo has more than one copy of react-native. In that setup the app crashed at startup with ReferenceError: Property 'window' doesn't exist, HMRClient.setup() was never registered, and Harness timed out with "did not become ready within 120000ms". The playground hit this after apps/playground-vega added React Native 0.83.0 to the workspace, which gave apps/playground its own nested copy of react-native.

How does it work?

@react-native/metro-config resolves InitializeCore from the project root and lists it in serializer.getModulesRunBeforeMainModule. The bundle, however, gets react-native through the Harness runtime, which can resolve to a different copy. Metro only emits a run-before-main call for paths that are in the module graph and silently drops the rest, so InitializeCore was bundled but never executed.

Harness now wraps getModulesRunBeforeMainModule and replaces any react-native/Libraries/Core/InitializeCore.js path with the one resolved from @react-native-harness/runtime, which is the copy in the bundle. Other run-before-main modules, such as the Vega fork's InitializeCore, are left unchanged.

Why is this useful?

Harness works in monorepos with mixed React Native versions instead of failing with a timeout that gives no hint of the cause. On the playground's Android emulator, hooks.harness.ts went from failing at startup to 14 of 14 tests passing, both in a plain run and in a --watch rerun, and the bundle now calls InitializeCore before the Harness entry point.

@vercel

vercel Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
react-native-harness Ready Ready Preview Oct 16, 2026 11:06am UTC

Request Review

@V3RON
V3RON merged commit 48abeeb into main Oct 16, 2026
6 checks passed
@V3RON
V3RON deleted the fix/run-before-main-module branch October 16, 2026 11:27

This branch was successfully deployed

1 active deployment
Preview — 30293fe5 Deployed Oct 16, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant