mirror of
https://github.com/bitwarden/browser
synced 2025-12-13 23:03:32 +00:00
[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 4ede7f9056.
* 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.
This commit is contained in:
@@ -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<true | UrlTree> => {
|
||||
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);
|
||||
}),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user