Skip to content

chore: move scroll restoration and focus reset out of client.js - #16980

Open
Nic-Polumeyv wants to merge 2 commits into
version-3from
client-focus-module
Open

chore: move scroll restoration and focus reset out of client.js#16980
Nic-Polumeyv wants to merge 2 commits into
version-3from
client-focus-module

Conversation

@Nic-Polumeyv

@Nic-Polumeyv Nic-Polumeyv commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Scroll restoration and focus reset live in client.js but read none of its state. This moves them, unchanged, into their own module, the shape snapshots.js took in #16685.

Summary by CodeRabbit

  • Improvements
    • Improved focus restoration after navigation, including autofocus targets, hash targets, and fallback to the page body.
    • Improved scroll-position restoration when navigating backward or forward.
    • Hash navigation now more reliably identifies and scrolls to the intended page element.
    • Preserved scroll and focus state during replacement navigation.
    • Prevented unwanted automatic scrolling when navigation explicitly manages scroll position.

@pkg-svelte-dev

pkg-svelte-dev Bot commented Aug 31, 2026

Copy link
Copy Markdown

Install the latest version of @sveltejs/kit from 01f7ffb:

pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/01f7ffb627052025412c596a1ca1ebb0cf40600c

Open in pkg.svelte.dev: https://pkg.svelte.dev/repos/kit/pr/16980

@changeset-bot

changeset-bot Bot commented Aug 31, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 01f7ffb

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
Copy Markdown

@coderabbitai

coderabbitai Bot commented Sep 1, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 7d120c65-4c93-44a1-baef-62f13dfd18fb

📥 Commits

Reviewing files that changed from the base of the PR and between 2eed638 and 01f7ffb.

📒 Files selected for processing (6)
  • packages/kit/src/runtime/client/client.js
  • packages/kit/src/runtime/client/focus.js
  • packages/kit/src/runtime/client/focus.spec.js
  • packages/kit/src/runtime/client/scroll.js
  • packages/kit/src/runtime/client/scroll.spec.js
  • packages/kit/src/runtime/client/utils.js

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

Focus, hash lookup, and scroll management move from client.js into dedicated runtime modules. Client navigation imports the new helpers. Vitest coverage validates focus restoration, hash navigation, scroll restoration, and one-navigation scroll suppression.

Changes

Client navigation focus and scroll handling

Layer / File(s) Summary
Focus restoration and hash lookup
packages/kit/src/runtime/client/focus.js, packages/kit/src/runtime/client/utils.js, packages/kit/src/runtime/client/focus.spec.js
Focus restoration now handles autofocus elements, hash targets, body fallback, selection cleanup, and decoded fragment lookup. Tests cover body focus and hash scroll restoration.
Scroll restoration and suppression
packages/kit/src/runtime/client/scroll.js, packages/kit/src/runtime/client/scroll.spec.js
Scroll handling restores saved coordinates, hash targets, or the top position. A suppression flag applies to one navigation and is consumed in all reset modes.
Navigation wiring
packages/kit/src/runtime/client/client.js
client.js imports the helpers and uses them for navigation scroll control, popstate focus checks, and focus and hash handling.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Merge Risk: ⚪ Minimal · up to 01f7f

This PR reorganizes existing focus-reset and scroll-restoration behavior without changing its intended runtime behavior. The change is localized and merge-ready after normal checks, with no actionable merge-blocking risk remaining.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 76.92% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: moving scroll restoration and focus reset logic out of client.js.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch client-focus-module

Warning

Some tools did not complete. Review the errors below.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed: private package registry requires authentication. Disable ESLint in CodeRabbit settings or use public packages.


Comment @coderabbitai help to get the list of available commands.

@Nic-Polumeyv
Nic-Polumeyv marked this pull request as ready for review September 1, 2026 19:57
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.

1 participant