From 3f8d5083f72d3fae98cd9a2f9431dacc2e4c40e4 Mon Sep 17 00:00:00 2001 From: Peter Argany Date: Wed, 31 Mar 2021 16:37:02 -0700 Subject: [PATCH] Avoid crashing in Fabric/Paper interop without bridge [1/n] Summary: Fabric/Paper interop expects bridge to be contained in `contextContainer`, and crashes if it's not there. This diff avoids a crash, and instead fails silently. Future diffs in stack will enable `RCTComponentData` and `RCTLegacyViewManagerInteropCoordinator` to function without the bridge. Changelog: [Internal] Reviewed By: fkgozali Differential Revision: D27374809 fbshipit-source-id: 2c9e03a1eaf5bcaa57887b203221111015cf4de5 --- .../LegacyViewManagerInteropComponentDescriptor.mm | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ReactCommon/react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropComponentDescriptor.mm b/ReactCommon/react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropComponentDescriptor.mm index 06f79b844af..3c6648d8fc3 100644 --- a/ReactCommon/react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropComponentDescriptor.mm +++ b/ReactCommon/react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropComponentDescriptor.mm @@ -59,8 +59,13 @@ static std::shared_ptr const constructCoordinator( auto moduleName = moduleNameFromComponentName(componentName); Class module = NSClassFromString(RCTNSStringFromString(moduleName)); assert(module); - RCTBridge *bridge = (RCTBridge *)unwrapManagedObjectWeakly(contextContainer->at>("Bridge")); - RCTComponentData *componentData = [[RCTComponentData alloc] initWithManagerClass:module bridge:bridge]; + auto optionalBridge = contextContainer->find>("Bridge"); + RCTBridge *bridge; + if (optionalBridge) { + bridge = unwrapManagedObjectWeakly(optionalBridge.value()); + } + RCTComponentData *componentData = [[RCTComponentData alloc] initWithManagerClass:module + bridge:bridge]; return wrapManagedObject([[RCTLegacyViewManagerInteropCoordinator alloc] initWithComponentData:componentData bridge:bridge]); }