-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DataGrid] Uncatchable Errors thrown if row validation fails #1804
Comments
The grid already comes with an error boundary so it should show an error overlay on errors. |
Having a look at the problem, it seems that there are multiple opportunities:
https://reactjs.org/docs/error-boundaries.html So it sounds to me that the "broken UI" argument has no foundations after all. We can remove the error boundary and still get the same outcome. @dtassone What's left to defend that we need a built-in ErrorBoundary?
@xadie Would it help if a. there were no
https://reactjs.org/docs/error-boundaries.html @xadie Or as an alternative option, b. if the data grid was rethrowing so your parent
|
FYI @oliviertassinari the datagrid is NOT swallowing errors as you can see in https://material-ui-x.netlify.app/storybook/?path=/story/x-grid-tests-error-handling--throw-exception |
@dtassone I didn't use this terminology but it depends on which dimension we look at. What I was considering is for developers to use the React error boundary pattern in their application. They can't use their own error boundary unless they manually rethrow, or we move with option a. or b. I have provided proof in:
I think that the most important aspect is why should we handle errors. How do we justify that one component needs a built-in error boundary? I personally fail to envision the value. At this point, I think that we should wait to hear more feedback from users like @xadie to know what's the most frequent use case/pain we can solve regarding error handling. |
This issue doesn't appear to be ready to be worked on. IHMO we should remove our |
@m4theushw I also feel that we don't have enough information around how developers handle error handling. I'm personally in the same boat as you are, and it's what React documents. But it doesn't mean that most devs are. For instance, maybe it's better to only crash the data grid and not the rest of the page? At least we don't document On the other hand, a prop to display an error inside the data grid seems valuable, e.g. network fail. |
It's in https://material-ui.com/api/data-grid/.
👍 |
Last summer, I didn't port https://master--material-ui-x.netlify.app/storybook/?path=/story/1-docs-13-error-handling--page into the docs because the feature felt too premature.
As we have seen "displaying corrupted data" is not a valid argument, the real argument seems around not "breaking the whole application", only the data grid. The behavior comes at the cost of breaking the natural flow React error boundary. You can only get one of the two. Maybe we should:
|
Errors can come from many different sources not only ajax. It's wrong to assume that. It could be a corrupt/bad data in the DB that cause the grid to crash due to a rendercell for example... |
@dtassone This is not accurate, see https://codesandbox.io/s/elated-stallman-8y1cy?file=/src/App.tsx. Developers have to rethrow the error in order for their own error boundary to catch it. If you don't want the error boundary of the data grid, it's relatively painful to override. |
The action to close this issue is to remove the error boundary and let the errors propagate. diff --git a/packages/grid/x-data-grid/src/DataGrid/DataGrid.tsx b/packages/grid/x-data-grid/src/DataGrid/DataGrid.tsx
index a9ed12e71..41ffa8456 100644
--- a/packages/grid/x-data-grid/src/DataGrid/DataGrid.tsx
+++ b/packages/grid/x-data-grid/src/DataGrid/DataGrid.tsx
@@ -26,14 +26,12 @@ const DataGridRaw = React.forwardRef(function DataGrid<R extends GridValidRowMod
return (
<GridContextProvider apiRef={apiRef} props={props}>
<GridRoot className={props.className} style={props.style} sx={props.sx} ref={ref}>
- <GridErrorHandler>
- <GridHeaderPlaceholder />
- <GridBody
- ColumnHeadersComponent={DataGridColumnHeaders}
- VirtualScrollerComponent={DataGridVirtualScroller}
- />
- <GridFooterPlaceholder />
- </GridErrorHandler>
+ <GridHeaderPlaceholder />
+ <GridBody
+ ColumnHeadersComponent={DataGridColumnHeaders}
+ VirtualScrollerComponent={DataGridVirtualScroller}
+ />
+ <GridFooterPlaceholder />
</GridRoot>
</GridContextProvider>
); |
The example is from v4, I updated it for v5. The initial behavior of swallowing errors from row validation doesn't appear anymore in v5. The error boundary now is only triggered if, for example, a cell or row throws an error. We can still remove the error boundary. |
Current Behavior 😯
When row validation fails the exception thrown is uncatchable. (I guess function checkGridRowIdIsValid is responsible for throwing the error).
Expected Behavior 🤔
Exception thrown should be able to be handled from the surrounding context. I would expect that if onError callback is provided, the raised error is catched and forwarded to the callback for instance.
Steps to Reproduce 🕹
https://codesandbox.io/s/peaceful-mclean-nqcnyn?file=/src/App.tsx (v5)
https://codesandbox.io/s/priceless-dewdney-9y9ko?file=/src/App.tsx(v4)Context 🔦
Implementing error handling for an application that uses Datagrid for data display
The text was updated successfully, but these errors were encountered: