Repro for memoized hook within logical expression

Repro of a bug in which we incorrect memoize hook calls that are inside logical 
expressions (though the bug could occur for ternaries, optional calls, and 
sequence expressions too).
This commit is contained in:
Joe Savona
2023-05-02 10:47:48 -07:00
parent c0b0119356
commit bfb84eed3b
2 changed files with 36 additions and 0 deletions
@@ -0,0 +1,32 @@
## Input
```javascript
function Component(props) {
const user = useFragment(graphql`...`, props.user) ?? {};
return user.name;
}
```
## Code
```javascript
import { unstable_useMemoCache as useMemoCache } from "react";
function Component(props) {
const $ = useMemoCache(2);
const c_0 = $[0] !== props.user;
let t0;
if (c_0) {
t0 = useFragment(graphql`...`, props.user) ?? {};
$[0] = props.user;
$[1] = t0;
} else {
t0 = $[1];
}
const user = t0;
return user.name;
}
```
@@ -0,0 +1,4 @@
function Component(props) {
const user = useFragment(graphql`...`, props.user) ?? {};
return user.name;
}