Skip to content

Commit 88d204c

Browse files
JuanKamranAsif
authored andcommitted
Dev Tools: Relax constraint on passing extensionId for backend init (facebook#22597)
1 parent e7610b1 commit 88d204c

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

packages/react-devtools-extensions/src/backend.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Running module factories is intentionally delayed until we know the hook exists.
33
// This is to avoid issues like: https://github.com/facebook/react-devtools/issues/1039
44

5-
/** @flow */
5+
// @flow strict-local
66

77
'use strict';
88

@@ -13,15 +13,16 @@ function welcome(event) {
1313
) {
1414
return;
1515
}
16+
const extensionId = event.data.extensionId;
1617

1718
window.removeEventListener('message', welcome);
1819

19-
setup(window.__REACT_DEVTOOLS_GLOBAL_HOOK__);
20+
setup(window.__REACT_DEVTOOLS_GLOBAL_HOOK__, extensionId);
2021
}
2122

2223
window.addEventListener('message', welcome);
2324

24-
function setup(hook) {
25+
function setup(hook, extensionId) {
2526
if (hook == null) {
2627
// DevTools didn't get injected into this page (maybe b'c of the contentType).
2728
return;
@@ -55,6 +56,7 @@ function setup(hook) {
5556
{
5657
source: 'react-devtools-bridge',
5758
payload: {event, payload},
59+
extensionId,
5860
},
5961
'*',
6062
transferable,

packages/react-devtools-extensions/src/contentScript.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
'use strict';
44

5+
import {CURRENT_EXTENSION_ID} from './constants';
6+
57
let backendDisconnected: boolean = false;
68
let backendInitialized: boolean = false;
79

@@ -10,6 +12,7 @@ function sayHelloToBackend() {
1012
{
1113
source: 'react-devtools-content-script',
1214
hello: true,
15+
extensionId: CURRENT_EXTENSION_ID,
1316
},
1417
'*',
1518
);
@@ -20,6 +23,7 @@ function handleMessageFromDevtools(message) {
2023
{
2124
source: 'react-devtools-content-script',
2225
payload: message,
26+
extensionId: CURRENT_EXTENSION_ID,
2327
},
2428
'*',
2529
);
@@ -49,6 +53,7 @@ function handleDisconnect() {
4953
type: 'event',
5054
event: 'shutdown',
5155
},
56+
extensionId: CURRENT_EXTENSION_ID,
5257
},
5358
'*',
5459
);

packages/react-devtools-extensions/src/injectGlobalHook.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ window.addEventListener('message', function onMessage({data, source}) {
3131
if (source !== window || !data) {
3232
return;
3333
}
34-
if (data.extensionId !== CURRENT_EXTENSION_ID) {
34+
if (data.extensionId != null && data.extensionId !== CURRENT_EXTENSION_ID) {
3535
if (__DEBUG__) {
3636
console.log(
3737
`[injectGlobalHook] Received message '${data.source}' from different extension instance. Skipping message.`,
3838
{
3939
currentExtension: EXTENSION_INSTALLATION_TYPE,
40+
currentExtensionId: CURRENT_EXTENSION_ID,
41+
providedExtensionId: data.extensionId,
4042
},
4143
);
4244
}

0 commit comments

Comments
 (0)