Conversation
|
It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging. If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group. |
There was a problem hiding this comment.
Code Review
This pull request makes IconData a final class and adds @mustBeConst to its constructor parameters, which is a great improvement for enforcing immutability and enabling compiler optimizations. My review includes a suggestion to apply the @mustBeConst annotation to all constructor parameters for completeness and consistency.
|
This pull request has been changed to a draft. The currently pending flutter-gold status will not be able to resolve until a new commit is pushed or the change is marked ready for review again. For more guidance, visit Writing a golden file test for Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
justinmc
left a comment
There was a problem hiding this comment.
Seems like a win to me. I want to be sure that Material and Cupertino don't have any breaking usages of IconData though (doesn't look like it to me if I grep through the codebase).
I haven't worked on the rfw codebase, but taking a look it seems like it won't be possible for it to support icon tree shaking. That makes sense for a package that can execute code at runtime that is unknown at compile time, so I expect users of rfw will understand.
|
FYI, some folks use the
This comment explains why folks use this pattern: #126261 (comment)
However, it seems that this improvement is nice enough to warrant breaking breaking this pattern. |
@Albert221 You rely on subtyping |
|
@dcharkes Hey! That is correct, they're not tree-shaken at all if I use Setup we use for many projects and that many clients use in their codebases usually is:
|
|
Thanks for the reply @Albert221 🙏 Okay, then the tree-shaking is WAI in your use case. I suppose asking you to migrate away from |
|
Not ideal but possible, yes. If that's for the sake of making Flutter better for everyone, go for it |
🙏 👍 ! Okay, when we do this as a breaking change, then older versions of WidgetBook will stop working in a newer Flutter version. Please let me know when you have migrated, and if the migration didn't caused breaking change issues on your side (looking at the code I don't think so, but I might be wrong). I'll wait with landing anything on master for a while (and need to file a breaking change announcement as well) to ensure no one breaks. |
6c1c25c to
63b8163
Compare
We are introducing the `@mustBeConst` annotation on `IconData` parameters that must be const in order for the icon tree shaker to work: * flutter/flutter#181344 * flutter/flutter#181345 RFW does not support tree-shaking. This PR adds the lint ignores with an explicit comment that the lint ignore is intentional.
63b8163 to
84a1207
Compare
84a1207 to
8569697
Compare
Roll in flutter/packages#11216. To make flutter/flutter#181345 go green.
8569697 to
f9750dd
Compare
Roll in flutter/devtools#9718. To make flutter/flutter#181345 go green.
f9750dd to
74fde38
Compare
There was a problem hiding this comment.
Code Review
This pull request enhances IconData by making it a final class and annotating its constructor parameters with @mustBeConst. These changes improve const-correctness, which is beneficial for optimizations like icon tree shaking. The implementation is sound, and I have one suggestion to apply the @mustBeConst annotation more consistently across all relevant parameters.
| this.matchTextDirection = false, | ||
| this.fontFamilyFallback, |
There was a problem hiding this comment.
For consistency and to ensure all properties used by the icon tree shaker are constant, consider also annotating matchTextDirection and fontFamilyFallback with @mustBeConst. All fields of IconData are marked with @_retainForIconTreeShaker, which suggests they are all relevant for tree shaking.
// ignore: experimental_member_use
@mustBeConst this.matchTextDirection = false,
// ignore: experimental_member_use
@mustBeConst this.fontFamilyFallback,There was a problem hiding this comment.
Nope they are not read:
final Object? package = iconDataMap['fontPackage'];
final Object? fontFamily = iconDataMap['fontFamily'];
final Object? codePoint = iconDataMap['codePoint'];packages/flutter_tools/lib/src/build_system/targets/icon_tree_shaker.dart
|
Do we have a migration guide staged in flutter/website for this? There is a template we used for explaining the context of the breakage and how to migrate, which ends up listed here: https://docs.flutter.dev/release/breaking-changes |
We haven't landed that yet, do we do that first? |
Nah, usually right after this lands. We just make sure they're both ready so we don't forget to add the guide later. :) |
2026-03-18 update, no push-back on the breaking changes. Migrations done downstream:
IconDatabeing markedfinalfluttercommunity/font_awesome_flutter#297IconDataasfinalFaFre/WebLibre#214Applying breaking changes:
class IconDataasfinal#181342IconData's constructor parameters as@mustBeConst#181344See the issue descriptions for the motivation.
cc @Piinks
It seems we have a non-const use in the Remote Flutter Widgets:
https://github.com/flutter/packages/blob/d0c7d1fad77331724882614345137221c77d5758/packages/rfw/lib/src/flutter/argument_decoders.dart#L801-L811
The package itself makes no mention of it not work with the Flutter Icon Tree Shaker. If it's a know issue that the icon tree shaker is not supported with
package:rfwwe can add// ignore: non_const_argument_for_const_parameter. (flutter/packages#10858)