Skip to content

Commit

Permalink
Fixed broken 'shutdown' event that lead to CPU problems when reloadin…
Browse files Browse the repository at this point in the history
…g DevTools
  • Loading branch information
tigrevol8888 committed Feb 20, 2019
1 parent 92de804 commit 3990717
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion shells/browser/shared/src/contentScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function handleDisconnect() {
source: 'react-devtools-content-script',
payload: {
type: 'event',
evt: 'shutdown',
event: 'shutdown',
},
},
'*'
Expand Down
5 changes: 5 additions & 0 deletions shells/browser/shared/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import Bridge from 'src/bridge';
import Store from 'src/devtools/Store';
import inject from './inject';

let panelCreated = false;

Expand Down Expand Up @@ -48,6 +49,10 @@ function createPanelIfReactLoaded() {

store = new Store(bridge);

// Initialize the backend only once the Store has been initialized.
// Otherwise the Store may miss important initial tree op codes.
inject(chrome.runtime.getURL('build/backend.js'));

if (elementsPanel !== null) {
elementsPanel.injectBridgeAndStore(bridge, store);
}
Expand Down
7 changes: 0 additions & 7 deletions shells/browser/shared/src/panels/utils.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
/* global chrome */

import { createElement } from 'react';
import { createRoot, flushSync } from 'react-dom';
import DevTools from 'src/devtools/views/DevTools';
import inject from '../inject';
import { getBrowserName, getBrowserTheme } from '../utils';

export function createPanel(defaultTab) {
Expand Down Expand Up @@ -45,9 +42,5 @@ export function createPanel(defaultTab) {
store: injectedStore,
})
);

// Initialize the backend only once the DevTools frontend Store has been initialized.
// Otherwise the Store may miss important initial tree op codes.
inject(chrome.runtime.getURL('build/backend.js'));
}
}
8 changes: 4 additions & 4 deletions src/backend/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ export type Hook = {
rendererInterfaces: Map<RendererID, RendererInterface>,
renderers: Map<RendererID, ReactRenderer>,

emit: (evt: string, data: any) => void,
emit: (event: string, data: any) => void,
getFiberRoots: (rendererID: RendererID) => Set<Object>,
inject: (renderer: ReactRenderer) => number | null,
on: (evt: string, handler: Handler) => void,
off: (evt: string, handler: Handler) => void,
on: (event: string, handler: Handler) => void,
off: (event: string, handler: Handler) => void,
reactDevtoolsAgent?: ?Object,
sub: (evt: string, handler: Handler) => () => void,
sub: (event: string, handler: Handler) => () => void,

// React uses these methods.
checkDCE: (fn: Function) => void,
Expand Down
10 changes: 6 additions & 4 deletions src/devtools/views/SelectedElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,20 +248,22 @@ function useInspectedElement(id: number | null): InspectedElement | null {

setInspectedElement(inspectedElement);

// Ask for an update in a second...
timeoutID = setTimeout(sendBridgeRequest, 1000);
// Ask for an update in a second.
// Make sure we only ask once though.
clearTimeout(((timeoutID: any): TimeoutID));
setTimeout(sendBridgeRequest, 1000);
};

bridge.addListener('inspectedElement', onInspectedElement);

sendBridgeRequest();

return () => {
bridge.removeListener('inspectedElement', onInspectedElement);

if (timeoutID !== null) {
clearTimeout(timeoutID);
}

bridge.removeListener('inspectedElement', onInspectedElement);
};
}, [bridge, id, idRef, store]);

Expand Down

0 comments on commit 3990717

Please sign in to comment.