@samitouri / QOS-React / commits / c91676b557

Don't change browser selection unless React selection changed

Dan committed Apr 8, 2019 at 21:57 UTC c91676b557438727cc0f13d462159f15cf9f908d
2 files changed +21 -2
shells/browser/shared/src/main.js
+19 -1
@@ -85,6 +85,16 @@ function createPanelIfReactLoaded() {
85 );
86 });
87
88 + // Remember if we should sync the browser DevTools to the React tab.
89 + // We'll only do that if user intentionally chooses a different React component.
90 + let lastSelectedID = null;
91 + bridge.addListener('selectElement', ({ id }) => {
92 + if (!hasReactSelectionChanged && lastSelectedID !== id) {
93 + hasReactSelectionChanged = true;
94 + lastSelectedID = id;
95 + }
96 + });
97 +
98 // This flag lets us tip the Store off early that we expect to be profiling.
99 // This avoids flashing a temporary "Profiling not supported" message in the Profiler tab,
100 // after a user has clicked the "reload and profile" button.
@@ -180,12 +190,20 @@ function createPanelIfReactLoaded() {
190 );
191 }
192
193 + let hasReactSelectionChanged = false;
194 +
195 function maybeSetBrowserSelectionFromReact() {
196 + // Don't change the browser element selection when navigating away
197 + // from the Components tab if the user didn't change the React selection.
198 + if (!hasReactSelectionChanged) {
199 + return;
200 + }
201 + hasReactSelectionChanged = false;
202 chrome.devtools.inspectedWindow.eval(
203 '(window.__REACT_DEVTOOLS_GLOBAL_HOOK__.$0 != null)' +
204 ' ? (inspect(window.__REACT_DEVTOOLS_GLOBAL_HOOK__.$0), true)' +
205 ' : false',
188 - (didChangeSelection, error) => {
206 + (_, error) => {
207 if (error) {
208 console.error(error);
209 }
src/backend/agent.js
+2 -1
@@ -304,7 +304,8 @@ export default class Agent extends EventEmitter {
304 if (node !== null) {
305 window.__REACT_DEVTOOLS_GLOBAL_HOOK__.$0 = node;
306 }
307 - this._bridge.send('selectElement', renderer.selectElement(id));
307 + renderer.selectElement(id);
308 + this._bridge.send('selectElement', { id });
309 }
310 };
311