From 3f28336d9a52d7e4364d455ee3128d14d10a078a Mon Sep 17 00:00:00 2001 From: Arsh <69170106+lilnasy@users.noreply.github.com> Date: Wed, 29 Nov 2023 21:47:48 +0000 Subject: [PATCH] fix(rendering): prevent error when slots is keyed into (#9179) Co-authored-by: Nate Moore --- .changeset/tall-hotels-argue.md | 5 +++++ packages/astro/src/core/render/core.ts | 2 +- packages/astro/src/runtime/server/render/page.ts | 2 +- packages/astro/test/astro-slots.test.js | 9 ++++++++- .../fixtures/astro-slots/src/pages/fallback-own.astro | 10 ++++++++++ .../test/fixtures/astro-slots/src/pages/fallback.astro | 4 +--- 6 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 .changeset/tall-hotels-argue.md create mode 100644 packages/astro/test/fixtures/astro-slots/src/pages/fallback-own.astro diff --git a/.changeset/tall-hotels-argue.md b/.changeset/tall-hotels-argue.md new file mode 100644 index 0000000000..aaa5c84dd6 --- /dev/null +++ b/.changeset/tall-hotels-argue.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes an issue where the presence of a slot in a page led to an error. diff --git a/packages/astro/src/core/render/core.ts b/packages/astro/src/core/render/core.ts index ed9ea7fdbb..25271a94d6 100644 --- a/packages/astro/src/core/render/core.ts +++ b/packages/astro/src/core/render/core.ts @@ -76,7 +76,7 @@ export async function renderPage({ mod, renderContext, env, cookies }: RenderPag result, Component, renderContext.props, - null, + {}, env.streaming, renderContext.route ); diff --git a/packages/astro/src/runtime/server/render/page.ts b/packages/astro/src/runtime/server/render/page.ts index 8bc5366cfb..fbfe567a83 100644 --- a/packages/astro/src/runtime/server/render/page.ts +++ b/packages/astro/src/runtime/server/render/page.ts @@ -25,7 +25,7 @@ export async function renderPage( componentFactory.name, componentFactory, pageProps, - null, + {}, true, route ); diff --git a/packages/astro/test/astro-slots.test.js b/packages/astro/test/astro-slots.test.js index 34f1d82255..69a0025e1f 100644 --- a/packages/astro/test/astro-slots.test.js +++ b/packages/astro/test/astro-slots.test.js @@ -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); diff --git a/packages/astro/test/fixtures/astro-slots/src/pages/fallback-own.astro b/packages/astro/test/fixtures/astro-slots/src/pages/fallback-own.astro new file mode 100644 index 0000000000..89319f8b18 --- /dev/null +++ b/packages/astro/test/fixtures/astro-slots/src/pages/fallback-own.astro @@ -0,0 +1,10 @@ + + + + + + +
+
+ + diff --git a/packages/astro/test/fixtures/astro-slots/src/pages/fallback.astro b/packages/astro/test/fixtures/astro-slots/src/pages/fallback.astro index 88aba06e9f..aa1a479585 100644 --- a/packages/astro/test/fixtures/astro-slots/src/pages/fallback.astro +++ b/packages/astro/test/fixtures/astro-slots/src/pages/fallback.astro @@ -7,8 +7,6 @@ import Fallback from '../components/Fallback.astro'; -
- -
+