Skip to content

Commit 7f49656

Browse files
mondaychenkassens
authored andcommitted
(patch)[DevTools] bug fix: backend injection logic not working for undocked devtools window (#26665)
bugfix for #26492 This bug would cause users unable to use the devtools (component tree empty). The else-if logic is broken when user switch to undocked devtools mode (separate window) because `sender.tab` would exist in that case. <img width="314" alt="image" src="https://user-images.githubusercontent.com/1001890/232930094-05a74445-9189-4d50-baf1-a0360b29ef7e.png"> Tested on Chrome with a local build
1 parent a3ac883 commit 7f49656

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
172172

173173
chrome.runtime.onMessage.addListener((request, sender) => {
174174
const tab = sender.tab;
175+
// sender.tab.id from content script points to the tab that injected the content script
175176
if (tab) {
176177
const id = tab.id;
177178
// This is sent from the hook content script.
@@ -214,7 +215,10 @@ chrome.runtime.onMessage.addListener((request, sender) => {
214215
break;
215216
}
216217
}
217-
} else if (request.payload?.tabId) {
218+
}
219+
// sender.tab.id from devtools page may not exist, or point to the undocked devtools window
220+
// so we use the payload to get the tab id
221+
if (request.payload?.tabId) {
218222
const tabId = request.payload?.tabId;
219223
// This is sent from the devtools page when it is ready for injecting the backend
220224
if (request.payload.type === 'react-devtools-inject-backend-manager') {

0 commit comments

Comments
 (0)