From e4a6462751725878bfe47632eeafa6854cad5bf2 Mon Sep 17 00:00:00 2001 From: firefoxic Date: Tue, 19 Mar 2024 17:51:08 +0300 Subject: [PATCH] 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> --- .changeset/thick-games-thank.md | 5 +++++ packages/astro/src/runtime/server/render/util.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/thick-games-thank.md diff --git a/.changeset/thick-games-thank.md b/.changeset/thick-games-thank.md new file mode 100644 index 0000000000..868747003d --- /dev/null +++ b/.changeset/thick-games-thank.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +`` 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. diff --git a/packages/astro/src/runtime/server/render/util.ts b/packages/astro/src/runtime/server/render/util.ts index 52149a0319..484a8bbbb2 100644 --- a/packages/astro/src/runtime/server/render/util.ts +++ b/packages/astro/src/runtime/server/render/util.ts @@ -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}`; }