Enable createRawSnippet()
to return a document fragment
#13566
Replies: 2 comments
-
Same issue I am running into today. I am building a dynamic grid of components with a limit and "See More" option. However, the The workaround now is:
Hide the useless However, a re-render will remove the hidden divs, leaving your mounted component in it's target, so you'll have to manually handle that. |
Beta Was this translation helpful? Give feedback.
-
Given that
It renders, but I do get the warning: |
Beta Was this translation helpful? Give feedback.
-
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