-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error on conflicting routes #7304
Conversation
|
(if they can't, there's still |
It is, yeah — it's come up in the past for things like
...then figures out all the permutations of those routes:
Since 3 (derived from 1) and 6 (derived from 2) are identical, those routes are identified as being incompatible. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
The only thing I'm not sure about - but relaxing this is always possible later in a non-breaking way - is the very strict conflict check.
Imagine you have a/[[b]]/c/[[d]]
and a/c
as routes. Under this algorithm, this is a conflict, but the user could say "yes I know that that's a conflict in one of these cases, but I don't want to duplicate routes into a/[b]/c/[d]
, a/[b]/c/
and a/c/[d]
(because a/[b]/c/[[d]]
and a/[[b]]/c/[d]
would also be a conflict in one case).
I don't know how a algorithm that relaxes this and at the same time sorts these things correctly without bringing the complexity of that other PR back would look like (probably something like "if this optional route only has one nn-conflicting permutation left it's an error), so I'm giving my approval regardless of this wrinkle. You can decide if this overly strict check is reason enough to use more complex sorting logic after all like in the other PR or not. I haven't decided yet.
Ah, that's an interesting case. It seems like a fairly unlikely one, but if it did arise then it would be possible to work around, or we could relax the conflict detection as you say. Aside from that edge case I think having the conflict detection is useful regardless (e.g. it found a conflicting route in the test app that wasn't doing any work) |
* [feat] implement optional route params Closes #5072 * docs * param fixes, tidy up, more tests * more tests, move some validations, sorting * better regex * sort to fix test * next try * fix validation * next try * Update documentation/docs/04-advanced-routing.md Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com> * simplify * disallow ambiguity in both directions * Error on conflicting routes (#7304) * more sorting logic into one place * better sorting algorithm * update tests * tidy up * use an array instead of a map * remove unused test files * relax constraint prohibiting [[optional]]/[...rest] * update docs * docs * fix disambiguation between x/y and x/[...rest]/y * more intelligent conflict detection * more accurate error message * fix regex * remove conflicting route from test app * handle edge case * oops * introcuce randomness to make test fail * fix conflict detection * make input valid * remove obsolete note * more tests * i think this is it? fingers crossed * Update documentation/docs/04-advanced-routing.md * changeset * Update documentation/docs/04-advanced-routing.md Co-authored-by: Conduitry <git@chor.date> Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com> Co-authored-by: Rich Harris <hello@rich-harris.dev> Co-authored-by: Rich Harris <richard.a.harris@gmail.com> Co-authored-by: Conduitry <git@chor.date>
Yet another follow-up to #7051, which can be considered an alternative to #7278. It reverts to the simpler algorithm initially present in that PR, but adds a check for routes that are in conflict with each other (for example
x/[[y]]
and[[y]]/x
, which can't meaningfully coexist) so that the algorithm doesn't need to consider the additional cases added later in the PR.The one case it doesn't handle is
x/[...rest]
vs[...rest]/x
(orx/[[optional]]
vs[...rest]/x
), which is the exception to the rule that a route ending with a rest/optional parameters comes after an otherwise-equivalent route. I'm hopeful that we can solve that case without introducing a lot more complexity, but I haven't nailed it yet.Another test that fails (both in this PR and in #7278) is
foo/bar[...rest]
vsfoo/[...rest]bar
.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. All changesets should bepatch
until SvelteKit 1.0