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] Updates handled with onRowSelectionModelChange while using treeData results in an error #14859

Closed
DoodleBobBuffPants opened this issue Oct 7, 2024 · 8 comments · Fixed by #14909
Labels
bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! support: pro standard Support request from a Pro standard plan user. https://mui.com/legal/technical-support-sla/

Comments

@DoodleBobBuffPants
Copy link

DoodleBobBuffPants commented Oct 7, 2024

Steps to reproduce

Link to live example: https://stackblitz.com/edit/mui-datagrid-treedata-repro-ircjfa0?file=README.md,package.json

Steps:

  1. Using sample component here
  2. Add some state for the selection model as in the live example linked above
  3. Update the state in onRowSelectionModelChange
  4. Upon rendering there is the error:
    Warning: Cannot update a component (`Repro`) while rendering a different component (`ForwardRef(DataGridPro)`). To locate the bad setState() call inside `ForwardRef(DataGridPro)`, follow the stack trace as described in https://reactjs.org/link/setstate-in-render
     at DataGridPro
     at div
     at Repro
    

Current behavior

An error (well, a warning logged to console.error)

Expected behavior

There shouldn't be an error

Context

This fails in 7.19.0 but works in 7.18.0

Your environment

npx @mui/envinfo
  System:
    OS: Linux 5.0 undefined
  Binaries:
    Node: 18.20.3 - /usr/local/bin/node
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  Browsers:
    Chrome: Not Found
  npmPackages:
    @emotion/react: 11.13.3 => 11.13.3 
    @emotion/styled: 11.13.0 => 11.13.0 
    @mui/core-downloads-tracker:  6.1.2 
    @mui/material:  6.1.2 
    @mui/private-theming:  6.1.2 
    @mui/styled-engine:  6.1.2 
    @mui/system:  6.1.2 
    @mui/types:  7.2.17 
    @mui/utils:  6.1.2 
    @mui/x-data-grid:  7.19.0 
    @mui/x-data-grid-pro: 7.19.0 => 7.19.0 
    @mui/x-internals:  7.18.0 
    @mui/x-license:  7.18.0 
    @types/react:  18.3.11 
    react: 18.3.1 => 18.3.1 
    react-dom: 18.3.1 => 18.3.1 

Also fails on a Windows machine when run in an Electron app; the above is for the StackBlitz repro

Search keywords: DataGridPro treeData state error react
Order ID: 65425

@DoodleBobBuffPants DoodleBobBuffPants added bug 🐛 Something doesn't work status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Oct 7, 2024
@github-actions github-actions bot added component: data grid This is the name of the generic UI component, not the React module! support: pro standard Support request from a Pro standard plan user. https://mui.com/legal/technical-support-sla/ labels Oct 7, 2024
@michelengelen michelengelen changed the title In 7.19.0, DataGridPro with treeData that specifies the onRowSelectionModelChange prop which updates state results in error [data grid] Updates handled with onRowSelectionModelChange while using treeData results in an error Oct 7, 2024
@michelengelen
Copy link
Member

It seems this is a bug with codesandbox and/or stackblitz... i cannot reproduce this locally.
There is another error when not using a React.useState that likely causes this to surface in the first place:

Warning: React instrumentation encountered an error: TypeError: ie.patchConsoleForStrictMode is not a function

I did also try to isolate the bug by removing all StyledEngineProvider code and also the strict mode, but with no success on this.
This might be related to this PR: mui/material-ui#43632
cc @siriwatknp

@DoodleBobBuffPants
Copy link
Author

i cannot reproduce this locally

As in the example renders fine in a browser for you locally, or the test in the linked example succeeds for you? I'd have thought the test would fail locally too...

@michelengelen
Copy link
Member

I did not run the tests, but since the recent CI runs where not complaining I guess this is not surfacing there as well ...

@siriwatknp
Copy link
Member

It seems this is a bug with codesandbox and/or stackblitz... i cannot reproduce this locally. There is another error when not using a React.useState that likely causes this to surface in the first place:

Warning: React instrumentation encountered an error: TypeError: ie.patchConsoleForStrictMode is not a function

I did also try to isolate the bug by removing all StyledEngineProvider code and also the strict mode, but with no success on this. This might be related to this PR: mui/material-ui#43632 cc @siriwatknp

I don't think that PR is related, there is no React related change in that PR.

@michelengelen
Copy link
Member

Right @siriwatknp ... sry for the confusion. It must have been a recent change introduced in v7.19.0 of the grid. Running this with v7.18.0 works.

@arminmeh do you have any idea where that error comes from?

@arminmeh
Copy link
Contributor

arminmeh commented Oct 9, 2024

Could it be related to the changes in Automatic parent selection PR @MBilalShafi?

@MBilalShafi
Copy link
Member

MBilalShafi commented Oct 10, 2024

It seems like a side effect of #14677

During the first render, when the filteredRowsSet event is fired as a result of the initial filter lookup computation, the setRowSelectionModel gets fired with the initial value [] again which sets the external state, but since the initial render is still in progress at this point, React throws the error.

I tried a fix in #14909

@MBilalShafi MBilalShafi removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Oct 10, 2024
Copy link

This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

Note

@DoodleBobBuffPants How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey.

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! support: pro standard Support request from a Pro standard plan user. https://mui.com/legal/technical-support-sla/
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants