{"record":{"id":"49b65b4c48ba1e23","repo":"sveltejs/kit","slug":"u001b-1m-u001b-31mreturning-promises-from-server","errorCode":null,"errorMessage":"\\u001B[1m\\u001B[31mReturning promises from server `load` functions will only work if `csr === true`\\u001B[39m\\u001B[22m","messagePattern":"\\\\u001B\\[1m\\\\u001B\\[31mReturning promises from server `load` functions will only work if `csr === true`\\\\u001B\\[39m\\\\u001B\\[22m","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/kit/src/runtime/server/page/render.js","lineNumber":648,"sourceCode":"\t\t\tdone: true\n\t\t})) || '';\n\n\tif (!chunks) {\n\t\theaders.set('etag', `\"${hash(transformed)}\"`);\n\t}\n\n\tif (DEV) {\n\t\tif (page_config.csr) {\n\t\t\tif (count_non_ssi_comments(transformed) < count_non_ssi_comments(html)) {\n\t\t\t\t// the \\u001B stuff is ANSI codes, so that we don't need to add a library to the runtime\n\t\t\t\t// https://svelte.dev/playground/1b3f49696f0c44c881c34587f2537aa2?version=4.2.19\n\t\t\t\tconsole.warn(\n\t\t\t\t\t\"\\u001B[1m\\u001B[31mRemoving comments in transformPageChunk can break Svelte's hydration\\u001B[39m\\u001B[22m\"\n\t\t\t\t);\n\t\t\t}\n\t\t} else {\n\t\t\tif (chunks) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t'\\u001B[1m\\u001B[31mReturning promises from server `load` functions will only work if `csr === true`\\u001B[39m\\u001B[22m'\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn chunks\n\t\t? new Response(stream_text(transformed + '\\n', chunks), { status, headers })\n\t\t: text(transformed, { status, headers });\n}\n\nclass Head {\n\t#rendered;\n\t/** @type {string[]} */\n\t#http_equiv = [];\n\t/** @type {string[]} */\n\t#link_tags = [];\n\t/** @type {string[]} */","sourceCodeStart":630,"sourceCodeEnd":666,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/runtime/server/page/render.js#L630-L666","documentation":"When csr is false, SvelteKit serializes the server render to static HTML with no client runtime, so there is no way to resolve promises returned from server load functions after the initial stream. In dev, if the page's server load returned promises (deferred streaming) and csr is disabled, SvelteKit warns that this pattern only works with csr === true.","triggerScenarios":"A +page.server.js (or +layout.server.js) load returns an object containing promise values (streaming pattern like { streamed: getStuff() }) while the route sets `export const csr = false`; occurs during dev SSR of a chunk set.","commonSituations":"Enabling prerendering/SPA-less output (csr = false) on routes that also use streaming load; migrating a streamed-data page to fully static output; docs example of csr=false combined with async load results.","solutions":["Set `export const csr = true` for routes whose server load returns promises","Resolve all promises before returning from server load (await everything) so nothing is deferred","Split the route: a static csr=false page without streaming plus a separate csr=true page for streamed data"],"exampleFix":"// before (+page.server.js, csr=false elsewhere)\nexport async function load() {\n  return { comments: getComments() }; // promise\n}\n\n// after\nexport async function load() {\n  return { comments: await getComments() };\n}","handlingStrategy":"validation","validationCode":"// ensure no promise values returned when csr is false\nexport const csr = false;\n// in load: assert every returned value is not a thenable\nObject.entries(result).forEach(([k, v]) => {\n  if (v && typeof v.then === 'function') throw new Error(`${k} must be awaited when csr=false`);\n});","typeGuard":"function isThenable(v) { return !!v && typeof v.then === 'function'; }","tryCatchPattern":null,"preventionTips":["Never mix csr=false with streaming load returns","Await all promises in server load when csr is disabled","Document per-route csr setting near the load function"],"tags":["ssr","load","streaming","csr"],"backgroundTag":"csr-false-with-streaming-load","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}