@samitouri / QOS-React / commits / b21ca44efc

[repro] bug repro

ghstack-source-id: 64d3266bf39ce5b1b9e9b9470910e029f0e951eb Pull Request resolved: https://github.com/facebook/react-forget/pull/2849

Mofei Zhang committed Apr 23, 2024 at 10:18 UTC b21ca44efc75178d797a6bd0427f83c966b2a00a
3 files changed +136 -2
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/bug-invalid-reactivity-value-block.expect.md new
+97
@@ -0,0 +1,97 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +import {
6 + CONST_TRUE,
7 + identity,
8 + makeObject_Primitives,
9 + useNoAlias,
10 +} from "shared-runtime";
11 +/**
12 + * BUG
13 + * Found differences in evaluator results
14 + * Non-forget (expected):
15 + * (kind: ok) [{"a":0,"b":"value1","c":true},"[[ cyclic ref *1 ]]"]
16 + * [{"a":0,"b":"value1","c":true},"[[ cyclic ref *1 ]]"]
17 + * Forget:
18 + * (kind: ok) [{"a":0,"b":"value1","c":true},"[[ cyclic ref *1 ]]"]
19 + * [[ (exception in render) Error: Oh no! ]]
20 + */
21 +
22 +function Foo() {
23 + const obj = makeObject_Primitives();
24 + // hook calls keeps the next two lines as its own reactive scope
25 + useNoAlias();
26 +
27 + const shouldCaptureObj = obj != null && CONST_TRUE;
28 + const result = [shouldCaptureObj ? identity(obj) : null, obj];
29 +
30 + useNoAlias(result, obj);
31 +
32 + if (shouldCaptureObj && result[0] !== obj) {
33 + throw new Error("Unexpected");
34 + }
35 + return result;
36 +}
37 +
38 +export const FIXTURE_ENTRYPOINT = {
39 + fn: Foo,
40 + params: [{}],
41 + sequentialRenders: [{}, {}],
42 +};
43 +
44 +```
45 +
46 +## Code
47 +
48 +```javascript
49 +import { unstable_useMemoCache as useMemoCache } from "react";
50 +import {
51 + CONST_TRUE,
52 + identity,
53 + makeObject_Primitives,
54 + useNoAlias,
55 +} from "shared-runtime";
56 +/**
57 + * BUG
58 + * Found differences in evaluator results
59 + * Non-forget (expected):
60 + * (kind: ok) [{"a":0,"b":"value1","c":true},"[[ cyclic ref *1 ]]"]
61 + * [{"a":0,"b":"value1","c":true},"[[ cyclic ref *1 ]]"]
62 + * Forget:
63 + * (kind: ok) [{"a":0,"b":"value1","c":true},"[[ cyclic ref *1 ]]"]
64 + * [[ (exception in render) Error: Oh no! ]]
65 + */
66 +
67 +function Foo() {
68 + const $ = useMemoCache(1);
69 + const obj = makeObject_Primitives();
70 +
71 + useNoAlias();
72 +
73 + const shouldCaptureObj = obj != null && CONST_TRUE;
74 + let t0;
75 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
76 + t0 = [shouldCaptureObj ? identity(obj) : null, obj];
77 + $[0] = t0;
78 + } else {
79 + t0 = $[0];
80 + }
81 + const result = t0;
82 +
83 + useNoAlias(result, obj);
84 + if (shouldCaptureObj && result[0] !== obj) {
85 + throw new Error("Unexpected");
86 + }
87 + return result;
88 +}
89 +
90 +export const FIXTURE_ENTRYPOINT = {
91 + fn: Foo,
92 + params: [{}],
93 + sequentialRenders: [{}, {}],
94 +};
95 +
96 +```
97 +
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/bug-invalid-reactivity-value-block.ts new
+38
@@ -0,0 +1,38 @@
1 +import {
2 + CONST_TRUE,
3 + identity,
4 + makeObject_Primitives,
5 + useNoAlias,
6 +} from "shared-runtime";
7 +/**
8 + * BUG
9 + * Found differences in evaluator results
10 + * Non-forget (expected):
11 + * (kind: ok) [{"a":0,"b":"value1","c":true},"[[ cyclic ref *1 ]]"]
12 + * [{"a":0,"b":"value1","c":true},"[[ cyclic ref *1 ]]"]
13 + * Forget:
14 + * (kind: ok) [{"a":0,"b":"value1","c":true},"[[ cyclic ref *1 ]]"]
15 + * [[ (exception in render) Error: Oh no! ]]
16 + */
17 +
18 +function Foo() {
19 + const obj = makeObject_Primitives();
20 + // hook calls keeps the next two lines as its own reactive scope
21 + useNoAlias();
22 +
23 + const shouldCaptureObj = obj != null && CONST_TRUE;
24 + const result = [shouldCaptureObj ? identity(obj) : null, obj];
25 +
26 + useNoAlias(result, obj);
27 +
28 + if (shouldCaptureObj && result[0] !== obj) {
29 + throw new Error("Unexpected");
30 + }
31 + return result;
32 +}
33 +
34 +export const FIXTURE_ENTRYPOINT = {
35 + fn: Foo,
36 + params: [{}],
37 + sequentialRenders: [{}, {}],
38 +};
compiler/packages/snap/src/SproutTodoFilter.ts
+1 -2
@@ -488,8 +488,7 @@ const skipFilter = new Set([
488 "rules-of-hooks/rules-of-hooks-69521d94fa03",
489
490 // bugs
491 - "bug-reduce-reactive-deps-return-in-scope",
492 - "bug-reduce-reactive-deps-break-in-scope",
491 + "bug-invalid-reactivity-value-block",
492
493 // 'react-forget-runtime' not yet supported
494 "flag-enable-emit-hook-guards",