@samitouri / QOS-React / commits / 2bd415355e

[compiler][repro] ValidatePreserveMemo x useRef bug

ghstack-source-id: 6ac5d58e97eba92642b5e4c5e2f915d91a5730dc Pull Request resolved: https://github.com/facebook/react/pull/30602

Mofei Zhang committed Aug 7, 2024 at 16:11 UTC 2bd415355e3ec9b87859b68af05972bc50390753
2 files changed +59
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/bug-maybe-mutable-ref-memo-not-preserved.expect.md new
+45
@@ -0,0 +1,45 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +// @validatePreserveExistingMemoizationGuarantees:true
6 +
7 +import {useRef, useMemo} from 'react';
8 +import {makeArray} from 'shared-runtime';
9 +
10 +function useFoo() {
11 + const r = useRef();
12 + return useMemo(() => makeArray(r), []);
13 +}
14 +
15 +export const FIXTURE_ENTRYPOINT = {
16 + fn: useFoo,
17 + params: [],
18 +};
19 +
20 +```
21 +
22 +## Code
23 +
24 +```javascript
25 +// @validatePreserveExistingMemoizationGuarantees:true
26 +
27 +import { useRef, useMemo } from "react";
28 +import { makeArray } from "shared-runtime";
29 +
30 +function useFoo() {
31 + const r = useRef();
32 + let t0;
33 + t0 = makeArray(r);
34 + return t0;
35 +}
36 +
37 +export const FIXTURE_ENTRYPOINT = {
38 + fn: useFoo,
39 + params: [],
40 +};
41 +
42 +```
43 +
44 +### Eval output
45 +(kind: ok) [{}]
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/bug-maybe-mutable-ref-memo-not-preserved.ts new
+14
@@ -0,0 +1,14 @@
1 +// @validatePreserveExistingMemoizationGuarantees:true
2 +
3 +import {useRef, useMemo} from 'react';
4 +import {makeArray} from 'shared-runtime';
5 +
6 +function useFoo() {
7 + const r = useRef();
8 + return useMemo(() => makeArray(r), []);
9 +}
10 +
11 +export const FIXTURE_ENTRYPOINT = {
12 + fn: useFoo,
13 + params: [],
14 +};