Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix slot fallbacks unexpectedly showing up in some cases #6819

Merged
merged 6 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/healthy-experts-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fix fallback content showing unexpectedly in some cases
2 changes: 1 addition & 1 deletion packages/astro/src/runtime/server/render/slot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export async function* renderSlot(
yield* iterator;
}

if (fallback) {
if (fallback && !slotted) {
MoustaphaDev marked this conversation as resolved.
Show resolved Hide resolved
yield* renderSlot(result, fallback);
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/astro/test/astro-slots.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
import Fallback from '../components/Fallback.astro';
import Fallback2 from '../components/Fallback2.astro';
---

<html>
Expand All @@ -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>