mousemove
event listener is being attached in setup_preload even if I am not using data-sveltekit-preload-[x]="hover"
#12664
Labels
feature request
New feature or request
Describe the bug
It can be seen here that the listener is attached inconditionally whenever the setup_preload function is calledhttps://github.com/sveltejs/kit/blob/873ec2b4d559adb969148113fe883696cf00fa0a/packages/kit/src/runtime/client/client.js#L1500-L1512
The functions is always called unless
navigator.connection.saveData
is trueWhile the annoyance is minor, its effects are perceptible as I found it because moving the mouse on sveltekit sites induce static noise in my loudspeakers and in my wired headphones, a sound I already relate with a cry for help from the event loop as it is also induced by other common but bad JS practices that clog the event loop with very short but periodic tasks like driving (usually clunky) animations by using
setTimeout(fn, 10)
.This is a devtool recording of ~3s of moving my mouse over the website. There is no JS activity on that page other than that generated by the
mousemove
event listener.While I don't think this is the most important thing in the world to change I don't think inconditionally attaching an event listener that serves no purpose if you don't use the feature it is meant for and causes subtle but
visibleaudible side-effects on a page whose only JS is the routing/preloading code is the right thing to do, specially on a framework using Svelte, which is usually picked because it has the "you don't pay for what you don't use" philosophy of most compilers.Personally I would like a way to opt-out of this behavior by being able to specify which ways of preloading can be used within the app and defaulting to all of them.
Another option for those who want to preload on hover but do not want to attach a global
mousemove
event would be being able to choose different strategies at compile time fordata-sveltekit-preload-[x]="hover"
. An alternative stategy would be attaching listeners to the elements with thedata-sveltekit-preload-[x]="hover"
attribute themselves. Maybe usingrequestIdleCallback()
(unsupported by Safari) can be helpful with performance so that other JS is not slowned down if there are lots of element to attach to. This way you can even use self-removingmouseenter
listeners if thedata-sveltekit-preload-[x]="hover"
is on the link itself.Reproduction
https://kit.svelte.dev (happens on any svelte-kit website unless csr is disabled)
Logs
No response
System Info
Severity
annoyance
Additional Information
No response
The text was updated successfully, but these errors were encountered: