Repository navigation
fix(bundler-metro): run InitializeCore from the react-native copy in the bundle - #207
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is this?
Harness no longer skips React Native's
InitializeCorewhen a monorepo has more than one copy ofreact-native. In that setup the app crashed at startup withReferenceError: 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 afterapps/playground-vegaadded React Native 0.83.0 to the workspace, which gaveapps/playgroundits own nested copy ofreact-native.How does it work?
@react-native/metro-configresolvesInitializeCorefrom the project root and lists it inserializer.getModulesRunBeforeMainModule. The bundle, however, getsreact-nativethrough 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, soInitializeCorewas bundled but never executed.Harness now wraps
getModulesRunBeforeMainModuleand replaces anyreact-native/Libraries/Core/InitializeCore.jspath 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'sInitializeCore, 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.tswent from failing at startup to 14 of 14 tests passing, both in a plain run and in a--watchrerun, and the bundle now callsInitializeCorebefore the Harness entry point.