Add back in support for children (#1486)
* Add back in support for children * Be more careful
This commit is contained in:
parent
21294f7e0b
commit
09038cd457
2 changed files with 5 additions and 12 deletions
|
@ -33,7 +33,7 @@ async function _render(child: any): Promise<any> {
|
||||||
// Special: If a child is a function, call it automatically.
|
// Special: If a child is a function, call it automatically.
|
||||||
// This lets you do {() => ...} without the extra boilerplate
|
// This lets you do {() => ...} without the extra boilerplate
|
||||||
// of wrapping it in a function and calling it.
|
// of wrapping it in a function and calling it.
|
||||||
return await child();
|
return _render(child());
|
||||||
} else if (typeof child === 'string') {
|
} else if (typeof child === 'string') {
|
||||||
return child;
|
return child;
|
||||||
} else if (!child && child !== 0) {
|
} 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<string | number, any>, slots?: any) {
|
export async function renderComponent(result: any, displayName: string, Component: unknown, _props: Record<string | number, any>, slots?: any) {
|
||||||
Component = await Component;
|
Component = await Component;
|
||||||
// children = await renderGenerator(children);
|
const children = await renderSlot(result, slots?.default);
|
||||||
const { renderers } = result._metadata;
|
const { renderers } = result._metadata;
|
||||||
|
|
||||||
if (Component && (Component as any).isAstroComponentFactory) {
|
if (Component && (Component as any).isAstroComponentFactory) {
|
||||||
|
@ -179,15 +179,15 @@ export async function renderComponent(result: any, displayName: string, Componen
|
||||||
|
|
||||||
let renderer = null;
|
let renderer = null;
|
||||||
for (const r of renderers) {
|
for (const r of renderers) {
|
||||||
if (await r.ssr.check(Component, props, null)) {
|
if (await r.ssr.check(Component, props, children)) {
|
||||||
renderer = r;
|
renderer = r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
({ html } = await renderer.ssr.renderToStaticMarkup(Component, props, null));
|
({ html } = await renderer.ssr.renderToStaticMarkup(Component, props, children));
|
||||||
|
|
||||||
if (!hydrationDirective) {
|
if (!hydrationDirective) {
|
||||||
return html;
|
return html.replace(/\<\/?astro-fragment\>/g, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
const astroId = shorthash.unique(html);
|
const astroId = shorthash.unique(html);
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
/**
|
|
||||||
* UNCOMMENT when Component slots lands in new compiler
|
|
||||||
|
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import cheerio from 'cheerio';
|
import cheerio from 'cheerio';
|
||||||
import { loadFixture } from './test-utils.js';
|
import { loadFixture } from './test-utils.js';
|
||||||
|
@ -15,7 +12,6 @@ before(async () => {
|
||||||
await fixture.build();
|
await fixture.build();
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: waiting on Component slots
|
|
||||||
describe('Component children', () => {
|
describe('Component children', () => {
|
||||||
it('Passes string children to framework components', async () => {
|
it('Passes string children to framework components', async () => {
|
||||||
const html = await fixture.readFile('/strings/index.html');
|
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');
|
expect($svelte.children(':last-child').text().trim()).to.equal('Goodbye world');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
*/
|
|
||||||
|
|
||||||
it.skip('is skipped', () => {});
|
|
||||||
|
|
Loading…
Reference in a new issue