-
Notifications
You must be signed in to change notification settings - Fork 47k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DevTools] Make function inspection instant (#30786)
I noticed that there is a delay due to the inspection being split into one part that gets the attribute and another eval that does the inspection. This is a bit hacky and uses temporary global names that are leaky. The timeout was presumably to ensure that the first step had fully propagated but it's slow. As we've learned, it can be throttled, and it isn't a guarantee either way. Instead, we can just consolidate these into a single operation that by-passes the bridge and goes straight to the renderer interface from the eval. I did the same for the viewElementSource helper even though that's not currently in use since #28471 but I think we probably should return to that technique when it's available since it's more reliable than the throw - at least in Chrome. I'm not sure about the status of React Native here. In Firefox, inspecting a function with source maps doesn't seem to work. It doesn't jump to original code.
- Loading branch information
1 parent
1b74782
commit f65ac7b
Showing
6 changed files
with
90 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
packages/react-devtools-extensions/src/main/sourceSelection.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* global chrome */ | ||
|
||
export function viewAttributeSource(rendererID, elementID, path) { | ||
chrome.devtools.inspectedWindow.eval( | ||
'{' + // The outer block is important because it means we can declare local variables. | ||
'const renderer = window.__REACT_DEVTOOLS_GLOBAL_HOOK__.rendererInterfaces.get(' + | ||
JSON.stringify(rendererID) + | ||
');' + | ||
'if (renderer) {' + | ||
' const value = renderer.getElementAttributeByPath(' + | ||
JSON.stringify(elementID) + | ||
',' + | ||
JSON.stringify(path) + | ||
');' + | ||
' if (value) {' + | ||
' inspect(value);' + | ||
' true;' + | ||
' } else {' + | ||
' false;' + | ||
' }' + | ||
'} else {' + | ||
' false;' + | ||
'}' + | ||
'}', | ||
(didInspect, evalError) => { | ||
if (evalError) { | ||
console.error(evalError); | ||
} | ||
}, | ||
); | ||
} | ||
|
||
export function viewElementSource(rendererID, elementID) { | ||
chrome.devtools.inspectedWindow.eval( | ||
'{' + // The outer block is important because it means we can declare local variables. | ||
'const renderer = window.__REACT_DEVTOOLS_GLOBAL_HOOK__.rendererInterfaces.get(' + | ||
JSON.stringify(rendererID) + | ||
');' + | ||
'if (renderer) {' + | ||
' const value = renderer.getElementSourceFunctionById(' + | ||
JSON.stringify(elementID) + | ||
');' + | ||
' if (value) {' + | ||
' inspect(value);' + | ||
' true;' + | ||
' } else {' + | ||
' false;' + | ||
' }' + | ||
'} else {' + | ||
' false;' + | ||
'}' + | ||
'}', | ||
(didInspect, evalError) => { | ||
if (evalError) { | ||
console.error(evalError); | ||
} | ||
}, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters