mirror of
https://github.com/facebook/react.git
synced 2026-11-18 20:15:56 +00:00
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:
1 parent
c0b0119356
commit
bfb84eed3b
2 files changed
+36
No files matched your search
+32
@@ -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;
|
||||
}
|
||||
Reference in new issue
Block a user