-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed as duplicate of#13883
Description
Describe the bug
kit/packages/kit/src/runtime/client/client.js
Line 2804 in 5594597
| if (!app.hash && location.hash && document.querySelector(location.hash)) { |
The call to
document.querySelector on this line throws when the hash is not found on the page. This is a regression introduced in 2.21.3 by #10856.
Reproduction
Visit any website with 2.21.3+, append an incorrect hash at the end of the URL, and refresh
Logs
Uncaught (in promise) SyntaxError: Failed to execute 'querySelector' on 'Document': '#somehash' is not a valid selector.
at reset_focus (client.js?v=3f49ea1a:2804:46)
at navigate (client.js?v=3f49ea1a:1630:3)
at async HTMLHtmlElement.<anonymous> (client.js?v=3f49ea1a:2381:3)System Info
System:
OS: macOS 15.5
CPU: (10) arm64 Apple M1 Pro
Memory: 155.81 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 24.2.0 - /opt/homebrew/bin/node
npm: 11.4.1 - /opt/homebrew/bin/npm
pnpm: 10.12.1 - /opt/homebrew/bin/pnpm
bun: 1.2.15 - ~/.bun/bin/bun
Browsers:
Chrome: 137.0.7151.104
Safari: 18.5
Safari Technology Preview: 18.4
npmPackages:
@sveltejs/adapter-vercel: ^5.7.2 => 5.7.2
@sveltejs/kit: ^2.21.4 => 2.21.4
@sveltejs/vite-plugin-svelte: ^5.1.0 => 5.1.0
svelte: ^5.33.19 => 5.33.19
vite: ^6.3.5 => 6.3.5Severity
serious, but I can work around it
Additional Information
As try-catching the call to querySelector is likely the easy fix, I'd love if you could make it so that the hash "DOM search" is run once again when the page is fully ready if the hash is not instantly found where this snippet is currently called.
{#await Promise.resolve() then _}
<span id="myhash">This text being rendered is what I consider a "ready" page</span>
{/await}Metadata
Metadata
Assignees
Labels
No labels