fix: support app-owned scroll containers - #16427
Conversation
|
Install the latest version of pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/4a4ea3aa581d7b228b9c9c614ca9bf34898178f4Open 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: 4a4ea3a 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 |
dfe5840 to
90d7f34
Compare
90d7f34 to
3ecd821
Compare
Resolve the client scroll restoration conflict by keeping the current history metadata flow and routing restored/top scroll operations through the scroll helper. Verification: pnpm install --frozen-lockfile with Node 22.23.1; focused basics cross-platform scroll-container tests passed in dev and build modes; pnpm -F @sveltejs/kit test:unit passed; pnpm -F @sveltejs/kit prepublishOnly passed; git diff --check passed.
Resolve the shallow popstate scroll restoration conflict by keeping upstream navigation snapshot capture/restore and routing restored scroll positions through the scroll-container-aware helper.\n\nVerification:\n- pnpm install --frozen-lockfile with Node v22.23.1 and pnpm v11.21.0\n- pnpm run test:cross-platform:dev -- --grep "app-owned container" (argument landed after an extra --, so the full basics cross-platform dev suite ran: 283 passed, 103 skipped)\n- pnpm run test:cross-platform:build --grep "app-owned container" (2 passed, 2 skipped)\n- pnpm -F @sveltejs/kit test:unit\n- pnpm -F @sveltejs/kit prepublishOnly\n- pnpm -F @sveltejs/kit lint\n- pnpm -F @sveltejs/kit check\n- git diff --cached --check upstream/version-3
Resolve the client popstate scroll restoration conflict by keeping upstream's current history index flow while routing restored scroll positions through the scroll-container-aware helper. Verification: npm exec --yes pnpm@12.2.1 -- pnpm install --frozen-lockfile; npm exec --yes pnpm@12.2.1 -- pnpm --dir packages/kit/test/apps/basics test:cross-platform:dev --grep "app-owned container" --project=chromium-dev; npm exec --yes pnpm@12.2.1 -- pnpm --dir packages/kit/test/apps/basics test:cross-platform:build --grep "app-owned container" --project=chromium-build; npm exec --yes pnpm@12.2.1 -- pnpm -F @sveltejs/kit test:unit; npm exec --yes pnpm@12.2.1 -- pnpm -F @sveltejs/kit prepublishOnly; npm exec --yes pnpm@12.2.1 -- pnpm -F @sveltejs/kit lint; npm exec --yes pnpm@12.2.1 -- pnpm -F @sveltejs/kit check; git diff --check. Signed-off-by: ScarabSystems <scarab.systems@yahoo.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository YAML (base), Organization UI (inherited) Review profile: QUIET Plan: Advanced Run ID: 📒 Files selected for processing (9)
🔗 Linked repositories identifiedCodeRabbit considers these linked repositories for cross-repo context during reviews:
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughSvelteKit now detects an enabled Fixed issue severity: Medium Merge Risk: ⚪ Minimal · up to Marked app-owned scroll containers now receive navigation scrolling and history restoration, while applications without the attribute retain window scrolling. Navigation reset and back-button restoration are covered, with no remaining merge-blocking risk identified. 🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
Comment |
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.