Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): support injection of object with null constructor. #56553

Closed
wants to merge 1 commit into from

Conversation

JeanMeche
Copy link
Member

This is debug only code, it shouldn't have any consequences on prod build.

fixes #56552

@angular-robot angular-robot bot added the area: core Issues related to the framework runtime label Jun 22, 2024
@ngbot ngbot bot added this to the Backlog milestone Jun 22, 2024
@JeanMeche JeanMeche added the action: review The PR is still awaiting reviews from at least one requested reviewer label Jun 22, 2024
@JeanMeche JeanMeche marked this pull request as ready for review June 22, 2024 19:05
@pullapprove pullapprove bot requested a review from AndrewKushnir June 22, 2024 19:05
@@ -211,7 +211,7 @@ function handleInstanceCreatedByInjectorEvent(
if (typeof value === 'object') {
standaloneComponent = value?.constructor as Type<unknown>;
}
if (standaloneComponent === undefined || !isStandaloneComponent(standaloneComponent)) {
if (standaloneComponent == undefined || !isStandaloneComponent(standaloneComponent)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd propose adding a quick comment here to mention that we handle both null and undefined (i.e. that the == is intentional).

Copy link
Member

Choose a reason for hiding this comment

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

A test would also be desirable. You may also considering widening the type of standaloneComponent to include null, as currently there's no indication that the == can make a difference vs ===

Copy link
Member Author

Choose a reason for hiding this comment

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

Object.constructor is defined as Function | undefined, won't even consider null if I give it let standaloneComponent: Type<unknown> | undefined | null = undefined;, so I'l go with the comment.

Copy link
Member

Choose a reason for hiding this comment

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

That's because of the (unsound) cast to Type<unknown>, which would cause any null in the declaration site to become irrelevant.

@AndrewKushnir AndrewKushnir added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews 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 labels Jun 23, 2024
@JeanMeche JeanMeche force-pushed the core/di-null-ctor branch 2 times, most recently from ec79c16 to 1946a66 Compare June 24, 2024 14:46
This is debug only code, it shouldn't have any consequences on prod build.

fixes angular#56552
Copy link
Member

@alxhub alxhub left a comment

Choose a reason for hiding this comment

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

+1 to adding a test if possible, but otherwise this LGTM

@JeanMeche JeanMeche added action: merge The PR is ready for merge by the caretaker and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Jul 2, 2024
thePunderWoman pushed a commit that referenced this pull request Jul 2, 2024
This is debug only code, it shouldn't have any consequences on prod build.

fixes #56552

PR Close #56553
thePunderWoman pushed a commit that referenced this pull request Jul 2, 2024
This is debug only code, it shouldn't have any consequences on prod build.

fixes #56552

PR Close #56553
@thePunderWoman
Copy link
Contributor

This PR was merged into the repository by commit 331b30e.

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

@JeanMeche JeanMeche deleted the core/di-null-ctor branch July 2, 2024 17:34
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.

useValue and useFactory providers throws error when value.constructor is null
5 participants