[charts] Reduce ChartsWrapper bundle size#22463
Conversation
Deploy previewhttps://deploy-preview-22463--material-ui-x.netlify.app/ Bundle size
PerformanceTotal duration: 918.03 ms -34.72 ms(-3.6%) | Renders: 30 (+0) | Paint: 1,284.69 ms -34.44 ms(-2.6%)
11 tests within noise — details Check out the code infra dashboard for more information about this PR. |
There was a problem hiding this comment.
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/.../elsechain computingareas,rows,columns, andtwoColumns. - Use small lookup objects (
JUSTIFY_ITEMS,ALIGN_ITEMS) forjustifyItems/alignItemsresolution. - Compute the toolbar grid-template-areas string from
twoColumnsinstead of splittinggridTemplateColumns.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
PR #19257 fixed toolbar positioning by switching
ChartsWrapperfrom 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 repeatedgridTemplate*property names.This PR simplifies the implementation by:
grid-template*property name is declared only once.:has()block’s runtimesplit/map/joinchain with a single boolean check.The result keeps the same layout behavior while reducing duplicated runtime and bundle output.