Skip to content

refactor(core): Instantiate the ErrorHandler lazily.#58984

Closed
JeanMeche wants to merge 2 commits intoangular:mainfrom
JeanMeche:fix/instantiate-error-handler
Closed

refactor(core): Instantiate the ErrorHandler lazily.#58984
JeanMeche wants to merge 2 commits intoangular:mainfrom
JeanMeche:fix/instantiate-error-handler

Conversation

@JeanMeche
Copy link
Copy Markdown
Member

This change prevents that user code in a custom ErrorHandler to run as part of ApplicationRef's creation.

fixes #58970

@angular-robot angular-robot bot added the area: core Issues related to the framework runtime label Nov 30, 2024
@ngbot ngbot bot added this to the Backlog milestone Nov 30, 2024
@JeanMeche JeanMeche force-pushed the fix/instantiate-error-handler branch from 038badc to 0cf45a6 Compare November 30, 2024 15:45
@angular-robot angular-robot bot added area: core Issues related to the framework runtime and removed area: core Issues related to the framework runtime labels Nov 30, 2024
@JeanMeche JeanMeche added the action: presubmit The PR is in need of a google3 presubmit label Nov 30, 2024
@JeanMeche JeanMeche force-pushed the fix/instantiate-error-handler branch from 0cf45a6 to 2e9411d Compare November 30, 2024 15:55
@angular-robot angular-robot bot added area: core Issues related to the framework runtime and removed area: core Issues related to the framework runtime labels Nov 30, 2024
@pkozlowski-opensource
Copy link
Copy Markdown
Member

Note: I was looking into a similar refactor from a perf point of view - the observation being that we don't really need ErrorHandler until there is an actual error to handle. At the same time profiling real life applications (including adev) revealed that ErrorHandler can have non-trivial logic / take non-negligible amount of time to boot up.

@JeanMeche JeanMeche force-pushed the fix/instantiate-error-handler branch from 2e9411d to 81608ce Compare December 3, 2024 19:06
@angular-robot angular-robot bot added area: core Issues related to the framework runtime and removed area: core Issues related to the framework runtime labels Dec 3, 2024
@ngbot ngbot bot modified the milestone: Backlog Dec 3, 2024
@pkozlowski-opensource pkozlowski-opensource added the action: merge The PR is ready for merge by the caretaker label Dec 4, 2024
@pkozlowski-opensource
Copy link
Copy Markdown
Member

FYI: it breaks some of the existing G3 tests: will require TGP and cleanup

@pkozlowski-opensource pkozlowski-opensource added state: blocked and removed action: merge The PR is ready for merge by the caretaker labels Dec 4, 2024
@JeanMeche JeanMeche modified the milestones: Backlog, v20 candidates Dec 18, 2024
crisbeto added a commit to crisbeto/angular that referenced this pull request Dec 20, 2024
In angular/components#30179 the CDK overlay started depending on the `Renderer2Factory`. Since the overlay is used in the `MatSnackbar` which is commonly used in error handlers, `Overlay` can end up being injected as a part of the app initialization. Because `AsyncAnimationRendererFactory` depends on the `ChangeDetectionScheduler`, it may cause a circular dependency.

These changes inject the `ChangeDetectionScheduler` lazily to avoid the error.

Note: this will also be resolved by angular#58984, but I decided to send it out, because:
1. angular#58984 seems to be stuck on some internal cleanup.
2. The `AsyncAnimationRendererFactory` doesn't need the `scheduler` eagerly anyway so the change is fairly safe.

Fixes angular#59255.
josephperrott pushed a commit that referenced this pull request Dec 20, 2024
)

In angular/components#30179 the CDK overlay started depending on the `Renderer2Factory`. Since the overlay is used in the `MatSnackbar` which is commonly used in error handlers, `Overlay` can end up being injected as a part of the app initialization. Because `AsyncAnimationRendererFactory` depends on the `ChangeDetectionScheduler`, it may cause a circular dependency.

These changes inject the `ChangeDetectionScheduler` lazily to avoid the error.

Note: this will also be resolved by #58984, but I decided to send it out, because:
1. #58984 seems to be stuck on some internal cleanup.
2. The `AsyncAnimationRendererFactory` doesn't need the `scheduler` eagerly anyway so the change is fairly safe.

Fixes #59255.

PR Close #59256
josephperrott pushed a commit to josephperrott/angular that referenced this pull request Dec 20, 2024
In angular/components#30179 the CDK overlay started depending on the `Renderer2Factory`. Since the overlay is used in the `MatSnackbar` which is commonly used in error handlers, `Overlay` can end up being injected as a part of the app initialization. Because `AsyncAnimationRendererFactory` depends on the `ChangeDetectionScheduler`, it may cause a circular dependency.

These changes inject the `ChangeDetectionScheduler` lazily to avoid the error.

Note: this will also be resolved by angular#58984, but I decided to send it out, because:
1. angular#58984 seems to be stuck on some internal cleanup.
2. The `AsyncAnimationRendererFactory` doesn't need the `scheduler` eagerly anyway so the change is fairly safe.

Fixes angular#59255.
josephperrott pushed a commit that referenced this pull request Dec 21, 2024
)

In angular/components#30179 the CDK overlay started depending on the `Renderer2Factory`. Since the overlay is used in the `MatSnackbar` which is commonly used in error handlers, `Overlay` can end up being injected as a part of the app initialization. Because `AsyncAnimationRendererFactory` depends on the `ChangeDetectionScheduler`, it may cause a circular dependency.

These changes inject the `ChangeDetectionScheduler` lazily to avoid the error.

Note: this will also be resolved by #58984, but I decided to send it out, because:
1. #58984 seems to be stuck on some internal cleanup.
2. The `AsyncAnimationRendererFactory` doesn't need the `scheduler` eagerly anyway so the change is fairly safe.

Fixes #59255.

PR Close #59271
@JeanMeche JeanMeche force-pushed the fix/instantiate-error-handler branch from 81ccc6a to e7781a5 Compare March 11, 2025 09:20
@atscott atscott force-pushed the fix/instantiate-error-handler branch 4 times, most recently from a326690 to 32ff162 Compare April 1, 2025 18:41
This change prevents that user code in a custom `ErrorHandler` to run as part of `ApplicationRef`'s creation.

fixes angular#58970
@atscott atscott force-pushed the fix/instantiate-error-handler branch 6 times, most recently from f491195 to df1de5a Compare April 1, 2025 19:46
@atscott
Copy link
Copy Markdown
Contributor

atscott commented Apr 2, 2025

Green TGP

@atscott atscott added action: merge The PR is ready for merge by the caretaker and removed state: blocked action: presubmit The PR is in need of a google3 presubmit labels Apr 2, 2025
@atscott atscott force-pushed the fix/instantiate-error-handler branch from df1de5a to f709a4b Compare April 2, 2025 18:17
@atscott atscott added the target: patch This PR is targeted for the next patch release label Apr 2, 2025
@thePunderWoman thePunderWoman added target: major This PR is targeted for the next major release and removed target: patch This PR is targeted for the next patch release labels Apr 2, 2025
@thePunderWoman
Copy link
Copy Markdown
Contributor

@JeanMeche Switching to target: major since there are conflicts with patch.

@thePunderWoman
Copy link
Copy Markdown
Contributor

This PR was merged into the repository by commit 1c1ad12.

The changes were merged into the following branches: main

@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 3, 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: major This PR is targeted for the next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Angular 19: NG0200: Circular dependency in DI detected for ChangeDetectionScheduler

5 participants