Investigate more tree-shaking-friendly approach for @angular/forms utils #39640
Labels
area: forms
cross-cutting: tree-shaking
feature: in backlog
Feature request for which voting has completed and is now in the backlog
feature
Issue that requests a new feature
Projects
Milestone
Important note: this ticket just describes possible ideas on how to make Forms code more tree-shakable. There are no specific actions planned/needed at this point.
Currently a lot of logic in Forms is stored in classes (such as AbstractControl, FormControl, FormGroup, FormArray, Validators, etc). The code in these classes is not tree-shakable by Terser. Closure can tree-shake unused class methods, but it requires advanced optimization mode turned on (which may or may not be enabled for different apps for various reasons).
There are some PRs that add more logic (util methods) into AbstractControl-based classes (see #27222, #34210 and also related issues #27171, #34186). Adding more methods into AbstractControl-based classes would lead to additional payload size even if applications do not use them. It'd be great to have a way to add this kind of helpers/utils in a tree-shakable way (otherwise we won't be able to include them into the Forms code).
One possible solution to consider is creating standalone functions that would take the necessary controls as arguments are perform some actions inside, for example with the
moveControlfunction (from #27222) that might look like:Note: there is a lot of consideration that should be taken into account (such as backwards-compatibility, DX, API consistency and ergonomics, etc) before creating any helper methods and more research/discussion is needed (when this work is prioritized).
The text was updated successfully, but these errors were encountered: