Skip to content

Commit

Permalink
fix: void elements (#10493)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
firefoxic and lilnasy authored Mar 19, 2024
1 parent ad57a02 commit e4a6462
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/thick-games-thank.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion packages/astro/src/runtime/server/render/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export function renderElement(
}
}
if ((children == null || children == '') && voidElementNames.test(name)) {
return `<${name}${internalSpreadAttributes(props, shouldEscape)} />`;
return `<${name}${internalSpreadAttributes(props, shouldEscape)}>`;
}
return `<${name}${internalSpreadAttributes(props, shouldEscape)}>${children}</${name}>`;
}
Expand Down

0 comments on commit e4a6462

Please sign in to comment.