{"record":{"id":"e205f8709ad8a9d4","repo":"sveltejs/kit","slug":"node-server-id-calling-event-fetch-in-a","errorCode":null,"errorMessage":"${node.server_id}: Calling `event.fetch(...)` in a promise handler after `load(...)` has returned will not cause the function to re-run when the dependency is invalidated","messagePattern":"(.+?): Calling `event\\.fetch\\(\\.\\.\\.\\)` in a promise handler after `load\\(\\.\\.\\.\\)` has returned will not cause the function to re-run when the dependency is invalidated","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/kit/src/runtime/server/page/load_data.js","lineNumber":91,"sourceCode":"\n\tconst result = await record_span({\n\t\tname: 'sveltekit.load',\n\t\tattributes: {\n\t\t\t'sveltekit.load.node_id': node.server_id || 'unknown',\n\t\t\t'sveltekit.load.node_type': get_node_type(node.server_id),\n\t\t\t'sveltekit.load.environment': 'server',\n\t\t\t'http.route': event.route.id || 'unknown'\n\t\t},\n\t\tfn: async (current) => {\n\t\t\tconst traced_event = merge_tracing(event, current);\n\t\t\tconst result = await with_request_store({ event: traced_event, state }, () =>\n\t\t\t\tload.call(null, {\n\t\t\t\t\t...traced_event,\n\t\t\t\t\tfetch: (info, init) => {\n\t\t\t\t\t\tconst url = new URL(info instanceof Request ? info.url : info, event.url);\n\n\t\t\t\t\t\tif (DEV && done && !uses.dependencies.has(url.href)) {\n\t\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t\t`${node.server_id}: Calling \\`event.fetch(...)\\` in a promise handler after \\`load(...)\\` has returned will not cause the function to re-run when the dependency is invalidated`\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Note: server fetches are not added to uses.depends due to security concerns\n\t\t\t\t\t\treturn event.fetch(info, init);\n\t\t\t\t\t},\n\t\t\t\t\t/** @param {string[]} deps */\n\t\t\t\t\tdepends: (...deps) => {\n\t\t\t\t\t\tfor (const dep of deps) {\n\t\t\t\t\t\t\tconst { href } = new URL(dep, event.url);\n\n\t\t\t\t\t\t\tif (DEV) {\n\t\t\t\t\t\t\t\tvalidate_depends(node.server_id || 'missing route ID', dep);\n\n\t\t\t\t\t\t\t\tif (done && !uses.dependencies.has(href)) {\n\t\t\t\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t\t\t\t`${node.server_id}: Calling \\`depends(...)\\` in a promise handler after \\`load(...)\\` has returned will not cause the function to re-run when the dependency is invalidated`","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/runtime/server/page/load_data.js#L73-L109","documentation":"SvelteKit warns when `event.fetch` is called inside a promise handler after the `load` function has returned, targeting a URL that was never fetched during the tracked portion of `load`. Such late fetches are not registered as dependencies, so invalidating them will not re-run `load`.","triggerScenarios":"Server `load` defers work in a `.then()`/post-await continuation and calls `event.fetch('/api/x')` there, where `/api/x` was not among `uses.dependencies` gathered during the synchronous run.","commonSituations":"Chained fetches where a second `event.fetch` happens in the `then` of the first; background prefetching after load returns.","solutions":["Move all `event.fetch` calls into the synchronous (pre-await) portion of `load`.","Pre-fetch any URLs you will need before returning, or use `depends()` synchronously to declare the dependency.","Restructure so dependent fetches are sequenced with `await` inside the load body."],"exampleFix":"// before\nexport function load({ fetch }) {\n  return fetch('/a').then(() => fetch('/b'));\n}\n// after\nexport async function load({ fetch }) {\n  await fetch('/a');\n  const b = await fetch('/b');\n  return { b };\n}","handlingStrategy":"validation","validationCode":"export async function load({ fetch }) {\n  // fetch everything before returning; no fetch after the first return/await-chain tail\n  const a = await fetch('/api/a').then((r) => r.json());\n  const b = await fetch('/api/b').then((r) => r.json());\n  return { a, b };\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep all `event.fetch` calls inside the synchronous/awaited load body.","Avoid fire-and-forget fetches in `load`; they are untracked.","Declare dependent resources with `depends()` up front if fetches must be conditional."],"tags":["load-function","fetch","sveltekit","server"],"backgroundTag":"load-deferred-fetch-warning","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}