Description
Describe the bug
On any SvelteKit site with default link settings (all links have data-sveltekit-preload-data
), hovering a link will prefetch that link's page's data and then clicking will navigate after all data has been fetched.
However, after clicking on a different link before the previous link has completed, the previous click's fetch
will continue to run. This does not free up memory and network resources for the user as they wait for their desired page to load.
Reproduction
- Go to https://www.sveltelab.dev/ftydq4t92gq0r37
- Open dev tools network inspector and filter by
Fetch/XHR
- Click on 'test' hyperlink, then immediately click on 'about' hyperlink
- Observe both requests are completed even though the 'test' page is no longer needed to load
Logs
No response
System Info
System:
OS: Linux 5.0 undefined
CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
Binaries:
Node: 18.20.3 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 10.2.3 - /usr/local/bin/npm
pnpm: 8.15.6 - /usr/local/bin/pnpm
npmPackages:
@sveltejs/adapter-auto: ^3.0.0 => 3.3.1
@sveltejs/kit: ^2.5.27 => 2.8.0
@sveltejs/vite-plugin-svelte: ^4.0.0 => 4.0.0
svelte: ^5 => 5.1.13
vite: ^5.4.4 => 5.4.10
Severity
annoyance
Additional Information
I think this can be addressed as a patch since cancelling unnecessary requests client-side will still complete their server-side load
process to completion. If any applications depend on that behaviour, it shouldn't change.
Potentially out of scope is applying a similar 'abort' behaviour to goto
and use:enhance
for forms using <form method="GET">
; though that's already solveable today in userland by providing wrappers.
Potentially related to
- Abortable PageLoad functions with AbortSignal #9637; in which case perhaps we can add control to link behaviour via a client-side hook. Regardless, I consider the problem outlined above as a bug.