Skip to content

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

Closed

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

Activity

  1. added
    featureLabel used to distinguish feature request from other issues
    needs triageThis issue needs to be triaged by the team
    and removed
    needs triageThis issue needs to be triaged by the team
    on Jun 9, 2020
  2. self-assigned this
    on Jun 9, 2020
  3. 79 remaining items

  4. angular-automatic-lock-bot commented on Jul 30, 2020

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  5. locked and limited conversation to collaborators on Jul 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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