New Arch Failure: RCTAppDelegate.bridge Is Permanently Nil, Blocking Subsequent Bundle Loading #3352
Replies: 1 comment 1 reply
-
|
Okay, I don't see how this is related to On new architecture there is no concept of bridge. Literally it is running in "bridgeless" mode. You won't find access to that object, because it simply does not exist. There were some compat layers in earlier RN versions, but I'm no longer sure they're still available. Most likely you want to make use of Please also note, that the names of notifications (constants) have changed. Check out RCTConstants.h (I believe these are the new ones, not sure though). |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Previously in old architecture to load new bundles dynamically inside an app we were creating an RCTBridge and a RCTRootView with this bridge and creating a rootViewController and assigning the RCTView to that rootViewController and loading that. That was working fine.
But now in new architecture all of that is taken care by dependencyProvider. But the self.bridge after we create the dependencyProvider and call super.application(application, didFinishLaunchingWithOptions: launchOptions) and return that always stays nil.
final class AppDelegate: RCTAppDelegate, ... {
// ...
override func application(...) -> Bool {
// New Arch Configuration (Correctly set BEFORE super)
self.moduleName = AppLaunchConstants.moduleName
self.dependencyProvider = RCTAppDependencyProvider()
self.initialProps = [:]
let result = super.application(application, didFinishLaunchingWithOptions: launchOptions)
self.sharedBridge = self.bridge
// CHECK: self.bridge is nil even after this line executes. I had even tried to access it after a delay or through notifications once //the screen with main bundle loads as self.bridge get created asynchronously. But it still came nil
return result
}
// ...
}
So later when I try to this while trying to load a different bundle:
func loadJsBundle(with url: URL) {
guard let app = UIApplication.shared.delegate as? AppDelegate else { return }
let b = RCTBridge(delegate: app, launchOptions: nil)
self.bridge = app.sharedBridge ?? b
notificationCenter.addObserver(self, selector: #selector(bundleDidLoad(:)),
name: .RCTJavaScriptDidLoad, object: b)
notificationCenter.addObserver(self, selector: #selector(bundleDidFail(:)),
name: .RCTJavaScriptDidFailToLoad, object: b)
}
I got error: Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'DeviceInfo' could not be found. Verify that a module by this name is registered in the native binary.
The reason also I understand. Creation of new RCTBridge(delegate: app, launchOptions: nil) is creating new Turbo module registry. We should be using the bridge of the app delegate and Turbo modules of it. But that is always nil. app.sharedBridge is always nil. So I am unable to load new bundles.
Beta Was this translation helpful? Give feedback.
All reactions