Repository navigation
Conversation
coado
marked this pull request as ready for review
October 20, 2025 13:59
RCTCustomBundleConfiguration for modifying bundle URLRCTBundleConfiguration for modifying bundle URL
…54006) Summary: ## Summary: Following the [RFC](react-native-community/discussions-and-proposals#933), this PR introduces a new `RCTBundleConfiguration` interface for modifying the bundle URL and exposes a new API for setting its instance in the `RCTReactNativeFactory`. The configuration object includes: - bundleFilePath - the URL of the bundle to load from the file system, - packagerServerScheme - the server scheme (e.g. http or https) to use when loading from the packager, - packagerServerHost - the server host (e.g. localhost) to use when loading from the packager. The `RCTBundleConfiguration` allows only for either `bundleFilePath` 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 by `RCTBundleManager` to set the configured `packagerServerHost` and `packagerServerScheme`. If the configuration is not defined, the `getBundleURL` method returns the result of the passed `fallbackURLProvider`. The `bundleFilePath` should be created with `[NSURL fileURLWithPath:<path>]`, as otherwise the HMR client is created and fails ungracefully. The check is added in the `getBundle` method to log the error beforehand: <img width="306" height="822" alt="Simulator Screenshot - iPhone 16 Pro - 2025-10-15 at 17 09 58" src="https://github.com/user-attachments/assets/869eed16-c5d8-4204-81d7-bd9cd42b2223" /> When the `bundleFilePath` is set in the `RCTBundleConfiguration` the `Connect to Metro...` message shouldn't be suggested. ## Changelog: [IOS][ADDED] - Add new `RCTBundleConfiguration` for modifying bundle URL on `RCTReactNativeFactory`. Test Plan: Test plan included in the last diff in the stack. Differential Revision: D84058022 Pulled By: coado
Collaborator
|
This pull request was successfully merged by @coado in 6fa75cc When will my fix make it into a release? | How to file a pick request? |
meta-codesync Bot
pushed a commit
that referenced
this pull request
Oct 12, 2026
) Summary: `-[RCTBundleURLProvider packagerServerHostPort]` probes `<jsLocation>/status`, and when the probe doesn't answer `packager-status:running` within `kRCTPackagerStatusRequestTimeout` (6 s, plus 2 s of grace) it drops the location for `guessPackagerHost` — the build machine's `ip.txt` address, or `localhost`, on 8081: ```objc if ([location length] && ![RCTBundleURLProvider isPackagerRunning:location scheme:scheme]) { location = nil; } ``` That recovery is right for a location saved in the defaults: the dev menu's "Configure Bundler" persists it, and it goes stale when the network changes. It is wrong for a location passed as a launch argument — `xcrun simctl launch <udid> <bundle> -RCT_jsLocation localhost:8099`, Detox `launchArgs`, XCUITest `launchArguments` — which is the launcher's instruction for this process and cannot be stale. **A Metro that is busy bundling can answer `/status` later than that, and the app then silently loads whatever answers on the guessed host:** another checkout's Metro on 8081 when one build is shared by several checkouts on their own ports, or nothing, which ends in `No script URL provided`. This skips the probe when `RCT_jsLocation` comes from `NSArgumentDomain` and keeps it for a saved location. The domain is read through `RCTLaunchArgumentForKey`, a new function in `RCTUtils`. An explicit `packagerServerHost` in `RCTBundleConfiguration` (#54006) is already used without a probe; this gives the launch argument the same treatment. ## Changelog: [IOS] [FIXED] - Keep a `RCT_jsLocation` passed as a launch argument when the packager answers `/status` late, instead of switching to a guessed host Pull Request resolved: #58877 Test Plan: - `RCTBundleURLProviderTests`: `testLaunchArgumentLocationIsKeptWhenPackagerDoesNotAnswer` puts `RCT_jsLocation` in the argument domain with `isPackagerRunning:scheme:` stubbed to `NO`. On `main` it fails — the URL falls back to `main.jsbundle` — and with this change it passes. `testSavedLocationGivesWayWhenPackagerDoesNotAnswer` pins the saved-location fallback: it passes before and after, and fails when the probe is skipped for every location. - RNTester (Debug) on an iPhone 16 simulator, iOS 18.0, with Metro on 8081 and a proxy on 8099 that forwards to it but holds `/status` for 10 s, launched with `xcrun simctl launch <udid> com.meta.RNTester.localDevelopment -RCT_jsLocation localhost:8099`: - `main`: the proxy logs `GET /status` twice and nothing else; the bundle is served from 8081. - this branch: the proxy serves `GET /js/RNTesterApp.ios.bundle?…`, the assets, and the `/message`, `/inspector/device` and `/hot` sockets, with no `/status` request. - `xcodebuild test -workspace RNTesterPods.xcworkspace -scheme RNTester -sdk iphonesimulator -destination 'platform=--sanitized-- Reviewed By: cipolleschi Differential Revision: D123673083 Pulled By: vzaidman fbshipit-source-id: 63c9a43b42b956395382309d1c12ea76f8716a59
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:
Following the RFC, this PR introduces a new
RCTBundleConfigurationinterface for modifying the bundle URL and exposes a new API for setting its instance in theRCTReactNativeFactory. The configuration object includes:The
RCTBundleConfigurationallows only for eitherbundleFilePathor(packagerServerScheme, packagerServerHost)to be set by defining appropriate initializers.The logic for creating bundle URL query items is extracted to a separate
createJSBundleURLQuerymethod and is used byRCTBundleManagerto set the configuredpackagerServerHostandpackagerServerScheme. If the configuration is not defined, thegetBundleURLmethod returns the result of the passedfallbackURLProvider.The
bundleFilePathshould be created with[NSURL fileURLWithPath:<path>], as otherwise the HMR client is created and fails ungracefully. The check is added in thegetBundlemethod to log the error beforehand:When the
bundleFilePathis set in theRCTBundleConfigurationtheConnect to Metro...message shouldn't be suggested.Changelog:
[IOS][ADDED] - Add new
RCTBundleConfigurationfor modifying bundle URL onRCTReactNativeFactory.Test Plan
Test plan included in the last diff in the stack.