Closed Oreilles closed 1 year ago
to add more info to this issue, it seems that optional matchers only shift values if the next segment is a rest
segment.
a test like this in packages/kit/src/utils/routing.spec.js
will fail:
{
route: '/[[slug=doesntmatch]]/[[slug2=doesntmatch]]/[...rest]',
path: '/foo/bar/baz',
expected: { rest: 'foo/bar/baz' }
},
from a (semi-)quick inspection, the problem seems to be in these lines, more specifically in if (next?.rest && next.chained)
– which isn't necessarily the case: you can have several optional segments that don't match that should shift their value to the next segment.
This relates to https://github.com/sveltejs/kit/pull/7753 and https://github.com/sveltejs/kit/issues/7548
A valid scenario for something like this would be:
[[lang=lang]]/[[region=region]]/[...rest]
'/foo/bar' // { rest: 'foo/bar' }
'/en/foo/bar' // { lang: 'en', rest: 'foo/bar' }
'/gbr/foo/bar' // { region: 'gbr', rest: 'foo/bar' }
'/en/gbr/foo/bar' // { lang: 'en', region: 'gbr', rest: 'foo/bar' }
Naturally we can work around this and use a single [...path]
and extract the segments ourselves but we have significant impact if, for instance, we have a +layout.server.ts
load function that depends on params.lang
to fetch layout data.
Now every path change will trigger an invalidation regardless of whether params.lang
changed – making a lot of unnecessary requests that will impact navigation performance.
marking this with the ready to implement
label though i know from bitter experience that this will likely be a tough issue to close...
Describe the bug
Considering the following route path:
/fr/about/something
succeed./about/something
succeed./fr/about/something/else
succeed./about/something/else
fails with 404 (not matched by the router).Reproduction
https://stackblitz.com/edit/sveltejs-kit-template-default-r3nnht
Logs
No response
System Info
Severity
serious, but I can work around it
Additional Information
No response