Commit 3d6d8be
refactor[devtools/extension]: migrate from using setInterval for polling if react is loaded (facebook#27323)
`chrome.devtools.inspectedWindow.eval` is asynchronous, so using it in
`setInterval` is a mistake.
Sometimes this results into mounting React DevTools twice, and user sees
errors about duplicated fibers in store.
With these changes, `executeIfReactHasLoaded` executed recursively with
a threshold (in case if page doesn't have react).
Although we minimize the risk of mounting DevTools twice here, this
approach is not the best way to have this problem solved. Dumping some
thoughts and ideas that I've tried, but which are out of the scope for
this release, because they can be too risky and time-consuming.
Potential changes:
- Have 2 content scripts:
- One `prepareInjection` to notify service worker on renderer attached
- One which runs on `document_idle` to finalize check, in case if there
is no react
- Service worker will notify devtools page that it is ready to mount
React DevTools panels or should show that there is no React to be found
- Extension port from devtools page should be persistent and connected
when `main.js` is executed
- Might require refactoring the logic of how we connect devtools and
proxy ports
Some corner cases:
- Navigating to restricted pages, like `chrome://<something>` and back
- When react is lazily loaded, like in an attached iframe, or just
opened modal
- In-tab navigation with pre-cached pages, I think only Chrome does it
- Firefox is still on manifest v2 and it doesn't allow running content
scripts in ExecutionWorld.MAIN, so it requires a different approach1 parent b149d22 commit 3d6d8be
1 file changed
Lines changed: 28 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
33 | 49 | | |
34 | 50 | | |
35 | 51 | | |
| |||
53 | 69 | | |
54 | 70 | | |
55 | 71 | | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
56 | 79 | | |
57 | 80 | | |
58 | 81 | | |
| |||
413 | 436 | | |
414 | 437 | | |
415 | 438 | | |
416 | | - | |
| 439 | + | |
417 | 440 | | |
418 | 441 | | |
419 | 442 | | |
| |||
453 | 476 | | |
454 | 477 | | |
455 | 478 | | |
456 | | - | |
| 479 | + | |
457 | 480 | | |
458 | 481 | | |
459 | 482 | | |
| |||
504 | 527 | | |
505 | 528 | | |
506 | 529 | | |
507 | | - | |
508 | | - | |
509 | | - | |
510 | | - | |
511 | | - | |
512 | | - | |
513 | | - | |
514 | 530 | | |
515 | | - | |
| 531 | + | |
516 | 532 | | |
517 | 533 | | |
518 | 534 | | |
519 | | - | |
| 535 | + | |
520 | 536 | | |
521 | 537 | | |
522 | | - | |
523 | | - | |
524 | 538 | | |
525 | 539 | | |
526 | 540 | | |
| |||
543 | 557 | | |
544 | 558 | | |
545 | 559 | | |
546 | | - | |
547 | | - | |
548 | 560 | | |
549 | 561 | | |
550 | 562 | | |
| |||
557 | 569 | | |
558 | 570 | | |
559 | 571 | | |
560 | | - | |
561 | | - | |
562 | | - | |
563 | | - | |
564 | | - | |
565 | 572 | | |
566 | 573 | | |
0 commit comments