-
Notifications
You must be signed in to change notification settings - Fork 26.3k
fix(core): call DestroyRef
on destroy callback if view is destroyed
#58008
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
Conversation
Is there a specific reason this is still a draft? |
a9b4147
to
b60f6eb
Compare
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.
LGTM. Thanks!
b60f6eb
to
6fe3567
Compare
6fe3567
to
60ea4a0
Compare
@thePunderWoman we prolly pushed simultaneously 😂 |
@arturovt Looks like this also has some legitimate failing tests that need to be addressed before we can merge it. |
In this commit, we introduce the ability to check whether `lView` has already been destroyed in `NodeInjectorDestroyRef`. If the `lView` is already destroyed, we call the on-destroy callback immediately, without trying to register it to be called later. This ensures that any necessary cleanup is handled gracefully and provides better reliability in managing resources. One of the use cases is `takeUntilDestroyed`, which aims to replace `takeUntil` in existing applications. While `takeUntil` can be safely called once the view is destroyed—resulting in no errors and finalizing the subscription depending on whether a subject or replay subject is used—replacing it with `takeUntilDestroyed` introduces a breaking change, as it throws an error if the `lView` is destroyed. Related issue: angular#54527
60ea4a0
to
af55238
Compare
@thePunderWoman fixed the unit test (removed the one which was testing previous behavior before that fix). |
@arturovt Looks like there's conflicts with patch. So I've switched it to |
This PR was merged into the repository by commit 5f7f046. The changes were merged into the following branches: main |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
In this commit, we introduce the ability to check whether
lView
has already been destroyed inNodeInjectorDestroyRef
. If thelView
is already destroyed, we call the on-destroy callback immediately, without trying to register it to be called later. This ensures that any necessary cleanup is handled gracefully and provides better reliability in managing resources.One of the use cases is
takeUntilDestroyed
, which aims to replacetakeUntil
in existing applications. WhiletakeUntil
can be safely called once the view is destroyed—resulting in no errors and finalizing the subscription depending on whether a subject or replay subject is used—replacing it withtakeUntilDestroyed
introduces a breaking change, as it throws an error if thelView
is destroyed.Related issue: #54527