Skip to content

[code-infra][icons-material] Avoid material utils barrel in createSvg…#48029

Merged
Janpot merged 7 commits intomui:masterfrom
anchmelev:issue-35840-icons-create-svg-icon
Mar 24, 2026
Merged

[code-infra][icons-material] Avoid material utils barrel in createSvg…#48029
Janpot merged 7 commits intomui:masterfrom
anchmelev:issue-35840-icons-create-svg-icon

Conversation

@anchmelev
Copy link
Contributor

@anchmelev anchmelev commented Mar 19, 2026

Part of #35840

Summary

  • inline createSvgIcon in @mui/icons-material so it no longer re-exports from @mui/material/utils
  • depend directly on @mui/material/SvgIcon
  • add generated typings for the local helper so the @mui/icons-material/* type path remains intact
  • add a narrow ESLint guard to keep @mui/material/utils out of packages/mui-icons-material/src

Why

A single icon import currently goes through the Material utils barrel:

@mui/icons-material/AbcRounded -> ./utils/createSvgIcon -> @mui/material/utils

That pulls extra modules into the dependency graph for an icon hot path. This PR keeps the scope intentionally small and only removes that barrel path from @mui/icons-material.

Because @mui/icons-material/* resolves through lib/*.mjs in this repo, the local helper also needs generated declarations to preserve the previous type behavior.

Benchmark

Standalone webpack check for AbcRounded:

  • before: 268 modules
  • after: 229 modules
  • delta: -39 modules (-14.6%)

Verification

  • pnpm -F @mui/icons-material build:typings
  • pnpm --filter docs typescript
  • pnpm -F @mui/icons-material test

@mui-bot
Copy link

mui-bot commented Mar 19, 2026

Netlify deploy preview

https://deploy-preview-48029--material-ui.netlify.app/

Bundle size report

Bundle Parsed size Gzip size
@mui/material 0B(0.00%) 0B(0.00%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/system 0B(0.00%) 0B(0.00%)
@mui/utils 0B(0.00%) 0B(0.00%)

Details of bundle changes

Generated by 🚫 dangerJS against ab7d1c5

@Janpot
Copy link
Member

Janpot commented Mar 19, 2026

To avoid duplication you can export createSvgIcon from @mui/material/SvgIcon, and then re-export it from the /utils barrel for backwards compatibility. That way you can avoid duplicating the function which would be a maintenance overhead.

@zannager zannager added scope: icons Changes related to the icons. scope: code-infra Involves the code-infra product (https://www.notion.so/mui-org/5562c14178aa42af97bc1fa5114000cd). labels Mar 19, 2026
@zannager zannager requested review from Janpot and brijeshb42 March 19, 2026 13:02
@anchmelev
Copy link
Contributor Author

To avoid duplication you can export createSvgIcon from @mui/material/SvgIcon, and then re-export it from the /utils barrel for backwards compatibility. That way you can avoid duplicating the function which would be a maintenance overhead.

Thanks, that makes sense.

I updated the PR in that direction.

createSvgIcon now lives under @mui/material/SvgIcon, @mui/material/utils/createSvgIcon remains a compatibility re-export, and @mui/icons-material re-exports from @mui/material/SvgIcon instead of duplicating the helper.

Copy link
Member

Choose a reason for hiding this comment

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

why did the quotes change? Did you edit this file manually? It should be generated from ./packages/mui-icons-material/src/utils/createSvgIcon.js

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch.

That quote/style change was just generated-artifact drift after the refactor. I’ve regenerated packages/mui-icons-material/lib/utils/createSvgIcon.{js,mjs} so the tracked lib files match the build output again.

The actual change is only the helper re-export path in the source.

Copy link
Member

Choose a reason for hiding this comment

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

I think we can drop the lint rule. Bit too much duplication, these restricted imports are already hard to manage. Instead, just add a @deprecated jsdoc comment on the @mui/material/utils/createSvgIcon export.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense to me.

I dropped the lint rule and added @deprecated markers to the compatibility re-export in:

  • packages/mui-material/src/utils/createSvgIcon.js
  • packages/mui-material/src/utils/createSvgIcon.d.ts

The actual helper path remains on @mui/material/SvgIcon.

},
},
{
files: [`packages/mui-icons-material/src/**/*${EXTENSION_TS}`],
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this already covered by https://github.com/anchmelev/material-ui/blob/8d187b6a70171a82a64e3c9c640d4abea767855a/eslint.config.mjs#L245-L267. I think you can restore the eslint configuration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right - packages//src/**/ already covers mui-icons-material. I restored it!

@@ -1,2 +1 @@
'use client';
Copy link
Member

Choose a reason for hiding this comment

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

You can keep the 'use client' for now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Restored 'use client' in src/utils/createSvgIcon.js and synced the generated lib helpers so they match the rest of the package.

@anchmelev anchmelev requested a review from Janpot March 24, 2026 04:21
@Janpot Janpot merged commit 9e9fda9 into mui:master Mar 24, 2026
19 checks passed
@Janpot
Copy link
Member

Janpot commented Mar 24, 2026

Thank you!

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

Labels

scope: code-infra Involves the code-infra product (https://www.notion.so/mui-org/5562c14178aa42af97bc1fa5114000cd). scope: icons Changes related to the icons.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants