-
Notifications
You must be signed in to change notification settings - Fork 46.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[compiler] Allow inferred non-optional paths when manual deps were op…
…tional If the inferred deps are more precise (non-optional) than the manual deps (optional) it should pass validation. The other direction also seems like it would be fine - inferring optional deps when the original was non-optional - but for now let's keep the "at least as precise" rule. ghstack-source-id: 8f34860deafefe48c7a374caa1b55482e571308d Pull Request resolved: #30816
- Loading branch information
1 parent
76ce3ed
commit ac01cf7
Showing
3 changed files
with
67 additions
and
4 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
50 changes: 50 additions & 0 deletions
50
.../compiler/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,50 @@ | ||
|
||
## 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} />; | ||
} | ||
|
||
``` | ||
## Code | ||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees | ||
function Component(props) { | ||
const $ = _c(4); | ||
|
||
props.items?.edges?.nodes; | ||
let t0; | ||
let t1; | ||
if ($[0] !== props.items.edges.nodes) { | ||
t1 = props.items.edges.nodes ?? []; | ||
$[0] = props.items.edges.nodes; | ||
$[1] = t1; | ||
} else { | ||
t1 = $[1]; | ||
} | ||
t0 = t1; | ||
const data = t0; | ||
let t2; | ||
if ($[2] !== data) { | ||
t2 = <Foo data={data} />; | ||
$[2] = data; | ||
$[3] = t2; | ||
} else { | ||
t2 = $[3]; | ||
} | ||
return t2; | ||
} | ||
|
||
``` | ||
### Eval output | ||
(kind: exception) Fixture not implemented |
9 changes: 9 additions & 0 deletions
9
..._tests__/fixtures/compiler/optional-member-expression-as-memo-dep-non-optional-in-body.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,9 @@ | ||
// @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} />; | ||
} |