-
-
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
load fall-through #548
Comments
This seems like in the all-failure case, we'd end up with a cryptic 404, because none of the errors we throw from the routes show up? Or do we merge the stacktrace somehow? If we load in parallel, what happens when two or more pages respond with a non-error? What mechanism do we use to identify the order in which the fall through happens? |
If a
Alphabetical? It isn't the most 'semantically correct' solution but if you really needed to check vegetables before minerals before animals you could do
The advantage of alphabetical instead of something out-of-band is that you can see the expected behaviour just by looking at your editor's file tree |
If a page does not define a |
this is why we can't have nice things 😭 . Though given how rare it would be to use numbers in this context, I think we can probably just disallow it
agree |
I'd suggest making the separator between the sort-thing and the slug name be a character that can't appear in variable names. This way we can easily strip it out of the param name. It seems more palatable to say that |
A not-insignificant benefit of completely dropping regex routes is that it would make #484 go away instead of being the small nightmare it is almost certain to be. |
huh, I'd imagined that |
All of If you'd rather have the things between the brackets be the literal param names, that's fine. We can always rename them when destructuring args to the |
I'm not aware of any such limitation on Ubuntu OS. Is this from Mac or Windows or elsewhere in SvelteKit? |
Yes, file and directory names can't have |
Oh right. Also, I sort of evaluated the regex in my head when reading the comment and thought the comment was saying there couldn't be spaces or numbers 😄 With the goal of minimizing unnecessary data transfer, I wonder if there's another way we could structure this. E.g. we could have |
That mechanism already exists: <script context="module">
export async function load({ page, fetch }) {
let Page;
switch (get_type(page)) {
case 'animal':
Page = (await import('./_Animal.svelte')).default;
break;
case 'mineral':
Page = (await import('./_Mineral.svelte')).default;
break;
case 'vegetable':
Page = (await import('./_Vegetable.svelte')).default;
break;
default:
return; // not found
}
return {
props: { Page }
}
}
</script>
<svelte:component this={Page}/> It's not exactly ergonomic but it works, no need to introduce some other mechanism. In the majority of cases loading both candidate routes simultaneously is fine, I think, so this would be a rare case |
Implemented in #583. |
@Rich-Harris why do it like this though? Why not just use I'm asking because at the moment I'm working on a page that uses the |
We want a route to be able to say 'I know this is intended for me and I know it's a 404' and not have to check any other routes. I'd expect you should be able to return just |
Ah sorry, I hadn't realized that returning |
I have a page named |
Suppose you had the following routes:
SvelteKit would throw an error on encountering these because they conflict — there's no way to know, given a URL like
/potato
, whether it's an animal, a vegetable, or a mineral.Our half-hearted solution to this is to allow a subset of regex syntax in filenames. But no regex exists that would allow you to disambiguate between those routes, and even when regex is suitable, the limitations of filenames (e.g. no
\d
or\w
) render them somewhat useless.Here's an alternative idea:
If all matching routes had
load
functions that returned falsy values, SvelteKit would render the error page with a generic 404.This isn't perfect: it requires the browser to load
src/routes/[animal]/index.svelte
and all its dependencies, only for SvelteKit to discover it's not what we wanted, potentially slowing navigations down unacceptably. But it gives us a degree of power and flexibility that isn't possible any other way.We can mitigate that by loading all matching routes in parallel, for the rare cases where there's more than one. The downside is that you might end up fetching more code than is necessary, but I think it's probably an acceptable trade-off.
If we had this, would we ditch regex routes? They allow routes to be rejected earlier, but as mentioned have limitations that make them pretty useless anyway.
The text was updated successfully, but these errors were encountered: