feat(ios): support bundled JS in debug builds#317
Draft
adamTrz wants to merge 10 commits into
Draft
Conversation
- Added a method to configure the development loading view based on the debug settings. - Introduced `BrownfieldDevLoadingViewBridge` to manage the loading view state. - Updated `BrownfieldAppleApp` to prefer bundled bundles in debug mode. - Adjusted `ExpoHostRuntime` and `ReactNativeHostRuntime` to call the new configuration method.
artus9033
requested changes
May 12, 2026
Collaborator
artus9033
left a comment
There was a problem hiding this comment.
Amazing work! Left some comments for naming conventions & few questions, LGTM after they are resolved.
| | `entryFile` | `String` | `index` | Path to JavaScript entry file in development. | | ||
| | `bundlePath` | `String` | `main.jsbundle` | Path to JavaScript bundle file. | | ||
| | `bundle` | `Bundle` | `Bundle.main` | Bundle instance to lookup the JavaScript bundle resource. | | ||
| | `preferBundledBundleInDebug` | `Bool` | `false` | Prefer the embedded JavaScript bundle instead of Metro when the framework is built in Debug. | |
| npx react-native start | ||
| ``` | ||
|
|
||
| If you want to run a **Debug-built** framework without Metro, enable the bundled bundle explicitly before calling `startReactNative`: |
Collaborator
There was a problem hiding this comment.
I'd add a ## Embedded bundle in Development section here
Comment on lines
+3
to
+6
| interface BrownfieldNavigationDelegate { | ||
| fun navigateToSettings() | ||
| fun navigateToReferrals(userId: String) | ||
| } |
Collaborator
There was a problem hiding this comment.
This is codegen-ed and should not be committed :)
Comment on lines
+10
to
+16
| override fun navigateToSettings() { | ||
| BrownfieldNavigationManager.getDelegate().navigateToSettings() | ||
| } | ||
|
|
||
| @ReactMethod | ||
| override fun navigateToReferrals(userId: String) { | ||
| BrownfieldNavigationManager.getDelegate().navigateToReferrals(userId) |
| @@ -0,0 +1,26 @@ | |||
| import Foundation | |||
|
|
|||
| enum BrownfieldBundleURLResolver { | |||
Collaborator
There was a problem hiding this comment.
How about we make that a class?
Comment on lines
+5
to
+9
| let package = Package( | ||
| name: "BrownfieldBundleSupport", | ||
| platforms: [ | ||
| .macOS(.v13), | ||
| ], |
Collaborator
There was a problem hiding this comment.
Are you sure we need this here? It may be a tad confusing to look at the ios folder with this macos package def. Can we move it to a subdir?
| * Prefer the embedded JavaScript bundle instead of Metro when this framework is built in Debug. | ||
| * Default value: false | ||
| */ | ||
| public var preferBundledBundleInDebug: Bool = false { |
| var entryFile = "index" | ||
| var bundlePath = "main.jsbundle" | ||
| var bundle = Bundle.main | ||
| var preferBundledBundleInDebug = false |
Comment on lines
+213
to
+214
| DYLIB_INSTALL_NAME_BASE: '"@rpath"', | ||
| INSTALL_PATH: '"$(LOCAL_LIBRARY_DIR)/Frameworks"', |
Collaborator
There was a problem hiding this comment.
Won't we need the same in non-Expo (RNC CLI) workflow?
…dled-bundle # Conflicts: # .gitignore # packages/react-native-brownfield/ios/ExpoHostRuntime.swift # packages/react-native-brownfield/src/expo-config-plugin/ios/withBrownfieldIos.ts # packages/react-native-brownfield/src/expo-config-plugin/ios/xcodeHelpers.ts
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
Fixes iOS Debug packaged-bundle loading for brownfield apps running without Metro.
This PR addresses the case where a consumed brownfield XCFramework is built in
Debugand the host app wants to load the packaged JavaScript bundle instead of relying on a dev server.Root cause
There were two separate issues:
Debug, the iOS runtime always preferred Metro and ignored the embeddedmain.jsbundleDebug, the simulator slice of the packagedBrownfieldLib.xcframeworkdid not containmain.jsbundleWhat changed
Runtime
preferBundledBundleInDebugtoReactNativeBrownfieldpreferBundledBundleInDebug = true, Debug builds load the embedded bundlebundleURLOverridefallback behavior when the override returnsnilPackaging
main.jsbundlefrom the device framework build product into the simulator framework build productBrownfieldLib.xcframeworkso the simulator slice also containsmain.jsbundleValidation / coverage
iOS native testsCI job for Swift-based iOS testsRepro note
This issue only reproduces when the consumed XCFrameworks are themselves built in
Debug.A
Debughost app linked againstRelease-built XCFrameworks is a false negative, because the framework runtime has already been compiled without the Debug Metro branch.Validation
swift testinpackages/react-native-brownfield/iosyarn workspace @callstack/brownfield-cli test src/brownfield/utils/__tests__/copy-debug-bundle-to-simulator-slice.test.tsyarn exec brownfield package:ios --scheme BrownfieldLib --configuration DebugDebug-iphonesimulator/BrownfieldLib.framework/main.jsbundleexistsBrownfieldLib.xcframework/ios-arm64_x86_64-simulator/BrownfieldLib.framework/main.jsbundleexistsUser impact
Host apps can now explicitly opt into running a Debug-built brownfield framework from the packaged bundle:
With the normal Debug packaging flow, the packaged simulator XCFramework now includes the bundle needed for that opt-in to work without Metro.