sveltejs / sveltejs/kit

Abort client-side navigation fetches when another link is clicked

Open
#12,981 2 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

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
  1. Go to https://www.sveltelab.dev/ftydq4t92gq0r37
  2. Open dev tools network inspector and filter by Fetch/XHR
  3. Click on 'test' hyperlink, then immediately click on 'about' hyperlink
  4. 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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue at the linked SvelteLab example with the browser network inspector filtered to Fetch/XHR, then trace the client-side navigation and link-prefetch handling. Done means that clicking a second link aborts the earlier navigation fetch so only the requested page's fetch completes.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.