Skip to content

[data grid] Fix crash when grouping/tree-data values match Object.prototype property names#22344

Merged
LukasTy merged 1 commit intomui:v7.xfrom
LukasTy:claude/22310-v7-backport
May 6, 2026
Merged

[data grid] Fix crash when grouping/tree-data values match Object.prototype property names#22344
LukasTy merged 1 commit intomui:v7.xfrom
LukasTy:claude/22310-v7-backport

Conversation

@LukasTy
Copy link
Copy Markdown
Member

@LukasTy LukasTy commented May 6, 2026

Backport of #22312 to v7.x. Fixes #22310 on v7.

Summary

The Data Grid (Pro & Premium) crashed with a white screen when a row-grouping value or tree-data path segment was equal to 'constructor' (or any other Object.prototype property name like '__proto__', 'toString', 'hasOwnProperty', 'valueOf').

The root cause is identical on v7.x as on master: childrenFromPath lookup objects were plain {}, so reading ({}).constructor returned Object.prototype.constructor instead of undefined. The tree builder then treated that function as an existing node id and crashed.

Differences from #22312

The master PR also patches treeDataReorderExecutor.ts, but that file does not exist on v7.x (the tree-data drag-and-drop reorder feature was added later). All other source-level changes are identical. Tests are ported to mocha + chai to match v7's test stack.

Files touched

  • packages/x-data-grid/src/hooks/features/rows/gridRowsUtils.ts (root group)
  • packages/x-data-grid-pro/src/utils/tree/insertDataRowInTree.ts (3 group node construction sites)
  • packages/x-data-grid-pro/src/utils/tree/utils.ts (inner per-field map in insertNodeInTree)

Test plan

  • New regression test in rowGrouping.DataGridPremium.test.tsx for row grouping with 'constructor', '__proto__', 'toString', 'hasOwnProperty' as grouping values.

  • New regression test in treeData.DataGridPro.test.tsx for tree-data paths starting with 'constructor'.

  • mocha 'packages/x-data-grid-pro/src/tests/treeData.DataGridPro.test.tsx' (45 passing).

  • mocha 'packages/x-data-grid-premium/src/tests/rowGrouping.DataGridPremium.test.tsx' (104 passing; one pre-existing flake in an unrelated sorting test reproduces on plain v7.x without this change).

  • pnpm --filter "@mui/x-data-grid*" run typescript.

  • pnpm prettier, eslint clean on touched files.

  • Maintainer to verify against the reporter's CodeSandbox.

…totype property names

The row-tree builder used plain `{}` objects as hash maps keyed by
user-supplied grouping values. Looking up `'constructor'` (or
`'__proto__'`, `'toString'`, etc.) returned the inherited
`Object.prototype` property instead of `undefined`, so the code thought
a node already existed at that path and crashed when it tried to use
the prototype function as a node id.

Switch the `childrenFromPath` lookup objects to `Object.create(null)`
so user-supplied keys can never collide with `Object.prototype`. This
matches existing usage in the sorting/filter selectors.

Backport of mui#22312 to v7.

Fixes mui#22310

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@mui-bot
Copy link
Copy Markdown

mui-bot commented May 6, 2026

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

Generated by 🚫 dangerJS against 131539e

@LukasTy LukasTy self-assigned this May 6, 2026
@LukasTy LukasTy added type: bug It doesn't behave as expected. scope: data grid Changes related to the data grid. cherry-pick The PR was cherry-picked from the newer alpha/beta/stable branch. labels May 6, 2026
@LukasTy LukasTy changed the title [v7][data grid] Fix crash when grouping/tree-data values match Object.prototype property names [data grid] Fix crash when grouping/tree-data values match Object.prototype property names May 6, 2026
@LukasTy LukasTy marked this pull request as ready for review May 6, 2026 08:58
@LukasTy
Copy link
Copy Markdown
Member Author

LukasTy commented May 6, 2026

Verified the fix solves the issue locally, since on v7 we no longer have PR package builds.

@LukasTy LukasTy merged commit 1b4d1b1 into mui:v7.x May 6, 2026
20 of 21 checks passed
@LukasTy LukasTy deleted the claude/22310-v7-backport branch May 6, 2026 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-pick The PR was cherry-picked from the newer alpha/beta/stable branch. scope: data grid Changes related to the data grid. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants