Skip to content

Commit 70fb6fc

Browse files
committed
Only prompt preserve-log settings for Fusebox targets
1 parent 6f29504 commit 70fb6fc

File tree

7 files changed

+54
-38
lines changed

7 files changed

+54
-38
lines changed

config/gni/devtools_grd_files.gni

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,7 @@ grd_files_debug_sources = [
772772
"front_end/core/sdk/EventBreakpointsModel.js",
773773
"front_end/core/sdk/FrameAssociated.js",
774774
"front_end/core/sdk/FrameManager.js",
775+
"front_end/core/sdk/FuseboxClientMetadataModel.js",
775776
"front_end/core/sdk/HeapProfilerModel.js",
776777
"front_end/core/sdk/HttpReasonPhraseStrings.js",
777778
"front_end/core/sdk/IOModel.js",

front_end/core/sdk/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ devtools_module("sdk") {
4444
"EventBreakpointsModel.ts",
4545
"FrameAssociated.ts",
4646
"FrameManager.ts",
47+
"FuseboxClientMetadataModel.ts",
4748
"HeapProfilerModel.ts",
4849
"HttpReasonPhraseStrings.ts",
4950
"IOModel.ts",
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) Meta Platforms, Inc. and affiliates.
2+
// Copyright 2024 The Chromium Authors. All rights reserved.
3+
// Use of this source code is governed by a BSD-style license that can be
4+
// found in the LICENSE file.
5+
6+
import * as Host from '../host/host.js';
7+
8+
import {SDKModel} from './SDKModel.js';
9+
import {type Target} from './Target.js';
10+
11+
export class FuseboxClientMetadataModel extends SDKModel<void> {
12+
constructor(target: Target) {
13+
super(target);
14+
Host.rnPerfMetrics.fuseboxSetClientMetadataStarted();
15+
target.fuseboxClientAgent()
16+
.invoke_setClientMetadata()
17+
.then(result => {
18+
const maybeError = result.getError();
19+
const success = !maybeError;
20+
Host.rnPerfMetrics.fuseboxSetClientMetadataFinished(success, maybeError);
21+
})
22+
.catch(reason => {
23+
const success = false;
24+
Host.rnPerfMetrics.fuseboxSetClientMetadataFinished(success, reason);
25+
});
26+
}
27+
}

front_end/core/sdk/sdk.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import * as EmulationModel from './EmulationModel.js';
4545
import * as EventBreakpointsModel from './EventBreakpointsModel.js';
4646
import * as FrameAssociated from './FrameAssociated.js';
4747
import * as FrameManager from './FrameManager.js';
48+
import * as FuseboxClientMetadataModel from './FuseboxClientMetadataModel.js';
4849
import * as HeapProfilerModel from './HeapProfilerModel.js';
4950
import * as IOModel from './IOModel.js';
5051
import * as IsolateManager from './IsolateManager.js';
@@ -120,6 +121,7 @@ export {
120121
EventBreakpointsModel,
121122
FrameAssociated,
122123
FrameManager,
124+
FuseboxClientMetadataModel,
123125
HeapProfilerModel,
124126
IOModel,
125127
IsolateManager,

front_end/entrypoints/rn_fusebox/rn_fusebox.ts

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -91,37 +91,19 @@ document.addEventListener('visibilitychange', () => {
9191
Host.rnPerfMetrics.browserVisibilityChanged(document.visibilityState);
9292
});
9393

94-
class FuseboxClientMetadataModel extends SDK.SDKModel.SDKModel<void> {
95-
constructor(target: SDK.Target.Target) {
96-
super(target);
97-
Host.rnPerfMetrics.fuseboxSetClientMetadataStarted();
98-
target.fuseboxClientAgent()
99-
.invoke_setClientMetadata()
100-
.then(result => {
101-
const maybeError = result.getError();
102-
const success = !maybeError;
103-
Host.rnPerfMetrics.fuseboxSetClientMetadataFinished(success, maybeError);
104-
})
105-
.catch(reason => {
106-
const success = false;
107-
Host.rnPerfMetrics.fuseboxSetClientMetadataFinished(success, reason);
108-
});
109-
}
110-
}
111-
11294
SDK.SDKModel.SDKModel.register(
113-
FuseboxClientMetadataModel,
114-
{
115-
capabilities: SDK.Target.Capability.None,
116-
autostart: true,
117-
// Ensure FuseboxClient.setClientMetadata is sent before most other CDP domains
118-
// are initialised. This allows the backend to confidently detect non-Fusebox
119-
// clients by the fact that they send e.g. Runtime.enable without sending any
120-
// Fusebox-specific messages first.
121-
// TODO: Explicitly depend on this model in RuntimeModel and LogModel, and
122-
// remove the `early` and `autostart` flags.
123-
early: true,
124-
},
95+
SDK.FuseboxClientMetadataModel.FuseboxClientMetadataModel,
96+
{
97+
capabilities: SDK.Target.Capability.None,
98+
autostart: true,
99+
// Ensure FuseboxClient.setClientMetadata is sent before most other CDP domains
100+
// are initialised. This allows the backend to confidently detect non-Fusebox
101+
// clients by the fact that they send e.g. Runtime.enable without sending any
102+
// Fusebox-specific messages first.
103+
// TODO: Explicitly depend on this model in RuntimeModel and LogModel, and
104+
// remove the `early` and `autostart` flags.
105+
early: true,
106+
},
125107
);
126108

127109
let loadedSourcesModule: (typeof Sources|undefined);

front_end/panels/console/ConsoleView.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -628,14 +628,16 @@ export class ConsoleView extends UI.Widget.VBox implements
628628
if (!Common.Settings.Settings.instance().moduleSetting('preserve-console-log').get() &&
629629
model.target().outermostTarget() === model.target()) {
630630
this.consoleCleared();
631-
this.addConsoleMessage(new SDK.ConsoleModel.ConsoleMessage(
632-
model.target().model(SDK.RuntimeModel.RuntimeModel), Protocol.Log.LogEntrySource.Recommendation,
633-
Protocol.Log.LogEntryLevel.Info,
634-
'[React Native] Console messages are currently cleared upon DevTools disconnection. You can preserve logs in settings: ',
635-
{
636-
type: SDK.ConsoleModel.FrontendMessageType.System,
637-
context: 'fusebox_preserve_log_rec',
638-
}));
631+
if (model.target().model(SDK.FuseboxClientMetadataModel.FuseboxClientMetadataModel)) {
632+
this.addConsoleMessage(new SDK.ConsoleModel.ConsoleMessage(
633+
model.target().model(SDK.RuntimeModel.RuntimeModel), Protocol.Log.LogEntrySource.Recommendation,
634+
Protocol.Log.LogEntryLevel.Info,
635+
'[React Native] Console messages are currently cleared upon DevTools disconnection. You can preserve logs in settings: ',
636+
{
637+
type: SDK.ConsoleModel.FrontendMessageType.System,
638+
context: 'fusebox_preserve_log_rec',
639+
}));
640+
}
639641
}
640642
}
641643

scripts/eslint_rules/lib/check_license_header.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ const EXCLUDED_FILES = [
6969
const META_CODE_PATHS = [
7070
'core/host/RNPerfMetrics.ts',
7171
'core/rn_experiments',
72+
'core/sdk/FuseboxClientMetadataModel.ts',
7273
'core/sdk/ReactNativeApplicationModel.ts',
7374
'entrypoints/rn_fusebox',
7475
'entrypoints/rn_inspector',

0 commit comments

Comments
 (0)