Skip to content

Conversation

@noobyogi0010
Copy link
Contributor

Change the comparison to consider the absolute value of children count, so that lazy load works even when the number of child nodes are unknow. In which case getChildrenCount returns -1.

Fixes issue #18663

Adding @noraleonte and @flaviendelangle for visibility and to opine more on the fix.

@mui-bot
Copy link

mui-bot commented Jul 3, 2025

Deploy preview: https://deploy-preview-18680--material-ui-x.netlify.app/

Bundle size report

Bundle Parsed size Gzip size
@mui/x-data-grid 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-pro 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-premium 0B(0.00%) 0B(0.00%)
@mui/x-charts 0B(0.00%) 0B(0.00%)
@mui/x-charts-pro 0B(0.00%) 0B(0.00%)
@mui/x-charts-premium 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers-pro 0B(0.00%) 0B(0.00%)
@mui/x-tree-view 0B(0.00%) 0B(0.00%)
@mui/x-tree-view-pro 🔺+2B(0.00%) 0B(0.00%)

Details of bundle changes

Generated by 🚫 dangerJS against 3bf2510

@noobyogi0010 noobyogi0010 changed the title fix: enable lazy load when children count is not know in tree view [Tree view] Enable lazy load when children count is not know in tree view Jul 3, 2025
@zannager zannager added the scope: tree view Changes related to the tree view. This includes TreeView, TreeItem. label Jul 4, 2025
@noraleonte
Copy link
Contributor

Thanks @noobyogi0010 for the contribution. 🎉

I think the change makes sense and it was the intended behavior, as described in the documentation:

getChildrenCount(): Returns the number of children for the item. If the children count is not available for some reason, but there are some children, returns -1.

I'd like to clarify a few behavioral things before merging and would like @flaviendelangle to weigh in:
What should happen if getChildrenCount returns -1, the item is expandable, but when expanding, the fetch returns an empty array? Should we

  • throw an error and handle this similarly to how we would handle a failing request?
  • Leave it to the user to handle it (this is what happens right now, and we end up in a weird state where there are no children but the item is expanded)
  • Collapse the item automatically if there are no children

@zannager zannager changed the title [Tree view] Enable lazy load when children count is not know in tree view [tree view] Enable lazy load when children count is not know in tree view Jul 29, 2025
@github-actions
Copy link

This pull request has been inactive for 30 days. Please remove the stale label or leave a comment to keep it open. Otherwise, it will be closed in 15 days.

@github-actions github-actions bot added the stale Inactive for 7 days (issues) or 30 days (PRs); closed after 5 or 15 more days if no update. label Aug 28, 2025
@flaviendelangle
Copy link
Member

I don't know the feature enough to have a valid opinion.
I'll go back to this PR once #19284 and I have a better understanding of the trade offs 👍

@github-actions github-actions bot removed the stale Inactive for 7 days (issues) or 30 days (PRs); closed after 5 or 15 more days if no update. label Sep 9, 2025
@github-actions
Copy link

github-actions bot commented Oct 1, 2025

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Oct 1, 2025
Signed-off-by: Flavien DELANGLE <flaviendelangle@gmail.com>
@github-actions
Copy link

github-actions bot commented Nov 6, 2025

This pull request has been inactive for 30 days. Please remove the stale label or leave a comment to keep it open. Otherwise, it will be closed in 15 days.

@github-actions github-actions bot added the stale Inactive for 7 days (issues) or 30 days (PRs); closed after 5 or 15 more days if no update. label Nov 6, 2025
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Nov 19, 2025
@flaviendelangle flaviendelangle added type: bug It doesn't behave as expected. and removed stale Inactive for 7 days (issues) or 30 days (PRs); closed after 5 or 15 more days if no update. labels Nov 19, 2025
@flaviendelangle flaviendelangle merged commit 7c16ba1 into mui:master Nov 19, 2025
21 of 22 checks passed
bernardobelchior added a commit to bernardobelchior/mui-x that referenced this pull request Nov 19, 2025
mapache-salvaje pushed a commit to mapache-salvaje/mui-x that referenced this pull request Dec 29, 2025
…view (mui#18680)

Signed-off-by: Flavien DELANGLE <flaviendelangle@gmail.com>
Co-authored-by: Flavien DELANGLE <flaviendelangle@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: tree view Changes related to the tree view. This includes TreeView, TreeItem. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants