1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-11 05:43:41 +00:00

avoid setting hasNavigated for the initial route

This commit is contained in:
Nick Krantz
2025-03-28 12:09:07 -05:00
parent bb6bf81f00
commit 68bd9268ae
5 changed files with 22 additions and 17 deletions

View File

@@ -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();

View File

@@ -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;
}),

View File

@@ -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);
});
});

View File

@@ -1,10 +1,5 @@
<popup-page [loading]="loading$ | async">
<popup-header
slot="header"
[pageTitle]="'atRiskPasswords' | i18n"
showBackButton
[backAction]="navigateToVault.bind(this)"
>
<popup-header slot="header" [pageTitle]="'atRiskPasswords' | i18n" showBackButton>
<ng-container slot="end">
<app-pop-out></app-pop-out>
</ng-container>

View File

@@ -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"]);
}
}