Skip to content

Commit

Permalink
fix(rendering): prevent error when slots is keyed into (#9179)
Browse files Browse the repository at this point in the history
Co-authored-by: Nate Moore <[email protected]>
  • Loading branch information
lilnasy and natemoo-re authored Nov 29, 2023
1 parent 8f8a40e commit 3f28336
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/tall-hotels-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes an issue where the presence of a slot in a page led to an error.
2 changes: 1 addition & 1 deletion packages/astro/src/core/render/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export async function renderPage({ mod, renderContext, env, cookies }: RenderPag
result,
Component,
renderContext.props,
null,
{},
env.streaming,
renderContext.route
);
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/runtime/server/render/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function renderPage(
componentFactory.name,
componentFactory,
pageProps,
null,
{},
true,
route
);
Expand Down
9 changes: 8 additions & 1 deletion packages/astro/test/astro-slots.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,20 @@ describe('Slots', () => {
expect($('#default').text().trim()).to.equal('Default');
});

it('Slots render fallback content by default', async () => {
it('Slots of a component render fallback content by default', async () => {
const html = await fixture.readFile('/fallback/index.html');
const $ = cheerio.load(html);

expect($('#default')).to.have.lengthOf(1);
});

it('Slots of a page render fallback content', async () => {
const html = await fixture.readFile('/fallback-own/index.html');
const $ = cheerio.load(html);

expect($('#default')).to.have.lengthOf(1);
});

it('Slots override fallback content', async () => {
const html = await fixture.readFile('/fallback-override/index.html');
const $ = cheerio.load(html);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<html>
<head>
<!-- Head Stuff -->
</head>
<body>
<slot>
<div id="default"></div>
</slot>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import Fallback from '../components/Fallback.astro';
<!-- Head Stuff -->
</head>
<body>
<div id="fallback">
<Fallback />
</div>
<Fallback />
</body>
</html>

0 comments on commit 3f28336

Please sign in to comment.