Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Closed
wants to merge 1 commit into from

Conversation

arturovt
Copy link
Contributor

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: #54527

@angular-robot angular-robot bot added the area: core Issues related to the framework runtime label Sep 28, 2024
@ngbot ngbot bot added this to the Backlog milestone Sep 28, 2024
@rhuijben
Copy link

Is there a specific reason this is still a draft?
This fix looks like a nice safety net

@arturovt arturovt marked this pull request as ready for review October 30, 2024 14:31
@AndrewKushnir AndrewKushnir modified the milestones: Backlog, v19 final Oct 30, 2024
Copy link
Contributor

@thePunderWoman thePunderWoman left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

@thePunderWoman thePunderWoman removed the request for review from alxhub April 2, 2025 13:46
@thePunderWoman thePunderWoman added action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release labels Apr 2, 2025
@ngbot
Copy link

ngbot bot commented Apr 2, 2025

I see that you just added the action: merge label, but the following checks are still failing:
    failure conflicts with base branch "main"
    pending status "google-internal-tests" is pending

If you want your PR to be merged, it has to pass all the CI checks.

If you can't get the PR to a green state due to flakes or broken main, please try rebasing to main and/or restarting the CI job. If that fails and you believe that the issue is not due to your change, please contact the caretaker and ask for help.

@thePunderWoman thePunderWoman added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews and removed action: merge The PR is ready for merge by the caretaker labels Apr 2, 2025
@angular-robot angular-robot bot requested a review from thePunderWoman April 2, 2025 13:52
@arturovt
Copy link
Contributor Author

arturovt commented Apr 2, 2025

@thePunderWoman we prolly pushed simultaneously 😂

@thePunderWoman
Copy link
Contributor

@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
@arturovt
Copy link
Contributor Author

arturovt commented Apr 2, 2025

@thePunderWoman fixed the unit test (removed the one which was testing previous behavior before that fix).

@thePunderWoman thePunderWoman removed the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Apr 2, 2025
@thePunderWoman thePunderWoman added action: merge The PR is ready for merge by the caretaker 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
Contributor

@arturovt Looks like there's conflicts with patch. So I've switched it to target: major. If you want this to land in patch as well, feel free to create a patch PR.

@thePunderWoman
Copy link
Contributor

This PR was merged into the repository by commit 5f7f046.

The changes were merged into the following branches: main

@arturovt arturovt deleted the fix/issue_54527 branch April 2, 2025 15:26
@angular-automatic-lock-bot
Copy link

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.

5 participants