-
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.
[compiler] Inferred deps must match exact optionality of manual deps
To prevent any difference in behavior, we check that the optionality of the inferred deps exactly matches the optionality of the manual dependencies. This required a fix, I was incorrectly inferring optionality of manual deps (they're only optional if OptionalTerminal.optional is true) - for nested cases of mixed optional/non-optional. [ghstack-poisoned]
- Loading branch information
1 parent
51d4844
commit 0691f5f
Showing
7 changed files
with
57 additions
and
72 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
38 changes: 38 additions & 0 deletions
38
...r.invalid-optional-member-expression-as-memo-dep-non-optional-in-body.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,38 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
// @validatePreserveExistingMemoizationGuarantees | ||
function Component(props) { | ||
const data = useMemo(() => { | ||
// actual code is non-optional | ||
return props.items.edges.nodes ?? []; | ||
// deps are optional | ||
}, [props.items?.edges?.nodes]); | ||
return <Foo data={data} />; | ||
} | ||
|
||
``` | ||
## Error | ||
``` | ||
1 | // @validatePreserveExistingMemoizationGuarantees | ||
2 | function Component(props) { | ||
> 3 | const data = useMemo(() => { | ||
| ^^^^^^^ | ||
> 4 | // actual code is non-optional | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
> 5 | return props.items.edges.nodes ?? []; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
> 6 | // deps are optional | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
> 7 | }, [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:7) | ||
8 | return <Foo data={data} />; | ||
9 | } | ||
10 | | ||
``` | ||
File renamed without changes.
50 changes: 0 additions & 50 deletions
50
.../compiler/optional-member-expression-as-memo-dep-non-optional-in-body.expect.md
This file was deleted.
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