kit icon indicating copy to clipboard operation
kit copied to clipboard

`[...rest]` route get's precedence over normal prerendered route in `production` mode

Open paoloricciuti opened this issue 1 year ago • 2 comments

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

  1. go here
  2. run npm run dev
  3. observe that the value displayed in the preview is a random number
  4. run npm run build && npm run preview
  5. observe that the value displayed in the preview is not a random number anymore but the response from the [...rest]/+server.ts endpoint

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

paoloricciuti avatar Aug 27 '24 17:08 paoloricciuti

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.

paoloricciuti avatar Aug 27 '24 20:08 paoloricciuti

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

paoloricciuti avatar Aug 27 '24 20:08 paoloricciuti

closing as duplicate of https://github.com/sveltejs/kit/issues/12739 see https://github.com/sveltejs/kit/issues/12739#issuecomment-2425524871 for a workaround

teemingc avatar Oct 23 '24 02:10 teemingc

closing as duplicate of #12739 see #12739 (comment) for a workaround

I'll check with the workaround

paoloricciuti avatar Oct 23 '24 06:10 paoloricciuti