Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mousemove event listener is being attached in setup_preload even if I am not using data-sveltekit-preload-[x]="hover" #12664

Open
kran6a opened this issue Sep 8, 2024 · 0 comments
Labels
feature request New feature or request

Comments

@kran6a
Copy link

kran6a commented Sep 8, 2024

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 true

While 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.
image

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 visible audible 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 for data-sveltekit-preload-[x]="hover". An alternative stategy would be attaching listeners to the elements with the data-sveltekit-preload-[x]="hover" attribute themselves. Maybe using requestIdleCallback() (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-removing mouseenter listeners if the data-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

Not important

Severity

annoyance

Additional Information

No response

@eltigerchino eltigerchino added the feature request New feature or request label Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants