refactor(form-field): use lightweight token for optimized treeshaking #19714
Conversation
Currently the `MatFormField` always retains `MatHint`, `MatError`, `MatPrefix` and `MatSuffix`. These are optional parts of a form-field so we ideally would not retain those always. We can achieve this by using lightweight injection tokens for querying of these directives, instead of using the actual implementations as query predicate token. The retention was already an issue in View Engine too, but the issue became more noticable in Ivy where factories and definitions are directly attached to the classes.
| @@ -1,3 +1,5 @@ | |||
| export declare const _MAT_HINT: InjectionToken<MatHint>; | |||
There was a problem hiding this comment.
Why is this one underscored, but the others aren't?
There was a problem hiding this comment.
There should be a JSDoc for the _MAT_HINT constant. In short: The MDC-based form-field uses MatHint directly, so it's never optional. Hence a lightweight token does not make any sense to have, and to avoid a breaking change when eventually the MDC-based form-field is used, the lightweight token for MatHint in non-MDC is private.
There was a problem hiding this comment.
Would it make sense to just keep it consistent in that case and not use the token? It's not that large to begin with.
There was a problem hiding this comment.
All of the classes are not really large in source here, but with the generated factory and definition they could easily sum-up (even more in ES5). IIRC for hint it's about 230kb.
I don't think that this should stop us from having a lightweight token in the non-MDC form-field. It's a non-public facing implementation detail, and the form-fields deviate quite a bit anyway already.
|
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. |
Currently the
MatFormFieldalways retainsMatHint,MatError,MatPrefixandMatSuffix. These are optional parts of a form-field sowe ideally would not retain those always.
We can achieve this by using lightweight injection tokens for querying
of these directives, instead of using the actual implementations as
query predicate token. The retention was already an issue in View Engine
too, but the issue became more noticeable in Ivy where factories and
definitions are directly attached to the classes.
In the basic case this signifies a reduction of ~800kb, while in the advanced
case (due to the referenced injection tokens), we increase by ~300kb.
Related to #19576