Only apply head propagation in trees that need it (#6363)
This commit is contained in:
parent
c87c16cfad
commit
d94aae7765
6 changed files with 51 additions and 4 deletions
5
.changeset/orange-cheetahs-hide.md
Normal file
5
.changeset/orange-cheetahs-hide.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fixes cases where head is injected in body when using Astro.slots.render()
|
|
@ -92,11 +92,11 @@ export function astroHeadPropagationBuildPlugin(
|
|||
for (const [info] of walkParentInfos(id, this)) {
|
||||
appendPropagation(info);
|
||||
}
|
||||
}
|
||||
|
||||
const info = this.getModuleInfo(id);
|
||||
if (info) {
|
||||
appendPropagation(info);
|
||||
const info = this.getModuleInfo(id);
|
||||
if (info) {
|
||||
appendPropagation(info);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
10
packages/astro/test/fixtures/head-injection/src/components/with-slot-render2/inner.astro
vendored
Normal file
10
packages/astro/test/fixtures/head-injection/src/components/with-slot-render2/inner.astro
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
---
|
||||
|
||||
<p>View link tag position</p>
|
||||
|
||||
<style>
|
||||
p {
|
||||
background: red;
|
||||
}
|
||||
</style>
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
const content = await Astro.slots.render('default')
|
||||
---
|
||||
|
||||
<Fragment set:html={content} />
|
19
packages/astro/test/fixtures/head-injection/src/pages/with-slot-render2.astro
vendored
Normal file
19
packages/astro/test/fixtures/head-injection/src/pages/with-slot-render2.astro
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
---
|
||||
import Inner from '../components/with-slot-render2/inner.astro'
|
||||
import SlotsRenderOuter from '../components/with-slot-render2/slots-render-outer.astro'
|
||||
---
|
||||
|
||||
<html lang='en'>
|
||||
<head>
|
||||
<meta charset='utf-8' />
|
||||
<link rel='icon' type='image/svg+xml' href='/favicon.svg' />
|
||||
<meta name='viewport' content='width=device-width' />
|
||||
<meta name='generator' content={Astro.generator} />
|
||||
<title>Astro</title>
|
||||
</head>
|
||||
<body>
|
||||
<SlotsRenderOuter>
|
||||
<Inner />
|
||||
</SlotsRenderOuter>
|
||||
</body>
|
||||
</html>
|
|
@ -58,6 +58,14 @@ describe('Head injection', () => {
|
|||
expect($('head link[rel=stylesheet]')).to.have.a.lengthOf(2);
|
||||
expect($('body link[rel=stylesheet]')).to.have.a.lengthOf(0);
|
||||
});
|
||||
|
||||
it('Using slots with Astro.slots.render() (layout)', async () => {
|
||||
const html = await fixture.readFile('/with-slot-render2/index.html');
|
||||
const $ = cheerio.load(html);
|
||||
|
||||
expect($('head link[rel=stylesheet]')).to.have.a.lengthOf(1);
|
||||
expect($('body link[rel=stylesheet]')).to.have.a.lengthOf(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue