Skip to content

Conversation

adrianliaw
Copy link
Contributor

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 Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

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?

  • Yes
  • No

Other information

… 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
@pullapprove pullapprove bot requested a review from atscott October 4, 2021 08:43
@google-cla google-cla bot added the cla: yes label Oct 4, 2021
@ngbot ngbot bot added this to the Backlog milestone Oct 4, 2021
@atscott atscott added the target: patch This PR is targeted for the next patch release label Oct 4, 2021
Copy link
Contributor

@atscott atscott left a 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.

@atscott atscott added the action: presubmit The PR is in need of a google3 presubmit label Oct 4, 2021
@adrianliaw
Copy link
Contributor Author

@atscott Thanks for the approval! I fixed the dumb test failure and code formatting, hopefully I've followed the conventions well :)

@atscott atscott added action: merge The PR is ready for merge by the caretaker and removed action: presubmit The PR is in need of a google3 presubmit labels Oct 5, 2021
@dylhunn
Copy link
Contributor

dylhunn commented Oct 5, 2021

This PR was merged into the repository by commit 2ab2a08.

dylhunn pushed a commit that referenced this pull request Oct 5, 2021
… 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
@dylhunn dylhunn closed this in 2ab2a08 Oct 5, 2021
@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 Nov 5, 2021
Serginho pushed a commit to TuLotero/angular that referenced this pull request Jan 20, 2022
… 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
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: router cla: yes target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Router-outlet mounts destroyed component if the component was re-attached via custom RouteReuseStrategy and router-outlet is destroyed and re-created
3 participants