-
-
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] Fix error caused by trying to render rows that are not in the state anymore #17057
Conversation
Thanks for adding a type label to the PR! 👍 |
@@ -98,7 +98,6 @@ export function useGridColumns( | |||
|
|||
apiRef.current.setState(mergeColumnsState(columnsState)); | |||
apiRef.current.publishEvent('columnsChange', columnsState.orderedFields); | |||
apiRef.current.updateRenderContext?.(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed this because it is being called after the event anyway
https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/hooks/features/virtualization/useGridVirtualScroller.tsx#L691
Deploy preview: https://deploy-preview-17057--material-ui-x.netlify.app/ |
@@ -125,7 +128,7 @@ const GridRow = forwardRef<HTMLDivElement, GridRowProps>(function GridRow(props, | |||
rowReordering, | |||
); | |||
const handleRef = useForkRef(ref, refProp); | |||
const rowNode = apiRef.current.getRowNode(rowId); | |||
const rowNode = gridRowNodeSelector(apiRef, rowId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change here just for the non-nullable return type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that and also because getRowNode
is deprecated
Cherry-pick PRs will be created targeting branches: v7.x |
…the state anymore (#17057)
Fixes #16638 (still have to verify since there is no reproduction code)
Fixes #17022
Removes the need for #16672
The root cause for this is dealing with state from different update cycles.
Rows are rendered from
getRows
which uses rows data obtained throughuseGridSelector
here.Once those rows are rendered, they use
getRowParam
API which throws if the row is not there, but it gets row information from the state directly.If the updates are too fast, it can happen that the rendering lags behind and tries to get params for the row that is not there anymore.
Worth mentioning is that I was able to reproduce this only on React 18, which might explain this.
Using selector directly here solves the linked issues, but introduces a lot of other issue where we need reactivity.
So, my solution is to check the row tree once more before setting a row to be rendered. Instead of doing this in the row component I have moved it up in the chain to prevent all other unnecessary row processing.