sveltejs/kit · error
Could not generate a snapshot id from the stack trace. Pass
Error message
Could not generate a snapshot id from the stack trace. Pass an `id` instead.
What it means
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.
Source
Thrown at packages/kit/src/runtime/client/snapshots.js:89
export function persist_navigation_snapshots(index) {
capture_navigation_snapshot(index);
storage.set(NAVIGATION_SNAPSHOT_KEY, navigation_snapshots);
}
/**
* @param {string | undefined} stack
* @returns {string}
*/
function callsite_id(stack) {
let frames = stack?.split('\n') ?? [];
if (frames[0]?.trim() === 'Error') frames = frames.slice(1);
// only the callsite frame is stable: frames above it differ between hydration and
// re-mounting, and Vite query strings (stripped here) change on module invalidation
const frame = frames[1]?.replace(/\?[^)\s]*(?=:\d+:\d+\)?$)/, '');
if (!frame) {
throw new Error('Could not generate a snapshot id from the stack trace. Pass an `id` instead.');
}
return hash(frame);
}
/**
* A lifecycle function that captures state before navigating and restores it when traversing history.
*
* 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.
*
* 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.
*
* `snapshot` must be called during a component initialization. It remains active as long as the component is mounted.
* @template T
* @param {{ id?: string; capture: () => T; restore: (value: T) => void; reset?: () => void }} options
* @returns {void}
*/
export function snapshot(options) {View on GitHub (pinned to 03f1687fe6)
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.
Example fix
// before
const snap = snapshot();
// after
const snap = snapshot({ id: 'user-preferences' }); Defensive patterns
Strategy: fallback
Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/0f3fe396a5ae0da4.
Report an issue: GitHub.