-
-
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
fetch from *.svelte (e.g. in button click) triggers repeated console warning not to use window.fetch #7992
Comments
yeah, the same... I understand that in most cases the main |
Same here. I'm using WebAssembly and as such, I'm fetching the .wasm binary on the client side after page load, but svelte keeps yelling at me. Having a way to disable this warning for parts of your code should be available. This warning is very useful for new people, but it's very annoying when you want to try without training wheels. |
Hi, I am the author of the stackoverflow question. Thank you for creating this issue! I switched to the most recent svelte/kit versions (1.0.1 / 3.55.0). |
The issue seems to be the heuristic that checks if I don't get the warning in Chrome, which doesn't have Can anyone else verify that? |
I can confirm. I'm not getting the warning in Chrome |
This still appears to be happening in Firefox (tested in 108 on Mac). Repro (from #8627): https://stackblitz.com/edit/sv-bug-fetch-demo I was able to repro myself on a fresh project (Kit 1.2.1) by simply adding the following to the demo app's root <script>
import Counter from "./Counter.svelte";
import welcome from "$lib/images/svelte-welcome.webp";
import welcome_fallback from "$lib/images/svelte-welcome.png";
import { onMount } from "svelte";
onMount(() => {
fetch("https://svelte.dev");
});
</script> |
Confirmed, even when running this project locally (so it's not a Stackblitz thing).
This is what [
"window.fetch@http://127.0.0.1:5173/node_modules/@sveltejs/kit/src/runtime/client/fetcher.js?v=11651678:31:46",
"instance/<@http://127.0.0.1:5173/src/routes/Fetcher.svelte:75:20",
"run@http://127.0.0.1:5173/node_modules/.vite/deps/chunk-K6MJRMI7.js?v=11651678:19:10",
"mount_component/<@http://127.0.0.1:5173/node_modules/.vite/deps/chunk-K6MJRMI7.js?v=11651678:1708:52",
"flush@http://127.0.0.1:5173/node_modules/.vite/deps/chunk-K6MJRMI7.js?v=11651678:1003:9",
"init@http://127.0.0.1:5173/node_modules/.vite/deps/chunk-K6MJRMI7.js?v=11651678:1789:5",
"Root@http://127.0.0.1:5173/.svelte-kit/generated/root.svelte:633:7",
"createProxiedComponent@http://127.0.0.1:5173/node_modules/svelte-hmr/runtime/svelte-hooks.js?v=11651678:341:9",
"ProxyComponent@http://127.0.0.1:5173/node_modules/svelte-hmr/runtime/proxy.js?v=11651678:242:29",
"Proxy<Root>@http://127.0.0.1:5173/node_modules/svelte-hmr/runtime/proxy.js?v=11651678:349:11",
"initialize@http://127.0.0.1:5173/node_modules/@sveltejs/kit/src/runtime/client/client.js?v=11651678:375:10",
"_hydrate@http://127.0.0.1:5173/node_modules/@sveltejs/kit/src/runtime/client/client.js?v=11651678:1643:14",
"async*start@http://127.0.0.1:5173/node_modules/@sveltejs/kit/src/runtime/client/start.js:38:16",
"@http://127.0.0.1:5173/:19:9",
""
] |
I have the same issue in Firefox (110.0b2). Is there a way to suppress this warning? |
I am having this issue on chromium 110.0.5481.100 (Official Build) Arch Linux (64-bit) but it looks like the warning is only showing up in dev (not showing on built deploy) |
I'm having this warning (only when fetch is used inside a .svelte component) when using |
I am getting the same warnings but in Chrome. I created a separate *.js file under $lib that i use across multiple components. My whole app is client side and embedded in a GoLang app that runs the backend. |
Hi! Just check parameters of load function: for it is passed object including fetch function. You need actually use this argument as fetch and it will call at SSR stage without browser console warning.
from the docs https://kit.svelte.dev/docs/load#making-fetch-requests see last list option. |
@creamsodainyourmouth: Thanks. In my case I need to call fetch e.g. from a button click. So currently I don't see how to replace the native |
Describe the bug
Since some recent sveltekit versions I am getting repeatedly the following developer warning in the browser console:
Loading /api/test?id=123 using
window.fetch
. For best results, use thefetch
that is passed to yourload
function: https://kit.svelte.dev/docs/load#making-fetch-requestsThis is triggered by a simple fetch('/api/test') from +page.svelte, after page load, so to reproduce place such a fetch() call in to a button click.
I am facing the exact same issue as in the mentioned in this stackoverflow link: https://stackoverflow.com/questions/74700331/how-to-fetch-endpoint-data-in-sveltekit-after-initial-load
Sidenote: Other than stated on stackoverflow, changing the GET request into PUT does not avoid the message.
Sidenote 2: In the stackoverflow comments it is assumed to be a bug / false positive.
Sidenote 3: Yes, as stated in the comments, it might be necessary to make the browser reload the page to trigger this.
Summary: There seems to be NO way at all to fetch() currently without getting this message repeatedly.
Reproduction
Sorry, no full demo code repository yet, but this explains it all in detail incl. code:
https://stackoverflow.com/questions/74700331/how-to-fetch-endpoint-data-in-sveltekit-after-initial-load
Logs
No response
System Info
Severity
annoyance
Additional Information
No response
The text was updated successfully, but these errors were encountered: