You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've now twice gotten burned by using the "wrong" fetch in my loaders. Running
fetch("/api/my-endpoint")
with the global fetch that's in scope will puke, since "/api/my-endpoint" has no way of resolving. Obviously you have to destructure the fetch that's passed to your loader. Simple enough, but it's an easy thing to miss when you're new (at SvelteKit), and it's maddening to debug.
Describe the proposed solution
Would it be possible for the global fetch to detect when an (otherwise valid) api endpoint is being requested, and error with something clear about needing to use the provided fetch to hit endpoints?
I know this woulnd't be foolproof, since shared loaders are (I assume?) using the browser's provided fetch, which would be hard for you all to wrap, but on the server you're already providing your own fetch, so could this check be added to that (presumably for non-production builds)?
Alternatives considered
n/a
Importance
nice to have
Additional Information
No response
The text was updated successfully, but these errors were encountered:
* error in dev mode if global fetch is used with relative URL - closes#7976
* Update packages/kit/src/exports/vite/dev/index.js
Co-authored-by: Rich Harris <richard.a.harris@gmail.com>
Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
Describe the problem
I've now twice gotten burned by using the "wrong" fetch in my loaders. Running
fetch("/api/my-endpoint")
with the global fetch that's in scope will puke, since "/api/my-endpoint" has no way of resolving. Obviously you have to destructure the fetch that's passed to your loader. Simple enough, but it's an easy thing to miss when you're new (at SvelteKit), and it's maddening to debug.
Describe the proposed solution
Would it be possible for the global fetch to detect when an (otherwise valid) api endpoint is being requested, and error with something clear about needing to use the provided fetch to hit endpoints?
I know this woulnd't be foolproof, since shared loaders are (I assume?) using the browser's provided fetch, which would be hard for you all to wrap, but on the server you're already providing your own fetch, so could this check be added to that (presumably for non-production builds)?
Alternatives considered
n/a
Importance
nice to have
Additional Information
No response
The text was updated successfully, but these errors were encountered: