Skip to content

Cannot pass children prop to <svelte:element>Β #13900

@rChaoz

Description

@rChaoz

Describe the bug

I have a custom component where the user can choose the base element like so:

<script lang="ts" generics="T extends keyof SvelteHTMLElements = 'div'">
  import type { SvelteHTMLElements } from 'svelte/elements';

  type Props = SvelteHTMLElements[T] & {
    as?: T;
  };

  const { as = 'div' as T, ...rest }: Props = $props();
</script>

<svelte:element this={as} {...rest} />

I would expect that the children prop, if passed, is forwarded to the custom element. This does not happen, and I have to manually use a render tag inside the <svelte:element>. This is fine, as dynamic_void_element_content is a warning, not an error, but it would be nice if it didn't need to be done.

Reproduction

https://svelte.dev/playground/74a0f0b5d2a64a7d9eb0c1915a2cf458?version=5.1.1

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions