@samitouri / QOS-React-1 / commits / a65de775e2

[compiler] Add repro for func properties bug with gating

When gating is enabled, any function declaration properties that were previously set (typically `Function.displayName`) would cause a crash after compilation as the original identifier is no longer present. ghstack-source-id: beb7e258561ea598d306fa67706d34a8788d9322 Pull Request resolved: https://github.com/facebook/react/pull/29802

Lauren Tan committed Jun 7, 2024 at 15:39 UTC a65de775e2120b7b8195bfdc75791fc1cb6ac14f
3 files changed +108
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/bug-gating-invalid-function-properties.expect.md new
+84
@@ -0,0 +1,84 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +// @gating
6 +
7 +/**
8 + * Fail: bug-gating-invalid-function-properties
9 + * Unexpected error in Forget runner
10 + * Component is not defined
11 + */
12 +export default function Component() {
13 + return <></>;
14 +}
15 +
16 +export function Component2() {
17 + return <></>;
18 +}
19 +
20 +Component.displayName = "Component ONE";
21 +Component2.displayName = "Component TWO";
22 +
23 +export const FIXTURE_ENTRYPOINT = {
24 + fn: Component,
25 + params: [],
26 + sequentialRenders: [],
27 +};
28 +
29 +```
30 +
31 +## Code
32 +
33 +```javascript
34 +import { isForgetEnabled_Fixtures } from "ReactForgetFeatureFlag";
35 +import { c as _c } from "react/compiler-runtime"; // @gating
36 +
37 +/**
38 + * Fail: bug-gating-invalid-function-properties
39 + * Unexpected error in Forget runner
40 + * Component is not defined
41 + */
42 +export default isForgetEnabled_Fixtures()
43 + ? function Component() {
44 + const $ = _c(1);
45 + let t0;
46 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
47 + t0 = <></>;
48 + $[0] = t0;
49 + } else {
50 + t0 = $[0];
51 + }
52 + return t0;
53 + }
54 + : function Component() {
55 + return <></>;
56 + };
57 +
58 +export const Component2 = isForgetEnabled_Fixtures()
59 + ? function Component2() {
60 + const $ = _c(1);
61 + let t0;
62 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
63 + t0 = <></>;
64 + $[0] = t0;
65 + } else {
66 + t0 = $[0];
67 + }
68 + return t0;
69 + }
70 + : function Component2() {
71 + return <></>;
72 + };
73 +
74 +Component.displayName = "Component ONE";
75 +Component2.displayName = "Component TWO";
76 +
77 +export const FIXTURE_ENTRYPOINT = {
78 + fn: Component,
79 + params: [],
80 + sequentialRenders: [],
81 +};
82 +
83 +```
84 +
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/bug-gating-invalid-function-properties.tsx new
+23
@@ -0,0 +1,23 @@
1 +// @gating
2 +
3 +/**
4 + * Fail: bug-gating-invalid-function-properties
5 + * Unexpected error in Forget runner
6 + * Component is not defined
7 + */
8 +export default function Component() {
9 + return <></>;
10 +}
11 +
12 +export function Component2() {
13 + return <></>;
14 +}
15 +
16 +Component.displayName = "Component ONE";
17 +Component2.displayName = "Component TWO";
18 +
19 +export const FIXTURE_ENTRYPOINT = {
20 + fn: Component,
21 + params: [],
22 + sequentialRenders: [],
23 +};
compiler/packages/snap/src/SproutTodoFilter.ts
+1
@@ -490,6 +490,7 @@ const skipFilter = new Set([
490 "bug-invalid-hoisting-functionexpr",
491 "original-reactive-scopes-fork/bug-nonmutating-capture-in-unsplittable-memo-block",
492 "original-reactive-scopes-fork/bug-hoisted-declaration-with-scope",
493 + "bug-gating-invalid-function-properties",
494
495 // 'react-compiler-runtime' not yet supported
496 "flag-enable-emit-hook-guards",