Skip to content

Commit

Permalink
[DevTools] Support object destructuring pattern without runtime errors (
Browse files Browse the repository at this point in the history
#22128)

## Summary

Before this commit, if a hook returned an object and we declared a variable using object destructuring on the returned value, we would produce a runtime error. This was detected via internal testing.

This commit fixes that and adds regression tests.


## Test Plan

- yarn flow
- yarn test
- yarn test-build-devtools
- added new regression tests 
- named hooks still work on manual test of browser extension on a few different apps (code sandbox, create-react-app, internally).
  • Loading branch information
Juan authored Aug 18, 2021
1 parent 7ed0706 commit f1db9c3
Show file tree
Hide file tree
Showing 26 changed files with 195 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ export class SourceMapMetadataConsumer {
return getHookNameForLocation({line, column}, hookMap);
}

hasHookMap(source: ?string) {
hasHookMap(source: ?string): boolean {
if (source == null) {
return null;
return false;
}
return this._getHookMapForSource(source) != null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
* @flow
*/

import React, {useEffect, useState} from 'react';
import React, {useDebugValue, useEffect, useState} from 'react';

export function Component() {
const [count, setCount] = useState(0);
const isDarkMode = useIsDarkMode();
const {foo} = useFoo();

useEffect(() => {
// ...
Expand All @@ -23,6 +24,7 @@ export function Component() {
<>
<div>Dark mode? {isDarkMode}</div>
<div>Count: {count}</div>
<div>Foo: {foo}</div>
<button onClick={handleClick}>Update count</button>
</>
);
Expand All @@ -37,3 +39,8 @@ function useIsDarkMode() {

return isDarkMode;
}

function useFoo() {
useDebugValue('foo');
return {foo: true};
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f1db9c3

Please sign in to comment.