[compiler] Repro: updates to globals should be retained
ghstack-source-id: 7ee813c0d72e3c752b299f63bfcec3647b022544 Pull Request resolved: https://github.com/facebook/react/pull/30470
Mofei Zhang committed
Jul 26, 2024 at 17:36 UTC
2a9274a73e52554f95b9420bf62c9f78d26c5d1e
5 files changed
+111
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/bug-invalid-update-global-should-bailout.expect.md
new
+32
@@ -0,0 +1,32 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+let renderCount = 0;
6
+function useFoo() {
7
+ renderCount += 1;
8
+ return renderCount;
9
+}
10
+
11
+export const FIXTURE_ENTRYPOINT = {
12
+ fn: useFoo,
13
+ params: [],
14
+};
15
+
16
+```
17
+
18
+## Code
19
+
20
+```javascript
21
+let renderCount = 0;
22
+function useFoo() {
23
+ return renderCount;
24
+}
25
+
26
+export const FIXTURE_ENTRYPOINT = {
27
+ fn: useFoo,
28
+ params: [],
29
+};
30
+
31
+```
32
+
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/bug-invalid-update-global-should-bailout.tsx
new
+10
@@ -0,0 +1,10 @@
1
+let renderCount = 0;
2
+function useFoo() {
3
+ renderCount += 1;
4
+ return renderCount;
5
+}
6
+
7
+export const FIXTURE_ENTRYPOINT = {
8
+ fn: useFoo,
9
+ params: [],
10
+};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/bug-update-global-in-callback.expect.md
new
+52
@@ -0,0 +1,52 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+import {Stringify} from 'shared-runtime';
6
+
7
+let renderCount = 0;
8
+function Foo() {
9
+ const cb = () => {
10
+ renderCount += 1;
11
+ return renderCount;
12
+ };
13
+ return <Stringify cb={cb} shouldInvokeFns={true} />;
14
+}
15
+
16
+export const FIXTURE_ENTRYPOINT = {
17
+ fn: Foo,
18
+ params: [{}],
19
+};
20
+
21
+```
22
+
23
+## Code
24
+
25
+```javascript
26
+import { c as _c } from "react/compiler-runtime";
27
+import { Stringify } from "shared-runtime";
28
+
29
+let renderCount = 0;
30
+function Foo() {
31
+ const $ = _c(1);
32
+ const cb = _temp;
33
+ let t0;
34
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
35
+ t0 = <Stringify cb={cb} shouldInvokeFns={true} />;
36
+ $[0] = t0;
37
+ } else {
38
+ t0 = $[0];
39
+ }
40
+ return t0;
41
+}
42
+function _temp() {
43
+ return renderCount;
44
+}
45
+
46
+export const FIXTURE_ENTRYPOINT = {
47
+ fn: Foo,
48
+ params: [{}],
49
+};
50
+
51
+```
52
+
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/bug-update-global-in-callback.tsx
new
+15
@@ -0,0 +1,15 @@
1
+import {Stringify} from 'shared-runtime';
2
+
3
+let renderCount = 0;
4
+function Foo() {
5
+ const cb = () => {
6
+ renderCount += 1;
7
+ return renderCount;
8
+ };
9
+ return <Stringify cb={cb} shouldInvokeFns={true} />;
10
+}
11
+
12
+export const FIXTURE_ENTRYPOINT = {
13
+ fn: Foo,
14
+ params: [{}],
15
+};
compiler/packages/snap/src/SproutTodoFilter.ts
+2
@@ -484,6 +484,8 @@ const skipFilter = new Set([
484
'rules-of-hooks/rules-of-hooks-69521d94fa03',
485
486
// bugs
487
+ 'bug-invalid-update-global-should-bailout',
488
+ 'bug-update-global-in-callback',
489
'bug-invalid-hoisting-functionexpr',
490
'original-reactive-scopes-fork/bug-nonmutating-capture-in-unsplittable-memo-block',
491
'original-reactive-scopes-fork/bug-hoisted-declaration-with-scope',