Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions packages/core/src/scroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
}
}
Expand Down