Skip to content

refactor(core): replace Optional/SkipSelf deps with inject() flags#63386

Closed
arturovt wants to merge 1 commit intoangular:mainfrom
arturovt:refactor/Optional_SkipSelf_tree-shake
Closed

refactor(core): replace Optional/SkipSelf deps with inject() flags#63386
arturovt wants to merge 1 commit intoangular:mainfrom
arturovt:refactor/Optional_SkipSelf_tree-shake

Conversation

@arturovt
Copy link
Copy Markdown
Contributor

This commit updates provider definitions that relied on the deps array with new Optional() and new SkipSelf() to instead use the modern inject(..., { optional: true, skipSelf: true }) API.

Previously:
deps: [[KeyValueDiffers, new SkipSelf(), new Optional()]]

Now:
const parent = inject(KeyValueDiffers, { optional: true, skipSelf: true });

Bundle size reduction: Optional and SkipSelf are runtime values created by makeParamDecorator(). Even in production builds, esbuild and other bundlers must keep their factory code because they are referenced with new Optional() / new SkipSelf(). With inject(), those classes are no longer referenced, allowing them and the makeParamDecorator scaffolding to be tree-shaken when unused.

As a result, production bundles can drop both Optional, SkipSelf, and their supporting factory code when not used elsewhere, reducing code size while keeping the same behavior.

This commit updates provider definitions that relied on the `deps` array
with `new Optional()` and `new SkipSelf()` to instead use the modern
`inject(..., { optional: true, skipSelf: true })` API.

Previously:
  deps: [[KeyValueDiffers, new SkipSelf(), new Optional()]]

Now:
  const parent = inject(KeyValueDiffers, { optional: true, skipSelf: true });

**Bundle size reduction**: `Optional` and `SkipSelf` are runtime values
created by `makeParamDecorator()`. Even in production builds, esbuild
and other bundlers must keep their factory code because they are
referenced with `new Optional()` / `new SkipSelf()`. With `inject()`,
those classes are no longer referenced, allowing them and the
`makeParamDecorator` scaffolding to be tree-shaken when unused.

As a result, production bundles can drop both `Optional`, `SkipSelf`, and
their supporting factory code when not used elsewhere, reducing code size
while keeping the same behavior.
@pullapprove pullapprove bot requested a review from JeanMeche August 25, 2025 20:28
@angular-robot angular-robot bot added the area: core Issues related to the framework runtime label Aug 25, 2025
@ngbot ngbot bot added this to the Backlog milestone Aug 25, 2025
@JeanMeche JeanMeche added the target: patch This PR is targeted for the next patch release label Aug 26, 2025
@thePunderWoman thePunderWoman added the action: merge The PR is ready for merge by the caretaker label Aug 28, 2025
@mmalerba
Copy link
Copy Markdown
Contributor

This PR was merged into the repository. The changes were merged into the following branches:

@mmalerba mmalerba closed this in ec65663 Aug 28, 2025
mmalerba pushed a commit that referenced this pull request Aug 28, 2025
…63386)

This commit updates provider definitions that relied on the `deps` array
with `new Optional()` and `new SkipSelf()` to instead use the modern
`inject(..., { optional: true, skipSelf: true })` API.

Previously:
  deps: [[KeyValueDiffers, new SkipSelf(), new Optional()]]

Now:
  const parent = inject(KeyValueDiffers, { optional: true, skipSelf: true });

**Bundle size reduction**: `Optional` and `SkipSelf` are runtime values
created by `makeParamDecorator()`. Even in production builds, esbuild
and other bundlers must keep their factory code because they are
referenced with `new Optional()` / `new SkipSelf()`. With `inject()`,
those classes are no longer referenced, allowing them and the
`makeParamDecorator` scaffolding to be tree-shaken when unused.

As a result, production bundles can drop both `Optional`, `SkipSelf`, and
their supporting factory code when not used elsewhere, reducing code size
while keeping the same behavior.

PR Close #63386
@arturovt arturovt deleted the refactor/Optional_SkipSelf_tree-shake branch August 28, 2025 19:39
@angular-automatic-lock-bot
Copy link
Copy Markdown

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants