Wrong error handling when using rest params and param matchers consecutively
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 20.8k
- Forks
- 2.3k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 156
Description
Describe the bug
Hi everyone,
Honestly I'm not quite sure where to start, I've hit a use case where the routing isn't quite working how I think it should be working, so I would very tentatively call it a bug.
Scenario
The page I'm concerned about is at the path event/:id and below.
- There can be any number of previous path segments before hand, thus I added a
[...path]before. - The "event" string could actually be multiple different strings,
event | project | job, so i have a param matcher for that - The
idbeing a slug is quite self explanatory - Then the main page of the
eventis actually underevent/:id/overview, so I've got that redirect inevent/[id]/+page.ts - Now if a path like
event/:id/invalidgets hit, I want to display an error inside of the event page, soevent/[id]/+error.svelte, thus theevent/:id/[...catchall]/+page.ts.
Entire Structure:
Expected Behaviour
Sveltekit hits the event/:id/[...catchall]/+page.ts, throws the 404 that gets caught in the event/[id]/+error.svelte.
Actual Behaviour
The entire route gets 404-ed and the generic 404 message gets displayed.
Now it does actually work as expected, if either one of these modifications is made:
/[id]/ -> /1/: If theidis not a slug, but a literal1(for example to match the hrefs), it does work correctly (the red outline around the 404 message shows that it's the correct+error.svelte/[event=eventSlug]/ -> /event/: If theeventsegment does not have a param matcher, it also works correctly
Addendum
I also think I experienced more weirdness, where the routing wouldn't behave the same when built on windows compare to linux, where on my local windows machine it would work as expected and on linux rest parameters would get hit instead of other explicit paths on the same level, but I haven't really been able to reproduce that so far.
Reproduction
https://stackblitz.com/edit/sveltejs-kit-template-default-win19u?file=src%2Fparams%2FidParam.ts
Logs
No response
System Info
Stackblitz:
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.3.1
@sveltejs/kit: ^2.9.0 => 2.9.0
@sveltejs/vite-plugin-svelte: ^5.0.0 => 5.0.1
svelte: ^5.0.0 => 5.5.2
vite: ^6.0.0 => 6.0.2
Local Machine:
System:
OS: Windows 11 10.0.26120
CPU: (16) x64 AMD Ryzen 7 5800X3D 8-Core Processor
Memory: 11.15 GB / 31.91 GB
Binaries:
Node: 20.9.0 - C:\Program Files\nodejs\node.EXE
npm: 10.2.5 - C:\Program Files\nodejs\npm.CMD
pnpm: 8.10.2 - ~\AppData\Local\pnpm\pnpm.EXE
bun: 1.1.38 - ~\.bun\bin\bun.EXE
Browsers:
Edge: Chromium (131.0.2903.36)
Internet Explorer: 11.0.26100.1
npmPackages:
@sveltejs/adapter-auto: ^3.0.0 => 3.3.1
@sveltejs/kit: ^2.9.0 => 2.9.0
@sveltejs/vite-plugin-svelte: ^5.0.0 => 5.0.1
svelte: ^5.0.0 => 5.5.2
vite: ^6.0.0 => 6.0.2
Severity
blocking all usage of SvelteKit
Additional Information
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked StackBlitz reproduction and inspect src/params/idParam.ts alongside the route structure described in the issue. Reproduce the combination of a rest parameter, a param matcher, and the catch-all route, then trace why the nested +error.svelte page is not selected. Done means the documented invalid route reaches the event-specific error page consistently.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100