sveltejs / sveltejs/kit

Clicking on a link multiple times results in the load function being executed over and over again

Open
#6,704 3 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Describe the bug

If a link is clicked on multiple times in quick succession, the load function of the corresponding page will be executed again and again. This behavior can be undesirable, it is at best wasteful (especially apparent when fetch requests are being made in the load function), and at worst the cause of obscure bugs.

Why don't you "throttle" navigation attempts (to the same page)? Such that any subsequent attempts (while the page still hasn't finished loading) won't cause a re-execution of the load function, etc? I was expecting SvelteKit to behave this way already.

Reproduction
  • Clone https://github.com/aradalvand/sveltekit-load-running-multiple-times
  • Run npm i and npm run dev
  • Once the app is open in the browser, open the console.
  • Click on the Go to foo link at the top of the page multiple times.
  • Notice how the load function of the foo page is run each time, leading to potentially multiple requests being sent:
    image
Logs

No response

System Info
System:
    OS: Linux 5.15 Ubuntu 20.04.4 LTS (Focal Fossa)
    CPU: (4) x64 Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz
    Memory: 1.79 GB / 3.77 GB
    Container: Yes
    Shell: 5.8 - /usr/bin/zsh
  Binaries:
    Node: 16.15.1 - /usr/bin/node
    Yarn: 1.22.15 - /usr/bin/yarn
    npm: 8.11.0 - /usr/bin/npm
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.72 
    @sveltejs/kit: next => 1.0.0-next.480 
    svelte: ^3.44.0 => 3.50.1 
    vite: ^3.1.0 => 3.1.0
Severity

serious, but I can work around it

Additional Information

No response

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

Start with the linked reproduction: run npm i and npm run dev, then click the Go to foo link repeatedly while watching the console. Trace SvelteKit's navigation and page load handling to determine where repeated pending navigations are processed. Done means repeated clicks to the same page do not re-execute its load function while the initial navigation is still loading.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.