feat(react-native-host): expose auxiliary RCTTurboModuleManagerDelegate via RNXHostConfig (2/3)#4145
Draft
Saadnajmi wants to merge 2 commits intomicrosoft:mainfrom
Draft
Conversation
Adds three optional lifecycle hooks to RNXHostConfig. All three are opt-in; consumers that don't implement them see no behavior change. * host:didLoadInstanceWithError: and hostWillUnloadInstance: ReactNativeHost subscribes to RCTJavaScriptDidLoad, RCTJavaScriptDidFailToLoad, and RCTBridgeWillBeInvalidated notifications and forwards to the config when the corresponding selectors are implemented. dealloc removes observers. * host:didInitializeRuntime: (Objective-C++ only) fires inside the bridgeless runtime-init lambda, after host bindings install but before the user JS bundle loads. Useful for loading pre-user JS (e.g. platform bundles) via runtime.evaluateJavaScript before the app bundle runs. Wired via an internal _RNXForwardingRCTHostDelegate passed as RCTHost's hostDelegate (was nil); retained as an ivar because RCTHost stores host delegates weakly.
…te via RNXHostConfig Add an optional `turboModuleManagerDelegate` property to `RNXHostConfig` that lets the consumer participate in TurboModule construction without replacing `RNXTurboModuleAdapter`. The adapter consults it via `respondsToSelector:` before its existing defaults; returning `Nil` / `nil` falls through to the previous behavior (`RCTCoreModulesClassProvider`, `RCTAppSetupDefaultModuleFromClass` / `[cls new]`). The shape mirrors how bridge mode lets consumers vend pre-constructed modules via `RCTBridgeDelegate.extraModulesForBridge:` -- a per-host injection point for modules that carry consumer-side state (e.g., `RCTExceptionsManager` with a custom delegate, `RCTDevSettings` with a custom data source).
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.
Description
Depends on #4144
Adds an optional
turboModuleManagerDelegateproperty toRNXHostConfigthat lets consumers participate in TurboModule construction without replacingRNXTurboModuleAdapter.Motivation
RNXTurboModuleAdapteris rnx-kit'sRCTTurboModuleManagerDelegate. Today it owns the full TurboModule construction path:getModuleClassFromName:falls back toRCTCoreModulesClassProvidergetModuleInstanceFromClass:falls back toRCTAppSetupDefaultModuleFromClassFor modules that need per-host state — e.g., an
RCTExceptionsManagerinitialized with a per-host delegate, or anRCTDevSettingswith a custom data source — there's no extensionpoint. In bridge mode this case is handled via
RCTBridgeDelegate.extraModulesForBridge:(the bridge prefers pre-constructed instances vended there). In bridgeless mode, that hookisn't called — modules go through
RCTTurboModuleManager.delegateinstead.Design
RNXHostConfigadds:@property (nonatomic, readonly, weak, nullable) id<RCTTurboModuleManagerDelegate> turboModuleManagerDelegate;RNXTurboModuleAdapteradds ahostConfigweak reference and, for eachRCTTurboModuleManagerDelegatemethod it implements, consults the auxiliary viarespondsToSelector:first;returning
nil/Nilfalls through to the existing default behavior.Same shape for
getModuleInstanceFromClass:.Properties
extraModulesForBridge:: the per-host injection point that bridge consumers use.turboModuleManagerDelegatesee no behavior change.RCTTurboModuleManagerDelegatemethod (getModuleProvider:,getTurboModule:jsInvoker:, etc.) the consumer implements is routedautomatically — no per-hook plumbing required in rnx-kit.
respondsToSelector:check.Example
Test plan
Tested internally