Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reattachment of the splash page event listeners (#22558) #22560

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/react-devtools-core/src/standalone.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 OnShutdownCallback = () => void;

let node: HTMLElement = ((null: any): HTMLElement);
let nodeWaitingToConnectHTML: string = '';
let projectRoots: Array<string> = [];
let statusListener: StatusListener = (message: string) => {};
let shutdownCallback: OnShutdownCallback = () => {};

// TODO (Webpack 5) Hopefully we can remove this prop after the Webpack 5 migration.
function hookNamesModuleLoaderFunction() {
Expand All @@ -73,6 +75,11 @@ function setStatusListener(value: StatusListener) {
return DevtoolsUI;
}

function setDisconnectedCallback(value: OnShutdownCallback) {
shutdownCallback = value;
return DevtoolsUI;
}

let bridge: FrontendBridge | null = null;
let store: Store | null = null;
let root = null;
Expand Down Expand Up @@ -153,6 +160,8 @@ function onDisconnected() {
safeUnmount();

node.innerHTML = nodeWaitingToConnectHTML;

shutdownCallback();
}

function onError({code, message}) {
Expand Down Expand Up @@ -389,6 +398,7 @@ const DevtoolsUI = {
setContentDOMNode,
setProjectRoots,
setStatusListener,
setDisconnectedCallback,
startServer,
openProfiler,
};
Expand Down
50 changes: 28 additions & 22 deletions packages/react-devtools/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -196,7 +194,9 @@
selection.removeAllRanges();
selection.addRange(range);
clipboard.writeText(event.target.textContent);


Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to move these query selectors inside the method because they kept referencing the past elements before the disconnection and didn't show the "Copied to clipboard" message.

const $promptDiv = $("#box-content-prompt");
const $confirmationDiv = $("#box-content-confirmation");
$promptDiv.classList.add('hidden');
$confirmationDiv.classList.remove('hidden');

Expand All @@ -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 = `<script src="${server}"></` + 'script>';
$localhost.addEventListener('click', selectAllAndCopy);
$localhost.addEventListener('focus', selectAllAndCopy);

const $byIp = $("#byip");
$byIp.innerText = `<script src="${serverIp}"></` + 'script>';
$byIp.addEventListener('click', selectAllAndCopy);
$byIp.addEventListener('focus', selectAllAndCopy);
function attachListeners() {
const link = $('#rn-help-link');
link.addEventListener('click', event => {
event.preventDefault();
require('electron').shell.openExternal(link.href);
});

const $localhost = $("#localhost");
$localhost.innerText = `<script src="${server}"></` + 'script>';
$localhost.addEventListener('click', selectAllAndCopy);
$localhost.addEventListener('focus', selectAllAndCopy);

const $byIp = $("#byip");
$byIp.innerText = `<script src="${serverIp}"></` + 'script>';
$byIp.addEventListener('click', selectAllAndCopy);
$byIp.addEventListener('focus', selectAllAndCopy);

const $profiler = $("#profiler");
$profiler.addEventListener('click', openProfiler);
};

const $profiler = $("#profiler");
$profiler.addEventListener('click', openProfiler);
// Initially attach the listeners
attachListeners();

let devtools;
try {
Expand All @@ -248,6 +253,7 @@
window.devtools = devtools;
window.server = devtools
.setContentDOMNode(document.getElementById("container"))
.setDisconnectedCallback(attachListeners)
.setStatusListener(function(status) {
const element = document.getElementById("loading-status");
if (element) {
Expand Down