@samitouri / QOS-React / commits / 7022e8d6a3

fix[devtools/extension]: fixed duplicating panels in firefox (#27320)

Multiple `chrome.panels.create` calls result into having duplicate panels created in Firefox, these changes fix that. Now calling `chrome.panels.create` only if there are no panels created yet.

Ruslan Lesiutin committed Aug 31, 2023 at 18:24 UTC 7022e8d6a3222c97d287dfa0f2361acc8a30683a
1 file changed +18
packages/react-devtools-extensions/src/main/index.js
+18
@@ -340,16 +340,24 @@ function ensureInitialHTMLIsCleared(container) {
340
341 function createComponentsPanel() {
342 if (componentsPortalContainer) {
343 + // Panel is created and user opened it at least once
344 render('components');
345
346 return;
347 }
348
349 + if (componentsPanel) {
350 + // Panel is created, but wasn't opened yet, so no document is present for it
351 + return;
352 + }
353 +
354 chrome.devtools.panels.create(
355 IS_CHROME || IS_EDGE ? '⚛️ Components' : 'Components',
356 IS_EDGE ? 'icons/production.svg' : '',
357 'panel.html',
358 createdPanel => {
359 + componentsPanel = createdPanel;
360 +
361 createdPanel.onShown.addListener(portal => {
362 componentsPortalContainer = portal.container;
363 if (componentsPortalContainer != null) {
@@ -370,16 +378,24 @@ function createComponentsPanel() {
378
379 function createProfilerPanel() {
380 if (profilerPortalContainer) {
381 + // Panel is created and user opened it at least once
382 render('profiler');
383
384 return;
385 }
386
387 + if (profilerPanel) {
388 + // Panel is created, but wasn't opened yet, so no document is present for it
389 + return;
390 + }
391 +
392 chrome.devtools.panels.create(
393 IS_CHROME || IS_EDGE ? '⚛️ Profiler' : 'Profiler',
394 IS_EDGE ? 'icons/production.svg' : '',
395 'panel.html',
396 createdPanel => {
397 + profilerPanel = createdPanel;
398 +
399 createdPanel.onShown.addListener(portal => {
400 profilerPortalContainer = portal.container;
401 if (profilerPortalContainer != null) {
@@ -510,6 +526,8 @@ let store = null;
526
527 let profilingData = null;
528
529 +let componentsPanel = null;
530 +let profilerPanel = null;
531 let componentsPortalContainer = null;
532 let profilerPortalContainer = null;
533