-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[compiler] Add DependencyPath optional property
Adds an `optional: boolean` property to each token in a DependencyPath, currently always set to false. Also updates the equality and printing logic for paths to account for this field. Subsequent PRs will update our logic to determine which manual dependencies were optional, then we can start inferring optional deps as well. ghstack-source-id: 882ee8745e6a115b3dc80eaff183e2a0e27ad6f6 Pull Request resolved: facebook/react#30813
- Loading branch information
1 parent
e9356cc
commit 7212340
Showing
8 changed files
with
55 additions
and
9 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
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
32 changes: 32 additions & 0 deletions
32
..._/fixtures/compiler/error.todo-optional-member-expression-as-memo-dep.expect.md
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,32 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
// @validatePreserveExistingMemoizationGuarantees | ||
function Component(props) { | ||
const data = useMemo(() => { | ||
return props.items?.edges?.nodes ?? []; | ||
}, [props.items?.edges?.nodes]); | ||
return <Foo data={data} />; | ||
} | ||
|
||
``` | ||
## Error | ||
``` | ||
1 | // @validatePreserveExistingMemoizationGuarantees | ||
2 | function Component(props) { | ||
> 3 | const data = useMemo(() => { | ||
| ^^^^^^^ | ||
> 4 | return props.items?.edges?.nodes ?? []; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
> 5 | }, [props.items?.edges?.nodes]); | ||
| ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected (3:5) | ||
6 | return <Foo data={data} />; | ||
7 | } | ||
8 | | ||
``` | ||
7 changes: 7 additions & 0 deletions
7
...iler/src/__tests__/fixtures/compiler/error.todo-optional-member-expression-as-memo-dep.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,7 @@ | ||
// @validatePreserveExistingMemoizationGuarantees | ||
function Component(props) { | ||
const data = useMemo(() => { | ||
return props.items?.edges?.nodes ?? []; | ||
}, [props.items?.edges?.nodes]); | ||
return <Foo data={data} />; | ||
} |