{"record":{"id":"0f3fe396a5ae0da4","repo":"sveltejs/kit","slug":"could-not-generate-a-snapshot-id-from-the-stack-tr","errorCode":null,"errorMessage":"Could not generate a snapshot id from the stack trace. Pass an `id` instead.","messagePattern":"Could not generate a snapshot id from the stack trace\\. Pass an `id` instead\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/kit/src/runtime/client/snapshots.js","lineNumber":89,"sourceCode":"export function persist_navigation_snapshots(index) {\n\tcapture_navigation_snapshot(index);\n\tstorage.set(NAVIGATION_SNAPSHOT_KEY, navigation_snapshots);\n}\n\n/**\n * @param {string | undefined} stack\n * @returns {string}\n */\nfunction callsite_id(stack) {\n\tlet frames = stack?.split('\\n') ?? [];\n\tif (frames[0]?.trim() === 'Error') frames = frames.slice(1);\n\n\t// only the callsite frame is stable: frames above it differ between hydration and\n\t// re-mounting, and Vite query strings (stripped here) change on module invalidation\n\tconst frame = frames[1]?.replace(/\\?[^)\\s]*(?=:\\d+:\\d+\\)?$)/, '');\n\n\tif (!frame) {\n\t\tthrow new Error('Could not generate a snapshot id from the stack trace. Pass an `id` instead.');\n\t}\n\n\treturn hash(frame);\n}\n\n/**\n * A lifecycle function that captures state before navigating and restores it when traversing history.\n *\n * By default, the snapshot `id` is generated from the call site. Pass an explicit `id` to keep snapshots stable across deployments or distinguish multiple uses of a shared helper.\n *\n * The optional `reset` callback runs on navigations where there is no captured value to restore, such as when a new history entry is created. Captured values are serialized with the app's transport hook.\n *\n * `snapshot` must be called during a component initialization. It remains active as long as the component is mounted.\n * @template T\n * @param {{ id?: string; capture: () => T; restore: (value: T) => void; reset?: () => void }} options\n * @returns {void}\n */\nexport function snapshot(options) {","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/runtime/client/snapshots.js#L71-L107","documentation":"snapshot() derives a stable id from the component's callsite stack trace when no explicit id is given. If the callsite frame cannot be extracted (frames[1] missing or empty after stripping Vite query strings), the library cannot build a stable snapshot id and throws, telling you to pass an explicit id.","triggerScenarios":"Calling snapshot() in an environment where stack traces are unavailable or rewritten (minified production builds without the callsite frame, custom error-stack handling, wrappers that consume the frame, exotic runtimes).","commonSituations":"Production minification mangling stack frames; running inside server-side rendering contexts or wrappers that shift the frame layout; non-V8 engines producing differently formatted stacks.","solutions":["Pass an explicit id: snapshot({ id: 'my-snapshot' }) instead of relying on callsite inference.","Ensure the component calls snapshot() directly at a stable callsite rather than through deep wrappers in production builds.","Verify your build pipeline does not strip or rewrite Error stack frames."],"exampleFix":"// before\nconst snap = snapshot();\n// after\nconst snap = snapshot({ id: 'user-preferences' });","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass an explicit id to snapshot() in code that runs in production/minified builds.","Avoid wrapping snapshot() in layers that obscure the callsite.","Test snapshot usage against a production build, not just dev."],"tags":["snapshots","stack-trace","build-pipeline"],"backgroundTag":"snapshot-id-generation-failed","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}