From a2e0fc27d72498fde1273b23aefcfcee65c5077d Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Tue, 5 Oct 2021 13:50:53 -0400 Subject: [PATCH] Add back in support for children (#1486) * Add back in support for children * Be more careful --- packages/astro/src/internal/index.ts | 10 +++++----- packages/astro/test/astro-children.test.js | 7 ------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/packages/astro/src/internal/index.ts b/packages/astro/src/internal/index.ts index 067fe6c67..f000900de 100644 --- a/packages/astro/src/internal/index.ts +++ b/packages/astro/src/internal/index.ts @@ -33,7 +33,7 @@ async function _render(child: any): Promise { // Special: If a child is a function, call it automatically. // This lets you do {() => ...} without the extra boilerplate // of wrapping it in a function and calling it. - return await child(); + return _render(child()); } else if (typeof child === 'string') { return child; } else if (!child && child !== 0) { @@ -143,7 +143,7 @@ export async function renderSlot(result: any, slotted: string, fallback?: any) { export async function renderComponent(result: any, displayName: string, Component: unknown, _props: Record, slots?: any) { Component = await Component; - // children = await renderGenerator(children); + const children = await renderSlot(result, slots?.default); const { renderers } = result._metadata; if (Component && (Component as any).isAstroComponentFactory) { @@ -179,15 +179,15 @@ export async function renderComponent(result: any, displayName: string, Componen let renderer = null; for (const r of renderers) { - if (await r.ssr.check(Component, props, null)) { + if (await r.ssr.check(Component, props, children)) { renderer = r; } } - ({ html } = await renderer.ssr.renderToStaticMarkup(Component, props, null)); + ({ html } = await renderer.ssr.renderToStaticMarkup(Component, props, children)); if (!hydrationDirective) { - return html; + return html.replace(/\<\/?astro-fragment\>/g, ''); } const astroId = shorthash.unique(html); diff --git a/packages/astro/test/astro-children.test.js b/packages/astro/test/astro-children.test.js index 9bb18b0fc..840c3422e 100644 --- a/packages/astro/test/astro-children.test.js +++ b/packages/astro/test/astro-children.test.js @@ -1,6 +1,3 @@ -/** - * UNCOMMENT when Component slots lands in new compiler - import { expect } from 'chai'; import cheerio from 'cheerio'; import { loadFixture } from './test-utils.js'; @@ -15,7 +12,6 @@ before(async () => { await fixture.build(); }); -// TODO: waiting on Component slots describe('Component children', () => { it('Passes string children to framework components', async () => { const html = await fixture.readFile('/strings/index.html'); @@ -74,6 +70,3 @@ describe('Component children', () => { expect($svelte.children(':last-child').text().trim()).to.equal('Goodbye world'); }); }); -*/ - -it.skip('is skipped', () => {});