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
{{ message }}
Repository navigation
Commit 8d78a0f
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: src/content/learn/react-compiler/debugging.md
+44-1Lines changed: 44 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,49 @@ This guide helps you identify and fix issues when using React Compiler. Learn ho
18
18
19
19
React Compiler is designed to handle code that follows the [Rules of React](/reference/rules). When it encounters code that might break these rules, it safely skips optimization rather than risk changing your app's behavior.
20
20
21
+
### Unsupported Syntax {/*unsupported-syntax*/}
22
+
23
+
Code can follow the Rules of React and still use syntax that the compiler doesn't support yet. With the default [`panicThreshold: 'none'`](/reference/react-compiler/panicThreshold), the compiler skips the affected component or Hook and continues building. The code runs normally, but without compiler optimizations.
24
+
25
+
For example, React Compiler 1.0 doesn't support these patterns:
26
+
27
+
- Conditional expressions (`condition ? a : b`), logical expressions (`&&`, `||`, `??`), and optional chaining (`?.`) inside a `try` block
28
+
-`throw` statements inside a `try` block
29
+
-`try` statements with a `finally` clause
30
+
31
+
These limitations can change between compiler versions. Some unsupported patterns aren't reported by ESLint. To see why a function was skipped in your version, configure the compiler's [`logger`](/reference/react-compiler/logger#detailed-error-logging) and inspect `CompileError` events.
32
+
33
+
Not every `try/catch` causes a skip. For example, calling `JSON.parse` inside `try` is supported, but adding a conditional expression causes this component to be skipped:
34
+
35
+
```js
36
+
functionPreview({text}) {
37
+
let data;
38
+
try {
39
+
data = text ?JSON.parse(text) :null;
40
+
} catch {
41
+
data =null;
42
+
}
43
+
return<div>{data?.name??'No data'}</div>;
44
+
}
45
+
```
46
+
47
+
If you need this syntax, move the parsing logic into a standalone utility function. The compiler can then optimize the component that calls it:
48
+
49
+
```js
50
+
functionparseData(text) {
51
+
try {
52
+
return text ?JSON.parse(text) :null;
53
+
} catch {
54
+
returnnull;
55
+
}
56
+
}
57
+
58
+
functionPreview({text}) {
59
+
constdata=parseData(text);
60
+
return<div>{data?.name??'No data'}</div>;
61
+
}
62
+
```
63
+
21
64
### Compiler Errors vs Runtime Issues {/*compiler-errors-vs-runtime-issues*/}
22
65
23
66
**Compiler errors** occur at build time and prevent your code from compiling. These are rare because the compiler is designed to skip problematic code rather than fail.
@@ -90,4 +133,4 @@ If you believe you've found a compiler bug:
90
133
## Next Steps {/*next-steps*/}
91
134
92
135
- Review the [Rules of React](/reference/rules) to prevent issues
93
-
- Check the [incremental adoption guide](/learn/react-compiler/incremental-adoption) for gradual rollout strategies
136
+
- Check the [incremental adoption guide](/learn/react-compiler/incremental-adoption) for gradual rollout strategies
0 commit comments