Skip to content

Commit 2b9ac13

Browse files
committed
Document syntax that is unsupported inside try/catch
1 parent 046f17d commit 2b9ac13

1 file changed

Lines changed: 27 additions & 1 deletion

File tree

‎src/content/learn/react-compiler/debugging.md‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,32 @@ Common scenarios where this occurs:
3737
- **Dependency arrays that need stable references** - When unstable dependencies cause effects to fire too often or create infinite loops
3838
- **Conditional logic based on reference checks** - When code uses referential equality checks for caching or optimization
3939

40+
## Unsupported Syntax {/*unsupported-syntax*/}
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:
43+
44+
- **Conditional expressions** - ternaries (`condition ? a : b`) and the logical operators `&&`, `||`, and `??`
45+
- **Optional chaining** - `object?.property`
46+
- **`throw` statements**
47+
- **Loops** - `for`, `for...of`, and `while` loops
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:
50+
51+
```js
52+
function WeatherReport({report}) {
53+
// ✅ Good: computed outside of try/catch
54+
const description = report.temperature > 30 ? "Warm" : "Mild";
55+
56+
try {
57+
return <div>{description}: {report.summary}</div>;
58+
} catch (error) {
59+
return <div>Report unavailable</div>;
60+
}
61+
}
62+
```
63+
64+
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.
65+
4066
## Debugging Workflow {/*debugging-workflow*/}
4167

4268
Follow these steps when you encounter issues:
@@ -90,4 +116,4 @@ If you believe you've found a compiler bug:
90116
## Next Steps {/*next-steps*/}
91117

92118
- 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
119+
- Check the [incremental adoption guide](/learn/react-compiler/incremental-adoption) for gradual rollout strategies

0 commit comments

Comments
 (0)