This repository demonstrates a bug in SvelteKit where the reset_focus
function crashes when the URL contains a hash fragment that is not a valid CSS selector.
SvelteKit's internal reset_focus
function calls document.querySelector(location.hash)
without validating that the hash is a valid CSS selector. This causes a SyntaxError
when the hash contains data that doesn't conform to CSS selector syntax.
Error message:
SyntaxError: '#gzip:H4sIAAAAAAAAA0sqTQcAFL+MNQMAAAA=' is not a valid selector.
This bug affects applications that use URL hash fragments for:
:
, +
, /
, etc.)npm install
npm run dev
location.hash
to a gzipped data string starting with #gzip:
use:enhance
triggers the reset_focus
functionreset_focus
attempts to call document.querySelector(location.hash)
#gzip:...
is not a valid CSS selector, querySelector
throws a SyntaxError
SvelteKit should either:
querySelector
querySelector
call in a try-catch block to handle invalid selectors gracefullyThis bug can crash the focus management in applications that legitimately use URL hash fragments for data storage, which is a common pattern in modern single-page applications.