You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Tree shake icon fonts with 0 icons retained #190902
With the migration to @RecordUse() in #190225 the compiler got smarter and figured out more unreachable const instances than const_finder did, leading to some fonts now having 0 IconData instances instead of a small number of const instances.
So, we need to somehow signal to the icon tree shaker that something is an icon font instead of a normal font.
If we move the icon fonts to DataAssets reported from the hook/build.dart as theorized in #174860 (comment), then we would know in those hooks which fonts are intended to be tree-shaken or not.
We do have @staticIconProvider annotations, which were used by const_finder (but also didn't prevent 0-icon fonts). We could theoretically try to use these to identify the fonts, but it would require a complete extra pass over the codebase.
Because @RecordUse() does not record annotations that are not runtime objects in the final program. (dart2js does not represent annotations as const instances.)
A short-term workaround for the two built-in fonts is to hardcode the font names in the icon_tree_shaker.dart. That doesn't work for user-defined icon fonts (but it is probably less likely users transitively depends on a user-defined icon font and not use it all).
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.
Activity
dcharkes commentedon Aug 11, 2026
One issue is that the asset declaration in the
pubspec.yamldoes not specify if a font is an icon font or a normal font.and
flutter/packages/flutter_tools/lib/src/asset.dart
Lines 113 to 129 in b5971ca
If we move the icon fonts to
DataAssets reported from thehook/build.dartas theorized in #174860 (comment), then we would know in those hooks which fonts are intended to be tree-shaken or not.We do have
@staticIconProviderannotations, which were used byconst_finder(but also didn't prevent 0-icon fonts). We could theoretically try to use these to identify the fonts, but it would require a complete extra pass over the codebase.We cannot do the following unfortunately:
Because
@RecordUse()does not record annotations that are not runtime objects in the final program. (dart2js does not represent annotations as const instances.)A short-term workaround for the two built-in fonts is to hardcode the font names in the
icon_tree_shaker.dart. That doesn't work for user-defined icon fonts (but it is probably less likely users transitively depends on a user-defined icon font and not use it all).[icon_tree_shaker] Tree-shake material and cupertino with 0 icons (fl…
bkonyi commentedon Aug 18, 2026
Fixed by #190905.
github-actions commentedon Sep 1, 2026
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.