{"record":{"id":"db7312e98413dd40","repo":"sveltejs/kit","slug":"snapshot-was-called-multiple-times-from-the-same","errorCode":null,"errorMessage":"snapshot() was called multiple times from the same call site. Pass a unique `id` to distinguish the instances.","messagePattern":"snapshot\\(\\) was called multiple times from the same call site\\. Pass a unique `id` to distinguish the instances\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/kit/src/runtime/client/snapshots.js","lineNumber":124,"sourceCode":" */\nexport function snapshot(options) {\n\tlet id = options.id;\n\tif (id === undefined) {\n\t\t// restore any lowered third-party limit, else every callsite collapses to one id\n\t\tconst limit = Error.stackTraceLimit;\n\t\tconst lowered = typeof limit === 'number' && limit < 3;\n\t\tif (lowered) Error.stackTraceLimit = 3;\n\t\tconst stack = new Error().stack;\n\t\tif (lowered) Error.stackTraceLimit = limit;\n\n\t\tid = callsite_id(stack);\n\t}\n\n\tconst registration = { ...options, id };\n\n\tonMount(() => {\n\t\tif (DEV && Array.from(snapshot_registrations).some((existing) => existing.id === id)) {\n\t\t\tthrow new Error(\n\t\t\t\toptions.id === undefined\n\t\t\t\t\t? 'snapshot() was called multiple times from the same call site. Pass a unique `id` to distinguish the instances.'\n\t\t\t\t\t: `A snapshot with id \"${options.id}\" is already registered. Pass a unique \\`id\\`.`\n\t\t\t);\n\t\t}\n\n\t\tconst index = get_idle_history_index();\n\t\tif (index !== null) {\n\t\t\tconst values = navigation_snapshots[index];\n\t\t\tif (values && Object.hasOwn(values, id)) {\n\t\t\t\tregistration.restore(parse(values[id]));\n\t\t\t}\n\t\t}\n\n\t\tsnapshot_registrations.add(registration);\n\n\t\treturn () => {\n\t\t\tsnapshot_registrations.delete(registration);","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/runtime/client/snapshots.js#L106-L142","documentation":"In dev mode, snapshot() registers each instance by id and throws if two live component instances register the same id. When the id was inferred from the callsite this means the same callsite rendered multiple snapshot() instances; when an explicit id was supplied the variant message names the duplicate id.","triggerScenarios":"Rendering multiple components (or one component type twice in a list) where each calls snapshot() at the same callsite without a unique id; re-mounting logic that registers twice.","commonSituations":"Using snapshot() inside an {#each} loop; rendering the same component in multiple slots; conditional rendering that keeps two instances alive simultaneously.","solutions":["Give each snapshot() call a unique id, composing it from loop indices or props: snapshot({ id: `item-${item.id}` }).","Move snapshot() into a child component so each instance has its own callsite.","If instances are truly transient, ensure only one is mounted at a time."],"exampleFix":"// before\n{#each items as item}\n  <Widget>{snapshot()}</Widget>\n{/each}\n// after\n{#each items as item}\n  <Widget>{snapshot({ id: `item-${item.id}` })}</Widget>\n{/each}","handlingStrategy":"validation","validationCode":"const seen = new Set();\nfunction uniqueSnapshotId(base) {\n  let id = base, n = 1;\n  while (seen.has(id)) id = `${base}-${n++}`;\n  seen.add(id);\n  return id;\n}\n// snapshot({ id: uniqueSnapshotId('widget') })","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never call snapshot() without an id inside {#each} loops or components rendered multiple times.","Compose ids from stable per-instance data (item.id, index).","Remember this check is DEV-only; duplicate ids still misbehave subtly in production."],"tags":["snapshots","duplicate-id","dev-only"],"backgroundTag":"duplicate-snapshot-registration","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}