Stop component crashing if children don't exist

This commit is contained in:
Andrew Kingston 2021-01-22 11:08:42 +00:00
parent 4188761ea6
commit 343687cbab
1 changed files with 7 additions and 3 deletions

View File

@ -21,7 +21,7 @@
// Extract component definition info
$: constructor = getComponentConstructor(definition._component)
$: children = definition._children
$: children = definition._children || []
$: id = definition._id
$: enrichComponentProps(definition, $dataContext, $bindingStore)
$: updateProps(enrichedProps)
@ -33,7 +33,11 @@
$builderStore.previewType === "layout" || screenslotContext
// Update component context
$: componentStore.set({ id, children: children.length, styles: { ...styles, id, allowSelection } })
$: componentStore.set({
id,
children: children.length,
styles: { ...styles, id, allowSelection },
})
// Updates the component props.
// Most props are deeply compared so that svelte will only trigger reactive
@ -78,7 +82,7 @@
{#if constructor && componentProps}
<svelte:component this={constructor} {...componentProps}>
{#if children && children.length}
{#if children.length}
{#each children as child (getChildKey(child._id))}
<svelte:self definition={child} />
{/each}