Performance: HTML rendering with {@html}
This affects how quickly the browser can render dynamic HTML content and impacts layout stability and interaction responsiveness.
<div>{#if safeHtml}<div>{@html safeHtml}</div>{/if}</div><div>{@html dynamicHtml}</div>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Direct {@html} injection without control | Inserts raw nodes dynamically | Multiple reflows if content changes | High paint cost due to layout shifts | [X] Bad |
| Conditional rendering with sanitized HTML | Controlled DOM insertion | Single or no reflows if stable | Lower paint cost with stable layout | [OK] Good |
{@html} tag do in a Svelte component?htmlContent inside a Svelte component?<div>{htmlContent}</div> renders as plain text, B uses invalid parentheses, D uses wrong block syntax. <script>
let htmlString = '<strong>Hello</strong> <em>World</em>';
</script>
<div>{@html htmlString}</div> <script>
let unsafeHtml = '';
</script>
<div>{@html unsafeHtml}</div>Pass the test and this pattern moves unknown