Skip to content

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

Draft
adamTrz wants to merge 2 commits intomainfrom
adamTrz-ios-debug-bundled-bundle
Draft

feat(ios): support bundled JS in debug builds#317
adamTrz wants to merge 2 commits intomainfrom
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 adamTrz requested a review from artus9033 May 8, 2026 13:23
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.

1 participant