Keep react-native/setup-env reachable in the module graph#57492
Open
cipolleschi wants to merge 1 commit into
Open
Keep react-native/setup-env reachable in the module graph#57492cipolleschi wants to merge 1 commit into
cipolleschi wants to merge 1 commit into
Conversation
#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).
1a7506e to
77d0d84
Compare
huntie
approved these changes
Jul 9, 2026
Member
There was a problem hiding this comment.
Thanks for this catch 🙏🏻
Edit: Just making sure why InitializeCore.js does get depended on as I can't see a code reference. But if E2E tests pass then let's land.
Edit 2: Found it!: https://github.com/react/react/blob/5123b063a7b3cd5c42ea2be2ccebe4e68d8b12e3/packages/react-native-renderer/src/ReactNativeInjectionShared.js#L17
|
@huntie has imported this pull request. If you are a Meta employee, you can view this in D111226610. |
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.
Summary
#57475 pointed Metro's
getModulesRunBeforeMainModuleatreact-native/setup-env(src/setup-env.js) instead ofInitializeCore.But Metro's serializer only emits a run-before-main require for modules already in the bundle graph — see
getAppendScripts:Nothing imports
src/setup-env.jsat runtime, so it was silently dropped. The RN environment setup (setUpDefaultReactNativeEnvironment:HMRClient, timers, batched bridge,AppRegistrysetup, …) then never ran before the app's main module, and the app redboxed on launch: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 (thetest (…)jobs are green only because the Maestro step runs withcontinue-on-error: true; the real failure surfaces via the retry chain and theretry_2 / reportjob).Fix
Have the deprecated
InitializeCoredelegate to'react-native/setup-env'via a side-effectfulrequire.InitializeCoreis a guaranteed graph entry (renderer →ReactNativePrivateInitializeCore→InitializeCore), so this pullssrc/setup-env.jsinto the graph, andgetModulesRunBeforeMainModuleruns it before the main module again.Behavior is unchanged:
setup-envandInitializeCoreboth call the idempotentsetUpDefaultReactNativeEnvironment(). This keeps #57475's move tosetup-envintact rather than reverting it.Changelog:
[General][Fixed] - Fix app failing to initialize (
HMRClient.setup()redbox) because the environment setup module was dropped from the bundleTest Plan
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)