diff --git a/.changeset/healthy-experts-worry.md b/.changeset/healthy-experts-worry.md new file mode 100644 index 000000000..901f0d971 --- /dev/null +++ b/.changeset/healthy-experts-worry.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix fallback content showing unexpectedly in some cases diff --git a/packages/astro/src/runtime/server/render/slot.ts b/packages/astro/src/runtime/server/render/slot.ts index afc956002..0cd477322 100644 --- a/packages/astro/src/runtime/server/render/slot.ts +++ b/packages/astro/src/runtime/server/render/slot.ts @@ -35,7 +35,7 @@ export async function* renderSlot( yield* iterator; } - if (fallback) { + if (fallback && !slotted) { yield* renderSlot(result, fallback); } } diff --git a/packages/astro/test/astro-slots.test.js b/packages/astro/test/astro-slots.test.js index db0d8d338..10422d745 100644 --- a/packages/astro/test/astro-slots.test.js +++ b/packages/astro/test/astro-slots.test.js @@ -52,6 +52,7 @@ describe('Slots', () => { const $ = cheerio.load(html); expect($('#override')).to.have.lengthOf(1); + expect($('#fallback-2').text()).to.equal('Slotty slot.'); }); it('Slots work with multiple elements', async () => { diff --git a/packages/astro/test/fixtures/astro-slots/src/components/Fallback2.astro b/packages/astro/test/fixtures/astro-slots/src/components/Fallback2.astro new file mode 100644 index 000000000..d03807053 --- /dev/null +++ b/packages/astro/test/fixtures/astro-slots/src/components/Fallback2.astro @@ -0,0 +1,2 @@ + +