refactor: use light-weight token for optgroup to optimize bundle size#19577
Conversation
8de6705 to
a62f1a5
Compare
a62f1a5 to
e63d9dd
Compare
| // TODO: Remove cast once https://github.com/angular/angular/pull/37506 is available. | ||
| /** @docs-private */ | ||
| @ContentChildren(MatOptgroup, {descendants: true}) optionGroups: QueryList<MatOptgroup>; | ||
| @ContentChildren(MAT_OPTGROUP as any, {descendants: true}) optionGroups: QueryList<MatOptgroup>; |
There was a problem hiding this comment.
I'm wondering whether this would have an effect, considering that MatOptgroup has a hard reference in MatOptionModule which is then referenced in MatAutocompleteModule. Since we have the size checks set up, it should be easy to find out.
There was a problem hiding this comment.
I'll double-check, but I was thinking "yes" (given the size in the test also decreased: e63d9dd). My thinking is that the module imports are just used for the compilation resolution, but the compiler will just reference the directives/components based on usage. Providers are persisted in the module injector definition.
There was a problem hiding this comment.
Okay, double-checked. Everything works as expected. The module definitions by default will not reference declarations etc. (as noted above). The compiler will only reference these when emitInline is set. This is only the case in JIT when it gets through the compiler facade.
e63d9dd to
086efd1
Compare
086efd1 to
c840d38
Compare
The `MatOptgroup` component is not always used in applications. e.g. it's an optional part of the autocomplete or select. Currently though, we always reference the `MatOpgroup` component directly as a value, and it will be retained in applications regardless of the usage. We can improve this by providing a light-weight injection token for the optgroup that we can then use in queries or optional DI injection. This obviously was already an issue in View Engine too, but it became significantly worse in Ivy as factories are now directly attached to the component class. Related to: angular#19576.
c840d38 to
d388020
Compare
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
The
MatOptgroupcomponent is not always used in applications. e.g.it's an optional part of the autocomplete or select. Currently though,
we always reference the
MatOpgroupcomponent directly at runtime,and it will be retained in applications regardless of the usage.
We can improve this by providing a light-weight injection token for
the optgroup that we can then use in queries or optional DI injection.
This obviously was already an issue in View Engine too, but it became
significantly worse in Ivy as factories are now directly attached to
the component class.
Related to: #19576.