Skip to content

Conversation

@corrideat
Copy link

Closes #16540
Follow up to a86e52b

This PR adds support for using Svelte in XHTML and XML documents by:

  1. Producing XML-compliant output for boolean attributes (e.g., required becomes required="")
  2. Using proper namespace checks for uses of tagName / nodeName, as well as ensuring that the values have the correct case.
  3. Replaces use of document.createElement with document.createElementNS, defaulting to the HTML namespace. This ensures that even documents loaded in pure XML mode (e.g., index.xml, as opposed to index.xhtml) will work correctly.

@changeset-bot
Copy link

changeset-bot bot commented Jan 4, 2026

🦋 Changeset detected

Latest commit: c11d75a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Jan 4, 2026

Playground

pnpm add https://pkg.pr.new/svelte@17418

@7nik
Copy link
Contributor

7nik commented Jan 4, 2026

What is the point of running Svelte on XML pages? It introduces checks and uppercasing which are wasteful for 99.9999999% of users.
Generating XML pages with Svelte is ok and does not require these changes.

@corrideat
Copy link
Author

corrideat commented Jan 4, 2026

Generating XML pages with Svelte is ok and does not require these changes.

Is it, though? It looks like it requires at least the changes to template.js (or similar changes) so that boolean attributes have a value.

It introduces checks and uppercasing which are wasteful for 99.9999999% of users.

The element.namespaceURI === NAMESPACE_HTML mostly are there for correctness and could probably (*) be removed. The point about wasteful uppercasing is valid, but it seemed like a pretty minor concern, considering that uppercasing is almost free, and that it's only done in a few places.

(*) Meaning, the check isn't necessary for the purposes of this PR the same way uppercasing is. If it's certain that elements won't have another namespace, the check is redundant.

What is the point of running Svelte on XML pages?

Is this question about documents served as text/xml or with the .xml extension (from file://), or is it about documents served as application/xhtml+xml or with the .xhtml extension? (Or possibly both?)

If it's regarding XHTML, it's IMHO a valid use-case for the framework, and one that didn't seem too hard to support. To support this, two changes were needed: the change in template.js (critical) and the uppercasing of .tagName / .nodeName (less critical but necessary).

If it's regarding XML, the answer is less clear, as probably using the correct file type would be preferred. However, again it didn't seem too hard to support (basically, just using createElementNS) and did in fact result in simplifying the code.

@corrideat corrideat force-pushed the xhtml branch 2 times, most recently from 4f1a6d5 to 8d8de65 Compare January 4, 2026 20:53
@7nik
Copy link
Contributor

7nik commented Jan 4, 2026

Generating XML pages with Svelte is ok and does not require these changes.

Is it, though?

Under "these" I meant the mentioned changes.

If it's regarding XML, the answer is less clear, as probably using the correct file type would be preferred. However, again it didn't seem too hard to support (basically, just using createElementNS) and did in fact result in simplifying the code.

I think the user just should set the correct file/content type.
It's funny that I found an example of XHTML page, but due to Content-Type: text/html is was rendered as HTML5 😆

Also, you should add to the code comments that those operations are needed for XHTML compliance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Boolean attributes break in XML syntax

2 participants