Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

svelte:element with static attributes and content gets compiled to innerHTML without tag name substitution #7937

Closed
ramonsnir opened this issue Oct 13, 2022 · 1 comment · Fixed by #7938

Comments

@ramonsnir
Copy link
Contributor

Describe the bug

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:element this="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:

<svelte:element this="slot" name="empty">{''}</svelte:element>

I intend to submit (my first) PR to fix this issue.

Related PRs:

Reproduction

See this REPL: https://svelte.dev/repl/d81915a399ff40dab45e4f00c17ce9b8?version=3.51.0

Logs

No response

System Info

N/A

Severity

annoyance

@ramonsnir 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
add optimization of static <svelte:element> and fix a bug
@Conduitry
Copy link
Member

This should be fixed in 3.55.1 - https://svelte.dev/repl/d81915a399ff40dab45e4f00c17ce9b8?version=3.55.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants