Skip to content

fix: respect scroll-margin when navigating to a url-supplied anchor#15246

Merged
Rich-Harris merged 15 commits intosveltejs:mainfrom
PatrickG:issue-15192
Feb 13, 2026
Merged

fix: respect scroll-margin when navigating to a url-supplied anchor#15246
Rich-Harris merged 15 commits intosveltejs:mainfrom
PatrickG:issue-15192

Conversation

@PatrickG
Copy link
Member

@PatrickG PatrickG commented Feb 3, 2026

fixes #15192

When we navigate to a url-supplied anchor, we don't need to scroll to it in reset_focus. The location.replace() call already scrolls to the anchor and respects scroll-margin-top/scroll-padding-top & smooth scrolling.
The previous solution (implemented in #14569) used getBoundingClientRect() which does not take scroll-margin-top/scroll-padding-top into account.


Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

@changeset-bot
Copy link

changeset-bot bot commented Feb 3, 2026

🦋 Changeset detected

Latest commit: 6fb92b7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

Not sure what this means? Click here to learn what changesets are.

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

@svelte-docs-bot
Copy link

Copy link
Member

@teemingc teemingc left a comment

Choose a reason for hiding this comment

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

LGTM! I made some suggestions to add comments that are pretty much what you've explained in the PR description. Although, I have a bit of uneasiness because I can't remember if all browsers (on different platforms) have the same behaviour for location.replace although I tested this many years ago. Also, sorry this took so long to get around to 😓

Maybe @Rich-Harris would want to take a second look to see if this would regress #14569 ? That one doesn't have a test and the PR description mentions it's difficult to reproduce (but it makes sense)

PatrickG and others added 2 commits February 11, 2026 16:29
Co-authored-by: Tee Ming <chewteeming01@gmail.com>
Co-authored-by: Tee Ming <chewteeming01@gmail.com>
@PatrickG
Copy link
Member Author

PatrickG commented Feb 11, 2026

IMO this should also fix sveltejs/svelte.dev#1693 but it still seems to be broken in the preview svelte-docs-bot posted.

Preview: https://svelte-dev-git-preview-kit-15246-svelte.vercel.app/

Wonder why.

But it fixes #15192 - see https://www.sveltelab.dev/qk496863qm9cro3

Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
@teemingc
Copy link
Member

teemingc commented Feb 11, 2026

IMO this should also fix sveltejs/svelte.dev#1693 but it still seems to be broken in the preview svelte-docs-bot posted.

Preview: svelte-dev-git-preview-kit-15246-svelte.vercel.app

Does the Kit version need to be updated manually? I think only the docs are updated from the bot

But it fixes #15192 - see sveltelab.dev/qk496863qm9cro3

This one's really strange because I couldn't reproduce it from the issue or from the sveltelab link. But I can reproduce it from the test scenario in this PR

@PatrickG
Copy link
Member Author

Does the Kit version need to be updated manually? I think only the docs are updated from the bot

Ahh, makes sense. Maybe it shouldn't create a preview when the PR does not touch any docs then? :D

This one's really strange because I couldn't reproduce it from the issue or from the sveltelab link. But I can reproduce it from the test scenario in this PR

The sveltelab link I posted uses the fix from this PR.

@teemingc
Copy link
Member

Does the Kit version need to be updated manually? I think only the docs are updated from the bot

Ahh, makes sense. Maybe it shouldn't create a preview when the PR does not touch any docs then? :D

You'll have to ask @elliott-with-the-longest-name-on-github if that's possible 😆

@Rich-Harris Rich-Harris merged commit 9f0292f into sveltejs:main Feb 13, 2026
24 checks passed
@Rich-Harris
Copy link
Member

very excited to apply this fix to svelte.dev 🎉

@github-actions github-actions bot mentioned this pull request Feb 13, 2026
Copilot AI pushed a commit to Stadly/kit that referenced this pull request Mar 6, 2026
…veltejs#15246)

* test

* fix

* changeset

* revert import sorting

* Update packages/kit/src/runtime/client/client.js

Co-authored-by: Tee Ming <chewteeming01@gmail.com>

* Update packages/kit/src/runtime/client/client.js

Co-authored-by: Tee Ming <chewteeming01@gmail.com>

* Update packages/kit/src/runtime/client/client.js

Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>

---------

Co-authored-by: Tee Ming <chewteeming01@gmail.com>
Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants