-
-
Notifications
You must be signed in to change notification settings - Fork 476
Open
Description
We're encountering an issue on our site where sometimes, when you click a link, it'll take you to part-way down the linked page, rather than snapping to the top. I've narrowed the "sometimes" down to "while lenis is animating scroll".
The core problem seems to be:
- It seems like setting
window.scrollTop
or callingwindow.scrollTo
do not function whilst lenis is currently animating scroll - CSR (eg Next router) will manually call some variation of
window.scrollTop(0,0)
when a routing change occurs
The sequence in practice looks something like this:
- The user scrolls some amount
- While the scroll value is still lerping (typically while it's eased to be single-digit or fractional pixels per frame), the user clicks a link
- The router updates the route, and calls its
window.scrollTo
or equivalent to snap the window to the top of the new page - Since lenis is still hijacking the scroll value, the scroll value does not snap to the top. It instead maintains its lerp to the original target scroll position (which might be greater than the new page's total
scrollHeight
), but now within the context of the new page. - The end result is the user is now scrolled partway down the new page.
This issue should be replicable on any project that uses some degree of client-side routing.
Metadata
Metadata
Assignees
Labels
No labels