From 68bd9268ae4d141f30aaeb4707f8716bfc09914a Mon Sep 17 00:00:00 2001 From: Nick Krantz Date: Fri, 28 Mar 2025 12:09:07 -0500 Subject: [PATCH] avoid setting `hasNavigated` for the initial route --- apps/browser/src/background/main.background.ts | 4 +++- .../popup/view-cache/popup-router-cache.service.ts | 9 ++++++++- .../popup/view-cache/popup-router-cache.spec.ts | 10 ++++++++++ .../at-risk-passwords/at-risk-passwords.component.html | 7 +------ .../at-risk-passwords/at-risk-passwords.component.ts | 9 --------- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/apps/browser/src/background/main.background.ts b/apps/browser/src/background/main.background.ts index 9d06cb7f003..81a1f409c89 100644 --- a/apps/browser/src/background/main.background.ts +++ b/apps/browser/src/background/main.background.ts @@ -1618,7 +1618,9 @@ export default class MainBackground { // Set route of the popup before attempting to open it. // If the vault is locked, this won't have an effect as the auth guards will // redirect the user to the login page. - await browserAction.setPopup({ popup: "popup/index.html#/at-risk-passwords" }); + await browserAction.setPopup({ + popup: "popup/index.html#/at-risk-passwords?initialRoute=true", + }); await this.openPopup(); diff --git a/apps/browser/src/platform/popup/view-cache/popup-router-cache.service.ts b/apps/browser/src/platform/popup/view-cache/popup-router-cache.service.ts index 3215893c634..9226b2aaa90 100644 --- a/apps/browser/src/platform/popup/view-cache/popup-router-cache.service.ts +++ b/apps/browser/src/platform/popup/view-cache/popup-router-cache.service.ts @@ -44,7 +44,14 @@ export class PopupRouterCacheService { this.router.events .pipe( filter((event) => event instanceof NavigationEnd), - tap(() => { + tap((event: NavigationEnd) => { + // Add ability to navigate back to the vault if the initial route query param is set + // Without this logic, if the initial route tries to navigate back without a history, + // location.back won't navigate at all. + if (event.url.includes("initialRoute=true")) { + return; + } + // `Location.back()` can now be called successfully this.hasNavigated = true; }), diff --git a/apps/browser/src/platform/popup/view-cache/popup-router-cache.spec.ts b/apps/browser/src/platform/popup/view-cache/popup-router-cache.spec.ts index 465a6e6c69c..39640a5c8aa 100644 --- a/apps/browser/src/platform/popup/view-cache/popup-router-cache.spec.ts +++ b/apps/browser/src/platform/popup/view-cache/popup-router-cache.spec.ts @@ -120,4 +120,14 @@ describe("Popup router cache guard", () => { expect(await firstValueFrom(service.history$())).toEqual(["/a"]); }); + + it("does not set `hasNavigated` flag when the `initialRoute` query param is set", async () => { + expect(service["hasNavigated"]).toBe(false); + + await router.navigate(["a"], { queryParams: { initialRoute: true } }); + + await flushPromises(); + + expect(service["hasNavigated"]).toBe(false); + }); }); diff --git a/apps/browser/src/vault/popup/components/at-risk-passwords/at-risk-passwords.component.html b/apps/browser/src/vault/popup/components/at-risk-passwords/at-risk-passwords.component.html index 87629ce5700..cd93401c861 100644 --- a/apps/browser/src/vault/popup/components/at-risk-passwords/at-risk-passwords.component.html +++ b/apps/browser/src/vault/popup/components/at-risk-passwords/at-risk-passwords.component.html @@ -1,10 +1,5 @@ - + diff --git a/apps/browser/src/vault/popup/components/at-risk-passwords/at-risk-passwords.component.ts b/apps/browser/src/vault/popup/components/at-risk-passwords/at-risk-passwords.component.ts index 66a14769a64..dd3d53fed7d 100644 --- a/apps/browser/src/vault/popup/components/at-risk-passwords/at-risk-passwords.component.ts +++ b/apps/browser/src/vault/popup/components/at-risk-passwords/at-risk-passwords.component.ts @@ -223,13 +223,4 @@ export class AtRiskPasswordsComponent implements OnInit { this.launchingCipher.set(null); } }; - - /** - * This page can be the first page the user sees when the extension launches, - * which can conflict with the `PopupRouterCacheService`. This replaces the - * built-in back button behavior so the user always navigates to the vault. - */ - protected async navigateToVault() { - await this.router.navigate(["/tabs/vault"]); - } }