-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Supporting hook variable names in devtools extension #115
Conversation
7401fb3
to
dd932fe
Compare
dd932fe
to
c6ba425
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just did a quick read through and left a few thoughts. Exciting progress!
packages/react-devtools-shared/src/devtools/views/Components/InspectedElement.js
Outdated
Show resolved
Hide resolved
c6ba425
to
1bd801d
Compare
9516688
to
5fae37c
Compare
64f9113
to
ff7b6c3
Compare
8efb506
to
31ce9bc
Compare
Hi @bvaughn, some updates:
We had some questions:
|
Excited to see this useful feature in future. Much appreciated your efforts 👍 |
Any updates when this feature will be released? |
I'm going to try to rebase this branch now. Looks like it's got a few conflicts. Hopefully it won't be too crazy 😅 The logic around suspending to inspect the selected element has changed a lot in recent months, to improve the Suspense/cache integration, so there are non-trivial conflicts in |
@VibhorCodecianGupta Agreed that this would be nicer than embedding the |
I've merged master into this branch and resolved a lot of conflicts, but some of them are pretty large (like in the inspected element context) so I'm going to be working on merging/rewriting that section for a little bit. For now, I'm going to be pushing my changes to a separate branch: facebook#21641 If either @saphal1998 or @VibhorCodecianGupta would be interested in talking through some of these changes, I'd be happy to. I know it's been a while though and the MLH program is over, so if you're both too busy– I understand that as well! Thanks for the work you did putting this PR together. :) |
function getSourceMapURL(url: string, urlResponse: string): string { | ||
const sourceMappingUrlRegExp = /\/\/[#@] ?sourceMappingURL=([^\s'"]+)\s*$/mg | ||
const sourceMappingURLInArray = urlResponse.match(sourceMappingUrlRegExp); | ||
if (sourceMappingURLInArray && sourceMappingURLInArray.length > 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Sandbox uses base64 encoded source maps. So maybe we could have a branch here that loads the file or decodes the inline source map using atob()
Hi @bvaughn! We would love to help out in any way we can! Unfortunately though, both @VibhorCodecianGupta and I, have lost context of the nitty gritty of the work done, we'll just go over it this PR again this weekend, to get some context back so that we are in better position to give inputs. Can you let us know if you have any specific things you want us to look into so that we can have a more focussed discussion on this? |
Hi @saphal1998! I've opened a PR against the React repo over here: facebook#21641 I've jotted down a checklist of things to do or look at there. I'll just be chipping away at them. If there's anything you or @VibhorCodecianGupta would be interested in picking up, let's just chat and you could maybe open a PR to my branch 😄 |
Hi again @saphal1998 and @VibhorCodecianGupta 😁 I've added some additional unit tests here: Which includes some tests that use inline and external source maps (using this test component compiled by this script). Unfortunately the test fails b'c there's a line number mismatch between the compiled source and source-map parsed original source, which causes the function useCustomHook() {
const [stateValue] = useState(true);
return stateValue;
} ~~I'm a little stumped and would welcome any ideas you two have 😄 ~~ Edit It seems that the majority of this was due to a Jest runner opting Errors into automatically taking source maps into accountability. This makes sense for testing simplicity in most cases, but was horribly breaking the logic in these tests specifically, so this behavior was disabled in facebook@9f4627f. |
@@ -516,13 +529,22 @@ function buildTree(rootStack, readHookLog): HooksTree { | |||
|
|||
// For the time being, only State and Reducer hooks support runtime overrides. | |||
const isStateEditable = primitive === 'Reducer' || primitive === 'State'; | |||
const hookSource: HookSource = {lineNumber: null, functionName: null, fileName: null, columnNumber: null} | |||
if (stack && stack.length >= 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OR
if (stack && stack.length >= 1) { | |
if (stack?.length) { |
@@ -172,6 +172,7 @@ function HookView({ | |||
|
|||
let displayValue; | |||
let isComplexDisplayValue = false; | |||
const customHookDisplayName = hookVariableName ? `${name}(${hookVariableName})` : name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 💯
value: mixed, | ||
subHooks: Array<HooksNode>, | ||
hookSource: HookSource, | ||
... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am just curious to know why you have spread operator here, I mean what's it's doing here? 🤔
This feature has just been merged into the React Thank you for all of your hard work! 🥳 |
Excellent work @bvaughn . How do we go about getting the latest update? Is it just a matter of updating the chrome extension? |
It will probably be released with the next major DevTools version, once it's been tested inside of Facebook for a bit. This is a pretty big feature and I want to give it a little of time to smoke test with a few hundred engineers before pushing it out to millions. |
@bvaughn thanks a lot for picking this up! We have not been able to give this any time at all due to other prior commitments, so we really appreciate this! |
Solves #72 #80 #116 #117 #118 #119
To obtain the names of the hooks, we adopt the following approach -