Repository navigation
Conversation
… `Location` subscription With the merging of angular#41730, our tests now more closely emulate real browser behavior. This means that we can make changes to the `Router` which depend on actual browser behavior rather than incorrectly mocked test behavior. This change updates the logic in the `Router` to only trigger navigations on `popstate` events. Since our `SpyLocation` now triggers the `popstate` event correctly on `simulateHashChange`, `back`, `forward`, and `simulatePopState`, we are able to rely on this being true for all of these navigations in tests when using `SpyLocation` (the default for `RouterTestingModule`). In addition, this behavior relies on documented browser behavior: The `popstate` event happens due to browser transitions as a result of user triggered "back" button or otherwise. https://developer.mozilla.org/en-US/docs/Web/API/Window/popstate_event#when_popstate_is_sent In addition, this change chooses `popstate` over `hashchange` because it is the event that is already being used for navigations since the documented behavior of browsers is that `popstate` happens before `hashchange`. fixes angular#41782
atscott
marked this pull request as ready for review
September 3, 2021 16:46
AndrewKushnir
approved these changes
Sep 8, 2021
AndrewKushnir
left a comment
Contributor
There was a problem hiding this comment.
LGTM (just one tiny comment to see if we can add more docs) 👍
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With the merging of #41730, our tests now more closely emulate real
browser behavior. This means that we can make changes to the
Routerwhich dependon actual browser behavior rather than incorrectly mocked test behavior.
This change updates the logic in the
Routerto only triggernavigations on
popstateevents. Since ourSpyLocationnow triggersthe
popstateevent correctly onsimulateHashChange,back,forward, andsimulatePopState, we are able to rely on this beingtrue for all of these navigations in tests when using
SpyLocation(thedefault for
RouterTestingModule).In addition, this behavior relies on documented browser behavior: The
popstateevent happens due to browser transitions as a result of usertriggered "back" button or otherwise.
https://developer.mozilla.org/en-US/docs/Web/API/Window/popstate_event#when_popstate_is_sent
In addition, this change chooses
popstateoverhashchangebecause itis the event that is already being used for navigations since the
documented behavior of browsers is that
popstatehappens beforehashchange.fixes #41782
reviewer note: this is marked as
majorbecause #41730 was merged as a breaking change to themajorbranch.green global presubmit train