Skip to content

fix(router): Pass correct component to canDeactivate checks when using two sibling router-outlets#36302

Closed
martinsik wants to merge 1 commit into
angular:masterfrom
martinsik:issue-34614
Closed

fix(router): Pass correct component to canDeactivate checks when using two sibling router-outlets#36302
martinsik wants to merge 1 commit into
angular:masterfrom
martinsik:issue-34614

Conversation

@martinsik

Copy link
Copy Markdown
Contributor

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

There's an edge case where if I use two (or more) sibling <router-outlet>s in two (or more) child routes where their parent route doesn't have a component then preactivation will trigger all canDeactivate checks with the same component because it will use wrong OutletContext.

{
 path: 'a',
 children: [
   {
     path: 'b1',
     component: BlankCmp,
     canDeactivate: ['RecordingDeactivate'],
   },
   {
     path: 'b2',
     canDeactivate: ['RecordingDeactivate'],
     component: SimpleCmp,
     outlet: 'aux',
   },
 ],
},
{
  path: 'c',
  component: BlankCmp,
},

Navigating from '/a/(b1//aux:b2)' to '/c' will call both canDeactivate guards with BlankCmp.

Replication steps are described in #34614.
Updated demo for Angular 9: https://stackblitz.com/edit/angular-named-outlet-enygni?file=app%2Fapp.component.html

What is the new behavior?

canDeactivate check is called with correct component.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

This fix will pass extra parameter to deactivateRouteAndItsChildren that is used in case a route is without a component because there's probably no other way to determine the correct OutletContext beforehand. The child routers are iterated inside deactivateRouteAndItsChildren where it can access only child OutletContexts. However, in this case the router-outlets are siblings.

@martinsik

Copy link
Copy Markdown
Contributor Author

The failing test is because the bundle size increased but it looks like the expected size was already outdated. It expects 226144 bytes but when I run the same integration test locally the same bundle has 226631. With this PR the same bundle has 226659.

@ngbot ngbot Bot added this to the needsTriage milestone Mar 30, 2020
Comment thread packages/router/src/utils/preactivation.ts Outdated
@atscott

atscott commented Mar 30, 2020

Copy link
Copy Markdown
Contributor

presubmit

@atscott

atscott commented Mar 30, 2020

Copy link
Copy Markdown
Contributor

global presubmit passed

@atscott

atscott commented Mar 30, 2020

Copy link
Copy Markdown
Contributor

As for the size failure, those need to be updated every once in a while. Lucky PR authors increase the size just enough to break the 500B threshold and have to update the _payload-limits.json :)

@atscott atscott added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews type: bug/fix labels Mar 31, 2020
@pullapprove pullapprove Bot requested a review from kara April 2, 2020 08:53
@martinsik martinsik force-pushed the issue-34614 branch 6 times, most recently from 225d5bf to f505eaa Compare April 2, 2020 10:14
@martinsik

Copy link
Copy Markdown
Contributor Author

I had to rebase to master and rerun yarn gulp format on integration.spec.ts to pass ci/circleci: lint. Although, I don't know why it made so many changes.

@atscott

atscott commented Apr 2, 2020

Copy link
Copy Markdown
Contributor

@martinsik - thanks for the update. The formatting changes are expected as clang format was just updated in c5c57f6.
Going to run a subset of presubmits as a final sanity check. This PR should get marked for merge later today.

@atscott atscott added the target: major This PR is targeted for the next major release label Apr 2, 2020

@atscott atscott left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just two nits to remove null assertion operator now that the type includes null

Comment thread packages/router/src/utils/preactivation.ts Outdated
Comment thread packages/router/src/utils/preactivation.ts Outdated
@atscott atscott 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 3, 2020
@kara kara added the action: presubmit The PR is in need of a google3 presubmit label Apr 3, 2020
@atscott

atscott commented Apr 3, 2020

Copy link
Copy Markdown
Contributor

FYI - I also just ran the size test locally at master and got 226611 for the size so the increase is only 48 between the PR and master.

@kara kara left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM for size changes (given that it's only 48)

@atscott atscott removed the action: presubmit The PR is in need of a google3 presubmit label Apr 3, 2020
@atscott atscott added action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release and removed action: presubmit The PR is in need of a google3 presubmit target: major This PR is targeted for the next major release labels Apr 9, 2020
atscott pushed a commit that referenced this pull request Apr 9, 2020
…g two or more sibling router-outlets (#36302)

fixes #34614

There's an edge case where if I use two (or more) sibling <router-outlet>s in two (or more) child routes where their parent route doesn't have a component then preactivation will trigger all canDeactivate checks with the same component because it will use wrong OutletContext.

PR Close #36302
@atscott atscott closed this in 80e6c07 Apr 9, 2020
matsko added a commit to matsko/angular that referenced this pull request Apr 17, 2020
…hen using two or more sibling router-outlets (angular#36302)"

This reverts commit 80e6c07.
@atscott

atscott commented Apr 17, 2020

Copy link
Copy Markdown
Contributor

Hi @martinsik - A failure was detected internally so this PR is being rolled back in #36697. I added a test in #36699 to cover the failing use-case.

@martinsik

Copy link
Copy Markdown
Contributor Author

@atscott Should I open another PR when that test is merged and I fix this PR?

matsko added a commit that referenced this pull request Apr 20, 2020
…hen using two or more sibling router-outlets (#36302)" (#36697)

This reverts commit 80e6c07.

PR Close #36697
matsko added a commit that referenced this pull request Apr 20, 2020
…hen using two or more sibling router-outlets (#36302)" (#36697)

This reverts commit 80e6c07.

PR Close #36697
@matsko matsko reopened this Apr 20, 2020
@matsko

matsko commented Apr 20, 2020

Copy link
Copy Markdown
Contributor

Hey @martinsik yes please if you could rebase + update this PR with the test that Andrew provided then we can reland this fix.

@matsko matsko removed the action: merge The PR is ready for merge by the caretaker label Apr 20, 2020
@martinsik

Copy link
Copy Markdown
Contributor Author

#36699

atscott added a commit to atscott/angular that referenced this pull request Apr 22, 2020
This PR adds test case to cover a failure that was detected after
merging angular#36302. That commit will be reverted and will need a new PR that
does not cause this test to fail.
matsko pushed a commit that referenced this pull request Apr 23, 2020
This PR adds test case to cover a failure that was detected after
merging #36302. That commit will be reverted and will need a new PR that
does not cause this test to fail.

PR Close #36699
matsko pushed a commit that referenced this pull request Apr 23, 2020
This PR adds test case to cover a failure that was detected after
merging #36302. That commit will be reverted and will need a new PR that
does not cause this test to fail.

PR Close #36699
@atscott atscott added the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Jun 15, 2020
@petebacondarwin

Copy link
Copy Markdown
Contributor

@martinsik - sorry that this PR got stuck. Could you rebase on master to check that it is still working after the new test was added, and to resolve the conflict? Then I think we should be able to land it.

@petebacondarwin

Copy link
Copy Markdown
Contributor

Actually this PR has been resolved via other commits.

@angular-automatic-lock-bot

Copy link
Copy Markdown

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 Jun 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews area: router cla: yes target: patch This PR is targeted for the next patch release type: bug/fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants