From af793dd14dc416b239169a2035ccc8cb824335be Mon Sep 17 00:00:00 2001 From: Paige Sun Date: Wed, 16 Feb 2022 14:16:17 -0800 Subject: [PATCH] Don't error to Logview APIs not supported by new architecture that are expected to happen often Summary: Changelog: [Internal] In the new architecture, when an interop component is being called, log instead of warn/error, since at the moment we expect this to happen often. Reviewed By: fkgozali Differential Revision: D34252666 fbshipit-source-id: 971156a1cd9ef9b788f677c49fa2c55bd86ad4fa --- Libraries/ReactNative/BridgelessUIManager.js | 3 +-- React/Base/RCTAssert.h | 2 ++ React/Base/RCTAssert.m | 9 +++++++++ React/Base/RCTBridge.m | 2 +- .../RCTLegacyViewManagerInteropComponentView.mm | 8 ++++++-- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Libraries/ReactNative/BridgelessUIManager.js b/Libraries/ReactNative/BridgelessUIManager.js index ed16799ff0b..d0d47a8b406 100644 --- a/Libraries/ReactNative/BridgelessUIManager.js +++ b/Libraries/ReactNative/BridgelessUIManager.js @@ -118,8 +118,7 @@ module.exports = { console.error(errorMessageForMethod('measureLayoutRelativeToParent')), setJSResponder: (reactTag: ?number, blockNativeResponder: boolean): void => console.error(errorMessageForMethod('setJSResponder')), - clearJSResponder: (): void => - console.error(errorMessageForMethod('clearJSResponder')), + clearJSResponder: (): void => {}, // Don't log error here because we're aware it gets called configureNextLayoutAnimation: ( config: Object, callback: () => void, diff --git a/React/Base/RCTAssert.h b/React/Base/RCTAssert.h index a0fad928ab1..d51f8607031 100644 --- a/React/Base/RCTAssert.h +++ b/React/Base/RCTAssert.h @@ -186,3 +186,5 @@ __attribute__((used)) RCT_EXTERN void RCTEnforceNotAllowedForNewArchitecture(id // When reporting is enabled, trigger an error but do not crash. Use this to prepare a specific callsite // for stricter enforcement. When ready, switch it to use the variant above. __attribute__((used)) RCT_EXTERN void RCTErrorNotAllowedForNewArchitecture(id context, NSString *extra); +// When reporting is enabled, log an message. When ready, switch it to use the variant above. +__attribute__((used)) RCT_EXTERN void RCTLogNotAllowedForNewArchitecture(id context, NSString *extra); diff --git a/React/Base/RCTAssert.m b/React/Base/RCTAssert.m index aeb07ddeff1..e385c4ae261 100644 --- a/React/Base/RCTAssert.m +++ b/React/Base/RCTAssert.m @@ -282,3 +282,12 @@ void RCTErrorNotAllowedForNewArchitecture(id context, NSString *extra) RCTLogError(@"%@", getNewArchitectureViolationMessage(context, extra)); } + +void RCTLogNotAllowedForNewArchitecture(id context, NSString *extra) +{ + if (!newArchitectureViolationReporting) { + return; + } + + RCTLogInfo(@"%@", getNewArchitectureViolationMessage(context, extra)); +} diff --git a/React/Base/RCTBridge.m b/React/Base/RCTBridge.m index 7ffc311fb78..0b40713bcb8 100644 --- a/React/Base/RCTBridge.m +++ b/React/Base/RCTBridge.m @@ -59,7 +59,7 @@ NSArray *RCTGetModuleClasses(void) void RCTRegisterModule(Class); void RCTRegisterModule(Class moduleClass) { - RCTErrorNotAllowedForNewArchitecture( + RCTLogNotAllowedForNewArchitecture( @"RCTRegisterModule()", [NSString stringWithFormat:@"'%@' was registered unexpectedly", moduleClass]); static dispatch_once_t onceToken; diff --git a/React/Fabric/Mounting/ComponentViews/LegacyViewManagerInterop/RCTLegacyViewManagerInteropComponentView.mm b/React/Fabric/Mounting/ComponentViews/LegacyViewManagerInterop/RCTLegacyViewManagerInteropComponentView.mm index a3885f618ca..52cfd1d9047 100644 --- a/React/Fabric/Mounting/ComponentViews/LegacyViewManagerInterop/RCTLegacyViewManagerInteropComponentView.mm +++ b/React/Fabric/Mounting/ComponentViews/LegacyViewManagerInterop/RCTLegacyViewManagerInteropComponentView.mm @@ -29,8 +29,6 @@ static NSString *const kRCTLegacyInteropChildIndexKey = @"index"; - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { - RCTErrorNotAllowedForNewArchitecture( - self, @"ViewManager with interop layer is not allowed in the new architecture."); static const auto defaultProps = std::make_shared(); _props = defaultProps; _viewsToBeMounted = [NSMutableArray new]; @@ -67,6 +65,12 @@ static NSString *const kRCTLegacyInteropChildIndexKey = @"index"; + (BOOL)isSupported:(NSString *)componentName { + RCTLogNotAllowedForNewArchitecture( + self, + [NSString + stringWithFormat: + @"Legacy ViewManagers should be migrated to Fabric ComponentViews in the new architecture to reduce risk. Component using interop layer: %@", + componentName]); return [[RCTLegacyViewManagerInteropComponentView supportedViewManagers] containsObject:componentName]; }