Skip to content

fix: avoid hashchange when resetting focus - #16985

Draft
svelte-triage-bot[bot] wants to merge 2 commits into
version-3from
triage/kit-16982-reset-focus-hashchange
Draft

fix: avoid hashchange when resetting focus#16985
svelte-triage-bot[bot] wants to merge 2 commits into
version-3from
triage/kit-16982-reset-focus-hashchange

Conversation

@svelte-triage-bot

@svelte-triage-bot svelte-triage-bot Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Fixes #16982.

Replace the fragment-navigation workaround in reset_focus with temporary programmatic focus. The target receives tabindex="-1", is focused without scrolling or a visible focus ring, and then has its original attribute restored synchronously.

This preserves the sequential focus-navigation starting point without changing the URL, mutating history state, scrolling, or leaking hashchange events to application listeners.

The existing hash-routing focus test now also verifies that focus reset dispatches no observable hashchange. Its focus assertions account for browser behavior: Firefox and Safari retain the fragment target as document.activeElement, while Chromium resets to BODY. Subsequent keyboard-navigation coverage remains intact.

@pkg-svelte-dev

pkg-svelte-dev Bot commented Aug 31, 2026

Copy link
Copy Markdown

Install the latest version of @sveltejs/kit from cb5e690:

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

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

Note

This PR is from a fork. A maintainer must approve approve each commit before it can be built and installed.

@changeset-bot

changeset-bot Bot commented Aug 31, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: cb5e690

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

@Nic-Polumeyv

Copy link
Copy Markdown
Contributor

@svelte-triage-bot On Firefox and Safari the target stays document.activeElement after focus_element. The hash-routing focus test asserts BODY there. Fold the hashchange test into that existing test

@svelte-triage-bot

Copy link
Copy Markdown
Contributor Author

Updated the existing hash-routing focus test and removed the standalone hashchange test.

  • Firefox/WebKit now expect the target (#p) to remain focused.
  • Chromium continues to expect BODY.
  • The existing test now also asserts no hashchange is dispatched.
  • Updated and pushed PR head: cb5e69040072630be54564cbe75d9aaa70466868
  • Formatting, lint, package check, and Kit unit tests passed. Playwright browsers could not launch in the sandbox due to missing system libraries.

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.

Set the sequential focus navigation starting point without location.replace

1 participant