Skip to content

fix(core): run ApplicationRef.prototype.bootstrap in NgZone#60720

Closed
dgp1130 wants to merge 1 commit intoangular:mainfrom
dgp1130:bootstrap-zone
Closed

fix(core): run ApplicationRef.prototype.bootstrap in NgZone#60720
dgp1130 wants to merge 1 commit intoangular:mainfrom
dgp1130:bootstrap-zone

Conversation

@dgp1130
Copy link
Copy Markdown
Contributor

@dgp1130 dgp1130 commented Apr 2, 2025

bootstrapApplication always creates the root component in the NgZone, however ApplicationRef.prototype.bootstrap historically did not, meaning that if users did not go out of their way to call ngZone.run(() => appRef.bootstrap(SomeComp)), components would not run change detection correctly.

This commit updates ApplicationRef.prototype.bootstrap to always run within NgZone, removing this hazard and ensuring components always run CD as expected.

TGP: http://test/OCL:743313795:BASE:743313664:1743645912499:dad01837

@dgp1130 dgp1130 added action: review The PR is still awaiting reviews from at least one requested reviewer area: core Issues related to the framework runtime target: major This PR is targeted for the next major release core: bootstrap labels Apr 2, 2025
@dgp1130 dgp1130 requested a review from atscott April 2, 2025 22:59
@ngbot ngbot bot modified the milestone: Backlog Apr 2, 2025
@angular-robot angular-robot bot added the detected: breaking change PR contains a commit with a breaking change label Apr 2, 2025
Copy link
Copy Markdown
Contributor

@atscott atscott left a comment

Choose a reason for hiding this comment

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

I don't know if I think this is worth mentioning as a breaking change especially if there were no failures in TGP

@dgp1130
Copy link
Copy Markdown
Contributor Author

dgp1130 commented Apr 3, 2025

Bootstrap isn't typically run in unit tests so I'm not entirely sure how much confidence TGP gives us (e2e tests should exercise this in some capacity). Clearly it wasn't that breaking in production.

Happy to defer to you or other FW folks if this is worth mentioning as a breaking change or not.

@angular-robot angular-robot bot requested a review from atscott April 4, 2025 00:17
@dgp1130 dgp1130 force-pushed the bootstrap-zone branch 2 times, most recently from 157c70d to 420dc15 Compare April 4, 2025 00:26
@atscott
Copy link
Copy Markdown
Contributor

atscott commented Apr 4, 2025

Bootstrap isn't typically run in unit tests so I'm not entirely sure how much confidence TGP gives us (e2e tests should exercise this in some capacity). Clearly it wasn't that breaking in production.

Happy to defer to you or other FW folks if this is worth mentioning as a breaking change or not.

There's only 1 place in g3 that appears that it could be running bootstrap outside the app's zone. I can't possibly imagine this is intentional or that it would break things to run it (correctly) inside the zone. If it was actually possible to keep things outside the zone, then maybe I could see it. But any time the application runs change detection automatically, it's going to run it inside the zone for that component, even if it was bootstrapped outside the zone.

I would personally omit the breaking change note since it would just create unnecessary noise. We can still land it in major instead of patch though if you want to be extra safe.

`bootstrapApplication` always creates the root component in the `NgZone`, however `ApplicationRef.prototype.bootstrap` historically did not, meaning that if users did not go out of their way to call `ngZone.run(() => appRef.bootstrap(SomeComp))`, components would not run change detection correctly.

This commit updates `ApplicationRef.prototype.bootstrap` to _always_ run within `NgZone`, removing this hazard and ensuring components always run CD as expected.
@angular-robot angular-robot bot removed the detected: breaking change PR contains a commit with a breaking change label Apr 4, 2025
@dgp1130
Copy link
Copy Markdown
Contributor Author

dgp1130 commented Apr 4, 2025

I would personally omit the breaking change note since it would just create unnecessary noise. We can still land it in major instead of patch though if you want to be extra safe.

Removed the breaking change note. I feel like you understand the implications of this better than I do, so I'm happy to defer to you whether we should merge to major or patch.

@dgp1130 dgp1130 closed this Apr 4, 2025
@dgp1130 dgp1130 reopened this Apr 4, 2025
@dgp1130 dgp1130 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 Apr 4, 2025
@atscott
Copy link
Copy Markdown
Contributor

atscott commented Apr 7, 2025

This PR was merged into the repository by commit 0ae1889.

The changes were merged into the following branches: main

@atscott atscott closed this in 0ae1889 Apr 7, 2025
@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 May 8, 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 core: bootstrap target: major This PR is targeted for the next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants