From 022e30675cbd8419a24fceee8921b68c1c97eb4d Mon Sep 17 00:00:00 2001 From: Mark Youssef <141061617+mark-youssef-bitwarden@users.noreply.github.com> Date: Wed, 19 Nov 2025 01:40:13 +0000 Subject: [PATCH] Fix issue where anchor scroll randomly doesn't work when the page loads --- packages/core/src/scroll.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/core/src/scroll.ts b/packages/core/src/scroll.ts index 2b30f193a..c95182642 100644 --- a/packages/core/src/scroll.ts +++ b/packages/core/src/scroll.ts @@ -35,11 +35,12 @@ export class Scroll { this.save() if (anchorHash) { - // We're using a setTimeout() here as a workaround for a bug in the React adapter where the - // rendering isn't completing fast enough, causing the anchor link to not be scrolled to. - setTimeout(() => { - const anchorElement = document.getElementById(anchorHash.slice(1)) - anchorElement ? anchorElement.scrollIntoView() : window.scrollTo(0, 0) + // Using double requestAnimationFrame to wait for the browser to complete the current render cycle + window.requestAnimationFrame(() => { + window.requestAnimationFrame(() => { + const anchorElement = document.getElementById(anchorHash.slice(1)) + anchorElement ? anchorElement.scrollIntoView() : window.scrollTo(0, 0) + }) }) } }