-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[data grid] Unexpected Application Error in GridDetailPanelToggleCell #12751
Comments
Hi @conerye |
Also, could you create a demo that would mimic your Data Grid setup? Thanks! |
I upgraded to version 6.19.9 and tried this scenario on our test environment again... Now every time I refresh there's no option for a detail panel expansion and clicking the row gives an app error. I was seeing this occasionally before but it's on every refresh post upgrade. |
We tried to create a demo... The issue doesn't show in codesandbox though, probably for the same reason it doesn't show in our development environment; it only shows with a production build/on our test machines. But here is the codesandbox that was created from altering the MUI demo code sandbox for the detail panel: It is a simple example to show what we are trying to do... in our scenario, if there is none of a particular type of item in the list, then we do not want to show the column for the expansion panel - shown in the demo as a check for a particular name: Is there is different/recommended way to do this? |
The way you pass in the getter function is slightly incorrect. Try refactoring to include the check and return const getDetailPanelContent = React.useCallback(
({ row }) => {
if (row.customer === "Matheus") return null
return <DetailPanelContent row={row} />
},
[],
); ... in the data grid props: <DataGridPro
columns={columns}
rows={rows}
getDetailPanelHeight={getDetailPanelHeight}
getDetailPanelContent={getDetailPanelContent}
/> That way you can ensure that the function is always callable and returns the desired result. Does that work for you? |
I downloaded the sandbox and ran it locally in production mode ( |
Changing our code, as michelengelen suggested, so that getDetailPanelContent always has a callable function and then refactoring the function to include the check and return null if the check fails, does work and we are not able to reproduce the Unexpected Application error with the code this way. The difference is that now the detail panel expansion column shows even when there are no rows in the table that meet the criteria for the detail panel expansion -> all rows have the expansion icon disabled. So, the Unexpected Application problem is resolved, BUT we would like to know if there is a way to hide the detail panel expansion column in this scenario (no rows will ever have the detail panel)? |
@conerye ... you would need to have an additional check for that: const needsDetailPanel = rows.some((row) => row.customer === 'Michel');
return (
<Box sx={{ width: '100%', height: 400 }}>
<DataGridPro
columns={columns}
rows={rows}
getDetailPanelHeight={getDetailPanelHeight}
getDetailPanelContent={needsDetailPanel ? getDetailPanelContent : undefined}
/>
</Box>
); That way the grid will know that there is not detail panel and does not render the toggle |
will give that a try with undefined and report back. but originally we were doing exactly that but with null and it was stated above that it was the cause of this error. Why would undefined work when null does not??? |
I think there might be a slight misunderstanding here: The condition The problem was that the rendering function was running into an error because the logic to return null if Is it clearer now? BTW: Did you get the chance to try the solution already? |
I’m a little confused... we know that the condition is only run once per render. That condition is used to determine if the expansion arrow column should be visible at all, not to determine the content of the detail panel. The condition looks at all the rows to determine if the column should show and then when getting the detail panel content, it is only looking at the content of that one row. If the data did not have a row with customer === 'Matheus' then the toggle column should not be shown. Using undefined vs null made no difference; both result in the Unexpected Application error when there is data such that the toggle column should not be shown. |
@conerye I did update the example showing 2 different approaches: Example The first data grid renders the toggle column because there are no rows that have a total above 1500. The other one shows that the toggle column will be rendered when there is a row that has a total of more than 1500. Additionally it will disable the toggle for details where there is no customer name in the row data. Is this what you were looking for? |
did you have the link to the right codesandbox? i am just seeing the original one that I posted? |
The issue has been inactive for 7 days and has been automatically closed. |
The problem in depth
We are getting ready to release the latest version of our application... Testing the production build, we are seeing an Unexpected Application Error in GridDetailPanelToggleCell and we are not sure how to determine what is causing this issue. It only occurs on production build, not in our development environment... It occurs on a page with a table that has row details panel, but not all rows have data in the details panel (so some rows will show with a disabled expand icon). Error is as follows:
TypeError: Cannot read properties of undefined (reading '2')
at h (GridDetailPanelToggleCell.js:34:56)
at wa (react-dom.production.min.js:167:137)
at wl (react-dom.production.min.js:290:337)
at vc (react-dom.production.min.js:280:389)
at mc (react-dom.production.min.js:280:320)
at Cc (react-dom.production.min.js:280:180)
at ac (react-dom.production.min.js:271:88)
at ic (react-dom.production.min.js:268:429)
at y (scheduler.production.min.js:13:203)
at MessagePort._ (scheduler.production.min.js:14:128)
Lines 33-34 of GridDetailPanelToggleCell.js:
const contentCache = useGridSelector(apiRef, gridDetailPanelExpandedRowsContentCacheSelector); const hasContent = /*#__PURE__*/React.isValidElement(contentCache[id]
contentCache is undefined and then trying to access the data associated with the specified id is causing an application error.
We are using a table that some entries have an expanding detail panel and some do not. That doesn’t seem to be the issue, when the contentCache object exists, there is null data associated with some ids and others have data corresponding to their detail panel, and there are no errors retrieving the null data and disabling the expansion panel arrow. This happens when the page initially loads and happens very quickly as the page is loading. Refreshing the page would often cause an application error, stating that we are trying to read properties of undefined on line 34 of GridDetailPanelToggleCell. I put a breakpoint and could see that contentCache was undefined when this error was being thrown.
Saw issues with simply refreshing the page on the following browsers. The page loads very quickly. This happened about every 3-4 refreshes:
Chrome 122.0.6261.112
Edge 122.0.2365.80
Could not replicate by simply refreshing, but I had right clicked and opened a right click menu and then refreshed and saw a similar error on the same line. I couldn’t get this one to happen as much as the previous:
Firefox 115.8.0
Some more details in addition...there have been times where I load the page and the detail panel expansion arrow is not there even when it should be and clicking the row and results in the same app error...
Seems like a timing thing??? Thoughts on how we can get more info and resolve this issue?
Your environment
`npx @mui/envinfo`
Search keywords: 'Unexpected Application Error' GridDetailPanelToggleCell
Order ID: 331993142
The text was updated successfully, but these errors were encountered: