@samitouri / QOS-React / commits / 68d5288359

[snap] Add react-compiler-runtime as a dependency (#31142)

We need `react-compiler-runtime` to use the same version of React as snap

lauren committed Oct 7, 2024 at 16:38 UTC 68d5288359c86f7761f099cde1c5c0d22f46757d
5 files changed +34 -15
compiler/package.json
-1
@@ -19,7 +19,6 @@
19 "test": "yarn workspaces run test",
20 "snap": "yarn workspace babel-plugin-react-compiler run snap",
21 "snap:build": "yarn workspace snap run build",
22 - "postinstall": "perl -p -i -e 's/react\\.element/react.transitional.element/' node_modules/fbt/lib/FbtReactUtil.js && perl -p -i -e 's/didWarnAboutUsingAct = false;/didWarnAboutUsingAct = true;/' node_modules/react-dom/cjs/react-dom-test-utils.development.js",
22 "npm:publish": "node scripts/release/publish"
23 },
24 "dependencies": {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/infer-component-props-non-null.expect.md
+20 -11
@@ -12,7 +12,7 @@ function Foo(props) {
12 * as it is arg[0] of a component function
13 */
14 const arr = [];
15 - if (cond) {
15 + if (props.cond) {
16 arr.push(identity(props.value));
17 }
18 return <Stringify arr={arr} />;
@@ -20,7 +20,7 @@ function Foo(props) {
20
21 export const FIXTURE_ENTRYPOINT = {
22 fn: Foo,
23 - params: [{value: 2}],
23 + params: [{value: 2, cond: true}],
24 };
25
26 ```
@@ -32,29 +32,38 @@ import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
32 import { identity, Stringify } from "shared-runtime";
33
34 function Foo(props) {
35 - const $ = _c(2);
35 + const $ = _c(5);
36 let t0;
37 - if ($[0] !== props.value) {
37 + if ($[0] !== props.cond || $[1] !== props.value) {
38 const arr = [];
39 - if (cond) {
40 - arr.push(identity(props.value));
39 + if (props.cond) {
40 + let t1;
41 + if ($[3] !== props.value) {
42 + t1 = identity(props.value);
43 + $[3] = props.value;
44 + $[4] = t1;
45 + } else {
46 + t1 = $[4];
47 + }
48 + arr.push(t1);
49 }
50
51 t0 = <Stringify arr={arr} />;
44 - $[0] = props.value;
45 - $[1] = t0;
52 + $[0] = props.cond;
53 + $[1] = props.value;
54 + $[2] = t0;
55 } else {
47 - t0 = $[1];
56 + t0 = $[2];
57 }
58 return t0;
59 }
60
61 export const FIXTURE_ENTRYPOINT = {
62 fn: Foo,
54 - params: [{ value: 2 }],
63 + params: [{ value: 2, cond: true }],
64 };
65
66 ```
67
68 ### Eval output
60 -(kind: exception) cond is not defined
\ No newline at end of file
69 +(kind: ok) <div>{"arr":[2]}</div>
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/infer-component-props-non-null.tsx
+2 -2
@@ -8,7 +8,7 @@ function Foo(props) {
8 * as it is arg[0] of a component function
9 */
10 const arr = [];
11 - if (cond) {
11 + if (props.cond) {
12 arr.push(identity(props.value));
13 }
14 return <Stringify arr={arr} />;
@@ -16,5 +16,5 @@ function Foo(props) {
16
17 export const FIXTURE_ENTRYPOINT = {
18 fn: Foo,
19 - params: [{value: 2}],
19 + params: [{value: 2, cond: true}],
20 };
compiler/packages/snap/package.json
+2 -1
@@ -9,7 +9,8 @@
9 "src"
10 ],
11 "scripts": {
12 - "build": "rimraf dist && tsc --build",
12 + "postinstall": "./scripts/link-react-compiler-runtime.sh && perl -p -i -e 's/react\\.element/react.transitional.element/' ../../node_modules/fbt/lib/FbtReactUtil.js && perl -p -i -e 's/didWarnAboutUsingAct = false;/didWarnAboutUsingAct = true;/' ../../node_modules/react-dom/cjs/react-dom-test-utils.development.js",
13 + "build": "rimraf dist && concurrently -n snap,runtime \"tsc --build\" \"yarn --silent workspace react-compiler-runtime build --silent\"",
14 "test": "echo 'no tests'",
15 "prettier": "prettier --write 'src/**/*.ts'"
16 },
compiler/packages/snap/scripts/link-react-compiler-runtime.sh new
+10
@@ -0,0 +1,10 @@
1 +#!/usr/bin/env bash
2 +# Copyright (c) Meta Platforms, Inc. and affiliates.
3 +#
4 +# This source code is licensed under the MIT license found in the
5 +# LICENSE file in the root directory of this source tree.
6 +
7 +set -eo pipefail
8 +
9 +yarn --silent workspace react-compiler-runtime link
10 +yarn --silent workspace snap link react-compiler-runtime