{"record":{"id":"fc6b7356f5bc60b1","repo":"sveltejs/kit","slug":"can-only-read-name-on-the-server-during-rende","errorCode":null,"errorMessage":"Can only read '${name}' on the server during rendering (not in e.g. `load` functions), as it is bound to the current request via component context. This prevents state from leaking between users\n\t\t\t\t'For more information, see https://svelte.dev/docs/kit/state-management#avoid-shared-state-on-the-server","messagePattern":"Can only read '(.+?)' on the server during rendering \\(not in e\\.g\\. `load` functions\\), as it is bound to the current request via component context\\. This prevents state from leaking between users\n\t\t\t\t'For more information, see https://svelte\\.dev/docs/kit/state-management#avoid-shared-state-on-the-server","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/kit/src/runtime/app/state/server.js","lineNumber":13,"sourceCode":"import { DEV } from 'esm-env';\nimport { getContext } from 'svelte';\n\nfunction context() {\n\treturn getContext('__request__');\n}\n\n/** @param {string} name */\nfunction context_dev(name) {\n\ttry {\n\t\treturn context();\n\t} catch {\n\t\tthrow new Error(\n\t\t\t`Can only read '${name}' on the server during rendering (not in e.g. \\`load\\` functions), as it is bound to the current request via component context. This prevents state from leaking between users. ` +\n\t\t\t\t'For more information, see https://svelte.dev/docs/kit/state-management#avoid-shared-state-on-the-server'\n\t\t);\n\t}\n}\n\nexport const page = {\n\tget data() {\n\t\treturn (DEV ? context_dev('page.data') : context()).page.data;\n\t},\n\tget error() {\n\t\treturn (DEV ? context_dev('page.error') : context()).page.error;\n\t},\n\tget form() {\n\t\treturn (DEV ? context_dev('page.form') : context()).page.form;\n\t},\n\tget params() {\n\t\treturn (DEV ? context_dev('page.params') : context()).page.params;","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/runtime/app/state/server.js#L1-L31","documentation":"Server-side `$app/state` exports (`page`, `form`, etc.) read request-specific data from Svelte component context, which only exists while rendering components. Accessing them outside rendering (e.g. inside a `load` function or module code) on the server would risk leaking one user's state to another, so `context_dev` throws. Read these states in components, or use `load`'s own event parameters.","triggerScenarios":"Calling `page.data`, `page.params`, `page.url`, `form`, `error`, or `route` from a `load` function, a module-level statement, or any non-component server code in DEV mode where Svelte's `context()` is unavailable.","commonSituations":"Migrating from `$app/stores` to `$app/state` and reading `page` in `load`; using `page.data` in a helper called from `load`; accessing `page` at module top level for SSR config.","solutions":["Move the read into a component (e.g. inside `onMount` or the component body) where context exists","In `load`, use the `event.params`, `event.url`, and returned `data` instead of `$app/state`","For server-side helpers, accept the needed values as explicit arguments"],"exampleFix":"// before (in load)\nimport { page } from '$app/state';\nexport const load = () => ({ id: page.params.id });\n// after\nexport const load = ({ params }) => ({ id: params.id });","handlingStrategy":"validation","validationCode":"import { browser } from '$app/environment';\nfunction safePageRead(read) {\n  if (!browser) throw new Error('read $app/state page only during component rendering or in browser');\n  return read();\n}","typeGuard":"const canUseAppState = () => { try { context(); return true; } catch { return false; } };","tryCatchPattern":"try {\n  const id = page.params.id;\n} catch (e) {\n  if (e.message.includes('bound to the current request')) {\n    // fall back to load-event params or pass value as argument\n  } else throw e;\n}","preventionTips":["Read `page`/`form` only inside components, never in `load` or module scope","In `load`, use `event.params`/`event.url` and returned data instead","Pass request values into server helpers as explicit arguments"],"tags":["state-management","ssr","component-context"],"backgroundTag":"shared-state-on-server","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}