0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

fix: void elements (#10493)

* Fix void elements

HTML is not XML. It doesn't have self-closing tags, it has void element tags that don't need closing slashes.

Now generated void elements (e.g. link with path to style file) do not pass validation, which can be easily fixed by simply removing two characters.

* Add changeset

* Apply suggestions from code review

---------

Co-authored-by: Arsh <69170106+lilnasy@users.noreply.github.com>
This commit is contained in:
firefoxic 2024-03-19 17:51:08 +03:00 committed by GitHub
parent ad57a02c33
commit e4a6462751
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
"astro": patch
---
`<link>` tags created by astro for optimized stylesheets now do not include the closing forward slash. This slash is optional for void elements such as link, but made some html validation fail.

View file

@ -144,7 +144,7 @@ export function renderElement(
} }
} }
if ((children == null || children == '') && voidElementNames.test(name)) { if ((children == null || children == '') && voidElementNames.test(name)) {
return `<${name}${internalSpreadAttributes(props, shouldEscape)} />`; return `<${name}${internalSpreadAttributes(props, shouldEscape)}>`;
} }
return `<${name}${internalSpreadAttributes(props, shouldEscape)}>${children}</${name}>`; return `<${name}${internalSpreadAttributes(props, shouldEscape)}>${children}</${name}>`;
} }