Skip to content

fix: restore icon centering after MUI v9 upgrade - #12440

Merged
guanbinrui merged 1 commit into
developfrom
fix/mui-v9-icon-centering
Sep 5, 2026
Merged

fix: restore icon centering after MUI v9 upgrade#12440
guanbinrui merged 1 commit into
developfrom
fix/mui-v9-icon-centering

Conversation

@swkatmask

Copy link
Copy Markdown
Contributor

Summary

  • Icons with dynamic color support (s: true, svg rendered as a child of the icon span — e.g. Icons.MaskBlue) drifted a few px down inside text-sized containers after the MUI v9 upgrade.
  • Root cause: __createIcon passed fontSize: 0 as a system prop to Box. MUI v5 converted system props to CSS (font-size: 0), zeroing the strut so the svg filled the span. Since 52d5bce (5.15.20 → 9.2.0), Box only styles through sx — the prop leaked to the DOM as a useless font-size="0" attribute, the strut came back, and the inline svg got pushed below the baseline. Smaller size made it more visible (e.g. MaskBlue size={16} in the ProfileCard avatar badge sitting in an IconButton with font-size: 24px).
  • Fix in packages/icons/utils/internal.js:
    • move fontSize: 0 into the sx base style (restores v5 semantics under v9);
    • add lineHeight: 0 to guard against host pages inheriting an absolute line-height;
    • drop the dead prop (also removes the React dev warning about the unrecognized fontSize prop).

Impact

__createIcon is the single factory for all generated icons, so this fixes every s: true icon at once. Background-image variants (no child element) are unaffected by fontSize/lineHeight. The SvgIcon-based createIcon() in utils/index.js is unaffected.

Verification

  • Rebuilt dev extension, reloaded x.com profile page and inspected the injected shadow-root UI:
    • icon spans compute font-size: 0px; line-height: 0px; no font-size DOM attribute remains;
    • MaskBlue size={16} in the avatar badge: svg center vs button center delta = 0px (was offset before);
    • MaskBlue size={24} dialog header icon likewise centered;
    • console no longer logs the React does not recognize the "fontSize" prop warning.
  • eslint on the changed file passes; commitlint passes.

MUI v5's Box converted the system prop fontSize={0} to font-size: 0,
zeroing the strut so the svg child filled the icon span. Since the v9
upgrade (52d5bce) Box only styles through sx, so the prop was passed
through as a dead font-size="0" DOM attribute and every s:true icon
(svg child path) drifted down a few px inside text-sized containers
(e.g. MaskBlue size={16} in the ProfileCard avatar badge).

Move fontSize: 0 into the sx base style (restoring v5 semantics), add
lineHeight: 0 to guard against host pages inheriting an absolute
line-height, and drop the dead prop.
@guanbinrui
guanbinrui merged commit 4c02ee4 into develop Sep 5, 2026
11 checks passed
@guanbinrui
guanbinrui deleted the fix/mui-v9-icon-centering branch September 5, 2026 16:51
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.

2 participants