@@ -323,8 +323,6 @@ function createBridgeAndStore() {
323
323
} ) ,
324
324
) ;
325
325
} ;
326
-
327
- render ( ) ;
328
326
}
329
327
330
328
const viewUrlSourceFunction = ( url , line , col ) => {
@@ -364,14 +362,14 @@ function createComponentsPanel() {
364
362
}
365
363
} ) ;
366
364
367
- // TODO: we should listen to extension .onHidden to unmount some listeners
365
+ // TODO: we should listen to createdPanel .onHidden to unmount some listeners
368
366
// and potentially stop highlighting
369
367
} ,
370
368
) ;
371
369
}
372
370
373
371
function createProfilerPanel ( ) {
374
- if ( componentsPortalContainer ) {
372
+ if ( profilerPortalContainer ) {
375
373
render ( 'profiler' ) ;
376
374
377
375
return ;
@@ -398,6 +396,9 @@ function createProfilerPanel() {
398
396
}
399
397
400
398
function performInTabNavigationCleanup ( ) {
399
+ // Potentially, if react hasn't loaded yet and user performs in-tab navigation
400
+ clearReactPollingInterval ( ) ;
401
+
401
402
if ( store !== null ) {
402
403
// Store profiling data, so it can be used later
403
404
profilingData = store . profilerStore . profilingData ;
@@ -435,6 +436,9 @@ function performInTabNavigationCleanup() {
435
436
}
436
437
437
438
function performFullCleanup ( ) {
439
+ // Potentially, if react hasn't loaded yet and user closed the browser DevTools
440
+ clearReactPollingInterval ( ) ;
441
+
438
442
if ( ( componentsPortalContainer || profilerPortalContainer ) && root ) {
439
443
// This should also emit bridge.shutdown, but only if this root was mounted
440
444
flushSync ( ( ) => root . unmount ( ) ) ;
@@ -455,14 +459,24 @@ function performFullCleanup() {
455
459
port = null ;
456
460
}
457
461
458
- function mountReactDevTools ( ) {
459
- registerEventsLogger ( ) ;
460
-
462
+ function connectExtensionPort ( ) {
461
463
const tabId = chrome . devtools . inspectedWindow . tabId ;
462
464
port = chrome . runtime . connect ( {
463
465
name : String ( tabId ) ,
464
466
} ) ;
465
467
468
+ // This port may be disconnected by Chrome at some point, this callback
469
+ // will be executed only if this port was disconnected from the other end
470
+ // so, when we call `port.disconnect()` from this script,
471
+ // this should not trigger this callback and port reconnection
472
+ port . onDisconnect . addListener ( connectExtensionPort ) ;
473
+ }
474
+
475
+ function mountReactDevTools ( ) {
476
+ registerEventsLogger ( ) ;
477
+
478
+ connectExtensionPort ( ) ;
479
+
466
480
createBridgeAndStore ( ) ;
467
481
468
482
setReactSelectionFromBrowser ( bridge ) ;
@@ -477,18 +491,20 @@ function mountReactDevToolsWhenReactHasLoaded() {
477
491
const checkIfReactHasLoaded = ( ) => executeIfReactHasLoaded ( onReactReady ) ;
478
492
479
493
// Check to see if React has loaded in case React is added after page load
480
- const reactPollingIntervalId = setInterval ( ( ) => {
494
+ reactPollingIntervalId = setInterval ( ( ) => {
481
495
checkIfReactHasLoaded ( ) ;
482
496
} , 500 ) ;
483
497
484
498
function onReactReady ( ) {
485
- clearInterval ( reactPollingIntervalId ) ;
499
+ clearReactPollingInterval ( ) ;
486
500
mountReactDevTools ( ) ;
487
501
}
488
502
489
503
checkIfReactHasLoaded ( ) ;
490
504
}
491
505
506
+ let reactPollingIntervalId = null ;
507
+
492
508
let bridge = null ;
493
509
let store = null ;
494
510
@@ -509,6 +525,8 @@ chrome.devtools.network.onNavigated.addListener(syncSavedPreferences);
509
525
510
526
// Cleanup previous page state and remount everything
511
527
chrome . devtools . network . onNavigated . addListener ( ( ) => {
528
+ clearReactPollingInterval ( ) ;
529
+
512
530
performInTabNavigationCleanup ( ) ;
513
531
mountReactDevToolsWhenReactHasLoaded ( ) ;
514
532
} ) ;
@@ -521,5 +539,10 @@ if (IS_FIREFOX) {
521
539
window . addEventListener ( 'beforeunload' , performFullCleanup ) ;
522
540
}
523
541
542
+ function clearReactPollingInterval ( ) {
543
+ clearInterval ( reactPollingIntervalId ) ;
544
+ reactPollingIntervalId = null ;
545
+ }
546
+
524
547
syncSavedPreferences ( ) ;
525
548
mountReactDevToolsWhenReactHasLoaded ( ) ;
0 commit comments