-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Incorrect validation for void svelte:element content presence #7566
Comments
I discussed this with the team when I create the previous PR. At that time we thought that we don't want to handle this. So now I close this issue. |
Thanks for looking at this @baseballyama. In my use case the app uses universal code to render an UI defined in a data structure (JSON) where I have various elements defined as data eg |
To create 1 wrapper component is not enough like below?. But if we need to create a lot of components due to this issue, I think we need to think about solving this issue. <!-- THIS IS JUST SAMPLE -->
<script>
export let tag = "input";
export let attrs = { value: 'bar' }
$: isVoidTag = ["area","base","br","col","command","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"].includes(tag);
</script>
{#if isVoidTag}
<svelte:element this="{tag}" {...attrs}></svelte:element>
{:else}
<svelte:element this="{tag}" {...attrs}>something</svelte:element>
{/if} |
@baseballyama I am going with what you suggested. The only main difference in my case is that my Example of one of my use cases:
I agree about the complexity around solving this problem at runtime. I also agree that no features added to Svelte should compromise it's performance. I was just wondering if there's perhaps a way to introduce a compiler option or a runtime switch (attribute of sorts) to turn the validator on/off. (behavior prior to the bug fix in 3.48). But if this is adding too much additional work to the team, I am ok with refactoring all my code and moving the above attributes template code to a function which I call with a spread operator. Some of the attributes will still remain inline - eg Lastly, I thought it's good to mention a bit more of my use case as I think that it is probably very different than most people's usage of svelte:element. The above markup is only used as a browser preview for users in and not intended as the final result. The tool I am building is a WYSWYG editor of sorts with export functionality. The end result is markup created by the export code (separate implementation from Svelte). This export code deals correctly with void tags markup, formatting and more. Thanks again for spending time on the above. I really appreciate it. |
@baseballyama I am also having this issue and it's particularly bad if you have multiple actions, event listeners and directives on the same element. I needed to refactor everything into one Svelte Action which is suboptimal. This is how it looked before: {#if isVoid(htmlBlockData.type)}
<svelte:element
this={htmlBlockData.type}
use:applyAttributes={htmlBlockData}
data-__id={htmlBlockData.__id}
on:mousemove|stopPropagation={() => setHoveredBlock(block)}
on:mouseleave|stopPropagation={() => setHoveredBlock(undefined)}
use:selectable
on:click|preventDefault|stopPropagation={() => selectBlock(block)}
class:__selected-frame={htmlBlockData === $selectedBlock}
/>
{:else}
<svelte:element
this={htmlBlockData.type}
use:applyAttributes={htmlBlockData}
data-__id={htmlBlockData.__id}
on:mousemove|stopPropagation={() => setHoveredBlock(block)}
on:mouseleave|stopPropagation={() => setHoveredBlock(undefined)}
use:selectable
on:click|preventDefault|stopPropagation={() => selectBlock(block)}
class:__selected-frame={htmlBlockData === $selectedBlock}
>
{#each htmlBlockData?.children ?? [] as id}
<svelte:self htmlBlockData={htmlBlockMap[id]} />
{/each}
</svelte:element>
{/if} |
I talked with the team, and we will consider how to handle it. |
Hey @baseballyama do you have an update for this issue? |
As of 3.51.0, this is now a runtime dev warning rather than an error - https://svelte.dev/repl/931558d3b0564db79064da1fedf0aa38?version=3.51.0 |
@baseballyama can we throw this warning only when there is actual content present. Right now I also get this warning when there is an |
I don't have a good idea to hundle it. I think there is workaround on userland isn't it? |
Describe the bug
with the fix for #7449 in 3.48.0 there was a new validation included which doesn't work correctly. The validation prevents content inside a void svelte:element and produces
<svelte:element this="input"> is self-closing and cannot have content.
if there is any content in the tag, including conditional ones, making it impossible to create universal code which dynamically contain content. For example this code is now considered invalid:although the above if statement will correctly not produce content.
Reproduction
See https://svelte.dev/repl/931558d3b0564db79064da1fedf0aa38?version=3.48.0 with a reproduced error.
Expected behavior - validation should either be optional or evaluate conditional content.
Current behavior - the fact that the content is not present is still considered as present.
Logs
No response
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: