From 77d401f4f8c31f3ae924d2404fed26b26567e67c Mon Sep 17 00:00:00 2001 From: Andreas Coroiu Date: Mon, 5 May 2025 09:41:05 +0200 Subject: [PATCH] [PM-19371] Blank Screen on Browser Extension Popup After Approving TDE Request on Popout (#14211) * feat: clear cached history after successfull login * Revert "feat: clear cached history after successfull login" This reverts commit 4ede7f90564135da97c754b6b90b26a483cb6b98. * feat: only restore router cache once per popup session The purpose of the router cache is to restore the last visited route during the startup of the popup, but without any explicit check the cache would try to restore the route an inifinite number of times. Because the router cache is never used to restore a route any other time it is safe to assume that we only want to run the restore function once. --- .../view-cache/popup-router-cache.service.ts | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) 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..aa0c0854eff 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 @@ -8,8 +8,9 @@ import { NavigationEnd, Router, UrlSerializer, + UrlTree, } from "@angular/router"; -import { filter, first, firstValueFrom, map, Observable, switchMap, tap } from "rxjs"; +import { filter, first, firstValueFrom, map, Observable, of, switchMap, tap } from "rxjs"; import { GlobalStateProvider } from "@bitwarden/common/platform/state"; @@ -31,6 +32,11 @@ export class PopupRouterCacheService { private hasNavigated = false; + private _hasRestoredCache = false; + get hasRestoredCache() { + return this._hasRestoredCache; + } + constructor() { // init history with existing state this.history$() @@ -107,21 +113,34 @@ export class PopupRouterCacheService { // if no history is present, fallback to vault page await this.router.navigate([""]); } + + /** + * Mark the cache as restored to prevent the router `popupRouterCacheGuard` from + * redirecting to the last visited route again this session. + */ + markCacheRestored() { + this._hasRestoredCache = true; + } } /** * Redirect to the last visited route. Should be applied to root route. **/ -export const popupRouterCacheGuard = (() => { +export const popupRouterCacheGuard = ((): Observable => { const popupHistoryService = inject(PopupRouterCacheService); const urlSerializer = inject(UrlSerializer); + if (popupHistoryService.hasRestoredCache) { + return of(true); + } + return popupHistoryService.last$().pipe( map((url: string) => { if (!url) { return true; } + popupHistoryService.markCacheRestored(); return urlSerializer.parse(url); }), );