From 169180100c6c9639375d37ff1736d9cefbaaa63b Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Thu, 25 May 2023 14:58:11 -0700 Subject: [PATCH] Temp: Always report debug info on module not found error Summary: The TurboModule interop layer causes a surge in "module not found" exceptions: T154044825. After D45102812, this exception **should** have included debug info. But, it didn't. ## Problems So, there are two problems: 1. No debug logs are getting printed. 2. In the TurboModule interop test group, global.RN$TurboInterop is false **for some reason.** This is **very** strange. ## Changes 1. **Always** print the debug logs. 2. Add more flag-related debug information to the "module not found" debug logs. This will help us validate whether global.RN$TurboInterop is truely false. ## Concerns > **Always** print the debug logs on Android. **Question:** Won't this be really expensive? This shouldn't be too expensive: There are about ~50 native module requires in Fb4a. So: (1) the exception message shouldn't grow to an unreasonable size, (2) we'll only use enough memory to store ~50 strings in the JS VM. Changelog: [Internal] Reviewed By: fkgozali Differential Revision: D46195117 fbshipit-source-id: 8215c7339d16a1adc063b674805063865d1f7ab6 --- .../TurboModule/TurboModuleRegistry.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/react-native/Libraries/TurboModule/TurboModuleRegistry.js b/packages/react-native/Libraries/TurboModule/TurboModuleRegistry.js index a069106ff29..e52cd1abdee 100644 --- a/packages/react-native/Libraries/TurboModule/TurboModuleRegistry.js +++ b/packages/react-native/Libraries/TurboModule/TurboModuleRegistry.js @@ -30,8 +30,9 @@ function isTurboModuleInteropEnabled() { return global.RN$TurboInterop === true; } -function shouldReportLoadedModules() { - return isTurboModuleInteropEnabled(); +// TODO(154308585): Remove "module not found" debug info logging +function shouldReportDebugInfo() { + return true; } // TODO(148943970): Consider reversing the lookup here: @@ -41,7 +42,7 @@ function requireModule(name: string): ?T { // Backward compatibility layer during migration. const legacyModule = NativeModules[name]; if (legacyModule != null) { - if (shouldReportLoadedModules()) { + if (shouldReportDebugInfo()) { moduleLoadHistory.NativeModules.push(name); } return ((legacyModule: $FlowFixMe): T); @@ -51,17 +52,16 @@ function requireModule(name: string): ?T { if (turboModuleProxy != null) { const module: ?T = turboModuleProxy(name); if (module != null) { - if (shouldReportLoadedModules()) { + if (shouldReportDebugInfo()) { moduleLoadHistory.TurboModules.push(name); } return module; } } - if (shouldReportLoadedModules()) { + if (shouldReportDebugInfo()) { moduleLoadHistory.NotFound.push(name); } - return null; } @@ -75,7 +75,12 @@ export function getEnforcing(name: string): T { `TurboModuleRegistry.getEnforcing(...): '${name}' could not be found. ` + 'Verify that a module by this name is registered in the native binary.'; - if (shouldReportLoadedModules()) { + if (shouldReportDebugInfo()) { + message += 'Bridgeless mode: ' + (isBridgeless() ? 'true' : 'false') + '. '; + message += + 'TurboModule interop: ' + + (isTurboModuleInteropEnabled() ? 'true' : 'false') + + '. '; message += 'Modules loaded: ' + JSON.stringify(moduleLoadHistory); }