{"record":{"id":"d6b3f538e24bfd5a","repo":"sveltejs/kit","slug":"can-only-call-updated-check-in-the-browser","errorCode":null,"errorMessage":"Can only call updated.check() in the browser","messagePattern":"Can only call updated\\.check\\(\\) in the browser","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/kit/src/runtime/app/state/server.js","lineNumber":64,"sourceCode":"\t\treturn (DEV ? context_dev('page.url') : context()).page.url;\n\t}\n};\n\nexport const navigating = {\n\tfrom: null,\n\tto: null,\n\ttype: null,\n\twillUnload: null,\n\tdelta: null,\n\tcomplete: null\n};\n\nexport const updated = {\n\tget current() {\n\t\treturn false;\n\t},\n\tcheck: () => {\n\t\tthrow new Error('Can only call updated.check() in the browser');\n\t}\n};\n","sourceCodeStart":46,"sourceCodeEnd":67,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/runtime/app/state/server.js#L46-L67","documentation":"On the server, `$app/state`'s `updated` object is a stub: `current` is always `false` and `check()` throws, because update detection depends on comparing deployed build assets, which is a browser-only operation. Call `updated.check()` (or read `updated.current`) only in the browser.","triggerScenarios":"Calling `updated.check()` during SSR (component runs on server), in a `load` function, in a server hook, or in a universal component without guarding for `browser`.","commonSituations":"Rendering a 'new version available' indicator component that calls `updated.check()` in its initialization on the server; shared util calling `updated.check()` during SSR.","solutions":["Call `updated.check()` inside `onMount` or after `browser` is true (`import { browser } from '$app/environment'`)","Use `updated.current` reactively in the component instead of eagerly calling check() on the server","Guard server execution: `if (browser) updated.check();`"],"exampleFix":"// before\nconst canUpdate = updated.check();\n// after\nimport { onMount } from 'svelte';\nlet canUpdate = false;\nonMount(() => { canUpdate = updated.check(); });","handlingStrategy":"type-guard","validationCode":"import { browser } from '$app/environment';\nif (browser) {\n  const canUpdate = updated.check();\n}","typeGuard":"const canCallCheck = () => typeof window !== 'undefined' && typeof document !== 'undefined';","tryCatchPattern":"try {\n  const result = updated.check();\n} catch (e) {\n  if (e.message.includes('in the browser')) {\n    const result = false; // server default: not updated\n  } else throw e;\n}","preventionTips":["Gate `updated` usage behind `browser` or `onMount`","Prefer reactive `updated.current` in components over imperative check() during SSR","Keep version-check logic in client-only components"],"tags":["ssr","updated","browser-only"],"backgroundTag":"browser-only-api-on-server","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}