Skip to content

Prerender cause 404 on refresh if the route params contains non-latin character #12865

@songkeys

Description

@songkeys

Describe the bug

When route param contains non-latin characters and prerender is enabled for these routes, you'll encounter 404 when hard refresh on these pages. Probably because the output are actually original character but when matching the path, it's encoded url.

SCR-20241023-mjcm SCR-20241023-mjir

Reproduction

https://github.com/songkeys/sveltekit-prerender-non-latin-route-params-repro

Logs

when visiting `/中文/`, server outputs:


SvelteKitError: Not found: /%E4%B8%AD%E6%96%87/
    at resolve2 (file:///Users/songkeys/Documents/GitHub/Songkeys/sveltekit-prerender-non-latin-route-params-repro/.svelte-kit/output/server/index.js:3714:18)
    at resolve (file:///Users/songkeys/Documents/GitHub/Songkeys/sveltekit-prerender-non-latin-route-params-repro/.svelte-kit/output/server/index.js:3547:34)
    at #options.hooks.handle (file:///Users/songkeys/Documents/GitHub/Songkeys/sveltekit-prerender-non-latin-route-params-repro/.svelte-kit/output/server/index.js:3792:71)
    at respond (file:///Users/songkeys/Documents/GitHub/Songkeys/sveltekit-prerender-non-latin-route-params-repro/.svelte-kit/output/server/index.js:3545:43)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  status: 404,
  text: 'Not Found'
}


### System Info

```Shell
System:
    OS: macOS 15.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 166.66 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.3.0 - ~/.local/state/fnm_multishells/88126_1729661413490/bin/node
    npm: 10.8.1 - ~/.local/state/fnm_multishells/88126_1729661413490/bin/npm
    pnpm: 9.12.2 - ~/.local/state/fnm_multishells/88126_1729661413490/bin/pnpm
    bun: 1.1.27 - ~/.bun/bin/bun
  Browsers:
    Chrome: 130.0.6723.59
    Safari: 18.1
  npmPackages:
    @sveltejs/adapter-auto: 3.3.0 => 3.3.0 
    @sveltejs/adapter-static: 3.0.5 => 3.0.5 
    @sveltejs/kit: 2.7.2 => 2.7.2 
    @sveltejs/vite-plugin-svelte: 4.0.0 => 4.0.0 
    svelte: 5.0.5 => 5.0.5 
    vite: 5.4.10 => 5.4.10

Severity

serious, but I can work around it

Additional Information

I can made a PR to output the encoded path as folder/filename. Or do you think there is a better way to solve this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions