diff --git a/.changeset/orange-cheetahs-hide.md b/.changeset/orange-cheetahs-hide.md new file mode 100644 index 000000000000..29d21173a8ac --- /dev/null +++ b/.changeset/orange-cheetahs-hide.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes cases where head is injected in body when using Astro.slots.render() diff --git a/packages/astro/src/vite-plugin-head-propagation/index.ts b/packages/astro/src/vite-plugin-head-propagation/index.ts index 93f5f5e79b4c..b17d5f382ef7 100644 --- a/packages/astro/src/vite-plugin-head-propagation/index.ts +++ b/packages/astro/src/vite-plugin-head-propagation/index.ts @@ -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); + } } } } diff --git a/packages/astro/test/fixtures/head-injection/src/components/with-slot-render2/inner.astro b/packages/astro/test/fixtures/head-injection/src/components/with-slot-render2/inner.astro new file mode 100644 index 000000000000..9af3df31d216 --- /dev/null +++ b/packages/astro/test/fixtures/head-injection/src/components/with-slot-render2/inner.astro @@ -0,0 +1,10 @@ +--- +--- + +
View link tag position
+ + diff --git a/packages/astro/test/fixtures/head-injection/src/components/with-slot-render2/slots-render-outer.astro b/packages/astro/test/fixtures/head-injection/src/components/with-slot-render2/slots-render-outer.astro new file mode 100644 index 000000000000..391b360cf6ca --- /dev/null +++ b/packages/astro/test/fixtures/head-injection/src/components/with-slot-render2/slots-render-outer.astro @@ -0,0 +1,5 @@ +--- +const content = await Astro.slots.render('default') +--- + +