Skip to content

Relative URLs resolve incorrectly if clicked while another route is currently loading. #2945

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

Closed
dimfeld opened this issue Nov 29, 2021 · 3 comments
Labels
bug Something isn't working router

Comments

@dimfeld
Copy link
Contributor

dimfeld commented Nov 29, 2021

Describe the bug

When a route is loading and the load is taking a while, clicking another link resolves the href against the destination page's URL instead of the current page, causing the navigation to go to the wrong place.

Say you have a page with this link: <a href="subdir/post">Go to page</a>, and the load function takes a while to resolve. Clicking it once will correctly navigate to /subdir/post, but if you click the link again while it's loading the router will try to access /subdir/subdir/post and encounter a 404 error.

Reproduction

I first encountered this on my own personal website when on a very slow internet connection, but I have a minimal reproduction at https://github.com/dimfeld/sveltekit-routing-double-click

Steps:

  1. This is a standard Sveltekit project. Install deps, run pnpm dev, and load the site.
  2. Click the "Go to page" link. The route that this loads intentionally delays the load function by 5 seconds.
  3. While it's loading, click "Go to page" again and see that it navigates to a nonexistent route.

Logs

No response

System Info

System:
    OS: macOS 12.0.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 1.37 GB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.13.0 - /opt/homebrew/Cellar/node@16/16.13.0/bin/node
    Yarn: 1.22.17 - /opt/homebrew/Cellar/node@16/16.13.0/bin/yarn
    npm: 8.1.0 - /opt/homebrew/Cellar/node@16/16.13.0/bin/npm
  Browsers:
    Brave Browser: 96.1.32.106
    Safari: 15.1
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.3
    @sveltejs/kit: next => 1.0.0-next.201
    svelte: ^3.44.0 => 3.44.2

Severity

blocking an upgrade

Additional Information

No response

@dummdidumm
Copy link
Member

dummdidumm commented Nov 29, 2021

Somewhat related to #2870, although the current stance is to not wait on changing the URL, so the solution to this is then probably independent of #2870

@dummdidumm dummdidumm added bug Something isn't working router labels Nov 29, 2021
@dimfeld
Copy link
Contributor Author

dimfeld commented Nov 29, 2021

Didn't notice this at first, but also notably, once you reproduce the problem, you end up with three history entries:

  1. /
  2. /subdir/post
  3. /subdir/subdir/post

That feels wrong since technically the user never sees page 2. Even without this bug you would see something like this (in a scenario where the second link clicked is different from the first):

  1. /
  2. /subdir/post
  3. /subdir/otherpost

So as part of this fix I wonder if it would be more correct to use replaceState instead of pushState if navigating during loading.

@dimfeld
Copy link
Contributor Author

dimfeld commented Feb 24, 2022

Fixed by #4070

@dimfeld dimfeld closed this as completed Feb 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working router
Projects
None yet
Development

No branches or pull requests

2 participants