Dont memoize hook calls in logical expressions
Fix the previous bug — this was a simple oversight, where FlattenScopesWithHooks overrode `visitValue()` but failed to call `traverseValue()`. This meant that when we reached compound expressions such as LogicalExpressions that we didn't traverse into their nested values, and didn't see the hooks hidden there.
Joe Savona committed
May 2, 2023 at 11:01 UTC
dd6a9d6a03a04ed21319da90c3c0967b53d7f738
2 files changed
+2
-12
compiler/forget/src/ReactiveScopes/FlattenScopesWithHooks.ts
+1
@@ -56,6 +56,7 @@ class Transform extends ReactiveFunctionTransform<State> {
56
value: ReactiveValue,
57
state: State
58
): void {
59
+ this.traverseValue(id, value, state);
60
if (
61
value.kind === "CallExpression" &&
62
isHookType(value.callee.identifier)
compiler/forget/src/__tests__/fixtures/compiler/hook-inside-logical-expression.expect.md
+1
-12
@@ -12,19 +12,8 @@ function Component(props) {
12
## Code
13
14
```javascript
15
-import { unstable_useMemoCache as useMemoCache } from "react";
15
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;
16
+ const user = useFragment(graphql`...`, props.user) ?? {};
17
return user.name;
18
}
19