Skip to content

Commit 8831e78

Browse files
authored
Replace Fusebox setClientMetadata handshake with ReactNativeApplicationModel (#139)
1 parent 0d6f1e4 commit 8831e78

File tree

9 files changed

+18
-95
lines changed

9 files changed

+18
-95
lines changed

front_end/core/protocol_client/InspectorBackend.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -672,10 +672,6 @@ export class TargetBase {
672672
return this.getAgent('Fetch');
673673
}
674674

675-
fuseboxClientAgent(): ProtocolProxyApi.FuseboxClientApi {
676-
return this.getAgent('FuseboxClient');
677-
}
678-
679675
heapProfilerAgent(): ProtocolProxyApi.HeapProfilerApi {
680676
return this.getAgent('HeapProfiler');
681677
}

front_end/core/sdk/ReactNativeApplicationModel.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import type * as ProtocolProxyApi from '../../generated/protocol-proxy-api.js';
77
import type * as Protocol from '../../generated/protocol.js';
88

9+
import * as Host from '../../core/host/host.js';
910
import {Capability, type Target} from './Target.js';
1011
import {SDKModel} from './SDKModel.js';
1112

@@ -18,17 +19,31 @@ export class ReactNativeApplicationModel extends SDKModel<EventTypes> implements
1819
constructor(target: Target) {
1920
super(target);
2021

22+
Host.rnPerfMetrics.fuseboxSetClientMetadataStarted();
23+
2124
this.#enabled = false;
2225
this.#agent = target.reactNativeApplicationAgent();
2326
target.registerReactNativeApplicationDispatcher(this);
27+
28+
// Auto-init. Paired with registering this model immediately in rn_fusebox.ts.
29+
this.ensureEnabled();
2430
}
2531

2632
ensureEnabled(): void {
2733
if (this.#enabled) {
2834
return;
2935
}
3036

31-
void this.#agent.invoke_enable();
37+
void this.#agent.invoke_enable()
38+
.then(result => {
39+
const maybeError = result.getError();
40+
const success = !maybeError;
41+
Host.rnPerfMetrics.fuseboxSetClientMetadataFinished(success, maybeError);
42+
})
43+
.catch(reason => {
44+
const success = false;
45+
Host.rnPerfMetrics.fuseboxSetClientMetadataFinished(success, reason);
46+
});
3247
this.#enabled = true;
3348
}
3449

@@ -45,11 +60,3 @@ export const enum Events {
4560
export type EventTypes = {
4661
[Events.MetadataUpdated]: Protocol.ReactNativeApplication.MetadataUpdatedEvent,
4762
};
48-
49-
SDKModel.register(
50-
ReactNativeApplicationModel,
51-
{
52-
capabilities: Capability.None,
53-
autostart: true,
54-
},
55-
);

front_end/entrypoints/rn_fusebox/rn_fusebox.ts

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

95-
class FuseboxClientMetadataModel extends SDK.SDKModel.SDKModel<void> {
96-
constructor(target: SDK.Target.Target) {
97-
super(target);
98-
Host.rnPerfMetrics.fuseboxSetClientMetadataStarted();
99-
target.fuseboxClientAgent()
100-
.invoke_setClientMetadata()
101-
.then(result => {
102-
const maybeError = result.getError();
103-
const success = !maybeError;
104-
Host.rnPerfMetrics.fuseboxSetClientMetadataFinished(success, maybeError);
105-
})
106-
.catch(reason => {
107-
const success = false;
108-
Host.rnPerfMetrics.fuseboxSetClientMetadataFinished(success, reason);
109-
});
110-
}
111-
}
112-
11395
SDK.SDKModel.SDKModel.register(
114-
FuseboxClientMetadataModel,
96+
SDK.ReactNativeApplicationModel.ReactNativeApplicationModel,
11597
{
11698
capabilities: SDK.Target.Capability.None,
11799
autostart: true,
118-
// Ensure FuseboxClient.setClientMetadata is sent before most other CDP domains
100+
// Ensure ReactNativeApplication.enable is sent before most other CDP domains
119101
// are initialised. This allows the backend to confidently detect non-Fusebox
120102
// clients by the fact that they send e.g. Runtime.enable without sending any
121103
// Fusebox-specific messages first.

front_end/generated/InspectorBackendCommands.js

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

front_end/generated/protocol-mapping.d.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -765,17 +765,6 @@ export namespace ProtocolMapping {
765765
}
766766

767767
export interface Commands {
768-
/**
769-
* Identifies the current client as being Fusebox.
770-
*
771-
* The Fusebox backend may use this knowledge to print an informational
772-
* message to the console, etc. The client should send this before enabling
773-
* the Runtime and Log domains.
774-
*/
775-
'FuseboxClient.setClientMetadata': {
776-
paramsType: [];
777-
returnType: void;
778-
};
779768
/**
780769
* Disables events from backend.
781770
*/

front_end/generated/protocol-proxy-api.d.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ declare namespace ProtocolProxyApi {
1818
export type ProtocolDomainName = keyof ProtocolApi;
1919

2020
export interface ProtocolApi {
21-
FuseboxClient: FuseboxClientApi;
22-
2321
ReactNativeApplication: ReactNativeApplicationApi;
2422

2523
Accessibility: AccessibilityApi;
@@ -123,8 +121,6 @@ declare namespace ProtocolProxyApi {
123121
}
124122

125123
export interface ProtocolDispatchers {
126-
FuseboxClient: FuseboxClientDispatcher;
127-
128124
ReactNativeApplication: ReactNativeApplicationDispatcher;
129125

130126
Accessibility: AccessibilityDispatcher;
@@ -227,21 +223,6 @@ declare namespace ProtocolProxyApi {
227223

228224
}
229225

230-
231-
export interface FuseboxClientApi {
232-
/**
233-
* Identifies the current client as being Fusebox.
234-
*
235-
* The Fusebox backend may use this knowledge to print an informational
236-
* message to the console, etc. The client should send this before enabling
237-
* the Runtime and Log domains.
238-
*/
239-
invoke_setClientMetadata(): Promise<Protocol.ProtocolResponseWithError>;
240-
241-
}
242-
export interface FuseboxClientDispatcher {
243-
}
244-
245226
export interface ReactNativeApplicationApi {
246227
/**
247228
* Disables events from backend.

front_end/generated/protocol.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@ export interface ProtocolResponseWithError {
1818
type OpaqueType<Tag extends string> = {protocolOpaqueTypeTag: Tag};
1919
type OpaqueIdentifier<RepresentationType, Tag extends string> = RepresentationType&OpaqueType<Tag>;
2020

21-
/**
22-
* A React Native-specific domain pertaining to the Fusebox (React Native
23-
* DevTools) client.
24-
*/
25-
export namespace FuseboxClient {
26-
}
27-
2821
/**
2922
* A React Native-specific domain for interacting with React Native application
3023
* features.

third_party/blink/public/devtools_protocol/browser_protocol.json

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,6 @@
44
"minor": "3"
55
},
66
"domains": [
7-
{
8-
"domain": "FuseboxClient",
9-
"description": "A React Native-specific domain pertaining to the Fusebox (React Native\nDevTools) client.",
10-
"experimental": true,
11-
"commands": [
12-
{
13-
"name": "setClientMetadata",
14-
"description": "Identifies the current client as being Fusebox.\n\nThe Fusebox backend may use this knowledge to print an informational\nmessage to the console, etc. The client should send this before enabling\nthe Runtime and Log domains."
15-
}
16-
]
17-
},
187
{
198
"domain": "ReactNativeApplication",
209
"description": "A React Native-specific domain for interacting with React Native application\nfeatures.",

third_party/blink/public/devtools_protocol/react_native_domains.pdl

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
# Copyright (c) Meta Platforms, Inc. and affiliates.
22

3-
# A React Native-specific domain pertaining to the Fusebox (React Native
4-
# DevTools) client.
5-
experimental domain FuseboxClient
6-
7-
# Identifies the current client as being Fusebox.
8-
#
9-
# The Fusebox backend may use this knowledge to print an informational
10-
# message to the console, etc. The client should send this before enabling
11-
# the Runtime and Log domains.
12-
command setClientMetadata
13-
143
# A React Native-specific domain for interacting with React Native application
154
# features.
165
experimental domain ReactNativeApplication

0 commit comments

Comments
 (0)