{"record":{"id":"dfe6db0c4db6004f","repo":"sveltejs/kit","slug":"node-server-id-calling-depends-in-a-pro","errorCode":null,"errorMessage":"${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","messagePattern":"(.+?): Calling `depends\\(\\.\\.\\.\\)` 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":108,"sourceCode":"\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`\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tuses.dependencies.add(href);\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\tparams: new Proxy(event.params, {\n\t\t\t\t\t\tget: (target, key) => {\n\t\t\t\t\t\t\tif (DEV && done && typeof key === 'string' && !uses.params.has(key)) {\n\t\t\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t\t\t`${node.server_id}: Accessing \\`params.${String(\n\t\t\t\t\t\t\t\t\t\tkey\n\t\t\t\t\t\t\t\t\t)}\\` in a promise handler after \\`load(...)\\` has returned will not cause the function to re-run when the param changes`\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/runtime/server/page/load_data.js#L90-L126","documentation":"`depends(...)` declares a custom invalidation dependency for a `load` function. Calling it in a promise handler after `load` has returned means the dependency is registered too late (and here triggers a warning when the href was not already tracked), so invalidating that dependency will not re-run `load`.","triggerScenarios":"Server `load` calls `depends('app:x', ...)` inside a `.then()`/post-await continuation after the body finished (`done === true`) and `app:x` (resolved href) is not in `uses.dependencies`.","commonSituations":"Registering custom dependencies after awaiting data; conditional `depends` calls in async callbacks that resolve post-return.","solutions":["Call `depends()` synchronously at the start of `load`, before any `await`.","Declare every custom dependency up front even if the related data is fetched later.","Move the deferred logic so dependency registration and data fetch happen together within the load body."],"exampleFix":"// before\nexport function load({ depends }) {\n  return getData().then((d) => { depends('app:data'); return d; });\n}\n// after\nexport async function load({ depends }) {\n  depends('app:data');\n  const d = await getData();\n  return { d };\n}","handlingStrategy":"validation","validationCode":"export async function load({ depends }) {\n  depends('app:data'); // register all custom deps first, unconditionally\n  const data = await getData();\n  return { data };\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Call `depends()` at the very top of `load`, before any `await`.","List every custom dependency explicitly rather than conditionally in async code.","Review load functions after refactors to ensure depends calls did not drift into callbacks."],"tags":["load-function","depends","sveltekit","server"],"backgroundTag":"load-deferred-dependency-warning","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}