Skip to content
Discussion options

You must be logged in to vote

SvelteKit's scroll restoration calls native positional scrollTo(x, y) with no behavior arg (the scrollTo(scroll.x, scroll.y) lines in client.js), so it just inherits whatever scroll-behavior your CSS sets. With html { scroll-behavior: smooth } global, every back/forward restore animates, and there's no built-in flag to make it instant per navigation.

So your onNavigate trick (flipping scrollBehavior to auto) is basically the intended fix. Cleaner alternative if you can: don't put smooth on html. Scope it to the specific containers or anchor links that need it, and restoration stays instant with zero JS.

fwiw behavior:'auto' wouldn't help even if you could pass it, since auto inherits your…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by teemingc
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants