You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When building for production, <img> elements are emitted without the closing /. Note that this applies only to situations where the compiler chooses to insert them into the DOM using innerHTML.
Logs
Chrome:
Uncaught (in promise) DOMException: Failed to set the 'innerHTML' property on 'Element': The provided markup is invalid XML, and therefore cannot be inserted into an XML document.
Safari (far less useful):
Unhandled Promise Rejection: SyntaxError: The string did not match the expected pattern.
To Reproduce
First, you'll need to create a fresh Svelte project and adapt it to support XHTML. The easiest way I've found to do the latter is to convert your public/index.html file to valid XHTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><head><metacharset='utf-8'/><metaname='viewport' content='width=device-width,initial-scale=1'/><title>Repro</title><linkrel='icon' type='image/png' href='./favicon.png'/><linkrel='stylesheet' href='./global.css'/><linkrel='stylesheet' href='./build/bundle.css'/><scriptdefersrc='/build/bundle.js'></script></head><bodyclass="hbbtv-viewport"></body></html>
... next, create a symlink named public/index.xhtml file that points to public/index.html:
ln -s public/index.html public/index.xhtml
Now insert the following code into src/App.svelte:
You'll find that although the development build is fine, the production build will minify it to something along the lines of this (when pretty-printed):
Production builds should emit XHTML-valid components just like dev builds do. That is to say, the trailing / shouldn't be removed from the <img> component.
It would be acceptable to implement XHTML support as a configuration flag in Svelte, of course. Because it would increase build sizes for non-XHTML projects.
Stacktraces
See "logs" section above for the important part of the stack trace.
Information about your Svelte project:
Your browser and the version: Safari 13.1.2; Chrome 84.0.4147.135.
Your operating system: macOS 10.15.6
Svelte version 3.24.1
Whether your project uses Webpack or Rollup: Rollup
Severity
It took many hours to track down the cause of the error (Safari's error message did not indicate it was an XML issue at all), but it is not a total blocker, as a workaround is perfectly possible:
By introducing a dependency on the <script> above, the compiler instead inserts the <img> element uses DOM operations like document.createElement('img') (which don't need to worry about XHTML validity) rather than setting innerHTML (which does require valid markup).
Additional context
From user Rainlife on the Svelte Discord (#svelte):
are to blame, they define which elements are 'void', this method is then used in Element.ts to render them differently or something. Can't think of any workaround there, but maybe if you post in #internals or make a Github issue one of the maintainers can give a more comprehensive answer
The text was updated successfully, but these errors were encountered:
Describe the bug
When building for production,
<img>
elements are emitted without the closing/
. Note that this applies only to situations where the compiler chooses to insert them into the DOM usinginnerHTML
.Logs
Chrome:
Safari (far less useful):
To Reproduce
First, you'll need to create a fresh Svelte project and adapt it to support XHTML. The easiest way I've found to do the latter is to convert your
public/index.html
file to valid XHTML:... next, create a symlink named
public/index.xhtml
file that points topublic/index.html
:Now insert the following code into
src/App.svelte
:You'll find that although the development build is fine, the production build will minify it to something along the lines of this (when pretty-printed):
Note how the closing
/
is removed from the img element when setting theinnerHTML
. This is what causes the XHTML syntax error.If you visit http://localhost:5000/index.xhtml, you will see the error reproduce.
Expected behavior
Production builds should emit XHTML-valid components just like dev builds do. That is to say, the trailing
/
shouldn't be removed from the<img>
component.It would be acceptable to implement XHTML support as a configuration flag in Svelte, of course. Because it would increase build sizes for non-XHTML projects.
Stacktraces
See "logs" section above for the important part of the stack trace.
Information about your Svelte project:
Your browser and the version: Safari 13.1.2; Chrome 84.0.4147.135.
Your operating system: macOS 10.15.6
Svelte version 3.24.1
Whether your project uses Webpack or Rollup: Rollup
Severity
It took many hours to track down the cause of the error (Safari's error message did not indicate it was an XML issue at all), but it is not a total blocker, as a workaround is perfectly possible:
By introducing a dependency on the
<script>
above, the compiler instead inserts the<img>
element uses DOM operations likedocument.createElement('img')
(which don't need to worry about XHTML validity) rather than settinginnerHTML
(which does require valid markup).Additional context
From user Rainlife on the Svelte Discord (
#svelte
):The text was updated successfully, but these errors were encountered: