Skip to content

fix: use instant scroll behavior during navigation to fix scroll-behavior: smooth#15521

Open
DukeDeSouth wants to merge 1 commit intosveltejs:mainfrom
DukeDeSouth:fix/2733-scroll-behavior-instant
Open

fix: use instant scroll behavior during navigation to fix scroll-behavior: smooth#15521
DukeDeSouth wants to merge 1 commit intosveltejs:mainfrom
DukeDeSouth:fix/2733-scroll-behavior-instant

Conversation

@DukeDeSouth
Copy link

When scroll-behavior: smooth is 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. The scrollIntoView() case for anchor links is intentionally left alone.

Fixes #2733

Made with Cursor

…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
@changeset-bot
Copy link

changeset-bot bot commented Mar 9, 2026

⚠️ No Changeset found

Latest commit: bc719ad

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@svelte-docs-bot
Copy link

@elliott-with-the-longest-name-on-github
Copy link
Contributor

looks like there are some lint checks failing!

Copy link
Member

@Conduitry Conduitry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also directly editing the changelog. It needs to create a changeset file instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Page scroll position not reset to top on navigation (regression)

3 participants