Skip to content

Svelte 5: <p><span><div> compiles but doesn't render #10123

@ppvg

Description

@ppvg

Describe the bug

Given this markup:

<p><div>hi</div></p>

...svelte 4 would happily compile and even render this (REPL).

The svelte 5 compiler correctly considers this a syntax error and provides a helpful error message (REPL):

</p> attempted to close element that was already automatically closed by <div>

However, when adding another element in between the div and p, e.g. <p><span><div></div></span></p>, it compiles without error. The JS output includes:

var frag = $.template(`<p><span><div></div></span></p>`);

Reproduction

This compiles:

<p><span><div>hi</div></span></p>

...and, when rendered, results in <p><span></span></p> (REPL).

This also compiles:

<script>let hi = $state('hi');</script>
<p><span><div>{hi}</div></span></p>

...and, when rendered, results in a confusing TypeError (REPL):

'get firstChild' called on an object that does not implement interface Node.

System Info

System:
    OS: Linux 6.6 Fedora Linux 39 (KDE Plasma)
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 20.10.0
    npm: 10.2.3
    pnpm: 8.13.1
  npmPackages:
    svelte: 5.0.0-next.30 => 5.0.0-next.30

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