Skip to content

feat(ios): support bundled JS in debug builds#317

Draft
adamTrz wants to merge 5 commits into
mainfrom
adamTrz-ios-debug-bundled-bundle
Draft

feat(ios): support bundled JS in debug builds#317
adamTrz wants to merge 5 commits into
mainfrom
adamTrz-ios-debug-bundled-bundle

Conversation

@adamTrz
Copy link
Copy Markdown
Collaborator

@adamTrz adamTrz commented May 8, 2026

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 Debug and the host app wants to load the packaged JavaScript bundle instead of relying on a dev server.

Root cause

There were two separate issues:

  1. Runtime resolution
  • in Debug, the iOS runtime always preferred Metro and ignored the embedded main.jsbundle
  1. Packaging
  • even after adding a runtime opt-in for bundled JS in Debug, the simulator slice of the packaged BrownfieldLib.xcframework did not contain main.jsbundle
  • React Native skips bundling for Debug simulator builds by default, so the packaged simulator artifact was not self-sufficient

What changed

Runtime

  • adds preferBundledBundleInDebug to ReactNativeBrownfield
  • extracts bundle URL selection into a small testable resolver
  • keeps current Debug behavior unchanged by default
  • when preferBundledBundleInDebug = true, Debug builds load the embedded bundle
  • fixes bundleURLOverride fallback behavior when the override returns nil

Packaging

  • after Debug iOS packaging, copies main.jsbundle from the device framework build product into the simulator framework build product
  • re-merges BrownfieldLib.xcframework so the simulator slice also contains main.jsbundle
  • keeps DX simple:
    • no new CLI flags
    • no extra Xcode env vars
    • no special simulator packaging flow

Validation / coverage

  • documents the new opt-in in iOS / Expo docs
  • adds native Swift tests for iOS bundle URL resolution
  • adds CLI tests for Debug simulator bundle copying
  • adds a generic iOS native tests CI job for Swift-based iOS tests

Repro note

This issue only reproduces when the consumed XCFrameworks are themselves built in Debug.

A Debug host app linked against Release-built XCFrameworks is a false negative, because the framework runtime has already been compiled without the Debug Metro branch.

Validation

  • swift test in packages/react-native-brownfield/ios
  • yarn workspace @callstack/brownfield-cli test src/brownfield/utils/__tests__/copy-debug-bundle-to-simulator-slice.test.ts
  • yarn exec brownfield package:ios --scheme BrownfieldLib --configuration Debug
  • verified that:
    • Debug-iphonesimulator/BrownfieldLib.framework/main.jsbundle exists
    • BrownfieldLib.xcframework/ios-arm64_x86_64-simulator/BrownfieldLib.framework/main.jsbundle exists
  • manual repro flow with Debug-built XCFrameworks and Metro stopped

User impact

Host apps can now explicitly opt into running a Debug-built brownfield framework from the packaged bundle:

ReactNativeBrownfield.shared.bundle = ReactNativeBundle
ReactNativeBrownfield.shared.preferBundledBundleInDebug = true
ReactNativeBrownfield.shared.startReactNative()

With the normal Debug packaging flow, the packaged simulator XCFramework now includes the bundle needed for that opt-in to work without Metro.

adamTrz added 3 commits May 6, 2026 17:19
- 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.
@adamTrz adamTrz requested a review from artus9033 May 8, 2026 13:23
Copy link
Copy Markdown
Collaborator

@artus9033 artus9033 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing work! Left some comments for naming conventions & few questions, LGTM after they are resolved.

| `entryFile` | `NSString` | `index` | Path to JavaScript entry file in development. |
| `bundlePath` | `NSString` | `main.jsbundle` | Path to JavaScript bundle file. |
| `bundle` | `NSBundle` | `Bundle.main` | Bundle instance to lookup the JavaScript bundle resource. |
| `preferBundledBundleInDebug` | `BOOL` | `NO` | Prefer the embedded JavaScript bundle instead of Metro when the framework is built in Debug. |
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit of a tongue twister ;) let's rename this to preferEmbeddedBundleInDebug

| `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. |
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

npx react-native start
```

If you want to run a **Debug-built** framework without Metro, enable the bundled bundle explicitly before calling `startReactNative`:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add a ## Embedded bundle in Development section here

Comment on lines +3 to +6
interface BrownfieldNavigationDelegate {
fun navigateToSettings()
fun navigateToReferrals(userId: String)
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above, revert

@@ -0,0 +1,26 @@
import Foundation

enum BrownfieldBundleURLResolver {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about we make that a class?

Comment on lines +5 to +9
let package = Package(
name: "BrownfieldBundleSupport",
platforms: [
.macOS(.v13),
],
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename like above

var entryFile = "index"
var bundlePath = "main.jsbundle"
var bundle = Bundle.main
var preferBundledBundleInDebug = false
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename like above

Comment on lines +213 to +214
DYLIB_INSTALL_NAME_BASE: '"@rpath"',
INSTALL_PATH: '"$(LOCAL_LIBRARY_DIR)/Frameworks"',
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't we need the same in non-Expo (RNC CLI) workflow?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants