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
After the error boundary catches an exception, it is no longer possible to reset its state. It should be possible to reset the state on demand, like when navigating to another page.
Thanks for taking a look! The problem with adding a key property is that it will unmount an remount the error boundary and everything below. All Observability apps uses the same template which has an error boundary wrapped around the content. This means the entire application will be remounted on every route change. This has pretty severe impact on performance and was exactly what was happening until I made this fix.
I'm not sure about the right solution. Maybe something like <EuiErrorBoundary conditional-key={errKey}> where it only remounts if conditional-key changes and hasError: true:
Trevor's approach is a good workaround (using key to force a re-mount is relatively common in React), but I want to also address this:
It should be possible to reset the state on demand, like when navigating to another page.
EuiErrorBoundary is (currently) not intended to be a super flexible or complex component - it's meant for very basic try/catch usage where its loading is, e.g. when a conditional wrapper, or its presence forces a hard page reload.
That being said, while EUI as team would not prioritize any work on changing it, we'd be open to a community contribution that improves consumer control & flexibility over it (e.g. a prop that allows passing an error directly to it or exposes an onError callback, e.g. #6127 as well). If you're interested in helping extend the component, let us know! Otherwise, I'd recommend using a conditional wrapper or a key remount workaround.
👋 Thank you for your suggestion or request! While the EUI team agrees that it's valid, it's unlikely that we will prioritize this issue on our roadmap. We'll leave the issue open if you or anyone else in the community wants to implement it by contributing to EUI. If not, this issue will auto close in one year.
All Observability apps uses the same template which has an error boundary wrapped around the content. This means the entire application will be remounted on every route change. This has pretty severe impact on performance
Oh wow, just saw this. I... don't know that we really intended EuiErrorBoundary to be a wrapper for an entire page template 😬 Maybe like a subsection of a page or a flyout or around a code block, but it feels extremely heavy-handed for an entire page where a lot of things can go wrong.
We need to figure out what the goal of Obs' error boundary is before we can recommend an approach. In general I don't know if I'd recommend a whole-template error boundary.
Oh wow, just saw this. I... don't know that we really intended EuiErrorBoundary to be a wrapper for an entire page template 😬 Maybe like a subsection of a page or a flyout or around a code block, but it feels extremely heavy-handed for an entire page where a lot of things can go wrong.
I can ask the team with the Observability Shared UX team to remove the error boundary from the template. This will mean that Observability apps will no longer have an error boundary (unless they implement one themselves). I'm not necessarily against it. Might be better that way.
I think the other option is to not add a key remount (which was the change you made) and simply force the user to refresh the page to "resolve" or retry the error. In theory a thrown error means the entire app has gone awry and a reload is often the "correct"/easiest way to handle app-wide thrown errors, rather than the entire page hanging or going blank.
@tkajtoch@ryankeairns y'all had some thoughts on this at today's sync - any thoughts on general recommendations we can make for last resort error boundaries for entire pages? Is "don't do it" the best path forward? 😅
@cee-chen Another problem I've noticed with the error boundary is that it catches the exception but doesn't log an error. This makes it very hard to figure out where the error occurred - normally you can click on an error in the browser's Dev Tools to navigate to the exact line of where it occurred.
@sqren That's a fair remark, but as far as I can tell that's the intended behavior of EuiErrorBoundary. It's meant to serve as the catch in try/catch and surface the error visually rather than in the console.
If you're open to contributing back to EUI, we'd certainly accept a new prop such as rethrowError or logError which re-throws or console.error()s the error if that's your desired behavior, but we probably wouldn't make it the default behavior.
Another (probably more flexible!) option would be for us to accept an onError callback where we pass the error back to the developer, whereupon you can then re-throw it or log the error to the console however you please. #6127
It looks like I've referenced that issue twice now as a viable solution to several issues you've mentioned in this thread. Honestly, I'm probably just going to move forward with that prop. It really feels like the most flexible solution.
Activity
1Copenut commentedon May 8, 2023
Hi @sqren. I did some research and was able to solve your issue by adding a
const errKey = page;and passing that unique key to<EuiErrorBoundary key={errKey}>. I forked your CodeSandbox to demonstrate the proposed solution: https://codesandbox.io/s/eui-error-boundary-problem-forked-ivxj49?file=/my_template.jsxsorenlouv commentedon May 8, 2023
Hi @1Copenut,
Thanks for taking a look! The problem with adding a
keyproperty is that it will unmount an remount the error boundary and everything below. All Observability apps uses the same template which has an error boundary wrapped around the content. This means the entire application will be remounted on every route change. This has pretty severe impact on performance and was exactly what was happening until I made this fix.I'm not sure about the right solution. Maybe something like
<EuiErrorBoundary conditional-key={errKey}>where it only remounts ifconditional-keychanges andhasError: true:eui/src/components/error_boundary/error_boundary.tsx
Lines 25 to 28 in 7255125
cee-chen commentedon May 8, 2023
Trevor's approach is a good workaround (using
keyto force a re-mount is relatively common in React), but I want to also address this:EuiErrorBoundaryis (currently) not intended to be a super flexible or complex component - it's meant for very basic try/catch usage where its loading is, e.g. when a conditional wrapper, or its presence forces a hard page reload.That being said, while EUI as team would not prioritize any work on changing it, we'd be open to a community contribution that improves consumer control & flexibility over it (e.g. a prop that allows passing an
errordirectly to it or exposes anonErrorcallback, e.g. #6127 as well). If you're interested in helping extend the component, let us know! Otherwise, I'd recommend using a conditional wrapper or akeyremount workaround.github-actions commentedon May 8, 2023
👋 Thank you for your suggestion or request! While the EUI team agrees that it's valid, it's unlikely that we will prioritize this issue on our roadmap. We'll leave the issue open if you or anyone else in the community wants to implement it by contributing to EUI. If not, this issue will auto close in one year.
cee-chen commentedon May 8, 2023
Oh wow, just saw this. I... don't know that we really intended
EuiErrorBoundaryto be a wrapper for an entire page template 😬 Maybe like a subsection of a page or a flyout or around a code block, but it feels extremely heavy-handed for an entire page where a lot of things can go wrong.We need to figure out what the goal of Obs' error boundary is before we can recommend an approach. In general I don't know if I'd recommend a whole-template error boundary.
sorenlouv commentedon May 8, 2023
I can ask the team with the Observability Shared UX team to remove the error boundary from the template. This will mean that Observability apps will no longer have an error boundary (unless they implement one themselves). I'm not necessarily against it. Might be better that way.
cee-chen commentedon May 8, 2023
I think the other option is to not add a
keyremount (which was the change you made) and simply force the user to refresh the page to "resolve" or retry the error. In theory a thrown error means the entire app has gone awry and a reload is often the "correct"/easiest way to handle app-wide thrown errors, rather than the entire page hanging or going blank.@tkajtoch @ryankeairns y'all had some thoughts on this at today's sync - any thoughts on general recommendations we can make for last resort error boundaries for entire pages? Is "don't do it" the best path forward? 😅
sorenlouv commentedon May 24, 2023
@cee-chen Another problem I've noticed with the error boundary is that it catches the exception but doesn't log an error. This makes it very hard to figure out where the error occurred - normally you can click on an error in the browser's Dev Tools to navigate to the exact line of where it occurred.
cee-chen commentedon May 25, 2023
@sqren That's a fair remark, but as far as I can tell that's the intended behavior of
EuiErrorBoundary. It's meant to serve as thecatchin try/catch and surface the error visually rather than in the console.If you're open to contributing back to EUI, we'd certainly accept a new prop such as
rethrowErrororlogErrorwhich re-throws orconsole.error()s the error if that's your desired behavior, but we probably wouldn't make it the default behavior.Another (probably more flexible!) option would be for us to accept an
onErrorcallback where we pass the error back to the developer, whereupon you can then re-throw it or log the error to the console however you please. #6127It looks like I've referenced that issue twice now as a viable solution to several issues you've mentioned in this thread. Honestly, I'm probably just going to move forward with that prop. It really feels like the most flexible solution.
cee-chen commentedon May 25, 2023
@sqren FYI I'll be adding
onErrorsupport anyway (it's easy to do and long overdue), but are you sure console errors aren't being thrown or that something else in Kibana isn't swallowing the error? I'm seeing https://elastic.github.io/eui/#/utilities/error-boundary throw an error in my console on latest Firefox.sorenlouv commentedon May 25, 2023
@cee-chen Thank you so much!
Hmm.. you may have a point. There could be other types of error boundaries (not the EUI one) at play. I'll take a look. Thanks again!