Skip to content

<!> is not valid XHTML regression in Svelte 5 #15799

Closed
@reckart

Description

@reckart

Describe the bug

Svelte 4 could be used on XHTML documents. With Svelte 5, this seems to be no longer the case.

One issue is that <!> is used as a hydration marker in Svelte 5.

HTML fragments containing this marker can then be passed to create_fragment_from_html in reconciler.js:

export function create_fragment_from_html(html) {
	var elem = document.createElement('template');
	elem.innerHTML = html;
	return elem.content;
}

This then fails when trying to assign the HTML fragment to the element.innerHTML with the error message that the fragment is not valid XML.

The only workaround I found was post-processing the generated JS file and replacing instances of <!> with <!---->. With this replacement, the code seems to work. However, having to post-process the generated JS file using string operations is a really bad hack.

I believe Svelte code should not use <!> but rather <!----> to be compatible with XHTML/XML environments in the same way that Svelte 4 was.

Reproduction

I don't think my report is vague.

Logs

System Info

System:
    OS: macOS 14.7.4
    CPU: (8) arm64 Apple M2
    Memory: 134.42 MB / 24.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.18.0 - ~/.nvm/versions/node/v18.18.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v18.18.0/bin/yarn
    npm: 9.8.1 - ~/.nvm/versions/node/v18.18.0/bin/npm
  Browsers:
    Chrome: 135.0.7049.96
  npmPackages:
    svelte: ^5.25.12 => 5.27.1

Severity

blocking an upgrade

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