Skip to content

fix(upgrade): Do not trigger duplicate navigation events from Angular… #43441

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

Closed
wants to merge 5 commits into from

Conversation

atscott
Copy link
Contributor

@atscott atscott commented Sep 13, 2021

… Router

This code mimics behavior that Google Analytics has been using to
prevent duplicate navigations. They set up their own HybridRoutingService
location sync to avoid duplicate navigations that came from the Angular
router. This would happen because the Angular router would trigger a
navigation, which would then get picked up by the $locationShim, which
would trigger a $locationChangeStart, which would then be picked up by
the setUpLocationSync watcher here, which would again trigger a
navigation in the Angular Router.

All of this can be prevented by checking if the navigationId exists on
the history state object. This property is added by the Angular router
during navigations.

fixes #21610

@atscott atscott added the area: upgrade Issues related to AngularJS → Angular upgrade APIs label Sep 13, 2021
@ngbot ngbot bot added this to the Backlog milestone Sep 13, 2021
@google-cla google-cla bot added the cla: yes label Sep 13, 2021
@atscott atscott added the target: patch This PR is targeted for the next patch release label Sep 13, 2021
@atscott atscott force-pushed the duplicateUpgradeNav branch 6 times, most recently from 81c016e to ace58dd Compare October 15, 2021 18:31
@atscott atscott requested a review from gkalpak October 15, 2021 23:27
@atscott atscott marked this pull request as ready for review October 15, 2021 23:27
new $locationShimProvider(ngUpgrade, location, platformLocation, urlCodec, locationStrategy);

$locationProvider.hashPrefix(config && config.hashPrefix);
$locationProvider.html5Mode(config && !config.useHash);
Copy link
Member

@gkalpak gkalpak Oct 16, 2021

Choose a reason for hiding this comment

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

Is it intentional that HTML5 mode is turned off if config is not passed in?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't actually know. This was a straight copy-paste job from the upgrade_location_test_module file in the common package.

@atscott atscott force-pushed the duplicateUpgradeNav branch from 73828d7 to ae63fe1 Compare February 1, 2022 17:48
@atscott atscott requested a review from gkalpak February 1, 2022 18:07
@atscott
Copy link
Contributor Author

atscott commented Feb 1, 2022

@gkalpak Could you take another look at this?

Copy link
Member

@gkalpak gkalpak left a comment

Choose a reason for hiding this comment

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

One small suggestion. Otherwise lgtm 👍

@atscott atscott force-pushed the duplicateUpgradeNav branch from c18a837 to 3f8a51b Compare February 1, 2022 22:10
atscott and others added 5 commits February 1, 2022 16:58

Verified

This commit was signed with the committer’s verified signature.
dmtucker David Tucker
This updates the router upgrade tests to use less mocked behavior. The
test upgrade location module is copied from the one that's used in the
common package. This update to the tests verifies more real behavior of
the upgrade module.
… Router

This code mimics behavior that Google Analytics has been using to
prevent duplicate navigations. They set up their own `HybridRoutingService`
location sync to avoid duplicate navigations that came from the Angular
router. This would happen because the Angular router would trigger a
navigation, which would then get picked up by the `$locationShim`, which
would trigger a `$locationChangeStart`, which would then be picked up by
the `setUpLocationSync` watcher here, which would again trigger a
navigation in the Angular Router.

All of this can be prevented by checking if the `navigationId` exists on
the history state object. This property is added by the Angular router
during navigations.

fixes angular#21610
@atscott atscott force-pushed the duplicateUpgradeNav branch from 3f8a51b to 8ec981c Compare February 2, 2022 00:58
@atscott atscott added the action: merge The PR is ready for merge by the caretaker label Feb 2, 2022
@jessicajaniuk
Copy link
Contributor

This PR was merged into the repository by commit 202a1a5.

jessicajaniuk pushed a commit that referenced this pull request Feb 2, 2022
This updates the router upgrade tests to use less mocked behavior. The
test upgrade location module is copied from the one that's used in the
common package. This update to the tests verifies more real behavior of
the upgrade module.

PR Close #43441
jessicajaniuk pushed a commit that referenced this pull request Feb 2, 2022
… Router (#43441)

This code mimics behavior that Google Analytics has been using to
prevent duplicate navigations. They set up their own `HybridRoutingService`
location sync to avoid duplicate navigations that came from the Angular
router. This would happen because the Angular router would trigger a
navigation, which would then get picked up by the `$locationShim`, which
would trigger a `$locationChangeStart`, which would then be picked up by
the `setUpLocationSync` watcher here, which would again trigger a
navigation in the Angular Router.

All of this can be prevented by checking if the `navigationId` exists on
the history state object. This property is added by the Angular router
during navigations.

fixes #21610

PR Close #43441
jessicajaniuk pushed a commit that referenced this pull request Feb 2, 2022
… Router (#43441)

This code mimics behavior that Google Analytics has been using to
prevent duplicate navigations. They set up their own `HybridRoutingService`
location sync to avoid duplicate navigations that came from the Angular
router. This would happen because the Angular router would trigger a
navigation, which would then get picked up by the `$locationShim`, which
would trigger a `$locationChangeStart`, which would then be picked up by
the `setUpLocationSync` watcher here, which would again trigger a
navigation in the Angular Router.

All of this can be prevented by checking if the `navigationId` exists on
the history state object. This property is added by the Angular router
during navigations.

fixes #21610

PR Close #43441
crapStone pushed a commit to Calciumdibromid/CaBr2 that referenced this pull request Feb 15, 2022
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [@angular/animations](https://github.com/angular/angular) | dependencies | patch | [`13.2.1` -> `13.2.2`](https://renovatebot.com/diffs/npm/@angular%2fanimations/13.2.1/13.2.2) |
| [@angular/common](https://github.com/angular/angular) | dependencies | patch | [`13.2.1` -> `13.2.2`](https://renovatebot.com/diffs/npm/@angular%2fcommon/13.2.1/13.2.2) |
| [@angular/compiler](https://github.com/angular/angular) | dependencies | patch | [`13.2.1` -> `13.2.2`](https://renovatebot.com/diffs/npm/@angular%2fcompiler/13.2.1/13.2.2) |
| [@angular/compiler-cli](https://github.com/angular/angular) | devDependencies | patch | [`13.2.1` -> `13.2.2`](https://renovatebot.com/diffs/npm/@angular%2fcompiler-cli/13.2.1/13.2.2) |
| [@angular/core](https://github.com/angular/angular) | dependencies | patch | [`13.2.1` -> `13.2.2`](https://renovatebot.com/diffs/npm/@angular%2fcore/13.2.1/13.2.2) |
| [@angular/forms](https://github.com/angular/angular) | dependencies | patch | [`13.2.1` -> `13.2.2`](https://renovatebot.com/diffs/npm/@angular%2fforms/13.2.1/13.2.2) |
| [@angular/platform-browser](https://github.com/angular/angular) | dependencies | patch | [`13.2.1` -> `13.2.2`](https://renovatebot.com/diffs/npm/@angular%2fplatform-browser/13.2.1/13.2.2) |
| [@angular/platform-browser-dynamic](https://github.com/angular/angular) | dependencies | patch | [`13.2.1` -> `13.2.2`](https://renovatebot.com/diffs/npm/@angular%2fplatform-browser-dynamic/13.2.1/13.2.2) |
| [@angular/router](https://github.com/angular/angular) | dependencies | patch | [`13.2.1` -> `13.2.2`](https://renovatebot.com/diffs/npm/@angular%2frouter/13.2.1/13.2.2) |

---

### Release Notes

<details>
<summary>angular/angular</summary>

### [`v13.2.2`](https://github.com/angular/angular/blob/HEAD/CHANGELOG.md#&#8203;1322-2022-02-08)

[Compare Source](angular/angular@13.2.1...13.2.2)

##### compiler

| Commit | Type | Description |
| -- | -- | -- |
| [37af6abb49](angular/angular@37af6ab) | fix | allow banana-in-a-box bindings to end with non-null assertion ([#&#8203;37809](angular/angular#37809)) |

##### forms

| Commit | Type | Description |
| -- | -- | -- |
| [b75e90f809](angular/angular@b75e90f) | fix | incorrectly keeping track of ngModel with ngFor inside a form ([#&#8203;40459](angular/angular#40459)) |

##### http

| Commit | Type | Description |
| -- | -- | -- |
| [3fae6637e7](angular/angular@3fae663) | perf | remove IE special status handling ([#&#8203;44354](angular/angular#44354)) |

##### upgrade

| Commit | Type | Description |
| -- | -- | -- |
| [b9aab0c87b](angular/angular@b9aab0c) | fix | Do not trigger duplicate navigation events from Angular Router ([#&#8203;43441](angular/angular#43441)) |

#### Special Thanks

Alan Agius, Alan Cohen, Andrew Kushnir, Andrew Scott, Daniel Díaz, Dario Piotrowicz, Doug Parker, Jayson Acosta, Joey Perrott, JoostK, Kristiyan Kostadinov, Olivier Capuozzo, Ramzan, Shai Reznik, TANMAY SRIVASTAVA, dario-piotrowicz, iRealNirmal, jhonyeduardo, mgechev and zuckjet

<!-- CHANGELOG SPLIT MARKER -->

</details>

---

### Configuration

📅 **Schedule**: At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).

Co-authored-by: cabr2-bot <cabr2.help@gmail.com>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1160
Reviewed-by: Epsilon_02 <epsilon_02@noreply.codeberg.org>
Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
@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 Mar 5, 2022
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: upgrade Issues related to AngularJS → Angular upgrade APIs 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.

setUpLocationSync causes an duplicate navigation events
3 participants