Skip to content
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

Attempt to error better when wrong fetch is used on an endpoint #7976

Closed
arackaf opened this issue Dec 7, 2022 · 0 comments · Fixed by #8370
Closed

Attempt to error better when wrong fetch is used on an endpoint #7976

arackaf opened this issue Dec 7, 2022 · 0 comments · Fixed by #8370
Labels
Milestone

Comments

@arackaf
Copy link

arackaf commented Dec 7, 2022

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

@Rich-Harris Rich-Harris added this to the whenever milestone Dec 9, 2022
Rich-Harris added a commit that referenced this issue Jan 7, 2023
Rich-Harris added a commit that referenced this issue Jan 9, 2023
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants