You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: contributingGuides/REACT_COMPILER.md
+41-3Lines changed: 41 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,9 +6,46 @@
6
6
7
7
At Expensify, we are early adopters of this tool and aim to fully leverage its capabilities.
8
8
9
-
## React Compiler compatibility check
9
+
## React Compiler compliance checker
10
10
11
-
To check if your code can be compiled by React Compiler and hence gets all its optimizations "for free", you can run the `npm run react-compiler-healthcheck-test` locally and analyze the output.
11
+
We provide a script, `scripts/react-compiler-compliance-check.ts`, which checks for "Rules of React" compliance locally and enforces these in PRs adding or changing React code through a CI check.
12
+
13
+
### What it does
14
+
15
+
Runs `react-compiler-healthcheck` in verbose mode, parses output, and summarizes which files compiled and which failed, including file, line, column, and reason. It can:
16
+
17
+
- Check all files or a specific file/glob
18
+
- Check only files changed relative to a base branch
19
+
- Optionally generate a machine-readable report `react-compiler-report.json`
20
+
- Exit with non-zero code when failures are found (useful for CI)
21
+
22
+
### Usage
23
+
24
+
> [!NOTE]
25
+
> This script uses `origin` as the base remote by default. If your GH remote is named differently, use the `--remote <name>` flag.
26
+
27
+
#### Check entire codebase or a specific file/glob
28
+
29
+
```bash
30
+
npm run react-compiler-compliance-check check # Check all files
31
+
npm run react-compiler-compliance-check check src/path/Component.tsx # Check specific file
32
+
npm run react-compiler-compliance-check check "src/**/*.tsx"# Check glob pattern
33
+
```
34
+
35
+
#### Check only changed files against a remote main (default remote is `origin`)
36
+
37
+
```bash
38
+
npm run react-compiler-compliance-check check-changed
39
+
```
40
+
41
+
#### Generate a detailed report (saved as `./react-compiler-report.json`)
42
+
43
+
You can use the `--report` flag with both of the above commands:
44
+
45
+
```bash
46
+
npm run react-compiler-compliance-check check --report
47
+
npm run react-compiler-compliance-check check-changed --report
48
+
```
12
49
13
50
## How can I check what exactly prevents file from successful optimization or whether my fix for passing `react-compiler` actually works?
14
51
@@ -36,6 +73,7 @@ If you encounter this error, you need to add the `Ref` postfix to the variable n
36
73
If you added a modification to `SharedValue`, you'll likely encounter this error. You can ignore this error for now because the current `react-native-reanimated` API is not compatible with `react-compiler` rules. Once [this PR](https://github.com/software-mansion/react-native-reanimated/pull/6312) is merged, we'll rewrite the code to be compatible with `react-compiler`. Until then, you can ignore this error.
37
74
38
75
### Existing manual memoization could not be preserved. [...]
76
+
39
77
These types of errors usually occur when the calls to `useMemo` that were made manually are too complex for react-compiler to understand. React compiler is still experimental so unfortunately this can happen.
40
78
41
79
Some specific cases of this error are described below.
@@ -96,7 +134,7 @@ return (
96
134
<ToggleSettingOptionRow
97
135
onToggle={item.onToggle}
98
136
// ❌ such code triggers the error - `qboConfig?.pendingFields` is an external variable from the closure
99
-
// so this code is pretty complicated for `react-compiler` optimizations
137
+
// so this code is pretty complicated for `react-compiler` optimizations
0 commit comments