Skip to content

Use light-weight injection pattern for optimized tree-shaking/bundle size #19576

@devversion

Description

@devversion

With Ivy, factories are directly attached to components, so we production bundles could end up with larger bundles if Angular components/directives are used as predicates for optional queries or DI.

See: angular/angular#36144 and https://github.com/angular/angular-cli/issues/16866.

Here is an example:

export class ListItem {
  constructor(@Optional() navigationList: NavList|null,
              @Optional() actionList: ActionList|null)
}

This will result in both NavList and ActionList being retained in production bundles as soon as the ListItem component/directive is used. It will become worse if NavList and ActionList have their own Angular factory/definition (that will also be retained now).

We need to go through our components and optimize these if they are affected by this issue that is now surfacing (more significantly) with Ivy.

Currently pending PRs:

What we need upstream:

  • NgForm used in MatChipList.
  • FormGroupDirective used in MatChipList
  • NgControl used in MatChipList.

What we should consider in the future?

  • Directionality
  • Using a light-weight token for the DateAdapter for better tree-shaking

Revisit after done:

  • MDC equivalents

Metadata

Metadata

Assignees

Labels

area: manyArea label for issues related to many componentsfeatureLabel used to distinguish feature request from other issuesin progressThis issue is currently in progress

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions