Skip to content

When using Svelte 5 release candidate with SvelteKit + a base dir + trailing slashes set to "always" relative links break #12254

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
phocks opened this issue May 23, 2024 · 1 comment · Fixed by sveltejs/svelte#13032
Labels

Comments

@phocks
Copy link

phocks commented May 23, 2024

Describe the bug

Relative links break when using "svelte": "^5.0.0-next.1", + base: '/base/path', + export const trailingSlash = "always";

eg. tries to go to /base/path/about/about etc.

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-wmkfab?file=.vscode%2Fsnippets.json

Click on links up the top

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.2.1 
    @sveltejs/kit: ^2.0.0 => 2.5.10 
    @sveltejs/vite-plugin-svelte: ^3.0.0 => 3.1.0 
    svelte: ^5.0.0-next.1 => 5.0.0-next.138 
    vite: ^5.0.3 => 5.2.11

Severity

serious, but I can work around it

Additional Information

No response

@eltigerchino
Copy link
Member

eltigerchino commented May 23, 2024

For whatever reason the anchor tag hrefs are not changing unlike Svelte 4 behaviour.
Here's a breakdown of what happens with Svelte 4:

  1. During SSR, the links are rendered relative e.g., ./about/.
  2. During hydration / CSR, the links are switched to root relative /base/path/about/.

What's happening with Svelte 5 now:

  1. During SSR, the links are rendered relative e.g., ./about/.
  2. The links are not switched to root relative /base/path/about/ and also do not change when we navigate to another page, e.g., after we navigate from the home page to the about page, the header links are still ./ and ./about/

dummdidumm added a commit to sveltejs/svelte that referenced this issue Aug 26, 2024
The reasoning in #9662 turns out to be false: While it's true that the href would resolve to the same URL on the initial page, once you're doing a client-side navigation to a URL at a different depth, the relative path would now point to the wrong location. Therefore we need to repair href hydration mismatches

fixes sveltejs/kit#12254
dummdidumm added a commit to sveltejs/svelte that referenced this issue Aug 26, 2024
The reasoning in #9662 turns out to be false: While it's true that the href would resolve to the same URL on the initial page, once you're doing a client-side navigation to a URL at a different depth, the relative path would now point to the wrong location. Therefore we need to repair href hydration mismatches

fixes sveltejs/kit#12254
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants