Skip to content

fix(router): ensure duplicate popstate/hashchange events are handled … - #37674

Closed
atscott wants to merge 1 commit into
angular:masterfrom
atscott:hashchange
Closed

atscott wants to merge 1 commit into
angular:masterfrom
atscott:hashchange

Conversation

@atscott

@atscott atscott commented Jun 22, 2020 •

Copy link
Copy Markdown
Contributor

…correctly

The current method of handling duplicate navigations caused by 'hashchange' and 'popstate' events for the same url change does not correctly handle cancelled navigations. Because scheduleNavigation is called in a setTimeout in the location change subscription, the duplicate navigations are not flushed at the same time. This means that if the initial navigation hits a guard that schedules a new navigation, the navigation for the duplicate event will not compare to the correct transition (because we inserted another navigation between the duplicates). See #16710 (comment)

Fixes #16710

Change summary:

  • Move the 'hashchange' / 'popstate' duplicate nav checks from scheduleNavigation to the location subscription. This is where the events are initially handled / detected
  • Use pairwise to compare with the previously detected 'hashchange' / 'popstate'
  • Save the current router transition id at the time of the location event to aid in comparison

@atscott atscott added area: router target: major This PR is targeted for the next major release risk: medium router: LocationStrategy router: navigation pipe events/scheduleNavigation/transitions observable labels Jun 22, 2020
@ngbot ngbot Bot modified the milestone: needsTriage Jun 22, 2020
@atscott
atscott force-pushed the hashchange branch 2 times, most recently from a0371aa to 9b09f4d Compare June 22, 2020 18:22
@atscott

atscott commented Jun 22, 2020

Copy link
Copy Markdown
Contributor Author

presubmit

@atscott

atscott commented Jun 23, 2020

Copy link
Copy Markdown
Contributor Author

global presubmit

@atscott
atscott marked this pull request as ready for review June 23, 2020 16:41

@jelbourn jelbourn 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.

Is this a do-over of the previous router change that was rolled back? If so, I would reference that original change and its revert in the commit message for reference.

Comment thread packages/router/src/router.ts Outdated
Comment thread packages/router/src/router.ts Outdated
Comment thread packages/router/src/router.ts Outdated
Comment thread packages/router/src/router.ts Outdated
Comment thread packages/router/src/router.ts Outdated
Comment thread packages/router/src/router.ts Outdated
Comment thread packages/router/src/router.ts Outdated
@pullapprove
pullapprove Bot requested a review from jelbourn June 23, 2020 18:54
@atscott

atscott commented Jun 23, 2020

Copy link
Copy Markdown
Contributor Author

Is this a do-over of the previous router change that was rolled back? If so, I would reference that original change and its revert in the commit message for reference.

This change is unrelated to the one that was rolled back.

@jelbourn jelbourn 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

@pullapprove
pullapprove Bot requested a review from jelbourn June 23, 2020 22:21

@jelbourn jelbourn 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

Reviewed-for: size-tracking

@atscott
atscott requested a review from JoostK June 25, 2020 16:57

@JoostK JoostK left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is generally a great cleanup! I left some suggestions in the code. Otherwise LGTM.

Comment thread packages/router/src/router.ts Outdated
Comment thread packages/router/src/router.ts Outdated
Comment thread packages/router/src/router.ts Outdated
Comment thread packages/router/src/router.ts Outdated
@JoostK JoostK 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 25, 2020

@IgorMinar IgorMinar 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.

Could we fix this bug without the ~800b penalty? @JoostK's suggestion looks reasonable to me. I know that it sucks, but 800b is quite a bit especially if it can be avoided.

Reviewed-for: size-tracking

@atscott
atscott force-pushed the hashchange branch 5 times, most recently from 79a7fb9 to 3e25e46 Compare June 29, 2020 16:49
@atscott

atscott commented Jun 29, 2020 •

Copy link
Copy Markdown
Contributor Author

updated presubmit
May want to do another global as well

edit: global presubmit

@atscott atscott added action: review The PR is still awaiting reviews from at least one requested reviewer and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Jun 29, 2020

@pkozlowski-opensource pkozlowski-opensource left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

Reviewed-for: size-tracking

@pkozlowski-opensource pkozlowski-opensource left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

Reviewed-for: size-tracking

@atscott
atscott force-pushed the hashchange branch 2 times, most recently from b3138ce to 52aaf45 Compare July 7, 2020 21:57
…correctly

The current method of handling duplicate navigations caused by 'hashchange' and 'popstate' events for the same url change does not correctly handle cancelled navigations. Because `scheduleNavigation` is called in a `setTimeout` in the location change subscription, the duplicate navigations are not flushed at the same time. This means that if the initial navigation hits a guard that schedules a new navigation, the navigation for the duplicate event will not compare to the correct transition (because we inserted another navigation between the duplicates). See angular#16710 (comment)

Fixes angular#16710

@alxhub alxhub left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed-for: size-tracking

@atscott
atscott removed the request for review from IgorMinar July 10, 2020 16:22
@atscott
atscott dismissed IgorMinar’s stale review July 13, 2020 21:21

Igor is OOO and can't re-review. His request has been addressed (changes no longer introduce new rxjs operators)

@atscott atscott added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Jul 13, 2020
@atscott atscott closed this in 9185c6e Jul 13, 2020
@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 Aug 13, 2020
profanis pushed a commit to profanis/angular that referenced this pull request Sep 5, 2020
…correctly (angular#37674)

The current method of handling duplicate navigations caused by 'hashchange' and 'popstate' events for the same url change does not correctly handle cancelled navigations. Because `scheduleNavigation` is called in a `setTimeout` in the location change subscription, the duplicate navigations are not flushed at the same time. This means that if the initial navigation hits a guard that schedules a new navigation, the navigation for the duplicate event will not compare to the correct transition (because we inserted another navigation between the duplicates). See angular#16710 (comment)

Fixes angular#16710

PR Close angular#37674
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 risk: medium router: LocationStrategy router: navigation pipe events/scheduleNavigation/transitions observable target: major This PR is targeted for the next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Navigation events are called twice when using HashLocationStrategy

7 participants