Enable createRawSnippet()
to return a document fragment
#13566
rikschennink
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently
createRawSnippet
requires you to return a root element, but that means it cannot be used in the same manner as the manually typed out snippet, see this example.Is there a way to return a document fragment? Perhaps if you leave out the
render()
function it could return a document fragment as target? Or if you don't supply a single root element in therender()
function it could automatically wrap your root elements in a fragment?Use case
I'm dynamically building a UI with Svelte, the UI is defined in a JSON object, it describes a tree of nodes (components, html elements, texts).
While I can define children dynamically, if I want to dynamically build slots it seems there's no way to do that apart from inserting an additional node per slot (as
createRawSnippet
requires you to return a root element inreander()
).So I can dynamically create a component like this:
But if that dynamic component has slots I can't set snippets to the slots without writing out all the slots manually
{#snippet mySlot()}
which is not possible as I'm dynamically building the UI.I can pass the snippets as
props
withcreateRawSnippet
but that results in the extra root element per snippet. The linked example shows the extra root element isn't required when manually defining snippets.Beta Was this translation helpful? Give feedback.
All reactions