From 14660ef3d8c772c8df706478b22e74a7934a2e41 Mon Sep 17 00:00:00 2001 From: Edmond Chui <1967998+EdmondChuiHW@users.noreply.github.com> Date: Thu, 5 Sep 2024 18:24:33 +0100 Subject: [PATCH] Add reload-to-profile for Fusebox --- .../panels/react_devtools/ReactDevToolsModel.ts | 13 ++++++++++++- .../react-devtools/package/frontend.d.ts | 4 +++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/front_end/panels/react_devtools/ReactDevToolsModel.ts b/front_end/panels/react_devtools/ReactDevToolsModel.ts index 34fa3a062e7..772d2be45da 100644 --- a/front_end/panels/react_devtools/ReactDevToolsModel.ts +++ b/front_end/panels/react_devtools/ReactDevToolsModel.ts @@ -80,6 +80,10 @@ export class ReactDevToolsModel extends SDK.SDKModel.SDKModel { window.addEventListener('beforeunload', () => this.#bridge?.shutdown()); } + override dispose(): void { + this.#bridge?.removeListener('reloadAppForProfiling', this.#handleReloadAppForProfiling); + } + ensureInitialized(): void { if (this.#initializeCalled) { return; @@ -163,10 +167,17 @@ export class ReactDevToolsModel extends SDK.SDKModel.SDKModel { #finishInitializationAndNotify(): void { this.#bridge = ReactDevTools.createBridge(this.#wall); - this.#store = ReactDevTools.createStore(this.#bridge); + this.#store = ReactDevTools.createStore(this.#bridge, { + supportsReloadAndProfile: true, + }); + this.#bridge.addListener('reloadAppForProfiling', this.#handleReloadAppForProfiling); this.dispatchEventToListeners(Events.InitializationCompleted); } + #handleReloadAppForProfiling(): void { + SDK.ResourceTreeModel.ResourceTreeModel.reloadAllPages(false); + } + #handleBackendExecutionContextUnavailable({data: errorMessage}: ReactDevToolsBindingsBackendExecutionContextUnavailableEvent): void { this.dispatchEventToListeners(Events.InitializationFailed, errorMessage); } diff --git a/front_end/third_party/react-devtools/package/frontend.d.ts b/front_end/third_party/react-devtools/package/frontend.d.ts index 74a88c36a85..52536739cca 100644 --- a/front_end/third_party/react-devtools/package/frontend.d.ts +++ b/front_end/third_party/react-devtools/package/frontend.d.ts @@ -15,7 +15,9 @@ export type Wall = { }; export type Bridge = { - shutdown: () => void, + addListener(event: string, listener: (params: unknown) => any): void; + removeListener(event: string, listener: Function): void; + shutdown: () => void; }; export type Store = Object; export type BrowserTheme = 'dark' | 'light';