kit icon indicating copy to clipboard operation
kit copied to clipboard

Route parameters missing when combining optional and rest

Open Vextil opened this issue 1 year ago • 1 comments

Describe the bug

When using a combination of [[optional]] and [...rest] route parameters, an [[optional]] parameter is removed completely. This did not happen on @sveltejs/kit 1.8.3 (previous version we were using), but is happening in the latest release.

I have defined the following route structure: [[lang=lang]] / [asset=asset] / [[categoryType]] / [...categories]

The 'lang' matcher checks it's either 'es', 'de' or 'pt-br'. The 'asset' matcher checks it's either 'music' or 'sfx'.

This is to support these route variations: /music /music/genre /music/genre/rock /sfx/category/car/crash /es/sfx/category/car/crash

For each case, the params should be:

/music
asset: music

---------------
/music/genre
asset: music
categoryType: genre

---------------
/music/genre/rock
asset: music
categoryType: genre
categories: rock

---------------
/sfx/category/car/crash
asset: sfx
categoryType: category
categories: car/crash

---------------
/es/sfx/category/car/crash
lang: es
asset: sfx
categoryType: category
categories: car/crash

But instead, I'm seeing the following behaviour:

/music
asset: music
This one works properly.

---------------
/music/genre
asset: music
categoryType: genre
This one works properly.

---------------
/music/genre/rock
asset: music
categoryType: rock
categories:
Bug: categoryType is what categories should be, and 'genre' disappears

---------------
/sfx/category/car/crash 
asset: sfx
categoryType: car
categories: crash
Bug: 'category' disappears, and the first categories section is placed in categoryType

---------------
/es/sfx/category/car/crash
lang: es
asset: sfx
categoryType: category
categories: car/crash
This one works properly.

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-aqodqc

In the repro load /music/genre/rock and you will see the parsed params: image

Logs

No response

System Info

System:
    OS: Linux 5.15 Ubuntu 22.04.1 LTS 22.04.1 LTS (Jammy Jellyfish)
    CPU: (8) x64 AMD Ryzen 5 5600G with Radeon Graphics
    Memory: 2.11 GB / 6.37 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 16.17.0 - /usr/local/bin/node
    npm: 8.15.0 - /usr/local/bin/npm
  npmPackages:
    @sveltejs/adapter-auto: ^2.1.0 => 2.1.0 
    @sveltejs/adapter-cloudflare: ^2.2.4 => 2.2.4 
    @sveltejs/adapter-node: ^1.2.4 => 1.2.4 
    @sveltejs/kit: 1.18.0 => 1.18.0 
    svelte: ^3.58.0 => 3.58.0 
    vite: ^4.3.2 => 4.3.2

Severity

blocking an upgrade

Additional Information

No response

Vextil avatar May 18 '23 16:05 Vextil

Git bisect reveals this was introduced by https://github.com/sveltejs/kit/commit/1e2c82697d501c88c6027722ea9b106e09a0eb6d

I opened #9979, which is just this issue converted to failing tests. I really don't have the mental energy to understand why they're failing right now, so if someone wants to take a crack at pushing to that PR, be my guest :lol: