Require BatchedBridge lazily in NativeModules - #58435
Open
shubh73 wants to merge 1 commit into
Open
Conversation
`NativeModules` requires `BatchedBridge` at module scope, which constructs a `MessageQueue` and defines `global.__fbBatchedBridge`. In bridgeless mode the module resolves to `global.nativeModuleProxy` and the bridge is never read again: its only users are `genModule` and `genMethod`, which run from the `__fbBatchedBridgeConfig` branch or via `__fbGenNativeModule` from the legacy executor. Bundles built with `inlineRequires` (the default in `@react-native/metro-config`) already defer this require. Bundles built without it, such as those from `@expo/metro-config`, evaluate `BatchedBridge` and `MessageQueue` at startup with no consumer. Move the require into a cached getter, matching the `RN$Bridgeless` guards in `registerCallableModule` and `JSTimers`. Changelog: [GENERAL] [CHANGED] - Require `BatchedBridge` lazily from `NativeModules` so bridgeless startup no longer instantiates `MessageQueue`. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
shubh73
force-pushed
the
lazy-batched-bridge-require
branch
from
September 10, 2026 05:58
61eb969 to
b0666a3
Compare
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:
NativeModulesrequiresBatchedBridgeat module scope, which constructs aMessageQueueand definesglobal.__fbBatchedBridge. In bridgeless mode the module resolves toglobal.nativeModuleProxyand the bridge is never read again: its only users aregenModuleandgenMethod, which run from the__fbBatchedBridgeConfigbranch or via__fbGenNativeModulefrom the legacy executor.Bundles built with
inlineRequires(the default in@react-native/metro-config) already defer this require. Bundles built without it, such as those from@expo/metro-config, evaluateBatchedBridgeandMessageQueueat startup with no consumer. This moves the require into a cached getter, matching theRN$Bridgelessguards inregisterCallableModuleandJSTimers. Bridge mode is unchanged, and bundle size is unchanged since Metro still follows the require.Changelog:
[GENERAL] [CHANGED] - Require
BatchedBridgelazily fromNativeModulesso bridgeless startup no longer instantiatesMessageQueue.Test Plan:
yarn test packages/react-native/Libraries/BatchedBridge packages/react-native/Libraries/TurboModule packages/react-native/Libraries/Core packages/react-native/Libraries/ReactNative— 6 suites, 102 tests passed.yarn flow-check— 0 errors. ESLint and Prettier clean on the file.private/helloworlddev bundle withinlineRequires: false, evaluated in a Node VM with bridgeless globals stubbed: 191 → 189 modules;BatchedBridge.jsandMessageQueue.jsno longer evaluate, nothing added.🤖 Generated with Claude Code