The library for web and native user interfaces.
Fixture for transitive invalidation of effect dep
This fixture shows that this optimization partially improves transitive checking for validateMemoizedEffectDependencies.
Joe Savona committed
Mar 6, 2024 at 09:28 UTC
4af3ff1e759682c05336341f242bb886a81839f3
2 files changed
+63
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.validate-memoized-effect-deps-invalidated-dep-value.expect.md
new
+44
@@ -0,0 +1,44 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+// @validateMemoizedEffectDependencies
6
+import { useHook } from "shared-runtime";
7
+
8
+function Component(props) {
9
+ const x = [];
10
+ useHook(); // intersperse a hook call to prevent memoization of x
11
+ x.push(props.value);
12
+
13
+ const y = [x];
14
+
15
+ useEffect(() => {
16
+ console.log(y);
17
+ }, [y]);
18
+}
19
+
20
+export const FIXTURE_ENTRYPOINT = {
21
+ fn: Component,
22
+ params: [{ value: "sathya" }],
23
+};
24
+
25
+```
26
+
27
+
28
+## Error
29
+
30
+```
31
+ 9 | const y = [x];
32
+ 10 |
33
+> 11 | useEffect(() => {
34
+ | ^^^^^^^^^^^^^^^^^
35
+> 12 | console.log(y);
36
+ | ^^^^^^^^^^^^^^^^^^^
37
+> 13 | }, [y]);
38
+ | ^^^^^^^^^^ [ReactForget] InvalidReact: This effect may trigger an infinite loop: one or more of its dependencies could not be memoized due to a later mutation (11:13)
39
+ 14 | }
40
+ 15 |
41
+ 16 | export const FIXTURE_ENTRYPOINT = {
42
+```
43
+
44
+
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.validate-memoized-effect-deps-invalidated-dep-value.js
new
+19
@@ -0,0 +1,19 @@
1
+// @validateMemoizedEffectDependencies
2
+import { useHook } from "shared-runtime";
3
+
4
+function Component(props) {
5
+ const x = [];
6
+ useHook(); // intersperse a hook call to prevent memoization of x
7
+ x.push(props.value);
8
+
9
+ const y = [x];
10
+
11
+ useEffect(() => {
12
+ console.log(y);
13
+ }, [y]);
14
+}
15
+
16
+export const FIXTURE_ENTRYPOINT = {
17
+ fn: Component,
18
+ params: [{ value: "sathya" }],
19
+};