Skip to content
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] Using rowSelectionPropagation and rowSelectionModel at the same time cause a crash #15619

Open
GabrielVooDB opened this issue Nov 26, 2024 · 2 comments
Labels
bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! feature: Selection Related to the data grid Selection feature support: premium standard Support request from a Premium standard plan user. https://mui.com/legal/technical-support-sla/

Comments

@GabrielVooDB
Copy link

GabrielVooDB commented Nov 26, 2024

Steps to reproduce

Steps:

  1. Open this link to live example: https://codesandbox.io/p/sandbox/selectionpropagation-and-selectionmodel-issue-svqxrm
  2. Wait a few seconds for the grid to crash

Current behavior

Initially, while our data is loading, we provide an empty rows array to the Grid. As soon as the data is received and the final rows array is created and provided to the Grid, a crash occurs.

Providing the "isLoading" flag to the Grid does not prevent the issue from happening.

A workaround is to wait a render frame before providing the rowSelectionModel to the grid, after the final rows array has been provided to the Grid.

Expected behavior

The grid should not crash.

Context

We were trying to have both row grouping with row propagation and row model selection to allow the user to select rows and do operations on them with an action menu.

Your environment

npx @mui/envinfo
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

Search keywords: rowSelectionPropagation rowSelectionModel row grouping
Order ID: 100223

@GabrielVooDB GabrielVooDB added bug 🐛 Something doesn't work status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Nov 26, 2024
@github-actions github-actions bot added component: data grid This is the name of the generic UI component, not the React module! support: premium standard Support request from a Premium standard plan user. https://mui.com/legal/technical-support-sla/ labels Nov 26, 2024
@michelengelen michelengelen changed the title Using rowSelectionPropagation and rowSelectionModel at the same time cause a crash [data grid] Using rowSelectionPropagation and rowSelectionModel at the same time cause a crash Nov 27, 2024
@michelengelen
Copy link
Member

@GabrielVooDB thanks for opening this. It is definitely a bug and can be fixed with a very simple change:

--- a/packages/x-data-grid/src/hooks/features/rowSelection/useGridRowSelection.ts
+++ b/packages/x-data-grid/src/hooks/features/rowSelection/useGridRowSelection.ts
@@ -484,7 +484,7 @@ export const useGridRowSelection = (
           return;
         }
         const node = tree[id];
-        if (node.type === 'group') {
+        if (node?.type === 'group') {
           const isAutoGenerated = (node as GridGroupNode).isAutoGenerated;
           if (isAutoGenerated) {
             delete selectionLookup[id];

I will open a PR in a minute! 👍🏼

@github-project-automation github-project-automation bot moved this to 🆕 Needs refinement in MUI X Data Grid Nov 27, 2024
@michelengelen michelengelen added feature: Selection Related to the data grid Selection feature and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Nov 27, 2024
@michelengelen
Copy link
Member

@GabrielVooDB thanks for opening this. It is definitely a bug and can be fixed with a very simple change:

--- a/packages/x-data-grid/src/hooks/features/rowSelection/useGridRowSelection.ts
+++ b/packages/x-data-grid/src/hooks/features/rowSelection/useGridRowSelection.ts
@@ -484,7 +484,7 @@ export const useGridRowSelection = (
           return;
         }
         const node = tree[id];
-        if (node.type === 'group') {
+        if (node?.type === 'group') {
           const isAutoGenerated = (node as GridGroupNode).isAutoGenerated;
           if (isAutoGenerated) {
             delete selectionLookup[id];

I will open a PR in a minute! 👍🏼

Just noticed that the propagation is not working in that case. Might be a bit harder than originally thought.

Could be a race condition where the tree is not ready yet and the selection takes place already.

I'll add it to the board!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! feature: Selection Related to the data grid Selection feature support: premium standard Support request from a Premium standard plan user. https://mui.com/legal/technical-support-sla/
Projects
Status: 🆕 Needs refinement
Development

No branches or pull requests

2 participants