Skip to content

Commit 68d5288

Browse files
authored
[snap] Add react-compiler-runtime as a dependency (#31142)
We need `react-compiler-runtime` to use the same version of React as snap
1 parent 0e43aa7 commit 68d5288

File tree

5 files changed

+34
-15
lines changed

5 files changed

+34
-15
lines changed

compiler/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
"test": "yarn workspaces run test",
2020
"snap": "yarn workspace babel-plugin-react-compiler run snap",
2121
"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",
2322
"npm:publish": "node scripts/release/publish"
2423
},
2524
"dependencies": {

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/infer-component-props-non-null.expect.md

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ function Foo(props) {
1212
* as it is arg[0] of a component function
1313
*/
1414
const arr = [];
15-
if (cond) {
15+
if (props.cond) {
1616
arr.push(identity(props.value));
1717
}
1818
return <Stringify arr={arr} />;
1919
}
2020

2121
export const FIXTURE_ENTRYPOINT = {
2222
fn: Foo,
23-
params: [{value: 2}],
23+
params: [{value: 2, cond: true}],
2424
};
2525

2626
```
@@ -32,29 +32,38 @@ import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
3232
import { identity, Stringify } from "shared-runtime";
3333

3434
function Foo(props) {
35-
const $ = _c(2);
35+
const $ = _c(5);
3636
let t0;
37-
if ($[0] !== props.value) {
37+
if ($[0] !== props.cond || $[1] !== props.value) {
3838
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);
4149
}
4250

4351
t0 = <Stringify arr={arr} />;
44-
$[0] = props.value;
45-
$[1] = t0;
52+
$[0] = props.cond;
53+
$[1] = props.value;
54+
$[2] = t0;
4655
} else {
47-
t0 = $[1];
56+
t0 = $[2];
4857
}
4958
return t0;
5059
}
5160

5261
export const FIXTURE_ENTRYPOINT = {
5362
fn: Foo,
54-
params: [{ value: 2 }],
63+
params: [{ value: 2, cond: true }],
5564
};
5665

5766
```
5867
5968
### Eval output
60-
(kind: exception) cond is not defined
69+
(kind: ok) <div>{"arr":[2]}</div>

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/infer-component-props-non-null.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ function Foo(props) {
88
* as it is arg[0] of a component function
99
*/
1010
const arr = [];
11-
if (cond) {
11+
if (props.cond) {
1212
arr.push(identity(props.value));
1313
}
1414
return <Stringify arr={arr} />;
1515
}
1616

1717
export const FIXTURE_ENTRYPOINT = {
1818
fn: Foo,
19-
params: [{value: 2}],
19+
params: [{value: 2, cond: true}],
2020
};

compiler/packages/snap/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"src"
1010
],
1111
"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\"",
1314
"test": "echo 'no tests'",
1415
"prettier": "prettier --write 'src/**/*.ts'"
1516
},
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

0 commit comments

Comments
 (0)