diff --git a/packages/react-native/Libraries/LogBox/Data/LogBoxData.js b/packages/react-native/Libraries/LogBox/Data/LogBoxData.js index 04f9ba2870bc47..5e42dfcdeadbdf 100644 --- a/packages/react-native/Libraries/LogBox/Data/LogBoxData.js +++ b/packages/react-native/Libraries/LogBox/Data/LogBoxData.js @@ -18,6 +18,7 @@ import type { Message, } from './parseLogBoxLog'; +import NativeDebuggerSessionObserver from '../../../src/private/specs/modules/NativeDebuggerSessionObserver'; import parseErrorStack from '../../Core/Devtools/parseErrorStack'; import NativeDevSettings from '../../NativeModules/specs/NativeDevSettings'; import NativeLogBox from '../../NativeModules/specs/NativeLogBox'; @@ -75,6 +76,7 @@ let updateTimeout: $FlowFixMe | null = null; let _isDisabled = false; let _selectedIndex = -1; let hasShownFuseboxWarningsMigrationMessage = false; +let hostTargetSessionObserverSubscription = null; let warningFilter: WarningFilter = function (format) { return { @@ -196,11 +198,36 @@ function appendNewLog(newLog: LogBoxLog) { } export function addLog(log: LogData): void { - if (log.level === 'warn' && global.__FUSEBOX_HAS_FULL_CONSOLE_SUPPORT__) { - // Under Fusebox, don't report warnings to LogBox. - showFuseboxWarningsMigrationMessageOnce(); + if ( + hostTargetSessionObserverSubscription == null && + NativeDebuggerSessionObserver != null + ) { + hostTargetSessionObserverSubscription = + NativeDebuggerSessionObserver.subscribe(hasActiveSession => { + if (hasActiveSession) { + clearWarnings(); + } else { + // Reset the flag so that we can show the message again if new warning was emitted + hasShownFuseboxWarningsMigrationMessage = false; + } + }); + } + + // If Host has Fusebox support + if ( + log.level === 'warn' && + global.__FUSEBOX_HAS_FULL_CONSOLE_SUPPORT__ && + NativeDebuggerSessionObserver != null + ) { + // And there is no active debugging session + if (!NativeDebuggerSessionObserver.hasActiveSession()) { + showFuseboxWarningsMigrationMessageOnce(); + } + + // Don't show LogBox warnings when Host has active debugging session return; } + const errorForStackTrace = new Error(); // Parsing logs are expensive so we schedule this @@ -484,7 +511,6 @@ function showFuseboxWarningsMigrationMessageOnce() { if (NativeDevSettings.openDebugger) { NativeDevSettings.openDebugger(); } - clearWarnings(); }, }), );