Skip to content

Conversation

@AndrewKushnir
Copy link
Contributor

This commit updates the logic that create an injector for defer blocks (when it's needed) to account for a situation when a component is instantiated without a connection to the current component tree. This can happen if a component is created using its factory function or via createComponent() call.

Resolves #56372.

PR Type

What kind of change does this PR introduce?

  • Bugfix

Does this PR introduce a breaking change?

  • Yes
  • No

@AndrewKushnir AndrewKushnir added state: WIP area: core Issues related to the framework runtime target: patch This PR is targeted for the next patch release core: defer Issues related to @defer blocks. labels Jun 28, 2024
@ngbot ngbot bot modified the milestone: Backlog Jun 28, 2024
…ttached to ApplicationRef

This commit updates the logic that create an injector for defer blocks (when it's needed) to account for a situation when a component is instantiated without a connection to the current component tree. This can happen if a component is created using its factory function or via `createComponent()` call.

Resolves angular#56372.
@AndrewKushnir AndrewKushnir added action: review The PR is still awaiting reviews from at least one requested reviewer and removed state: WIP labels Jun 29, 2024
@AndrewKushnir AndrewKushnir requested a review from alxhub June 29, 2024 00:02
@AndrewKushnir AndrewKushnir marked this pull request as ready for review June 29, 2024 00:02
@AndrewKushnir
Copy link
Contributor Author

Exploratory Presubmit.

// 1. Provided `parentInjector`
// 2. Newly-created `EnvironmentInjector` with extra providers
// 3. `EnvironmentInjector` from the `parentInjector`
if (parentEnvInjector !== parentInjector) {
Copy link
Member

Choose a reason for hiding this comment

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

This logic looks reasonable, but I wonder if it's necessary - are there cases where parentInjector is not directly an EnvironmentInjector? I suspect this is more possible in tests than production applications.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, this is probably very uncommon. As a potential followup we can explore whether we can change the type of lView[INJECTOR] from an Injector (which is also optional) to ChainedInjector|EnvironmentInjector, in which case we can drop this condition as well.

Copy link
Member

Choose a reason for hiding this comment

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

Ideally, we'd have a devmodeassert for the cast that passes TGP...

@AndrewKushnir AndrewKushnir added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Jul 3, 2024
@AndrewKushnir
Copy link
Contributor Author

Caretaker note: TGP is "green", this PR is ready for merge.

@AndrewKushnir AndrewKushnir added the merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note label Jul 3, 2024
thePunderWoman pushed a commit that referenced this pull request Jul 3, 2024
…ttached to ApplicationRef (#56763)

This commit updates the logic that create an injector for defer blocks (when it's needed) to account for a situation when a component is instantiated without a connection to the current component tree. This can happen if a component is created using its factory function or via `createComponent()` call.

Resolves #56372.

PR Close #56763
thePunderWoman pushed a commit that referenced this pull request Jul 3, 2024
…ttached to ApplicationRef (#56763)

This commit updates the logic that create an injector for defer blocks (when it's needed) to account for a situation when a component is instantiated without a connection to the current component tree. This can happen if a component is created using its factory function or via `createComponent()` call.

Resolves #56372.

PR Close #56763
@thePunderWoman
Copy link
Contributor

This PR was merged into the repository by commit 00d9cd2.

The changes were merged into the following branches: main, 18.0.x, 18.1.x

@angular-automatic-lock-bot
Copy link

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 Aug 3, 2024
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 core: defer Issues related to @defer blocks. merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Component under @defer can not find injected services - R3InjectorError(DeferBlock Injector) error.

3 participants