From 76dd53e3f69d596754795710a457a1e570a3bad4 Mon Sep 17 00:00:00 2001 From: Happydev <81974850+MoustaphaDev@users.noreply.github.com> Date: Wed, 12 Apr 2023 12:23:14 +0000 Subject: [PATCH] Fix slot fallbacks unexpectedly showing up in some cases (#6819) * test: add test fixture * test: add test case * test: revert unneeded changes in fixture * fix * chore: changeset --- .changeset/healthy-experts-worry.md | 5 +++++ packages/astro/src/runtime/server/render/slot.ts | 2 +- packages/astro/test/astro-slots.test.js | 1 + .../test/fixtures/astro-slots/src/components/Fallback2.astro | 2 ++ .../fixtures/astro-slots/src/pages/fallback-override.astro | 2 ++ 5 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 .changeset/healthy-experts-worry.md create mode 100644 packages/astro/test/fixtures/astro-slots/src/components/Fallback2.astro 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 @@ + +