{"record":{"id":"5f782ed5a1d11474","repo":"sveltejs/kit","slug":"export-const-snapshot-is-deprecated-use-the-sn","errorCode":null,"errorMessage":"`export const snapshot` is deprecated. Use the `snapshot` helper from `$app/navigation` instead.","messagePattern":"`export const snapshot` is deprecated\\. Use the `snapshot` helper from `\\$app/navigation` instead\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/kit/src/runtime/client/client.js","lineNumber":709,"sourceCode":"\tawait Promise.all(promises).catch(noop);\n}\n\nfunction reset_invalidation() {\n\tinvalidated.length = 0;\n\tforce_invalidation = false;\n}\n\nlet warned_snapshot_export = false;\n\n/**\n * @param {number} index\n * @deprecated TODO 4.0 get rid of this\n */\nfunction capture_snapshot(index) {\n\tif (props.components.some((c) => c?.snapshot)) {\n\t\tif (DEV && !warned_snapshot_export) {\n\t\t\twarned_snapshot_export = true;\n\t\t\tconsole.warn(\n\t\t\t\t'`export const snapshot` is deprecated. Use the `snapshot` helper from `$app/navigation` instead.'\n\t\t\t);\n\t\t}\n\t\tsnapshots[index] = props.components.map((c) => c?.snapshot?.capture());\n\t}\n}\n\n/**\n * @param {number} index\n * @deprecated TODO 4.0 get rid of this\n */\nfunction restore_snapshot(index) {\n\tsnapshots[index]?.forEach((value, i) => {\n\t\tprops.components[i]?.snapshot?.restore(value);\n\t});\n}\n\nfunction persist_state() {","sourceCodeStart":691,"sourceCodeEnd":727,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/runtime/client/client.js#L691-L727","documentation":"Page components used to export a `snapshot` object directly; SvelteKit 2 introduced the `snapshot` helper from `$app/navigation` (and `$app/state`) instead, so component exports can be removed. When a component still exports `snapshot`, the router captures it but warns once in DEV that the export form is deprecated.","triggerScenarios":"A `+page.svelte`/`+layout.svelte` contains `export const snapshot = { capture, restore }`; navigation happens and `capture_snapshot` in packages/kit/src/runtime/client/client.js detects it via `props.components.some((c) => c?.snapshot)` and warns once.","commonSituations":"Code following SvelteKit 2 early-adopter docs or pre-release syntax before the helper API settled; component libraries exporting snapshot support in the old shape.","solutions":["Delete `export const snapshot` from the component","Import `{ snapshot }` from `$app/navigation` and use it at the call site to save/restore scroll and state","Store captured state explicitly if you need custom serialize/restore behaviour"],"exampleFix":"// before (+page.svelte)\nexport const snapshot = { capture: () => data, restore: (d) => (data = d) };\n// after\nimport { snapshot } from '$app/navigation';\nconst snap = snapshot.capture();\n// later: snapshot.restore(snap);","handlingStrategy":"validation","validationCode":"// detect deprecated component snapshot exports\nimport { readFileSync } from 'node:fs';\nif (/export\\s+const\\s+snapshot/.test(readFileSync('+page.svelte', 'utf8'))) {\n  console.warn('use `snapshot` helper from $app/navigation instead');\n}","typeGuard":"function exportsSnapshot(comp) { return comp != null && 'snapshot' in comp; }","tryCatchPattern":null,"preventionTips":["Use the `snapshot` helper from `$app/navigation` for capturing page state","Remove `export const snapshot` from all components before the next major"],"tags":["deprecation","snapshot","client-side"],"backgroundTag":"deprecated-snapshot-export","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}