feat(react-native-host): extend RNXHostConfig with optional host hooks (1/3)#4144
Draft
Saadnajmi wants to merge 1 commit intomicrosoft:mainfrom
Draft
feat(react-native-host): extend RNXHostConfig with optional host hooks (1/3)#4144Saadnajmi wants to merge 1 commit intomicrosoft:mainfrom
Saadnajmi wants to merge 1 commit intomicrosoft:mainfrom
Conversation
0f20017 to
a1128b2
Compare
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.
a1128b2 to
1685ee4
Compare
Saadnajmi
commented
May 11, 2026
|
|
||
| /// Called after the JS instance has finished loading. ``error`` is ``nil`` | ||
| /// on success. | ||
| - (void)host:(ReactNativeHost *)host didLoadInstanceWithError:(nullable NSError *)error |
Contributor
Author
There was a problem hiding this comment.
I'm a little iffy with the optional error parameter.. the signature makes it feel like there is always an error despite the comment. Alternative is to also expose failedtoLoadInstanceWithError. Thoughts?
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
Adds three optional lifecycle hooks to
RNXHostConfig. All three are opt-in viarespondsToSelector:— consumers that don't implement them see no behavior change.host:didLoadInstanceWithError:andhostWillUnloadInstance:ReactNativeHostsubscribes toRCTJavaScriptDidLoadNotification,RCTJavaScriptDidFailToLoadNotification, andRCTBridgeWillBeInvalidatedNotificationwhen the config implements thecorresponding selectors, and forwards.
-deallocremoves the observers.Works in both bridge and bridgeless modes — the same notifications fire in both.
host:didInitializeRuntime:(Objective-C++ only)Fires inside the bridgeless
RCTHostruntime-initialization lambda, after host bindings install (TurboModules, native logger, native component registry) but before the user JSbundle loads. Useful for evaluating pre-user JS on the runtime — e.g., bundles that must be available before app code runs via
runtime.evaluateJavaScript.Bridgeless mode only. Wired via an internal
_RNXForwardingRCTHostDelegatepassed asRCTHost'shostDelegate(wasnil). Retained as an ivar becauseRCTHoststores host delegatesweakly. C++-typed (
jsi::Runtime &), so only visible to Objective-C++ consumers.Test plan
Tested internally