@samitouri / QOS-React-2 / commits / bfb84eed3b

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).

Joe Savona committed May 2, 2023 at 10:47 UTC bfb84eed3b4c863474e0b2fa1d5dde3c638ec470
2 files changed +36
compiler/forget/src/__tests__/fixtures/compiler/hook-inside-logical-expression.expect.md new
+32
@@ -0,0 +1,32 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +function Component(props) {
6 + const user = useFragment(graphql`...`, props.user) ?? {};
7 + return user.name;
8 +}
9 +
10 +```
11 +
12 +## Code
13 +
14 +```javascript
15 +import { unstable_useMemoCache as useMemoCache } from "react";
16 +function Component(props) {
17 + const $ = useMemoCache(2);
18 + const c_0 = $[0] !== props.user;
19 + let t0;
20 + if (c_0) {
21 + t0 = useFragment(graphql`...`, props.user) ?? {};
22 + $[0] = props.user;
23 + $[1] = t0;
24 + } else {
25 + t0 = $[1];
26 + }
27 + const user = t0;
28 + return user.name;
29 +}
30 +
31 +```
32 +
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/hook-inside-logical-expression.js new
+4
@@ -0,0 +1,4 @@
1 +function Component(props) {
2 + const user = useFragment(graphql`...`, props.user) ?? {};
3 + return user.name;
4 +}