@samitouri / QOS-React-2 / commits / 5ca4b04332

Dev Tools: Relax constraint on passing extensionId for backend init (#22597)

Juan committed Oct 20, 2021 at 09:50 UTC 5ca4b0433205d01294b6306a3a90af1103e37dc9
3 files changed +13 -4
packages/react-devtools-extensions/src/backend.js
+5 -3
@@ -2,7 +2,7 @@
2 // Running module factories is intentionally delayed until we know the hook exists.
3 // This is to avoid issues like: https://github.com/facebook/react-devtools/issues/1039
4
5 -/** @flow */
5 +// @flow strict-local
6
7 'use strict';
8
@@ -13,15 +13,16 @@ function welcome(event) {
13 ) {
14 return;
15 }
16 + const extensionId = event.data.extensionId;
17
18 window.removeEventListener('message', welcome);
19
19 - setup(window.__REACT_DEVTOOLS_GLOBAL_HOOK__);
20 + setup(window.__REACT_DEVTOOLS_GLOBAL_HOOK__, extensionId);
21 }
22
23 window.addEventListener('message', welcome);
24
24 -function setup(hook) {
25 +function setup(hook, extensionId) {
26 if (hook == null) {
27 // DevTools didn't get injected into this page (maybe b'c of the contentType).
28 return;
@@ -55,6 +56,7 @@ function setup(hook) {
56 {
57 source: 'react-devtools-bridge',
58 payload: {event, payload},
59 + extensionId,
60 },
61 '*',
62 transferable,
packages/react-devtools-extensions/src/contentScript.js
+5
@@ -2,6 +2,8 @@
2
3 'use strict';
4
5 +import {CURRENT_EXTENSION_ID} from './constants';
6 +
7 let backendDisconnected: boolean = false;
8 let backendInitialized: boolean = false;
9
@@ -10,6 +12,7 @@ function sayHelloToBackend() {
12 {
13 source: 'react-devtools-content-script',
14 hello: true,
15 + extensionId: CURRENT_EXTENSION_ID,
16 },
17 '*',
18 );
@@ -20,6 +23,7 @@ function handleMessageFromDevtools(message) {
23 {
24 source: 'react-devtools-content-script',
25 payload: message,
26 + extensionId: CURRENT_EXTENSION_ID,
27 },
28 '*',
29 );
@@ -49,6 +53,7 @@ function handleDisconnect() {
53 type: 'event',
54 event: 'shutdown',
55 },
56 + extensionId: CURRENT_EXTENSION_ID,
57 },
58 '*',
59 );
packages/react-devtools-extensions/src/injectGlobalHook.js
+3 -1
@@ -31,12 +31,14 @@ window.addEventListener('message', function onMessage({data, source}) {
31 if (source !== window || !data) {
32 return;
33 }
34 - if (data.extensionId !== CURRENT_EXTENSION_ID) {
34 + if (data.extensionId != null && data.extensionId !== CURRENT_EXTENSION_ID) {
35 if (__DEBUG__) {
36 console.log(
37 `[injectGlobalHook] Received message '${data.source}' from different extension instance. Skipping message.`,
38 {
39 currentExtension: EXTENSION_INSTALLATION_TYPE,
40 + currentExtensionId: CURRENT_EXTENSION_ID,
41 + providedExtensionId: data.extensionId,
42 },
43 );
44 }