-
Notifications
You must be signed in to change notification settings - Fork 26.3k
fix(core): avoid injecting ErrorHandler
from a destroyed injector
#61886
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
base: main
Are you sure you want to change the base?
Conversation
464cf17
to
1c1bc54
Compare
1c1bc54
to
1f55347
Compare
I'm not sure that swallowing the error is the correct behavior. If errors are happening in the application after it was destroyed, I don't know that the correct behavior is to swallow the error entirely. |
Since the error handler isn’t available, can we re throw the error in a micro task or setTimeout? |
Yea, I think that would be appropriate. I think |
1f55347
to
20e744e
Compare
inject(ApplicationRef).onDestroy(() => { | ||
// Note: The unit test environment differs from the real browser environment. | ||
// This is a simple test that ensures that if an error event is dispatched | ||
// during destruction, it does not attempt to inject the `ErrorHandler`. | ||
// Before the `if (injector.destroyed)` checks were added, this would | ||
// throw a "destroyed injector" error. | ||
dispatched = window.dispatchEvent(new Event('error')); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This actually came up today that the injector is marked as destroyed before the onDestroy
hooks are invoked. I'm wondering if we want to change that behavior so onDestroy hooks still have the ability to use the injector since it's really not fully destroyed yet.
Can this change to account for the potential change above and dispatch the error event in a promise or timeout instead?
packages/core/src/change_detection/scheduling/ng_zone_scheduling.ts
Outdated
Show resolved
Hide resolved
20e744e
to
1a66a21
Compare
@arturovt Looks like you have one failing test you'll need to fix. |
1a66a21
to
613d146
Compare
packages/core/src/change_detection/scheduling/ng_zone_scheduling.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting review to request changes so it doesn’t appear that I’ve approved
613d146
to
f1e13e2
Compare
packages/core/src/change_detection/scheduling/ng_zone_scheduling.ts
Outdated
Show resolved
Hide resolved
This commit prevents lazy injection of the internal `ErrorHandler` from a destroyed injector, as it would result in another "destroyed injector" error.
f1e13e2
to
1d437de
Compare
This commit prevents lazy injection of the internal
ErrorHandler
from a destroyed injector, as it would result in another "destroyed injector" error.