Fix <link>
tag not being self-closing (#3506)
* fix(#392): ensure link tags are rendered as void elements * test: ensure html does not include a `</link>` end tag * chore: add changeset
This commit is contained in:
parent
207f58d171
commit
d41540cc77
3 changed files with 14 additions and 1 deletions
5
.changeset/new-knives-raise.md
Normal file
5
.changeset/new-knives-raise.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fix issue where generated `link` tags would have an invalid closing tag
|
|
@ -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}</${name}>`;
|
||||
}
|
||||
|
|
|
@ -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("</link>");
|
||||
});
|
||||
|
||||
it('No <style> skips scoping', async () => {
|
||||
// Astro component without <style> should not include scoped class
|
||||
expect($('#no-scope').attr('class')).to.equal(undefined);
|
||||
|
|
Loading…
Reference in a new issue