Skip to content

Abort client-side navigation fetches when another link is clicked #12981

Open
@theetrain

Description

@theetrain

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions