{"record":{"id":"7e90d6cf482cdc10","repo":"sveltejs/kit","slug":"loading-url-using-window-fetch-for-best-resu","errorCode":null,"errorMessage":"Loading ${url} using `window.fetch`. For best results, use the `fetch` that is passed to your `load` function: https://svelte.dev/docs/kit/load#making-fetch-requests","messagePattern":"Loading (.+?) using `window\\.fetch`\\. For best results, use the `fetch` that is passed to your `load` function: https://svelte\\.dev/docs/kit/load#making-fetch-requests","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/kit/src/runtime/client/fetcher.js","lineNumber":54,"sourceCode":"\t\t// We use just the filename as the method name sometimes does not appear on the CI.\n\t\tconst url = input instanceof Request ? input.url : input.toString();\n\t\tconst stack_array = /** @type {string} */ (new Error().stack).split('\\n');\n\t\t// We need to do a cutoff because Safari and Firefox maintain the stack\n\t\t// across events and for example traces a `fetch` call triggered from a button\n\t\t// back to the creation of the event listener and the element creation itself,\n\t\t// where at some point client.js will show up, leading to false positives.\n\t\tconst cutoff = stack_array.findIndex((a) => a.includes('load@') || a.includes('at load'));\n\t\tconst stack = stack_array.slice(0, cutoff + 2).join('\\n');\n\n\t\tconst in_load_heuristic = can_inspect_stack_trace\n\t\t\t? stack.includes('src/runtime/client/client.js')\n\t\t\t: loading;\n\n\t\t// This flag is set in initial_fetch and subsequent_fetch\n\t\tconst used_kit_fetch = init?.__sveltekit_fetch__;\n\n\t\tif (in_load_heuristic && !used_kit_fetch) {\n\t\t\tconsole.warn(\n\t\t\t\t`Loading ${url} using \\`window.fetch\\`. For best results, use the \\`fetch\\` that is passed to your \\`load\\` function: https://svelte.dev/docs/kit/load#making-fetch-requests`\n\t\t\t);\n\t\t}\n\n\t\tconst method = input instanceof Request ? input.method : init?.method || 'GET';\n\n\t\tif (method !== 'GET') {\n\t\t\tcache.delete(build_selector(requested_url(input)));\n\t\t}\n\n\t\treturn native_fetch(input, init);\n\t};\n} else {\n\twindow.fetch = (input, init) => {\n\t\tconst method = input instanceof Request ? input.method : init?.method || 'GET';\n\n\t\tif (method !== 'GET') {\n\t\t\tcache.delete(build_selector(requested_url(input)));","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/runtime/client/fetcher.js#L36-L72","documentation":"During a `load` run, SvelteKit detects that a fetch was made with the global `window.fetch` rather than the specialized `fetch` passed to `load`. The kit fetch enables request memoization, dependency tracking, and forwarding of cookies/headers, so plain window.fetch yields worse performance and possibly duplicated or unauthenticated requests. This DEV warning fires once when the heuristic detects a non-kit fetch inside load.","triggerScenarios":"Inside a `load` function (or nested code during load), calling `fetch(...)` directly (module-scope reference, `globalThis.fetch`, or an imported wrapper) instead of the `fetch` argument provided by `load`, for a request that is actually executed.","commonSituations":"Using axios or a custom API client that captures global fetch; calling fetch in a helper that receives no fetch parameter; copy-pasted code from non-SvelteKit projects.","solutions":["Use the `fetch` passed to `load`: `({ fetch }) => { ... }` and pass it into helpers/clients","If using a library like axios, configure its fetch/adapter to use the load-provided fetch","Suppress only if the native fetch behavior is intentional and understood"],"exampleFix":"// before\nexport async function load() {\n  const res = await window.fetch('/api/data');\n  return { data: await res.json() };\n}\n// after\nexport async function load({ fetch }) {\n  const res = await fetch('/api/data');\n  return { data: await res.json() };\n}","handlingStrategy":"validation","validationCode":"export async function load({ fetch }) { if (typeof window !== 'undefined' && fetch === window.fetch) console.warn('using window.fetch in load — use the provided fetch'); }","typeGuard":"const isKitFetch = (fetch) => typeof fetch === 'function' && fetch.__sveltekit_fetch__ === true;","tryCatchPattern":null,"preventionTips":["Always destructure { fetch } from load and pass it into API clients/wrappers","Configure axios/ofetch/custom clients to accept an injected fetch","Grep for bare `fetch(` inside load functions and route them through the provided fetch"],"tags":["fetch","load","performance","ssr","sveltekit"],"backgroundTag":"window-fetch-in-load","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}