Skip to content

fetch from *.svelte (e.g. in button click) triggers repeated console warning not to use window.fetch #7992

@m1027

Description

@m1027

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 the fetch that is passed to your load function: https://kit.svelte.dev/docs/load#making-fetch-requests

This 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

System:
    OS: Linux 6.0 Gentoo Linux
    CPU: (4) x64 Intel(R) Core(TM) i5-8350U CPU @ 1.70GHz
    Memory: 12.92 GB / 15.51 GB
    Container: Yes  [WRONG REPORT? THERE IS NO CONTAINER]
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 18.12.1 - /usr/bin/node
    npm: 8.19.2 - /usr/bin/npm
  Browsers:
    Firefox: 107.0.1
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.90 
    @sveltejs/adapter-node: ^1.0.0-next.100 => 1.0.0-next.102 
    @sveltejs/kit: next => 1.0.0-next.572 
    svelte: ^3.44.0 => 3.54.0 
    vite: ^3.1.0 => 3.2.5

Severity

annoyance

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions