Skip to content

Commit b6c0aa8

Browse files
authored
[compiler]: fix link compiler & 4 broken tests from path containing spaces (#33409)
## Summary Problem #1: Running the `link-compiler.sh` bash script via `"prebuild"` script fails if a developer has cloned the `react` repo into a folder that contains _any_ spaces. 3 tests fail because of this. <img width="1003" alt="fail-1" src="https://github.com/user-attachments/assets/1fbfa9ce-4f84-48d7-b49c-b6e967b8c7ca" /> <img width="1011" alt="fail-2" src="https://github.com/user-attachments/assets/0a8c6371-a2df-4276-af98-38f4784cf0da" /> <img width="1027" alt="fail-3" src="https://github.com/user-attachments/assets/1c4f4429-800c-4b44-b3da-a59ac85a16b9" /> For example, my current folder is: `/Users/wes/Development/Open Source Contributions/react` The link compiler error returns: `./scripts/react-compiler/link-compiler.sh: line 15: cd: /Users/wes/Development/Open: No such file or directory` Problem #2: 1 test in `ReactChildren-test.js` fails due the existing stack trace regex which should be lightly revised. `([^(\[\n]+)[^\n]*/g` is more robust for stack traces: it captures the function/class name (with dots) and does not break on spaces in file paths. `([\S]+)[^\n]*/g` is simpler but breaks if there are spaces and doesn't handle dotted names well. Additionally, we trim the whitespace off the name to resolve extra spaces breaking this test as well: ``` - in div (at **) + in div (at **) ``` <img width="987" alt="fail-4" src="https://github.com/user-attachments/assets/56a673bc-513f-4458-95b2-224129c77144" /> All of the above tests pass if I hyphenate my local folder: `/Users/wes/Development/Open-Source-Contributions/react` I selfishly want to keep spaces in my folder names. 🫣 ## How did you test this change? **npx yarn prebuild** Before: <img width="896" alt="Screenshot at Jun 01 11-42-56" src="https://github.com/user-attachments/assets/4692775c-1e5c-4851-9bd7-e12ed5455e47" /> After: <img width="420" alt="Screenshot at Jun 01 11-43-42" src="https://github.com/user-attachments/assets/4e303c00-02b7-4540-ba19-927b2d7034fb" /> **npx yarn test** **npx yarn test ./packages/react/src/\_\_tests\_\_/ReactChildren-test.js** **npx yarn test -r=xplat --env=development --variant=true --ci --shard=3/5** Before: <img width="438" alt="before" src="https://github.com/user-attachments/assets/f5eedb22-18c3-4124-a04b-daa95c0f7652" /> After: <img width="439" alt="after" src="https://github.com/user-attachments/assets/a94218ba-7c6a-4f08-85d3-57540e9d0029" /> <img width="650" alt="Screenshot at Jun 02 18-03-39" src="https://github.com/user-attachments/assets/3eae993c-a56b-46c8-ae02-d249cb053fe7" /> <img width="685" alt="Screenshot at Jun 03 12-53-47" src="https://github.com/user-attachments/assets/5b2caa33-d3dc-4804-981d-52cb10b6226f" />
1 parent 428ab82 commit b6c0aa8

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

compiler/apps/playground/scripts/link-compiler.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ set -eo pipefail
88

99
HERE=$(pwd)
1010

11-
cd ../../packages/react-compiler-runtime && yarn --silent link && cd $HERE
12-
cd ../../packages/babel-plugin-react-compiler && yarn --silent link && cd $HERE
11+
cd ../../packages/react-compiler-runtime && yarn --silent link && cd "$HERE"
12+
cd ../../packages/babel-plugin-react-compiler && yarn --silent link && cd "$HERE"
1313

1414
yarn --silent link babel-plugin-react-compiler
1515
yarn --silent link react-compiler-runtime

packages/internal-test-utils/consoleMock.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ function normalizeCodeLocInfo(str) {
156156
// at Component (/path/filename.js:123:45)
157157
// React format:
158158
// in Component (at filename.js:123)
159-
return str.replace(/\n +(?:at|in) ([\S]+)[^\n]*/g, function (m, name) {
159+
return str.replace(/\n +(?:at|in) ([^(\[\n]+)[^\n]*/g, function (m, name) {
160+
name = name.trim();
160161
if (name.endsWith('.render')) {
161162
// Class components will have the `render` method as part of their stack trace.
162163
// We strip that out in our normalization to make it look more like component stacks.

scripts/react-compiler/link-compiler.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ fi
1212

1313
HERE=$(pwd)
1414

15-
cd compiler/packages/babel-plugin-react-compiler && yarn --silent link && cd $HERE
15+
cd compiler/packages/babel-plugin-react-compiler && yarn --silent link && cd "$HERE"
1616

1717
yarn --silent link babel-plugin-react-compiler

0 commit comments

Comments
 (0)