iOS: Add new RCTCustomBundleConfiguration
for modifying bundle URL
#54006
+292
−60
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:
Following the RFC, this PR introduces a new
RCTCustomBundleConfiguration
interface for modifying the bundle URL and exposes a new API for setting its instance in theRCTReactNativeFactory
. The configuration object includes:It associates
RCTPackagerConnection
(previously singleton) with theRCTDevSettings
instance, which has access to theRCTBundleManager
, which contains the specified configuration object. The connection is now established in theRCTDevSettings initialize
method, called after the bundle manager is set by invoking the newstartWithBundleManager
method on theRCTPackagerConnection
.The
RCTCustomBundleConfiguration
allows only for eitherbundleFilePath
or(packagerServerScheme, packagerServerHost)
to be set by defining appropriate initializers.The logic for creating bundle URL query items is extracted to a separate
createJSBundleURLQuery
method and is used byRCTBundleManager
to set the configuredpackagerServerHost
andpackagerServerScheme
. If the configuration is not defined, thegetBundleURL
method returns the result of the passedfallbackURLProvider
.The
bundleFilePath
should be created as[NSURL fileURLWithPath:<path>]
, as otherwise the HMR client is created and fails ungracefully. The check is added in thegetBundle
method to log the error beforehand.Changelog:
[IOS][ADDED] - Add new
RCTCustomBundleConfiguration
for modifying bundle URL onRCTReactNativeFactory
.Test Plan:
Tested changing
packagerServerHost
from theAppDelegate
by re-creating the React Native instance with updatedRCTCustomBundleConfiguration
. I've run two Metro instances, each serving a different JS bundle (changed background) on8081
and8082
ports. The nativeRestart RN:<current port>
button on top of the screen toggles between ports (used in bundle configuration) and re-creates connections.port-toggle-recording.mov
code:
AppDelegate.mm
AppDelegate.h