[test] Add failing test showing useMemo bug

This commit is contained in:
Sathya Gunasekaran
2023-04-17 20:59:35 +01:00
parent 34bca247d6
commit 31f6dd8070
2 changed files with 55 additions and 0 deletions
@@ -0,0 +1,46 @@
## Input
```javascript
// @inlineUseMemo
function component(a, b) {
let x = useMemo(() => {
if (a) {
return { b };
}
}, [a, b]);
return x;
}
```
## Code
```javascript
// @inlineUseMemo
function component(a, b) {
const $ = React.unstable_useMemoCache(3);
if (a) {
const c_0 = $[0] !== b;
let t0;
if (c_0) {
t0 = { b };
$[0] = b;
$[1] = t0;
} else {
t0 = $[1];
}
let t1;
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
t1 = t0;
$[2] = t1;
} else {
t1 = $[2];
}
}
const x = t1;
return x;
}
```
@@ -0,0 +1,9 @@
// @inlineUseMemo
function component(a, b) {
let x = useMemo(() => {
if (a) {
return { b };
}
}, [a, b]);
return x;
}