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 97d018a
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
+23-8Lines changed: 23 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,32 +39,47 @@ Common scenarios where this occurs:
39
39
40
40
## Unsupported Syntax {/*unsupported-syntax*/}
41
41
42
-
A few syntax patterns are not supported inside `try/catch` statements yet. When React Compiler encounters one of them, it skips the whole component instead of compiling it:
42
+
A few syntax patterns are not supported inside `try/catch` statements yet. When React Compiler encounters one of them, it skips the whole component or hook instead of compiling it:
43
43
44
44
-**Conditional expressions** - ternaries (`condition ? a : b`) and the logical operators `&&`, `||`, and `??`
45
45
-**Optional chaining** - `object?.property`
46
46
-**`throw` statements**
47
47
-**Loops** - `for`, `for...of`, and `while` loops
48
48
49
-
These patterns are fully supported outside of `try/catch`, so moving them out of the `try/catch` (or extracting the fallible code into a separate function) restores compilation:
49
+
These patterns are fully supported outside of `try/catch`. Even a single guard inside the `try` is enough to lose the optimization:
Evaluate the guard before the `try`, or extract the fallible code into a separate function, and the same component compiles:
55
66
56
-
let summary =null;
67
+
```js
68
+
functionWeatherReport({report}) {
69
+
// ✅ Compiles: the guard runs before the try
70
+
constsource= report?.data??"";
71
+
let summary;
57
72
try {
58
-
summary =parseSummary(report.data);
73
+
summary =parseSummary(source);
59
74
} catch (error) {
60
75
summary ="Report unavailable";
61
76
}
62
77
63
-
return<div>{description}: {summary}</div>;
78
+
return<div>{summary}</div>;
64
79
}
65
80
```
66
81
67
-
Skipped components still build and run normally, so the only difference is that they are not optimized. To notice them, check that the component shows the ✨ badge in React DevTools, or log skipped components with the [`logger`](/reference/react-compiler/logger) option.
82
+
Skipped components and hooks still build and run normally, so the only difference is that they are not optimized. To notice them, check that the component shows the ✨ badge in React DevTools, or log skipped components and hooks with the [`logger`](/reference/react-compiler/logger) option.
0 commit comments