From d41540cc772c7003a73cc5971598e5dd1255cbc9 Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Thu, 2 Jun 2022 13:03:37 -0500 Subject: [PATCH] Fix `` tag not being self-closing (#3506) * fix(#392): ensure link tags are rendered as void elements * test: ensure html does not include a `` end tag * chore: add changeset --- .changeset/new-knives-raise.md | 5 +++++ packages/astro/src/runtime/server/index.ts | 3 +++ packages/astro/test/0-css.test.js | 7 ++++++- 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 .changeset/new-knives-raise.md diff --git a/.changeset/new-knives-raise.md b/.changeset/new-knives-raise.md new file mode 100644 index 000000000..7d1fd490a --- /dev/null +++ b/.changeset/new-knives-raise.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix issue where generated `link` tags would have an invalid closing tag diff --git a/packages/astro/src/runtime/server/index.ts b/packages/astro/src/runtime/server/index.ts index e3c280642..0892f2227 100644 --- a/packages/astro/src/runtime/server/index.ts +++ b/packages/astro/src/runtime/server/index.ts @@ -715,5 +715,8 @@ function renderElement( children = defineScriptVars(defineVars) + '\n' + children; } } + if ((children == null || children == '') && voidElementNames.test(name)) { + return `<${name}${internalSpreadAttributes(props, shouldEscape)} />`; + } return `<${name}${internalSpreadAttributes(props, shouldEscape)}>${children}`; } diff --git a/packages/astro/test/0-css.test.js b/packages/astro/test/0-css.test.js index 3d91b6135..63e6bfe67 100644 --- a/packages/astro/test/0-css.test.js +++ b/packages/astro/test/0-css.test.js @@ -18,6 +18,7 @@ describe('CSS', function () { // test HTML and CSS contents for accuracy describe('build', () => { let $; + let html; let bundledCSS; before(async () => { @@ -25,7 +26,7 @@ describe('CSS', function () { await fixture.build(); // get bundled CSS (will be hashed, hence DOM query) - const html = await fixture.readFile('/index.html'); + html = await fixture.readFile('/index.html'); $ = cheerio.load(html); const bundledCSSHREF = $('link[rel=stylesheet][href^=/assets/]').attr('href'); bundledCSS = (await fixture.readFile(bundledCSSHREF.replace(/^\/?/, '/'))) @@ -49,6 +50,10 @@ describe('CSS', function () { expect(bundledCSS).to.include(expected); }); + it('Generated link tags are void elements', async () => { + expect(html).to.not.include(""); + }); + it('No