[DataGridPremium] Nested Lazy Loading#21043
Conversation
|
Deploy preview: https://deploy-preview-21043--material-ui-x.netlify.app/ Updated pages: Bundle size reportBundle size will be reported once CircleCI build #790195 finishes. |
This comment was marked as outdated.
This comment was marked as outdated.
Resolved import conflicts by: - Using 'type' keyword for type-only imports (consistent-type-imports rule) - Preserving branch-specific imports needed for nested lazy loading feature Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
I've been testing these changes in our product, and it seems pretty good as far as I can tell. We have lazy loaded groups with more fetched as you scroll around, along with lazy loaded children also adding more as you scroll around. It would be nice to get this as it's a nice feature. 👍 |
|
@mbiggs-gresham Thank you for the feedback. I've been trying to implement a better cache invalidation strategy before we can proceed with this PR. I've just opened a PR for that matter (#21282) and as soon as it's merged, I plan to port the same to this PR and open it for review. Thanks for your continued interest and patience. 🙏 |
|
That's great news, thanks for the update. We're really keen to get this feature. One issue I have discovered is that |
This comment was marked as outdated.
This comment was marked as outdated.
|
Having an official nested lazy loading solution for tree data would be truly wonderful for us ! It would simplify our code a lot and make our implementation much more reliable in production. Do you have any rough idea of when this might ship ? @MBilalShafi . Thanks for pushing this forward. |
Deploy previewBundle size
Check out the code infra dashboard for more information about this PR. |
|
@MBilalShafi much more green 🤩! We've been struggling with our hand-rolled solution for a couple weeks. Gonna love an official solution. Thank you! |
|
The PR is now generally ready for review, I'll be keep polishing a few things here or there in the meantime. CC @mui/grid @mui/cse |
|
@MBilalShafi That's excellent news thanks. I've tried the latest version but seem to get an error. We have a grid with only a depth of 1. If i expand the very first group, then scroll down (roughly 80 parent rows), then expand that 80th row, it fetches it's children, if i then collapse it the following occurs: This seems recent and I didn't get this previously. Is that stacktrace useful? |
@mbiggs-gresham Thank you for the early feedback. Update: I added a defensive check on the place likely causing issue due to some outdated nodes. Would appreciate having a double check at your end. |
|
@MBilalShafi Sorry it's taken me a while to get a reproduction working with the bug, but have managed to do so here. Feel free to clone the repo, run I'm not sure i'd take what claude's analysis/workaround has said as necessarily correct.
Updated version gives |
|
@mbiggs-gresham Thank you for providing the reproduction example. It seems that the custom cache being used in the demo is not using the cache keys properly. Can you check if the issue still reproduces for you in the attached StackBlitz example? |
|
@MBilalShafi I think i've finally gotten to the bottom of this, and apologise for all the noise/confusion. It seems we had multiple groups/parents that had the same child rows under them and therefore the same id's. eg a child can be in multiple different groups. It's been incredibly difficult to try to track the root cause down but also probably a good exercise. This didn't seem to be a problem before, so not sure what changed to cause this. I don't know if the grid would even be able to detect this and report it or if it's just a case of not providing it with duff data. Our main app doesn't even have a custom datasource cache but the repro produced the same error we were seeing. Overall very happy with the new group grid, i guess we'll just have to try to generate more unique id's when a child is under multiple parents. |
|
|
||
| The demo below exhibits the behavior of the nested lazy loading with tree data. | ||
|
|
||
| {{"demo": "ServerSideTreeDataNestedLazyLoading.js", "bg": "inline"}} |
There was a problem hiding this comment.
It looks like sorting breaks children expansions – both in tree view and row grouping.
Same with filtering.
Screen.Recording.2026-05-01.at.19.45.45.mov
| isAutoGenerated: false, | ||
| groupingField: props.treeData ? null : (groupFields[parentPath.length] ?? null), | ||
| serverChildrenCount: childrenCount, | ||
| childrenFromPath: {}, |
Fixes #14527
Summary
This PR adds server-side nested lazy loading for Data Grid Pro/Premium. Lazy loading now works with tree data and row grouping by fetching visible root and child skeleton ranges through the Data Source layer.
It also adds support for
defaultGroupingExpansionDepthandisGroupExpandedByDefaultin nested lazy loading, including groups loaded later while scrolling.Motivation
Flat lazy loading could fetch root rows as they entered the viewport, but nested data needs parent-scoped ranges. Without a dedicated strategy, tree data and row grouping could not lazily fetch descendants,
revalidation could not target the right parent, and collapsing expanded parents could try to delete skeleton rows through
updateRows().Changes
LazyLoadedGroupedDatadata source strategy.useGridDataSourceNestedLazyLoaderfor tree data and row grouping.groupFields, group paths, and grouping fields.defaultGroupingExpansionDepthandisGroupExpandedByDefault.dataSourceRevalidateMs.showChildrenLoadingto suppress child loading indicators during background revalidation.updateRows()with invalid delete rows.Docs
Nested lazy loadingdemos for tree data and row grouping.Group expansiondemos for tree data and row grouping.Behavior Notes
rowCountand each parentgetChildrenCount()must be known.skipFallbackRevalidationonly applies to the extra scan after automatic expansion; normal viewport and polling revalidation still run.Tests
isGroupExpandedByDefault, scroll-loaded groups, nested polling, cache-aware polling, same-id updates, changed-id replacement, andcollapse behavior.
isGroupExpandedByDefault, and collapse behavior.Preview
https://deploy-preview-21043--material-ui-x.netlify.app/x/react-data-grid/server-side-data/lazy-loading/#nested-lazy-loading
In Progress
defaultGroupingExpansionDepthandisGroupExpandedByDefault