{"record":{"id":"e8ee4f61dce9607e","repo":"sveltejs/svelte","slug":"svelte-element-invalid-this-value","errorCode":"svelte_element_invalid_this_value","errorMessage":"svelte_element_invalid_this_value\nThe `this` prop on `<svelte:element>` must be a string, if defined\nhttps://svelte.dev/e/svelte_element_invalid_this_value","messagePattern":"svelte_element_invalid_this_value\nThe `this` prop on `<svelte:element>` must be a string, if defined\nhttps://svelte\\.dev/e/svelte_element_invalid_this_value","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/svelte/src/internal/shared/errors.js","lineNumber":149,"sourceCode":"\t\tthrow error;\n\t} else {\n\t\tthrow new Error(`https://svelte.dev/e/store_invalid_shape`);\n\t}\n}\n\n/**\n * The `this` prop on `<svelte:element>` must be a string, if defined\n * @returns {never}\n */\nexport function svelte_element_invalid_this_value() {\n\tif (DEV) {\n\t\tconst error = new Error(`svelte_element_invalid_this_value\\nThe \\`this\\` prop on \\`<svelte:element>\\` must be a string, if defined\\nhttps://svelte.dev/e/svelte_element_invalid_this_value`);\n\n\t\terror.name = 'Svelte error';\n\n\t\tthrow error;\n\t} else {\n\t\tthrow new Error(`https://svelte.dev/e/svelte_element_invalid_this_value`);\n\t}\n}","sourceCodeStart":131,"sourceCodeEnd":151,"githubUrl":"https://github.com/sveltejs/svelte/blob/20b341f10048cf1016a2028ac7eee5595cfef6a5/packages/svelte/src/internal/shared/errors.js#L131-L151","documentation":"`<svelte:element this={...}>` dynamically renders an HTML element; the `this` prop must be a tag-name string (e.g. `'div'`, `'span'`) when defined. If `this` is a non-string (number, object, function) and not `null`/`undefined`, Svelte throws. `null`/`undefined` means 'render nothing', which is allowed.","triggerScenarios":"Binding `this` to a non-string value — a component reference, a number, or an object; computing `this` from unvalidated user/API input without coercing to a string.","commonSituations":"Dynamic tag rendering where the tag variable is mis-typed; passing a component constructor instead of a tag name; data-driven UI where the tag comes from unvalidated input.","solutions":["Ensure `this` is a string tag name or `null`/`undefined`.","Coerce or validate: `this={typeof tag === 'string' ? tag : null}`.","If you meant to render a component, use dynamic component syntax (Svelte 5) instead of `svelte:element`."],"exampleFix":"<!-- before -->\n<svelte:element this={tag}>...</svelte:element> <!-- tag is a number/object -->\n<!-- after -->\n<svelte:element this={typeof tag === 'string' ? tag : null}>...</svelte:element>","handlingStrategy":"type-guard","validationCode":"if (tag != null && typeof tag !== 'string') {\n\tthrow new Error('svelte:element this must be a string tag name or null');\n}","typeGuard":"function isValidThisTag(v) {\n\treturn v == null || typeof v === 'string';\n}","tryCatchPattern":null,"preventionTips":["Validate `this` is a string tag name or null/undefined.","Coerce API-driven tag names with `typeof tag === 'string' ? tag : null`.","Use dynamic component syntax for component references, not `svelte:element`.","Treat unvalidated input as untrusted before binding to `this`."],"tags":["svelte-element","this-prop","dynamic-tag","dom","validation"],"backgroundTag":null,"analyzedSha":"20b341f10048cf1016a2028ac7eee5595cfef6a5","analyzedAt":"2026-08-12T23:37:30.399Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}