-
-
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
Lazy-loading tree data rows is resetting expanded state from other rows when using with Apollo #9002
Comments
hey @lucapasquale The Apollo provider is causing the grid to re-render, and I don't think the datagrid is caching the expansion state, so it's being reset every time you fetch new data. One possible solution is to memoize the datagrid separately so that it's not re-rendered unnecessarily. This can help improve performance and prevent the expansion state from being reset every time you fetch data. Demo : https://codesandbox.io/s/datagridpro-v6-lazy-load-example-forked-j8niyt?file=/src/App.tsx |
Since it's due to an external library which is causing the whole grid to re-render, there's not much we can do here. |
Since the issue is missing key information and has been inactive for 7 days, it has been automatically closed. If you wish to see the issue reopened, please provide the missing information. |
I was able to make it work by using export const ExpandableDataGridPro = React.memo(
DataGridPro,
(prevProps, nextProps) => {
return prevProps.rows === nextProps.rows;
}
); Not the greatest solution, but it worked for us so far |
Thanks for posting the solution, since you have a workaround, I'll close the issue. Feel free to open again if you feel there's an opportunity on the Grid's side. |
Duplicates
Latest version
Steps to reproduce 🕹
Link to live example: https://codesandbox.io/s/datagridpro-v6-lazy-load-example-7d4gns?file=/src/App.tsx
Steps:
Current behavior 😯
Any row previously expanded is collapsed when a lazy-loaded row is expanded. So in the steps above, the row on
1.
is collapsed after we expand2.
. After the request for the children has been made, expanding/collapsing works normallyScreen.Recording.2023-05-15.at.18.22.05.mov
Expected behavior 🤔
Clicking to expand a row shouldn't affect other rows state
Context 🔦
This issue seems to only happen when using
useQuery
anduseLazyQuery
from@apollo/client
. I tried replacing with mock API calls like the examples provided in your docs, and the issue doesn't seem to happen. Even if I query for a row's data, but don't use it onapiRef.current.updateRows
, the same behavior occurs.I can't share my real API since it's internal, but I was able to replicate it with that public API for star wars movies. It's not the best example since it has a max depth of 2, but its able to show the issue happening.
Your environment 🌎
npx @mui/envinfo
Order ID or Support key 💳 (optional)
65461
The text was updated successfully, but these errors were encountered: