I faced a weird edge case with React ErrorBoundary. Exceptions are not being processed if they happen in inline expression. For example:
const page = webtexts[courseId].pages[pageFamilyId]; // Returns undefined
...
<ErrorBoundary>
// "Cannot read properties of undefined (reading 'page_name')" won't be processed in ErrorBoundary
<span>{page.page_name}</span>
</ErrorBoundary>
But if I wrap a problematic place in the component, it works properly.
const page = webtexts[courseId].pages[pageFamilyId]; // Returns undefined
...
const WrapFailingPage: React.FC<{ page: any }> = ({ page }) => {
return <span>{page.page_name}</span>;
};
...
<ErrorBoundary>
<WrapFailingPage page={page} /> // The error is properly processed in ErrorBoundary
</ErrorBoundary>
For the demo, I made a simple Codepen - https://codepen.io/OlexanderD/pen/wvpdpxY.
Should the ErrorBoundary behave in that way? Why the inline expressions can be problematic?