Skip to content

reset_focus crashes on invalid CSS selectors in URL hash #13883

Closed
@taasan

Description

@taasan

Describe the bug

I have some routes where I store application data encoded in the URL hash (not for routing). When the data is gzipped with a gzip: prefix, SvelteKit's reset_focus function crashes because it tries to call document.querySelector(location.hash) with an invalid CSS selector.

if (!app.hash && location.hash && document.querySelector(location.hash)) {

Reproduction

https://github.com/taasan/sveltekit-reset-focus-bug/

Logs

Edit: replaced firefox backtrace, which was a mile long, with the chrome stacktrace

Uncaught (in promise) SyntaxError: Failed to execute 'querySelector' on 'Document': '#gzip:H4sIAAAAAAAAA0sqTQcAFL+MNQMAAAA=' is not a valid selector.
    at reset_focus (client.js?v=2915ee31:2804:46)

System Info

System:
    OS: Linux 6.14 Fedora Linux 42 (Workstation Edition)
    CPU: (8) x64 Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz
    Memory: 19.58 GB / 31.09 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 22.16.0 - /usr/bin/node
    npm: 10.9.2 - /usr/bin/npm
  Browsers:
    Chrome: 137.0.7151.68
  npmPackages:
    @sveltejs/adapter-auto: ^6.0.0 => 6.0.1 
    @sveltejs/kit: ^2.16.0 => 2.21.4 
    @sveltejs/vite-plugin-svelte: ^5.0.0 => 5.1.0 
    svelte: ^5.0.0 => 5.33.19 
    vite: ^6.2.6 => 6.3.5

Severity

annoyance

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions