Skip to content

Conversation

@crisbeto
Copy link
Member

@crisbeto crisbeto commented Dec 2, 2025

When registering providers, the DI system assumes that viewProviders are registered before plain providers. This was reinforced by components always being first in the array of directive matches, only one component being allowed per node and the fact that only components can have viewProviders.

This breaks down if there are host directives with providers on the component, because they'll execute earlier, throwing off the order of operations.

These changes fix the issue by separating out the resolvers for viewProviders and plain providers and explicitly running the component's viewProviders resolver before any others. This also has the benefit of not attempting to resolve viewProviders for directives which are guaranteed not to have them.

Fixes #65724.

@crisbeto crisbeto added action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release labels Dec 2, 2025
@angular-robot angular-robot bot added the area: core Issues related to the framework runtime label Dec 2, 2025
@ngbot ngbot bot added this to the Backlog milestone Dec 2, 2025
…oviders is present

When registering providers, the DI system assumes that `viewProviders` are registered before plain `providers`. This was reinforced by components always being first in the array of directive matches, only one component being allowed per node and the fact that only components can have `viewProviders`.

This breaks down if there are host directives with `providers` on the component, because they'll execute earlier, throwing off the order of operations.

These changes fix the issue by separating out the resolvers for `viewProviders` and plain `providers` and explicitly running the component's `viewProviders` resolver before any others. This also has the benefit of not attempting to resolve `viewProviders` for directives which are guaranteed not to have them.

Fixes angular#65724.
@crisbeto crisbeto force-pushed the view-providers-host-dirs branch from 220b6c9 to fc6fbea Compare December 2, 2025 09:22
@crisbeto crisbeto added the action: global presubmit The PR is in need of a google3 global presubmit label Dec 2, 2025
@crisbeto
Copy link
Member Author

crisbeto commented Dec 2, 2025

Passing TGP

@crisbeto crisbeto removed the action: global presubmit The PR is in need of a google3 global presubmit label Dec 2, 2025
@crisbeto crisbeto marked this pull request as ready for review December 2, 2025 15:59
Copy link
Contributor

@thePunderWoman thePunderWoman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release and removed action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release labels Dec 2, 2025
@pkozlowski-opensource pkozlowski-opensource merged commit 886cf6c into angular:main Dec 3, 2025
31 of 32 checks passed
@pkozlowski-opensource
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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.

Host directive with provider breaks viewProviders

3 participants