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

trailingSlash option not working correctly or consistently in SvelteKit 2 #11382

Closed
CaptainCodeman opened this issue Dec 18, 2023 · 1 comment · Fixed by #11388
Closed

trailingSlash option not working correctly or consistently in SvelteKit 2 #11382

CaptainCodeman opened this issue Dec 18, 2023 · 1 comment · Fixed by #11388
Labels
bug Something isn't working paths.base bugs relating to `config.kit.paths.base`

Comments

@CaptainCodeman
Copy link
Contributor

Describe the bug

A static site using +layout.ts

export const prerender = true
export const trailingSlash = 'never'

Navigating to the website includes a trailing '/' (due to gh pages 301 redirect):
https://captaincodeman.github.io/svelte-headlessui/

Inspecting a link shows the correct URL in the HTML without any trailing slash (also when viewing page source):
Screenshot 2023-12-18 at 7 47 39 AM

But clicking the link takes you to the URL with the trailing slash added:
https://captaincodeman.github.io/svelte-headlessui/combobox/

This causes relative paths to be incorrect (in this case, an iframe src) resulting in a 404:
Screenshot 2023-12-18 at 7 52 21 AM

Have tried every combination of paths.relative and trailingSlash, all fail in some way.

Removing the trailing slash manually (on a non root page) fixes the rendering and also subsequent navigation.

Reproduction

Live site: https://captaincodeman.github.io/svelte-headlessui/combobox/

Source: https://github.com/CaptainCodeman/svelte-headlessui

Logs

No response

System Info

System:
    OS: macOS 14.2
    CPU: (6) x64 Intel(R) Core(TM) i5-8500B CPU @ 3.00GHz
    Memory: 66.75 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.6.1 - ~/Library/pnpm/node
    npm: 9.8.1 - ~/Library/pnpm/npm
    pnpm: 8.12.1 - ~/Library/pnpm/pnpm
    bun: 1.0.0 - ~/.bun/bin/bun
  Browsers:
    Brave Browser: 106.1.44.112
    Chrome: 120.0.6099.109
    Chrome Canary: 122.0.6192.0
    Safari: 17.2
    Safari Technology Preview: 17.4
  npmPackages:
    @sveltejs/adapter-static: ^3.0.0 => 2.0.3 
    @sveltejs/kit: ^2.0.1 => 1.26.0 
    svelte: ^4.2.8 => 4.2.2 
    vite: ^5.0.10 => 4.5.0

Severity

blocking an upgrade

Additional Information

Most routes use a [...slug] route.

@CaptainCodeman
Copy link
Contributor Author

Stepping through the client side routing code, on the home page it ends up setting the trailing slash to 'always' at runtime and it then stays as that, whatever the actual root layout setting was.

Adding the trailingSlash option to all child routes make them apply correctly and the routes then work. So the way the root option is overridden to become 'always' appears to be the issue.

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

Successfully merging a pull request may close this issue.

2 participants