Title: Changing the URI in the browser directly will fire guards and resolvers of the route TWICE · Issue #41782 · angular/angular · GitHub
Open Graph Title: Changing the URI in the browser directly will fire guards and resolvers of the route TWICE · Issue #41782 · angular/angular
X Title: Changing the URI in the browser directly will fire guards and resolvers of the route TWICE · Issue #41782 · angular/angular
Description: 🐞 Changing the URI in the browser directly will fire guards and resolvers of the route TWICE Affected Package The issue is caused by package @angular/router when using "useHash: true" FYI / Heads Up: This issue is reproducible in Firefox...
Open Graph Description: 🐞 Changing the URI in the browser directly will fire guards and resolvers of the route TWICE Affected Package The issue is caused by package @angular/router when using "useHash: true" FYI / Heads U...
X Description: 🐞 Changing the URI in the browser directly will fire guards and resolvers of the route TWICE Affected Package The issue is caused by package @angular/router when using "useHash: true" FYI...
Opengraph URL: https://github.com/angular/angular/issues/41782
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Changing the URI in the browser directly will fire guards and resolvers of the route TWICE","articleBody":"# 🐞 Changing the URI in the browser directly will fire guards and resolvers of the route TWICE\r\n\r\n\r\n### Affected Package\r\nThe issue is caused by package @angular/router when using \"useHash: true\"\r\n\r\n\r\n**FYI / Heads Up:** This issue is reproducible in Firefox based browsers ONLY - so it MAY be a browser bug (emitting the 'popstate' / 'hashchange' events). On the other hand - it may be working in Chromium based browsers because of sheer race-condition luck, I don't know.\r\n\r\nThis issue is reproducible with Waterfox G3.2.1 64-Bit (which is based on Firefox ESR), and the up-to-date (as of this writing) versions of regular Firefox and its Developer Edition.\r\n\r\n\r\n### Description\r\n\r\nWhen changing the URL in the browser's location bar *directly* - by\r\n- copy/pasting a link from an email into it\r\n- dragging a link from the Angular app into it\r\n- or just manually typing it\r\n\r\nthe guards and resolvers of this route will fire TWICE each.\r\n\r\n**This is especially bad when the resolver is trying to get a LOCK for a mutable resource!!**\r\nWeird things happen: While the component to update the resource is about to be created by the Angular router, the second resolve fails (because the resource is locked now) and redirects the user to some kind of resource overview page. **So the lock is now being held by US (unknowingly).**\r\n\r\n\r\n\r\n## 🔬 Minimal Reproduction\r\n[https://stackblitz.com/edit/angular-11-hashchange-bug](Stackblitz)\r\nPlease remember the issue only manifests when dragging the link into the URI bar.\r\nClicking the links (and thus opening a new window) works as expected. 👍\r\n\r\n## Demonstration\r\n\r\n\r\n### Expectation:\r\n1. the guard will fire (once!)\r\n2. on error the router redirects (once!)\r\n3. on success the routing process continues\r\n4. the resolver will fire (once!)\r\n5. on error the router redirects (once!)\r\n6. on success the lock.component is created and everything is fine\r\n\r\n### Outcome:\r\nAs you can see, the guard and resolver fire twice for a single URI change. The outcome is based on the combination of whether the guard and the resolver are succeeding or not. There are multiple variants, the worst one being the one described above at 'This is especially bad...'.\r\nBut if the resource was locked (e.g. by a third-party) already - it can result in double error boxes, etc.\r\n\r\n\r\n\r\n### Here is a browser log of a case:\r\n\r\n\r\nAfter the routing to '/redirect-to' just finished (NavigationEnd / Scroll) - just milliseconds later the router is detecting a request to route to '/lock-something' again (with navigationTrigger: \"hashchange\") and re-starts the navigation (NavigationStart) - including all guards and resolvers of course! 😶\r\n\r\n\r\n\r\n\r\n## 🌍 Your Environment\r\n\u003cpre>\u003ccode>\r\n _ _ ____ _ ___\r\n / \\ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|\r\n / △ \\ | '_ \\ / _` | | | | |/ _` | '__| | | | | | |\r\n / ___ \\| | | | (_| | |_| | | (_| | | | |___| |___ | |\r\n /_/ \\_\\_| |_|\\__, |\\__,_|_|\\__,_|_| \\____|_____|___|\r\n |___/\r\n\r\n\r\nAngular CLI: 11.2.10\r\nNode: 14.13.1\r\nOS: win32 x64\r\n\r\nAngular: 11.2.11\r\n... animations, common, compiler, compiler-cli, core, forms\r\n... platform-browser, platform-browser-dynamic, router\r\nIvy Workspace: Yes\r\n\r\nPackage Version\r\n---------------------------------------------------------\r\n@angular-devkit/architect 0.1102.10\r\n@angular-devkit/build-angular 0.1102.10\r\n@angular-devkit/core 11.2.10\r\n@angular-devkit/schematics 11.2.10\r\n@angular/cli 11.2.10\r\n@schematics/angular 11.2.10\r\n@schematics/update 0.1102.10\r\nrxjs 6.6.7\r\ntypescript 4.1.5\r\n\u003c/code>\u003c/pre>\r\n\r\n\r\nP.S.: This bug sounds a lot like it should've been squashed by this PR: https://github.com/angular/angular/pull/37674\r\nBut it still remains in Angular 11.2.11","author":{"url":"https://github.com/Sgt-Nukem","@type":"Person","name":"Sgt-Nukem"},"datePublished":"2021-04-23T11:50:18Z","url":"https://github.com/angular/angular/issues/41782"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:43a579c4-6bf7-924b-7979-5dafb9a3cd0c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E6C6:2D40DE:1D3948:250626:6B00FCA3 |
| html-safe-nonce | a8f0c525996ffbe42f557adb31171a8ccce337a0774fffe50b6d0e0efa2b9503 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNkM2OjJENDBERToxRDM5NDg6MjUwNjI2OjZCMDBGQ0EzIiwidmlzaXRvcl9pZCI6IjMxNDc0MDY3NzAzNDQ0MTg5MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | f5fe04dcf1359dd880a81e9ad393e885a6b9a68c7972431561082b7076792858 |
| hovercard-subject-tag | issue:866037313 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/41782/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a61f368d6eed1c6e0b39db78a2d5f5f845e5c64a5f80114132a260d5c69002fb/angular/angular/issues/41782 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a61f368d6eed1c6e0b39db78a2d5f5f845e5c64a5f80114132a260d5c69002fb/angular/angular/issues/41782 |
| og:image:alt | 🐞 Changing the URI in the browser directly will fire guards and resolvers of the route TWICE Affected Package The issue is caused by package @angular/router when using "useHash: true" FYI / Heads U... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Sgt-Nukem |
| hostname | github.com |
| expected-hostname | github.com |
| None | e208d86428ec00a57ade75058166297440e8128a01e5287c31a53dc042bbf187 |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7dafd017fb7809a839c443dba08622af38e63c09 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width