-
-
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
Resolve relative fetch
from +layout
relative to the layout's route, not the leaf's route
#6337
Comments
This makes intuitive sense, though a surprisingly non-trivial question is 'relative to what'? In a case like this...
...if you visit But should it resolve relative to |
We discussed this earlier today and concluded that we should always include the trailing slash, since it's easy to do |
I feel a bit conflicted about this. It's kind of the only way relative fetches make sense in layouts, but it's a non-standard way for |
Absolute fetches (especially when a relative fetch would be just fine) are complete anathema to me, especially when I'm actively developing an app. I'll often copy a folder into another folder or rename a parent folder (changing its route). With relative fetches, I'd have to change nothing in my actual files -- without, I have to go through every file to make sure all of the absolute fetches have switched to the new route. |
What sorts of things are you fetching? |
Revisiting this I vote for closing this - as Ben says, this is the standard browser behavior and we shouldn't mess with that (also it's probably a bunch of extra code, also on the client side). |
Closing since Rich agreed in Discord |
Describe the problem
Pardon the dense title. I'm sure someone else could word it better.
Consider the following file structure:
Now let's say we make a relative
fetch
in+layout.svelte
:const resp = await fetch('data');
When visiting
/foo/foo2/foo3/foo4
, where do you suppose that fetch goes?Something like
/foo/foo2/foo3/data
. That's confusing. The unfortunate thing is, this becomes more annoying if you have alayout
further down the tree, as the only way to reliably fetch an adjacent resource is to specify the whole path from the root manually, whereas if you actually wanted the above relative behavior, you could easily achieve it yourself:await fetch(`${$page.url.pathname}/data`)
.Describe the proposed solution
Relative
fetch
es in+layout
files should resolve relative to the layout's directory, not relative to whatever leaf happens to be rendering.Alternatives considered
Just be annoyed. 🤷🏻
Importance
would make my life easier
Additional Information
It's like, almost 3AM. If I've said anything stupid, please correct me.
The text was updated successfully, but these errors were encountered: