From 9d3d03025cf2474286ee5d9ba642f3ea9377a435 Mon Sep 17 00:00:00 2001 From: Gabriel Trompiz Date: Fri, 15 Oct 2021 08:16:43 -0500 Subject: [PATCH] Reattachment of the splash page event listeners (#22558) (#22560) --- .../react-devtools-core/src/standalone.js | 10 ++++ packages/react-devtools/app.html | 50 +++++++++++-------- 2 files changed, 38 insertions(+), 22 deletions(-) diff --git a/packages/react-devtools-core/src/standalone.js b/packages/react-devtools-core/src/standalone.js index fae70937ea0aa..1ef01e8ffc026 100644 --- a/packages/react-devtools-core/src/standalone.js +++ b/packages/react-devtools-core/src/standalone.js @@ -42,11 +42,13 @@ import type {InspectedElement} from 'react-devtools-shared/src/devtools/views/Co installHook(window); export type StatusListener = (message: string) => void; +export type OnDisconnectedCallback = () => void; let node: HTMLElement = ((null: any): HTMLElement); let nodeWaitingToConnectHTML: string = ''; let projectRoots: Array = []; let statusListener: StatusListener = (message: string) => {}; +let disconnectedCallback: OnDisconnectedCallback = () => {}; // TODO (Webpack 5) Hopefully we can remove this prop after the Webpack 5 migration. function hookNamesModuleLoaderFunction() { @@ -73,6 +75,11 @@ function setStatusListener(value: StatusListener) { return DevtoolsUI; } +function setDisconnectedCallback(value: OnDisconnectedCallback) { + disconnectedCallback = value; + return DevtoolsUI; +} + let bridge: FrontendBridge | null = null; let store: Store | null = null; let root = null; @@ -153,6 +160,8 @@ function onDisconnected() { safeUnmount(); node.innerHTML = nodeWaitingToConnectHTML; + + disconnectedCallback(); } function onError({code, message}) { @@ -389,6 +398,7 @@ const DevtoolsUI = { setContentDOMNode, setProjectRoots, setStatusListener, + setDisconnectedCallback, startServer, openProfiler, }; diff --git a/packages/react-devtools/app.html b/packages/react-devtools/app.html index fc631cea1ca6a..b60ef3c094b8b 100644 --- a/packages/react-devtools/app.html +++ b/packages/react-devtools/app.html @@ -182,11 +182,9 @@ const server = defaultPort ? `${protocol}://${host}` : `${protocol}://${host}:${port}`; const serverIp = defaultPort ? `${protocol}://${localIp}` : `${protocol}://${localIp}:${port}`; const $ = document.querySelector.bind(document); - const $promptDiv = $("#box-content-prompt"); - const $confirmationDiv = $("#box-content-confirmation"); - + let timeoutID; - + function selectAllAndCopy(event) { const element = event.target; if (window.getSelection) { @@ -196,7 +194,9 @@ selection.removeAllRanges(); selection.addRange(range); clipboard.writeText(event.target.textContent); - + + const $promptDiv = $("#box-content-prompt"); + const $confirmationDiv = $("#box-content-confirmation"); $promptDiv.classList.add('hidden'); $confirmationDiv.classList.remove('hidden'); @@ -217,24 +217,29 @@ .openProfiler(); } - const link = $('#rn-help-link'); - link.addEventListener('click', event => { - event.preventDefault(); - require('electron').shell.openExternal(link.href); - }); - - const $localhost = $("#localhost"); - $localhost.innerText = `