-
Notifications
You must be signed in to change notification settings - Fork 26.7k
fix(router): unset attachRef when router-outlet is destroyed to avoid mounting a destroyed component #43697
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
fix(router): unset attachRef when router-outlet is destroyed to avoid mounting a destroyed component #43697
Conversation
… mounting a destroyed component Previously, when a router-outlet is conditionally shown with an ngIf, and a sub-route was re-attached via a custom RouteReuseStrategy, router-outlet would try to mount a destroyed component into the view if the router-outlet is destroyed and re-initialized. This commit fixes it by unsetting context.attachRef when router-outlet is destroyed, so when the router-outlet is being initialized again, it no longer sees an attachRef that it needs to mount to the view. Fixes angular#43696
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.
Thanks for the fix! The bug report/issue explanation, commit message, and test all made this an easy review.
…o avoid mounting a destroyed component
…o avoid mounting a destroyed component
@atscott Thanks for the approval! I fixed the dumb test failure and code formatting, hopefully I've followed the conventions well :) |
This PR was merged into the repository by commit 2ab2a08. |
… mounting a destroyed component (#43697) Previously, when a router-outlet is conditionally shown with an ngIf, and a sub-route was re-attached via a custom RouteReuseStrategy, router-outlet would try to mount a destroyed component into the view if the router-outlet is destroyed and re-initialized. This commit fixes it by unsetting context.attachRef when router-outlet is destroyed, so when the router-outlet is being initialized again, it no longer sees an attachRef that it needs to mount to the view. Fixes #43696 PR Close #43697
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. |
… mounting a destroyed component (angular#43697) Previously, when a router-outlet is conditionally shown with an ngIf, and a sub-route was re-attached via a custom RouteReuseStrategy, router-outlet would try to mount a destroyed component into the view if the router-outlet is destroyed and re-initialized. This commit fixes it by unsetting context.attachRef when router-outlet is destroyed, so when the router-outlet is being initialized again, it no longer sees an attachRef that it needs to mount to the view. Fixes angular#43696 PR Close angular#43697
Previously, when a
router-outlet
is conditionally shown with anngIf
, and a sub-route was re-attachedvia a custom
RouteReuseStrategy
,router-outlet
would try to mount a destroyed component into the viewif the
router-outlet
is destroyed and re-initialized.This commit fixes it by unsetting
context.attachRef
whenrouter-outlet
is destroyed, so when therouter-outlet
is being initialized again, it no longer sees anattachRef
that it needs to mount to theview.
Fixes #43696
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: #43696
What is the new behavior?
Router-outlet re-creates the component for child route if it is previously destroyed.
Does this PR introduce a breaking change?
Other information