fix: support app-owned scroll containers#16427
Open
scarab-systems wants to merge 1 commit into
Open
Conversation
|
Install the latest version of pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/3ecd821e85598cdfb37d71b80c6e651995b38758Open in Note This PR is from a fork. A maintainer must approve approve each commit before it can be built and installed. |
🦋 Changeset detectedLatest commit: 3ecd821 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
scarab-systems
force-pushed
the
scarab-systems/sveltekit-2733-scroll-container
branch
from
July 24, 2026 21:14
dfe5840 to
90d7f34
Compare
scarab-systems
force-pushed
the
scarab-systems/sveltekit-2733-scroll-container
branch
from
July 24, 2026 21:18
90d7f34 to
3ecd821
Compare
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.
closes #2733
This takes a focused pass at the scroll-container part of this issue. I used Scarab boundary diagnostics to look for where the reported behavior crossed from app layout into router-owned scroll management, then used that as the repair boundary.
The boundary I found was that SvelteKit's router captures/restores scroll state from the window and applies navigation scrolls with
window.scrollTo(...), while a common app-shell layout keeps the document fixed and scrolls an inner element instead. In that layout, SvelteKit can successfully navigate but still preserve the old visual scroll position because it is reading and writing the wrong scroll owner.This PR adds an explicit
data-sveltekit-scroll-containeropt-in for that case. When present, SvelteKit reads/restores that element'sscrollLeft/scrollTop; otherwise the existing window behavior is unchanged.I looked through the previous attempts/discussion before shaping this:
scroll-behavior: smoothworkaround from fix: iOSscroll-behavior: smoothbreaks navigation scrolling #8724/fix: use instant scroll behavior during navigation to fix scroll-behavior: smooth #15521. It leaves the existing window/smooth-scroll behavior alone and addresses the maintainer feedback that the main unresolved issue is finding the correct container to scroll.The regression fixture uses a fixed app shell with an inner
<main data-sveltekit-scroll-container>. It verifies both forward navigation to the top and back-button scroll restoration. It also includes adata-sveltekit-scroll-container="false"wrapper so the selected scroll owner is explicit and test-protected.Happy to adjust the attribute name, docs location, or shape of the opt-in if maintainers prefer a different public API.
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChecked in an isolated repo workspace:
pnpm run formatpnpm -F @sveltejs/kit prepublishOnlyNODE_OPTIONS=--max-old-space-size=4096 pnpm run lintNODE_OPTIONS=--max-old-space-size=4096 pnpm run checkNODE_OPTIONS=--max-old-space-size=4096 pnpm -F @sveltejs/kit test:unitpnpm --dir packages/kit/test/apps/basics test:cross-platform:dev --grep "app-owned container" --project=chromium-devpnpm --dir packages/kit/test/apps/basics test:cross-platform:dev --grep "Scrolling" --project=chromium-devpnpm --dir packages/kit/test/apps/basics test:cross-platform:build --grep "app-owned container" --project=chromium-buildChangesets
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfix:,feat:, orchore:.Edits
Disclosure: This PR was prepared with AI assistance under human direction and review.