diff --git a/apps/browser/src/vault/popup/services/vault-popup-scroll-position.service.spec.ts b/apps/browser/src/vault/popup/services/vault-popup-scroll-position.service.spec.ts index 28ab8076dda..af21f664f2d 100644 --- a/apps/browser/src/vault/popup/services/vault-popup-scroll-position.service.spec.ts +++ b/apps/browser/src/vault/popup/services/vault-popup-scroll-position.service.spec.ts @@ -108,27 +108,6 @@ describe("VaultPopupScrollPositionService", () => { }); expect((scrollElement as any).scrollTop).toBe(500); })); - - it("forces scroll to top on next start when requested", fakeAsync(() => { - service["scrollPosition"] = 500; - - service.start(scrollElement); - - tick(); - expect((scrollElement as any).scrollTo).toHaveBeenCalledWith({ - behavior: "instant", - top: 0, - }); - expect((scrollElement as any).scrollTop).toBe(0); - - // A follow-up scroll is scheduled to defeat Firefox scroll restoration. - ((scrollElement as any).scrollTo as jest.Mock).mockClear(); - tick(300); - expect((scrollElement as any).scrollTo).toHaveBeenCalledWith({ - behavior: "instant", - top: 0, - }); - })); }); describe("scroll listener", () => { diff --git a/apps/browser/src/vault/popup/services/vault-popup-scroll-position.service.ts b/apps/browser/src/vault/popup/services/vault-popup-scroll-position.service.ts index 54406ed59da..e0779fc7b4a 100644 --- a/apps/browser/src/vault/popup/services/vault-popup-scroll-position.service.ts +++ b/apps/browser/src/vault/popup/services/vault-popup-scroll-position.service.ts @@ -31,9 +31,12 @@ export class VaultPopupScrollPositionService { /** Scrolls the user to the stored scroll position and starts tracking scroll of the page. */ start(scrollElement: HTMLElement) { - setTimeout(() => { - scrollElement.scrollTo({ top: this.scrollPosition!, behavior: "instant" }); - }); + if (this.hasScrollPosition()) { + // Use `setTimeout` to scroll after rendering is complete + setTimeout(() => { + scrollElement.scrollTo({ top: this.scrollPosition, behavior: "instant" }); + }); + } this.scrollSubscription?.unsubscribe();