Skip to content

Use static const IconData on MaterialSymbols for tree-shaking - #14151

Open
schultek wants to merge 3 commits into
feat/svg-material-symbolsfrom
feat/tree-shakeable-icons
Open

schultek wants to merge 3 commits into
feat/svg-material-symbolsfrom
feat/tree-shakeable-icons

Conversation

@schultek

@schultek schultek commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Description of what this PR is changing or adding, and why:

Replaces string-based icon lookups with static const IconData properties on MaterialSymbols so Dart can tree-shake unused icons from client JS/Wasm bundles:

  • Move IconData into packages/site_shared/lib/src/icon/icon_data.dart and material_symbols_data.dart into packages/site_shared/lib/src/icon/.
  • Update dart run dash_site update-icons to generate MaterialSymbols with static const IconData fields and a MaterialSymbols.byName lookup method for dynamic server-side uses.
  • Rename MaterialIcon to Icon accepting an IconData directly, and move Markdown <Icon> tag parsing into IconMarkdownComponent (CustomComponentBase) so client bundles never reference MaterialSymbols.byName.
  • Migrate all components across site_shared, docs, and www to pass MaterialSymbols.<name> directly (with MaterialSymbols.byName used only for dynamic server-side YAML/Markdown data).

Issues fixed by this PR (if any):

Fixes #14120

PRs or commits this PR depends on (if any):

Presubmit checklist

  • If you are unwilling, or unable, to sign the CLA, even for a tiny, one-word PR, please file an issue instead of a PR.
  • If this PR is not meant to land until a future stable release, mark it as draft with an explanation.
  • This PR follows the Google Developer Documentation Style Guidelines—for example, it doesn't use i.e. or e.g., and it avoids I and we (first-person pronouns).
  • This PR uses semantic line breaks
    of 80 characters or fewer.

@schultek
schultek force-pushed the feat/tree-shakeable-icons branch from 498f7b1 to 47f412c Compare December 1, 2026 13:01

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the icon system across the repository by replacing the string-based MaterialIcon component with a strongly-typed Icon component that accepts IconData from the generated MaterialSymbols class. This change enables tree-shaking of unused icons, reducing client bundle sizes. The code generator tool has been updated to output these static icon definitions, and tests and components across all sites have been migrated to use the new typed icons. One issue was identified in IconMarkdownComponent where the regular expression pattern for matching the "Icon" tag lacks anchors, which could cause it to incorrectly match other tags containing "icon" as a substring (e.g., <IconButton>).

@flutter-website-bot

flutter-website-bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Staged preview of the updated docs.flutter.dev site (updated for commit 50ab7d8):

https://flutter-docs-prod--docs-pr14151-feat-tree-shakeable-ic-lhettnlv.web.app

@flutter-website-bot

flutter-website-bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Staged preview of the updated flutter.dev site (updated for commit 50ab7d8):

https://flutter-dev-230821--www-pr14151-feat-tree-shakeable-ic-9foyir51.web.app

@schultek
schultek added this pull request to stack #14152 December 1, 2026 13:11
@schultek
schultek requested a review from parlough December 1, 2026 13:25
@schultek
schultek force-pushed the feat/tree-shakeable-icons branch from 48688d1 to 472e13f Compare December 1, 2026 13:33
@parlough parlough self-assigned this Dec 1, 2026
@schultek
schultek force-pushed the feat/tree-shakeable-icons branch from 472e13f to 378364f Compare December 2, 2026 14:38
@schultek
schultek force-pushed the feat/tree-shakeable-icons branch from 378364f to 50ab7d8 Compare December 2, 2026 14:45
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.

Implement icon font subsetting

4 participants