From 6debf33f0da6fea14f8588c6ff05e8bcda51cf18 Mon Sep 17 00:00:00 2001 From: Tommy Nguyen <4123478+tido64@users.noreply.github.com> Date: Wed, 17 Jul 2024 09:09:54 +0200 Subject: [PATCH] fix(apple): fix crash on startup on 0.75 + New Arch (#2127) --- ios/ReactTestApp/ReactInstance.swift | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/ios/ReactTestApp/ReactInstance.swift b/ios/ReactTestApp/ReactInstance.swift index 16fec34d3..86ee798ea 100644 --- a/ios/ReactTestApp/ReactInstance.swift +++ b/ios/ReactTestApp/ReactInstance.swift @@ -11,7 +11,9 @@ final class ReactInstance: NSObject, RNXHostConfig { } var remoteBundleURL: URL? { - didSet { + get { remoteBundleURLInternal } + set { + remoteBundleURLInternal = newValue initReact(bundleRoot: bundleRoot, onDidInitialize: { /* noop */ }) } } @@ -19,11 +21,20 @@ final class ReactInstance: NSObject, RNXHostConfig { private(set) var host: ReactNativeHost? private var bundleRoot: String? - override init() { + // This needs to be lazy because `ReactInstance.jsBundleURL()` will call + // `InspectorFlags::getFuseboxEnabled()` -> + // `ReactNativeFeatureFlags::fuseboxEnabledRelease()` before any overrides + // are set. Setting overrides after this will trigger asserts and crash the + // app on startup. + private lazy var remoteBundleURLInternal: URL? = { #if DEBUG - remoteBundleURL = ReactInstance.jsBundleURL() + ReactInstance.jsBundleURL() + #else + nil #endif + }() + override init() { super.init() // Bridged