You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If an element has entirely static contents, Svelte compiles it to a simple component that uses innerHTML in c() that includes all of its static content. The bug occurs when <svelte:element /> is used without dynamic attributes and without dynamic content. We noticed this when creating an HTML slot (not Svelte slot) for a custom element that didn't have default content:
<svelte:elementthis="slot" name="empty" />
Svelte 3.51.0 compiles the parent of this element with div.innerHTML = '<svelte:element name="empty"></svelte:element>';, which is not the intended result (the final HTML should be <slot name="empty" />).
This is an annoyance and a pitfall. If the issue is known to the user, an easy workaround it to add content that seems dynamic:
ramonsnir
changed the title
svelte:element is not regarded as dynamic, so gets compiled to innerHTML if it has no dynamic content
svelte:element with static attributes and content gets compiled to innerHTML without tag name substitution
Oct 14, 2022
ramonsnir
added a commit
to ramonsnir/svelte
that referenced
this issue
Dec 4, 2022
Describe the bug
If an element has entirely static contents, Svelte compiles it to a simple component that uses
innerHTML
inc()
that includes all of its static content. The bug occurs when<svelte:element />
is used without dynamic attributes and without dynamic content. We noticed this when creating an HTML slot (not Svelte slot) for a custom element that didn't have default content:Svelte 3.51.0 compiles the parent of this element with
div.innerHTML = '<svelte:element name="empty"></svelte:element>';
, which is not the intended result (the final HTML should be<slot name="empty" />
).This is an annoyance and a pitfall. If the issue is known to the user, an easy workaround it to add content that seems dynamic:
I intend to submit (my first) PR to fix this issue.
Related PRs:
style:prop
wasn't regarded as dynamic)Reproduction
See this REPL: https://svelte.dev/repl/d81915a399ff40dab45e4f00c17ce9b8?version=3.51.0
Logs
No response
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: