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

Invalid output and infinite redirect loop with adapter-static and trailingSlash: "always" #1486

Closed
mvolfik opened this issue May 18, 2021 · 4 comments · Fixed by #1507
Closed
Labels
bug Something isn't working

Comments

@mvolfik
Copy link
Contributor

mvolfik commented May 18, 2021

Describe the bug
Only <meta http-equiv="refresh" content="0;url=/test/"> is written to build/test/index.html when using static adapter and always trailing slash.

Logs
None, build runs successfully, maybe just that 301 /test -> /test/ is printed during build.

To Reproduce

Use npm init svelte@next test, choose skeleton project.

Create a page src/routes/test/index.svelte with any content (<p>hello</p>). Have svelte.config.js like this:

import adapter from "@sveltejs/adapter-static";

/** @type {import('@sveltejs/kit').Config} */
const config = {
  kit: {
    // hydrate the <div id="svelte"> element in src/app.html
    target: "#svelte",
    adapter: adapter(),
    trailingSlash: "always",
  },
};

export default config;

Reproduction repo with individual setup steps in https://github.com/mvolfik/probable-disco

Expected behavior
No redirects should be needed at all. build/test/index.html should contain normal html page with <p>hello</p>.

Stacktraces
N/A

Information about your SvelteKit Installation:

Diagnostics
$ npx envinfo --system --npmPackages svelte,@sveltejs/kit,vite,@sveltejs/adapter-static --binaries --browsers

  System:
    OS: Linux 5.4 Ubuntu 20.04.2 LTS (Focal Fossa)
    CPU: (4) x64 Intel(R) Core(TM) i3-3110M CPU @ 2.40GHz
    Memory: 292.40 MB / 7.35 GB
    Container: Yes
    Shell: 3.1.0 - /usr/bin/fish
  Binaries:
    Node: 14.16.0 - ~/.local/bin/node
    Yarn: 1.22.10 - ~/.local/bin/yarn
    npm: 7.6.3 - ~/.local/bin/npm
  Browsers:
    Chromium: 90.0.4430.212
    Firefox: 88.0.1
  npmPackages:
    @sveltejs/adapter-static: next => 1.0.0-next.9 
    @sveltejs/kit: next => 1.0.0-next.107
    svelte: ^3.34.0 => 3.38.2

Severity
Bad bad. Makes adapter-static unusable with trailingSlash: "always".

Additional context
There is one similar issue #1346, but that is apparently caused by Netlify redirects, while this is only sveltekit.

@mvolfik mvolfik changed the title Invalide output and infinite redirect loop with adapter-static and trailingSlash: "always" Invalid output and infinite redirect loop with adapter-static and trailingSlash: "always" May 18, 2021
@benmccann
Copy link
Member

The value of trailingSlash shouldn't have much impact if you're using adapter-static, so I'd suggest just removing that option for now. adapter-static just outputs .html files which cannot control whether or not they are served with a trailing slash. You may be able to configure that with your hosting provider when generating static files. trailingSlash on the other hand will only be able to be utilized if you're using one of the other adapters which has a server-side component

@mvolfik
Copy link
Contributor Author

mvolfik commented May 18, 2021

I'm aware of that, though it does have some impact - SvelteKit rewrites the urls client-side upon navigation

@benmccann benmccann added the bug Something isn't working label May 18, 2021
@mvolfik
Copy link
Contributor Author

mvolfik commented May 19, 2021

Yayy, found a workaround - all my pages are interlinked, so I can rely on crawling and set config.kit.prerender.pages = ["/"], and if all links in the app end with the trailing slash, the issue doesn't happen.

pzerelles pushed a commit to pzerelles/sveltekit that referenced this issue May 20, 2021
pzerelles pushed a commit to pzerelles/sveltekit that referenced this issue May 20, 2021
pzerelles pushed a commit to pzerelles/sveltekit that referenced this issue May 20, 2021
pzerelles pushed a commit to pzerelles/sveltekit that referenced this issue May 20, 2021
pzerelles pushed a commit to pzerelles/sveltekit that referenced this issue May 21, 2021
pzerelles pushed a commit to pzerelles/sveltekit that referenced this issue May 22, 2021
@deepmouse
Copy link

deepmouse commented May 23, 2021

Probably related to this: I am getting an infinite redirect loop even without trailingSlash: "always" on, all it needs is one link on my site that uses a trailing slash, and this "redirect loop page" is generated.

pzerelles pushed a commit to pzerelles/sveltekit that referenced this issue May 26, 2021
pzerelles pushed a commit to pzerelles/sveltekit that referenced this issue May 29, 2021
Rich-Harris added a commit that referenced this issue May 29, 2021
* fix: normalize trailing slash in prerender (#1486)

* this is a camelCase-free zone, except for public APIs

Co-authored-by: Rich Harris <[email protected]>
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.

3 participants