fix: use instant scroll behavior during navigation to fix scroll-behavior: smooth#15521
Open
DukeDeSouth wants to merge 1 commit intosveltejs:mainfrom
Open
fix: use instant scroll behavior during navigation to fix scroll-behavior: smooth#15521DukeDeSouth wants to merge 1 commit intosveltejs:mainfrom
DukeDeSouth wants to merge 1 commit intosveltejs:mainfrom
Conversation
…vior: smooth When `scroll-behavior: smooth` is set on the html element, calling `scrollTo(0, 0)` starts a smooth animation. SvelteKit reads back the scroll position immediately after via `scroll_state()`, getting a non-zero value and storing it as the page's scroll position. This causes subsequent navigations to restore the wrong scroll position. Fix by passing `behavior: 'instant'` to all navigation scroll calls so they complete synchronously, regardless of CSS scroll-behavior. The anchor link `scrollIntoView()` case is intentionally unchanged since that already respects the CSS scroll-behavior property. Fixes sveltejs#2733
|
Contributor
|
looks like there are some lint checks failing! |
Conduitry
requested changes
Mar 9, 2026
Member
Conduitry
left a comment
There was a problem hiding this comment.
This is also directly editing the changelog. It needs to create a changeset file instead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
scroll-behavior: smoothis set on the html element,scrollTo(0, 0)starts an animation instead of jumping immediately. SvelteKit reads the scroll position right after the call and stores the mid-animation value, causing subsequent navigations to land at the wrong offset.Fix: pass
behavior: 'instant'to all navigation scroll calls. ThescrollIntoView()case for anchor links is intentionally left alone.Fixes #2733
Made with Cursor