Skip to content

[DataGrid] Avoid reading type of undefined in gridRowUtils#21808

Merged
cherniavskii merged 4 commits into
mui:masterfrom
timbuckley:patch-2
Jun 25, 2026
Merged

[DataGrid] Avoid reading type of undefined in gridRowUtils#21808
cherniavskii merged 4 commits into
mui:masterfrom
timbuckley:patch-2

Conversation

@timbuckley

@timbuckley timbuckley commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

Bugfix: Add optional chaining to tree node type checks for graceful failure instead of the Cannot read properties of undefined (reading 'type') error.


@timbuckley timbuckley changed the title Add optional chaining to tree node type checks Bugfix: Cannot read properties of undefined (reading 'type') in gridRowUtils Mar 20, 2026
@mui-bot

mui-bot commented Mar 20, 2026

Copy link
Copy Markdown

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

Bundle size report

Bundle Parsed size Gzip size
@mui/x-data-grid 🔺+2B(0.00%) 🔺+1B(0.00%)
@mui/x-data-grid-pro 🔺+2B(0.00%) 🔺+2B(0.00%)
@mui/x-data-grid-premium 🔺+2B(0.00%) 🔺+2B(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 0B(0.00%) 0B(0.00%)

Details of bundle changes

Generated by 🚫 dangerJS against 5785884

@zannager zannager added the scope: data grid Changes related to the data grid. label Mar 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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 Apr 23, 2026
@code-infra-dashboard

code-infra-dashboard Bot commented Apr 23, 2026

Copy link
Copy Markdown

Deploy preview

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

Bundle size

Bundle Parsed size Gzip size
@mui/x-data-grid 🔺+1B(0.00%) 🔺+1B(0.00%)
@mui/x-data-grid-pro 🔺+1B(0.00%) 🔺+1B(0.00%)
@mui/x-data-grid-premium 🔺+1B(0.00%) 🔺+1B(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 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.

@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 Apr 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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 stale Inactive for 7 days (issues) or 30 days (PRs); closed after 5 or 15 more days if no update. and removed stale Inactive for 7 days (issues) or 30 days (PRs); closed after 5 or 15 more days if no update. labels May 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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 stale Inactive for 7 days (issues) or 30 days (PRs); closed after 5 or 15 more days if no update. and removed stale Inactive for 7 days (issues) or 30 days (PRs); closed after 5 or 15 more days if no update. labels Jun 24, 2026
@LukasTy LukasTy changed the title Bugfix: Cannot read properties of undefined (reading 'type') in gridRowUtils [DataGrid] Avoid reading type of undefined in gridRowUtils Jun 25, 2026
@LukasTy LukasTy added the type: bug It doesn't behave as expected. label Jun 25, 2026

@LukasTy LukasTy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution. 🙏
Could you address these review findings?


Verdict: One half is a correct fix, the other half is a no-op. Request changes (or split).

Findings:

  1. getTreeNodeDescendants (node?.type) - correct and relevant. This is the real fix for the reported "Cannot read properties of undefined (reading 'type')". getRowGroupChildren is public pro/premium API; applySorting is undefined by default, so the default path hits the else branch that calls getTreeNodeDescendants directly (useGridRows.ts:397). A stale/invalid groupId makes tree[parentId] undefined and crashes on node.type. The sibling applySorting branch already guards with if (!groupNode) return [] (useGridRows.ts:375), so this change just aligns the two paths. Good.

  2. getTopLevelRowCount (rootGroupNode?.footerId) - ineffective, does not fix anything. On the same line, rootGroupNode.children.length is dereferenced WITHOUT optional chaining and is evaluated first (left-to-right), so if rootGroupNode is undefined it throws "Cannot read properties of undefined (reading 'children')" before ?.footerId ever runs. The ?. is dead code. It also guards children/footerId, not .type, so it is unrelated to the reported error. The root group node is built by buildRootGroup and is effectively always present, so the real-world risk here is near-zero. Recommendation: drop this hunk (preferred), or guard properly, e.g. early-return when !rootGroupNode.

Test coverage: Yes, for the effective half. Add a regression test in packages/x-data-grid-premium/src/tests/rowGroupingApiRef.DataGridPremium.test.tsx asserting getRowGroupChildren({ groupId: }) returns [] (and the same with applySorting: true for symmetry). Cheap, documents the contract, prevents regression. The getTopLevelRowCount hunk cannot be meaningfully tested because it still throws - which is itself the signal it should be removed or fixed.

Comment thread packages/x-data-grid/src/hooks/features/rows/gridRowsUtils.ts Outdated
@timbuckley
timbuckley requested a review from LukasTy June 25, 2026 10:24
@timbuckley

Copy link
Copy Markdown
Contributor Author

Thank you @LukasTy, I have made all your suggestions. Please re-review!

@LukasTy LukasTy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for addressing this. 🙏

Could you please run prettier and commit changes?

timbuckley and others added 4 commits June 25, 2026 20:15
Graceful failure to prevent `Level: Error
Cannot read properties of undefined (reading 'type')` errors

Signed-off-by: Tim Buckley <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
@cherniavskii cherniavskii added the needs cherry-pick The PR should be cherry-picked to master after merge. label Jun 25, 2026
@cherniavskii
cherniavskii enabled auto-merge (squash) June 25, 2026 18:17
@cherniavskii
cherniavskii merged commit 6c7795c into mui:master Jun 25, 2026
25 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Cherry-pick PRs will be created targeting branches: v8.x

mbrookes pushed a commit to mbrookes/mui-x that referenced this pull request Jun 27, 2026
…1808)

Co-authored-by: Claude Opus 4.8 <[email protected]>
Signed-off-by: Tim Buckley <[email protected]>
Signed-off-by: Tim <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs cherry-pick The PR should be cherry-picked to master after merge. scope: data grid Changes related to the data grid. type: bug It doesn't behave as expected. v8.x

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants