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

[DevTools] Emit new event when DevTools connects in standalone app #22848

Merged
merged 1 commit into from
Dec 6, 2021
Merged
Changes from all commits
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
16 changes: 12 additions & 4 deletions packages/react-devtools-core/src/standalone.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@ import type {InspectedElement} from 'react-devtools-shared/src/devtools/views/Co

installHook(window);

export type StatusListener = (message: string) => void;
export type StatusTypes = 'server-connected' | 'devtools-connected' | 'error';
export type StatusListener = (message: string, status: StatusTypes) => void;
export type OnDisconnectedCallback = () => void;

let node: HTMLElement = ((null: any): HTMLElement);
let nodeWaitingToConnectHTML: string = '';
let projectRoots: Array<string> = [];
let statusListener: StatusListener = (message: string) => {};
let statusListener: StatusListener = (
message: string,
status?: StatusTypes,
) => {};
let disconnectedCallback: OnDisconnectedCallback = () => {};

// TODO (Webpack 5) Hopefully we can remove this prop after the Webpack 5 migration.
Expand Down Expand Up @@ -260,6 +264,7 @@ function initialize(socket: WebSocket) {
});

log('Connected');
statusListener('DevTools initialized.', 'devtools-connected');
reload();
}

Expand Down Expand Up @@ -372,12 +377,15 @@ function startServer(

httpServer.on('error', event => {
onError(event);
statusListener('Failed to start the server.');
statusListener('Failed to start the server.', 'error');
startServerTimeoutID = setTimeout(() => startServer(port), 1000);
});

httpServer.listen(port, () => {
statusListener('The server is listening on the port ' + port + '.');
statusListener(
'The server is listening on the port ' + port + '.',
'server-connected',
);
});

return {
Expand Down