-
Notifications
You must be signed in to change notification settings - Fork 47.4k
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
DevTools: Show hook names based on variable usage #21641
Merged
+2,966
−74
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
d75814c
Initial work to support hook variable names in devtools extension.
3dd1247
Moved named hooks feature before enableHookNameParsing flag
48632b7
Moved hook names parsing behind user setting
6a1eecd
Moved feature flag override logic into test helper
f502611
Added compiled test sources to Git repo
cb80fba
Test script auto-compiles all source files
81770cd
Added Jest serializer for Hooks (to sanitize source location)
d508c43
Removed injectHookVariableNames-test in favor of less hard-coded pars…
75d2256
Don't generate hook source unless feature flag is enabled
8075462
Remove hard-coded mappings.wasm file from source
7f3af1c
Reorganized tests slightly
49dd494
Fixed stack trace errors. Added additional tests
f91e8d8
Prevent Jest from configuring Error source-maps
43bd1b2
Account for Error stack frames having source maps already applied
475ef1b
Refactored AST utils slightly
9b7d709
Fixed timeout logic error in hook names cache
57f15ac
Map hook to hook name (rather than array) for sub hooks
064da9e
Added DEBUG logging to parseHookNames util
6222d7f
Updated hook names tests to account for map vs array
615d8e4
Added option to lazily parse hook names for only the currently inspec…
9f7a22f
Added an LRU cache and eviction strategy for source code/ASTs
73fafbe
Enabled external hooks test
8c4fcb9
Error source map stack frame check is now lazy instead of during modu…
3bf7311
Styled custom hook names too
401b94e
Reverted files that were accidentally modified from main branch
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Map hook to hook name (rather than array) for sub hooks
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
packages/react-devtools-extensions/src/__tests__/__source__/ComponentWithCustomHook.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,39 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
import React, {useEffect, useState} from 'react'; | ||
|
||
export function Component() { | ||
const [count, setCount] = useState(0); | ||
const isDarkMode = useIsDarkMode(); | ||
|
||
useEffect(() => { | ||
// ... | ||
}, []); | ||
|
||
const handleClick = () => setCount(count + 1); | ||
|
||
return ( | ||
<> | ||
<div>Dark mode? {isDarkMode}</div> | ||
<div>Count: {count}</div> | ||
<button onClick={handleClick}>Update count</button> | ||
</> | ||
); | ||
} | ||
|
||
function useIsDarkMode() { | ||
const [isDarkMode] = useState(false); | ||
|
||
useEffect(function useEffectCreate() { | ||
// Here is where we may listen to a "theme" event... | ||
}, []); | ||
|
||
return isDarkMode; | ||
} |
42 changes: 42 additions & 0 deletions
42
...ools-extensions/src/__tests__/__source__/__compiled__/external/ComponentWithCustomHook.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
...-extensions/src/__tests__/__source__/__compiled__/external/ComponentWithCustomHook.js.map
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
42 changes: 42 additions & 0 deletions
42
...vtools-extensions/src/__tests__/__source__/__compiled__/inline/ComponentWithCustomHook.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Are we assuming that a line number is sufficient to identify a hook call? Seems like that assumption breaks down in edge cases:
IMO it's safer to use all the information we have from the source map / AST and consider both lines and columns everywhere.
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.
Yeah. Sounds reasonable. I've created #21792 to follow up.