Skip to content

[tree view] Use useId for the default tree id - #23341

Open
Anexus5919 wants to merge 1 commit into
mui:masterfrom
Anexus5919:fix/tree-view-default-id-use-id
Open

[tree view] Use useId for the default tree id#23341
Anexus5919 wants to merge 1 commit into
mui:masterfrom
Anexus5919:fix/tree-view-default-id-use-id

Conversation

@Anexus5919

Copy link
Copy Markdown
Contributor

Split out of #23337 at @noraleonte's request.

Changes

treeId starts as undefined and is only generated by the first updateStateFromParameters, which runs in a layout effect after mount. Until then treeItemIdAttribute resolves to -<itemId>, so:

  • two Tree Views on the same page emit the same item ids in the server output and in the first client render
  • every item re-renders right after mount when the real id arrives

The default id now comes from useId and is passed to the store through the parameters, the same way isRtl already is. It is stable from the first render, unique per instance, and consistent between server and client. createTreeViewDefaultId and its module-global counter are gone.

useId is @mui/utils/useId, which is what the Data Grid uses. It delegates to React's useId on React 18+, and falls back to a post-mount id on React 17, which matches the current behaviour there.

No public API change.

@code-infra-dashboard

Copy link
Copy Markdown

Deploy preview

https://deploy-preview-23341--material-ui-x.netlify.app/
QR code for https://deploy-preview-23341--material-ui-x.netlify.app/

Bundle size

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 🔺+167B(+0.24%) 🔺+64B(+0.31%)
@mui/x-tree-view-pro 🔺+167B(+0.12%) 🔺+51B(+0.13%)
@mui/x-scheduler 🔺+171B(+0.04%) 🔺+58B(+0.06%)
@mui/x-scheduler-premium 🔺+171B(+0.03%) 🔺+56B(+0.04%)
@mui/x-chat 0B(0.00%) 0B(0.00%)
@mui/x-license 0B(0.00%) 0B(0.00%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant