1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-14 07:23:45 +00:00

fix scroll positon after delete

This commit is contained in:
jaasen-livefront
2026-02-03 17:11:31 -08:00
parent 27baba9b06
commit d1d104ad69
3 changed files with 5 additions and 34 deletions

View File

@@ -265,9 +265,9 @@ export class ViewV2Component {
return false;
}
// Navigate directly to vault instead of back() to avoid Firefox bfcache scroll restoration
this.popupScrollPositionService.stop(true);
this.popupScrollPositionService.forceTopOnNextVaultStart();
await this.popupRouterCacheService.back();
await this.router.navigate(["/tabs/vault"]);
this.toastService.showToast({
variant: "success",

View File

@@ -111,7 +111,6 @@ describe("VaultPopupScrollPositionService", () => {
it("forces scroll to top on next start when requested", fakeAsync(() => {
service["scrollPosition"] = 500;
service.forceTopOnNextVaultStart();
service.start(scrollElement);

View File

@@ -18,9 +18,6 @@ export class VaultPopupScrollPositionService {
/** Subscription associated with the virtual scroll element. */
private scrollSubscription: Subscription | null = null;
/** When true, the next call to `start()` will force scroll position back to the top. */
private forceTopOnNextStart = false;
constructor() {
this.router.events
.pipe(
@@ -34,26 +31,9 @@ export class VaultPopupScrollPositionService {
/** Scrolls the user to the stored scroll position and starts tracking scroll of the page. */
start(scrollElement: HTMLElement) {
// Use `setTimeout` to scroll after rendering is complete.
// Firefox can sometimes restore scroll position on history navigation (back/forward)
// after our initial scroll call. When we explicitly want to reset to the top (e.g. after
// deleting an item), we schedule an extra follow-up scroll to ensure the final position is 0.
if (this.forceTopOnNextStart) {
this.forceTopOnNextStart = false;
this.scrollPosition = 0;
// try to set scroll to top immediately
setTimeout(() => {
scrollElement.scrollTo({ top: 0, behavior: "instant" });
}, 0);
// wait for FF to possibly restore scroll position after UI settles, then enforce top=0
setTimeout(() => {
scrollElement.scrollTo({ top: 0, behavior: "instant" });
}, 250);
} else if (this.hasScrollPosition()) {
setTimeout(() => {
scrollElement.scrollTo({ top: this.scrollPosition!, behavior: "instant" });
});
}
setTimeout(() => {
scrollElement.scrollTo({ top: this.scrollPosition!, behavior: "instant" });
});
this.scrollSubscription?.unsubscribe();
@@ -83,14 +63,6 @@ export class VaultPopupScrollPositionService {
return this.scrollPosition !== null;
}
/**
* Forces the next vault list render to start at scroll position 0.
* Useful for flows where we don't want browser back/forward scroll restoration (e.g. after delete).
*/
forceTopOnNextVaultStart() {
this.forceTopOnNextStart = true;
}
/** Conditionally resets the scroll listeners based on the ending path of the navigation */
private resetListenerForNavigation(event: NavigationEnd): void {
// The vault page is the target of the scroll listener, return early