kit
kit copied to clipboard
`[...rest]` route get's precedence over normal prerendered route in `production` mode
Describe the bug
if i have a folder structure like this
routes/
├─ api/
│ ├─ [...rest]/
│ │ ├─ +server.ts
│ ├─ random/
│ │ ├─ +server.ts <-- this is preredered
in dev mode if i try to fetch /api/random from a server load function it correctly reaches the prerendered route. However after building the file is correctly prerendered but the fetch actually reaches the rest endpoint.
Reproduction
- go here
- run
npm run dev - observe that the value displayed in the preview is a random number
- run
npm run build && npm run preview - observe that the value displayed in the preview is not a random number anymore but the response from the
[...rest]/+server.tsendpoint
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.4
@sveltejs/kit: ^2.0.0 => 2.5.24
@sveltejs/vite-plugin-svelte: ^3.0.0 => 3.1.2
svelte: ^4.0.0 => 4.2.19
vite: ^5.0.0 => 5.4.2
Severity
serious, but I can work around it
Additional Information
No response
So after a bit of digging it seems like it was made on purpose in this PR
https://github.com/sveltejs/kit/pull/7541
this doesn't seem to be problematic when accessing the page directly in the browser but it's problematic when fetching something on the server.
Ok so i tried to add back the route in the manifest and it's still failing even if i remove the conflicting rule...and that's because the actual prerendered endpoint is not available through fetch on the server...it tries to fetch /api/random but since the file is only served as a static asset it fails when using fetch without a full URL. What's worst is that with pnpm preview this problem is not visible
closing as duplicate of https://github.com/sveltejs/kit/issues/12739 see https://github.com/sveltejs/kit/issues/12739#issuecomment-2425524871 for a workaround