fix: add global error boundary to prevent full app crashes (#251) - #253
Conversation
👷 Deploy request for finnboard0 pending review.Visit the deploys page to approve it
|
✅ Deploy Preview for finnboard ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Hey @JyantiM This looks great 🙌 Nice that you wrapped it right at the top so it catches provider/router errors too. And are you planning to hook this into Sentry or similar later, or is console logging fine for now? |
|
Hey @JyantiM, merging now, really solid work on this 🙌 Feel free to circle back on the role="alert"/Sentry stuff whenever, no pressure. If you enjoyed working on this, would mean a lot if you starred the repo ⭐ |
|
Thanks for the feedback! I actually tested the "Try again" button. When you click it, the boundary successfully clears its state and remounts the tree. As long as the error was transient, it perfectly recovers the app without just crashing again. Great catch on using the alert role for screen readers. I will open a quick follow-up PR to add that in so we can keep this one focused. As for error tracking, I just stuck to basic console logging for now to get the baseline boundary in place. However, if you would like me to wire it up to Sentry or our preferred tracking service right now, just let me know and I am completely happy to add that in! Otherwise, we can definitely set that up later. |
Description
This PR addresses Issue #251 by introducing a global React
ErrorBoundaryat the top of the component tree inApp.jsx.Previously, any unhandled render exception within the context providers or routing layer would crash the entire application, leaving the user stuck on a blank white screen. With this change, exceptions are caught gracefully and the user is presented with a themed, friendly fallback UI that allows them to attempt recovery.
What changed
ErrorBoundary.jsx: A new class component implementinggetDerivedStateFromErrorandcomponentDidCatch.App.jsx: TheErrorBoundarynow wraps the entire provider and router tree. Note: The large diff inApp.jsxis primarily due to the 2-space indentation shift required to wrap the existing<ThemeProvider>block.var(--color-fin-bg),var(--color-fin-accent)) so it adapts to both dark and light modes automatically, without any hardcoded colors.Why a class component?
I opted for a standard class component rather than bringing in the
react-error-boundarypackage. This keeps our dependencies light and avoids adding unnecessary bundle weight for functionality that React supports natively out of the box.Visual Proof
Dark Mode
Light Mode
How to test
App.jsxand temporarily add a component that throws inside the<ErrorBoundary>.[ErrorBoundary]log fromcomponentDidCatch.Closes #251