{"record":{"id":"3ce5bdde78c3f763","repo":"sveltejs/svelte","slug":"this-migration-would-change-the-name-of-a-slot","errorCode":null,"errorMessage":"This migration would change the name of a slot (${slot_name} to ${name}) making the component unusable","messagePattern":"This migration would change the name of a slot \\((.+?) to (.+?)\\) making the component unusable","errorType":"exception","errorClass":"MigrationError","httpStatus":null,"severity":"warning","filePath":"packages/svelte/src/compiler/migrate/index.js","lineNumber":1315,"sourceCode":"\t\t\t\t\t\t\t.toString();\n\t\t\t\t\t}\n\t\t\t\t\tslot_props += value === attr.name ? `${value}, ` : `${attr.name}: ${value}, `;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tslot_props += '}';\n\t\tif (slot_props === '{ }') {\n\t\t\tslot_props = '';\n\t\t}\n\n\t\tconst existing_prop = state.props.find((prop) => prop.slot_name === slot_name);\n\t\tif (existing_prop) {\n\t\t\tname = existing_prop.local;\n\t\t} else if (slot_name !== 'default') {\n\t\t\tname = state.scope.generate(slot_name);\n\t\t\tif (name !== slot_name) {\n\t\t\t\tthrow new MigrationError(\n\t\t\t\t\t`This migration would change the name of a slot (${slot_name} to ${name}) making the component unusable`\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (!existing_prop) {\n\t\t\tstate.props.push({\n\t\t\t\tlocal: name,\n\t\t\t\texported: name,\n\t\t\t\tinit: '',\n\t\t\t\tbindable: false,\n\t\t\t\toptional: true,\n\t\t\t\tslot_name,\n\t\t\t\ttype: `import('svelte').${slot_props ? 'Snippet<[any]>' : 'Snippet'}`\n\t\t\t});\n\t\t} else if (existing_prop.needs_refine_type) {\n\t\t\texisting_prop.type = `import('svelte').${slot_props ? 'Snippet<[any]>' : 'Snippet'}`;\n\t\t\texisting_prop.needs_refine_type = false;","sourceCodeStart":1297,"sourceCodeEnd":1333,"githubUrl":"https://github.com/sveltejs/svelte/blob/20b341f10048cf1016a2028ac7eee5595cfef6a5/packages/svelte/src/compiler/migrate/index.js#L1297-L1333","documentation":"Thrown when migrating a named `<slot>` to a snippet prop would require renaming the slot (because `state.scope.generate(slot_name)` returns a different identifier than the original slot name, meaning that name is already taken in scope). Renaming would silently break consumers that pass that slot name, so the codemod refuses. Only applies to non-default slots.","triggerScenarios":"Running `migrate()` on a Svelte 4 component that declares a named slot (e.g. `<slot name=\"header\"/>`) whose name collides with an existing in-scope identifier, forcing `scope.generate()` to deduplicate it (e.g. `header` → `header_1`).","commonSituations":"Components with slots named identically to other locals — e.g. a `header` slot in a component that also imports or declares `header`. More likely after partial migration where snippet props already occupy the name.","solutions":["Rename the colliding local identifier so the slot name can be preserved, then re-run migrate.","Migrate the file by hand and rename both the slot usage and all consumer call sites consistently.","Rename the slot itself (updating all consumers) before migrating."],"exampleFix":"// before\n<script>\n  let header = 'x';\n</script>\n<slot name=\"header\" />\n\n<!-- consumer -->\n<Comp>\n  <template #header>...</template>\n</Comp>\n\n<!-- after (manual: rename the local so the slot keeps its name) -->\n<script>\n  let headerValue = 'x';\n</script>\n{@render header()}","handlingStrategy":"validation","validationCode":"// Detect named slots whose names collide with in-scope identifiers.\nfunction namedSlotCollisions(source) {\n  const slots = [...source.matchAll(/<slot\\s+name=[\"']([\\w-]+)[\"']/g)].map(m => m[1]);\n  const idents = [...source.matchAll(/\\b(?:let|const|var|function|import)\\s+([\\w$]+)/g)].map(m => m[1]);\n  return slots.filter(s => idents.includes(s));\n}\nconst collisions = namedSlotCollisions(componentSource);\nif (collisions.length) { /* rename one side */ }","typeGuard":null,"tryCatchPattern":"const { code } = migrate({ filename, source });\nif (code.startsWith('<!-- @migration-task') && /migration would change the name of a slot/i.test(code)) {\n  // rename the colliding identifier or hand-migrate the slot to a snippet prop\n}","preventionTips":["Keep slot names distinct from component-local identifiers.","When adopting snippets early, reserve slot names as prop names to avoid future collisions.","Audit named slots before migrating components that have many locals."],"tags":["svelte5","migration","slots","snippets","naming-collision","codemod"],"backgroundTag":null,"analyzedSha":"20b341f10048cf1016a2028ac7eee5595cfef6a5","analyzedAt":"2026-08-12T23:37:30.399Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}