Skip to content

Commit

Permalink
Use NativeDebuggerSessionObserver in LogBox (facebook#45578)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#45578

# Changelog: [Internal]

Use previously introduced native module for managing the presence of warning notifications in LogBox:
- Don't display warnings and Fusebox migration message if there is an active debugging session
- If the session has just been started, clear warnings to hide Fusebox migration message
- If there is no active debugging session (even if there were some at some point of Host lifetime), display Fusebox migration message

See demo in test plan.

Reviewed By: huntie

Differential Revision: D59975265

fbshipit-source-id: 87d91b4d7f3c825dc795ec1b5b3073f969bc7b60
  • Loading branch information
hoxyq authored and facebook-github-bot committed Jul 25, 2024
1 parent 6fde836 commit 9c61d9a
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions packages/react-native/Libraries/LogBox/Data/LogBoxData.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -484,7 +511,6 @@ function showFuseboxWarningsMigrationMessageOnce() {
if (NativeDevSettings.openDebugger) {
NativeDevSettings.openDebugger();
}
clearWarnings();
},
}),
);
Expand Down

0 comments on commit 9c61d9a

Please sign in to comment.