diff options
author | 2023-04-12 12:23:14 +0000 | |
---|---|---|
committer | 2023-04-12 08:23:14 -0400 | |
commit | 76dd53e3f69d596754795710a457a1e570a3bad4 (patch) | |
tree | ca30ed8bb492a08a5dc0b09bf71eda166bf8485f | |
parent | bdfbe000d88d9bb425d4a856aaff5965d0eeae24 (diff) | |
download | astro-76dd53e3f69d596754795710a457a1e570a3bad4.tar.gz astro-76dd53e3f69d596754795710a457a1e570a3bad4.tar.zst astro-76dd53e3f69d596754795710a457a1e570a3bad4.zip |
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
5 files changed, 11 insertions, 1 deletions
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 @@ +<!-- note: to make testing easier this was inlined --> +<div id="fallback-2"><slot name="override-2">Fallback should only show when no slot has been provided.</slot></div>
\ No newline at end of file diff --git a/packages/astro/test/fixtures/astro-slots/src/pages/fallback-override.astro b/packages/astro/test/fixtures/astro-slots/src/pages/fallback-override.astro index 76389c36c..1563c81b7 100644 --- a/packages/astro/test/fixtures/astro-slots/src/pages/fallback-override.astro +++ b/packages/astro/test/fixtures/astro-slots/src/pages/fallback-override.astro @@ -1,5 +1,6 @@ --- import Fallback from '../components/Fallback.astro'; +import Fallback2 from '../components/Fallback2.astro'; --- <html> @@ -11,6 +12,7 @@ import Fallback from '../components/Fallback.astro'; <Fallback> <div id="override" /> </Fallback> + <Fallback2><div slot="override-2">Slotty slot.</div></Fallback2> </div> </body> </html> |