Skip to content

[charts] Reduce ChartsWrapper bundle size#22463

Open
sai6855 wants to merge 6 commits into
mui:masterfrom
sai6855:charts-wrapper
Open

[charts] Reduce ChartsWrapper bundle size#22463
sai6855 wants to merge 6 commits into
mui:masterfrom
sai6855:charts-wrapper

Conversation

@sai6855
Copy link
Copy Markdown
Member

@sai6855 sai6855 commented May 15, 2026

PR #19257 fixed toolbar positioning by switching ChartsWrapper from flex to CSS grid. The fix itself is correct and remains unchanged, but it introduced 5 small helpers that each duplicated branching logic along with repeated gridTemplate* property names.

This PR simplifies the implementation by:

  • Collapsing the 5 helper functions into a single inline branch inside the styled callback.
  • Ensuring each grid-template* property name is declared only once.
  • Replacing the :has() block’s runtime split/map/join chain with a single boolean check.

The result keeps the same layout behavior while reducing duplicated runtime and bundle output.

image

@sai6855 sai6855 changed the title Refactor ChartsWrapper layout handling with data attributes for impro… [charts] Refactor ChartsWrapper layout handling with data attributes May 15, 2026
@sai6855 sai6855 added type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature. scope: charts Changes related to the charts. labels May 15, 2026
@code-infra-dashboard
Copy link
Copy Markdown

code-infra-dashboard Bot commented May 15, 2026

Deploy preview

https://deploy-preview-22463--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 ▼-337B(-0.09%) ▼-58B(-0.05%)
@mui/x-charts-pro ▼-337B(-0.07%) ▼-59B(-0.04%)
@mui/x-charts-premium ▼-337B(-0.06%) ▼-55B(-0.03%)
@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

Performance

Total duration: 918.03 ms -34.72 ms(-3.6%) | Renders: 30 (+0) | Paint: 1,284.69 ms -34.44 ms(-2.6%)

Test Duration Renders
LineChart with big data amount (with marks) 89.88 ms 🔺+18.73 ms(+26.3%) 2 (+0)
ScatterChartPro with big data amount and zoomed in (single renderer) 11.36 ms 🔺+3.04 ms(+36.6%) 2 (+0)
ScatterChartPro with big data amount and zoomed in (batch renderer) 9.69 ms 🔺+1.74 ms(+21.9%) 2 (+0)

11 tests within noise — details


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

@sai6855 sai6855 changed the title [charts] Refactor ChartsWrapper layout handling with data attributes [charts] Reduce ChartsWrapper bundle size May 15, 2026
@sai6855 sai6855 marked this pull request as ready for review May 15, 2026 13:03
Copilot AI review requested due to automatic review settings May 15, 2026 13:03
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the styled callback in ChartsWrapper to inline what were five separate helpers (getJustifyItems, getAlignItems, getGridTemplateAreas, getTemplateColumns, getTemplateRows) into a single branching block. It also replaces the previous split/map/join runtime computation for the toolbar's grid areas with a boolean (twoColumns) tracked at the same time as the columns string. The goal is reducing duplicated branch logic and bundle size while preserving the layout behavior introduced by #19257.

Changes:

  • Replace five branching helpers with a single inline if/else if/.../else chain computing areas, rows, columns, and twoColumns.
  • Use small lookup objects (JUSTIFY_ITEMS, ALIGN_ITEMS) for justifyItems/alignItems resolution.
  • Compute the toolbar grid-template-areas string from twoColumns instead of splitting gridTemplateColumns.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Labels

scope: charts Changes related to the charts. type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants