From 0bdf7bf2c466895dd8686426ad03ff24abcdd415 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Sun, 20 Apr 2025 13:44:24 -0700 Subject: [PATCH] Log LegacyArchitectureLogger asserts only in Debug mode (#50818) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/50818 Logging LegacyArchitectureLogger asserts only in Debug mode as that will give us enough information about wrong usages of Legacy Architecture at this point changelog: [internal] internal Reviewed By: fkgozali Differential Revision: D73322301 fbshipit-source-id: 981a26b1bd7c89080f35ef0ab27677b0a38f2665 --- .../internal/LegacyArchitectureLogger.kt | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/annotations/internal/LegacyArchitectureLogger.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/annotations/internal/LegacyArchitectureLogger.kt index f5d20bf2265..faf71095237 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/annotations/internal/LegacyArchitectureLogger.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/annotations/internal/LegacyArchitectureLogger.kt @@ -83,14 +83,20 @@ public object LegacyArchitectureLogger { name: String, logLevel: LegacyArchitectureLogLevel = LegacyArchitectureLogLevel.WARNING ) { - when (logLevel) { - LegacyArchitectureLogLevel.ERROR -> { - throw AssertionException("$name $exceptionMessage") - } - LegacyArchitectureLogLevel.WARNING -> { - ReactSoftExceptionLogger.logSoftException( - ReactSoftExceptionLogger.Categories.SOFT_ASSERTIONS, - ReactNoCrashSoftException("$name $exceptionMessage")) + // Assert is being reported only in DEBUG mode to prevent over logging in production while we + // we are working on decoupling legacy / new architecture. + // Long term the assert will be executed in production and debug environments. + if (ReactBuildConfig.DEBUG) { + when (logLevel) { + LegacyArchitectureLogLevel.ERROR -> { + throw AssertionException("$name $exceptionMessage") + } + + LegacyArchitectureLogLevel.WARNING -> { + ReactSoftExceptionLogger.logSoftException( + ReactSoftExceptionLogger.Categories.SOFT_ASSERTIONS, + ReactNoCrashSoftException("$name $exceptionMessage")) + } } } }