From 5eafcf74b3b4bab7a0b37b25311b617dd9d1bbd3 Mon Sep 17 00:00:00 2001 From: Kevin Gozali Date: Fri, 15 Feb 2019 13:26:55 -0800 Subject: [PATCH] Don't attempt to load RCTDevLoadingView lazily Summary: There's a very old issue with reload logic: invalidation and resetting up of the bridge could be racing. In this case, we hit a redbox when: * Chrome debugger is enabled in previous app run, then we launch the app again * The bridge starts, then immediately reloads itself to connect to Chrome * On the 2nd setup, the logic to update the green loading bar, with the % indicator for loading off metro, failed to find the DevLoadingView module instance because the bridge is in the middle of invalidating See https://github.com/facebook/react-native/issues/23235 To test: Using react-native init from github, do the steps in https://github.com/facebook/react-native/issues/23235, no more redbox. Note that the loading indicator % won't be proper still, but at least it doesn't crash/redbox. Reviewed By: JoshuaGross Differential Revision: D14110814 fbshipit-source-id: 835061e50acc6968bffbcc2ddfbe8da79a100df9 --- React/Base/RCTBridge.m | 2 ++ React/CxxBridge/RCTCxxBridge.mm | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/React/Base/RCTBridge.m b/React/Base/RCTBridge.m index 98f4a4972400fd..e0d6c76f520bc6 100644 --- a/React/Base/RCTBridge.m +++ b/React/Base/RCTBridge.m @@ -287,6 +287,8 @@ - (void)reload * Any thread */ dispatch_async(dispatch_get_main_queue(), ^{ + // WARNING: Invalidation is async, so it may not finish before re-setting up the bridge, + // causing some issues. TODO: revisit this post-Fabric/TurboModule. [self invalidate]; [self setUp]; }); diff --git a/React/CxxBridge/RCTCxxBridge.mm b/React/CxxBridge/RCTCxxBridge.mm index 74ec4ec0325fd9..645c13bb680e23 100644 --- a/React/CxxBridge/RCTCxxBridge.mm +++ b/React/CxxBridge/RCTCxxBridge.mm @@ -357,7 +357,9 @@ - (void)start dispatch_group_leave(prepareBridge); } onProgress:^(RCTLoadingProgress *progressData) { #if RCT_DEV && __has_include("RCTDevLoadingView.h") - RCTDevLoadingView *loadingView = [weakSelf moduleForClass:[RCTDevLoadingView class]]; + // Note: RCTDevLoadingView should have been loaded at this point, so no need to allow lazy loading. + RCTDevLoadingView *loadingView = [weakSelf moduleForName:RCTBridgeModuleNameForClass([RCTDevLoadingView class]) + lazilyLoadIfNecessary:NO]; [loadingView updateProgress:progressData]; #endif }];