Skip to content
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

Default behaviour of trailingSlash violated #11317

Closed
mledl opened this issue Dec 14, 2023 · 4 comments · Fixed by #11357
Closed

Default behaviour of trailingSlash violated #11317

mledl opened this issue Dec 14, 2023 · 4 comments · Fixed by #11357
Labels
bug Something isn't working
Milestone

Comments

@mledl
Copy link

mledl commented Dec 14, 2023

Describe the bug

SvelteKit will remove trailing slashes from URLs by default according to the docs. This functionality is not fully provided anymore since #10763 got merged.

Using the default value for paths.base the trailing slash will be added to any sub route like /home/foo/. However, this trailing slash will be removed after reloading the page. Moreover, in case of the default value for paths.base there is no trailing slash at root.

I would expect that the default behaviour of trailingSlash page option is still valid for default paths.base even after merging #10763.

Reproduction

A minimal repro example of the issue can be found in this repo.

Logs

No response

System Info

System:
    OS: Windows 11 10.0.22621
    CPU: (16) x64 11th Gen Intel(R) Core(TM) i7-11850H @ 2.50GHz
    Memory: 16.05 GB / 31.73 GB
  Binaries:
    Node: 20.9.0 - ~\AppData\Local\Volta\tools\image\node\20.9.0\node.EXE
    Yarn: 1.22.18 - ~\AppData\Local\Volta\tools\image\yarn\1.22.18\bin\yarn.CMD
    npm: 10.1.0 - ~\AppData\Local\Volta\tools\image\npm\10.1.0\bin\npm.CMD
    pnpm: 8.4.0 - ~\AppData\Local\Volta\bin\pnpm.EXE
  Browsers:
    Edge: Chromium (120.0.2210.61)
    Internet Explorer: 11.0.22621.1
  npmPackages:
    @sveltejs/adapter-node: ^1.3.1 => 1.3.1 
    @sveltejs/kit: ^1.30.3 => 1.30.3 
    svelte: ^4.2.2 => 4.2.8 
    vite: ^4.5.0 => 4.5.1

Severity

serious, but I can work around it

Additional Information

No response

@dangelomedinag
Copy link

same $page.url.pathname
bug

@mass8326
Copy link

Ran into this in production! Was wondering why I was suddenly getting reports of 404s.

Digging into this, I noticed several more things:

  • If the page you initially visit is root ("/"), all pages are treated as trailingSlash = "always" until you refresh the page
  • If the first page you visit is a subdirectory ("/"), trailingSlash is properly respected until you refresh the page
  • Using the browser back button at any point seems to cause trailingSlash become properly respected
  • Explicitly defining trailingSlash = "never" does not change this behavior
  • This issue exists in both SvelteKit 1.30.1 and 2.0.0

Downgrading to 1.30.0 or earlier is my current solution

AyushSehrawat added a commit to rivenmedia/riven that referenced this issue Dec 16, 2023
dreulavelle pushed a commit to rivenmedia/riven that referenced this issue Dec 16, 2023
* deps: downgrade to fix sveltejs/kit#11317

* fix: fixed the api problems on frontend

* feat: improvements to +page.server.ts and moved backend api host to localhost
@eltigerchino eltigerchino added the bug Something isn't working label Dec 16, 2023
@eltigerchino eltigerchino added this to the soon milestone Dec 16, 2023
kenkunz added a commit to tradingstrategy-ai/frontend that referenced this issue Feb 22, 2024
- see SvelteKit bug: sveltejs/kit#11317
- downgrading to @sveltejs/kit@1.30.0 until we're ready for 2.x
- fixes #681
StevenClontz added a commit to pi-base/web that referenced this issue Mar 24, 2024
@th0rgall
Copy link

For people still bumping on this, the latest 1.x version at the time of writing (1.30.4) still has the code that causes the trailing slash to always be added on navigations from the root page.

This was fixed in #11388 - but it seems that fix is only available in 2.x.

So your options on ^1.30.1 are either downgrading to 1.30.0, as mentioned above here, or upgrading to 2.x.

th0rgall added a commit to WelcometoMyGarden/welcometomygarden that referenced this issue May 13, 2024
@JTCorrin
Copy link

For people still bumping on this, the latest 1.x version at the time of writing (1.30.4) still has the code that causes the trailing slash to always be added on navigations from the root page.

This was fixed in #11388 - but it seems that fix is only available in 2.x.

So your options on ^1.30.1 are either downgrading to 1.30.0, as mentioned above here, or upgrading to 2.x.

I'm on kit v2.0.0 and have this bug. This:

on:click={() => goto('/enterprise')}

gives this in the address bar of the browser:

http://localhost:5173/enterprise/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants