[ci] format

This commit is contained in:
matthewp 2023-05-17 14:20:24 +00:00 committed by fredkbot
parent 3d525efc95
commit 34202616c2
6 changed files with 32 additions and 20 deletions

View file

@ -77,7 +77,7 @@ async function renderFrameworkComponent(
const { renderers, clientDirectives } = result._metadata; const { renderers, clientDirectives } = result._metadata;
const metadata: AstroComponentMetadata = { const metadata: AstroComponentMetadata = {
astroStaticSlot: true, astroStaticSlot: true,
displayName displayName,
}; };
const { hydration, isPage, props } = extractDirectives(_props, clientDirectives); const { hydration, isPage, props } = extractDirectives(_props, clientDirectives);
@ -273,7 +273,9 @@ If you're still stuck, please open an issue on GitHub or join us at https://astr
if (isPage || renderer?.name === 'astro:jsx') { if (isPage || renderer?.name === 'astro:jsx') {
yield html; yield html;
} else if (html && html.length > 0) { } else if (html && html.length > 0) {
yield markHTMLString(removeStaticAstroSlot(html, renderer?.ssr?.supportsAstroStaticSlot ?? false)); yield markHTMLString(
removeStaticAstroSlot(html, renderer?.ssr?.supportsAstroStaticSlot ?? false)
);
} else { } else {
yield ''; yield '';
} }
@ -298,8 +300,10 @@ If you're still stuck, please open an issue on GitHub or join us at https://astr
if (html) { if (html) {
if (Object.keys(children).length > 0) { if (Object.keys(children).length > 0) {
for (const key of Object.keys(children)) { for (const key of Object.keys(children)) {
let tagName = renderer?.ssr?.supportsAstroStaticSlot ? let tagName = renderer?.ssr?.supportsAstroStaticSlot
!!metadata.hydrate ? 'astro-slot' : 'astro-static-slot' ? !!metadata.hydrate
? 'astro-slot'
: 'astro-static-slot'
: 'astro-slot'; : 'astro-slot';
let expectedHTML = key === 'default' ? `<${tagName}>` : `<${tagName} name="${key}">`; let expectedHTML = key === 'default' ? `<${tagName}>` : `<${tagName} name="${key}">`;
if (!html.includes(expectedHTML)) { if (!html.includes(expectedHTML)) {

View file

@ -11,7 +11,7 @@ const slotName = (str: string) => str.trim().replace(/[-_]([a-z])/g, (_, w) => w
let originalConsoleError: typeof console.error; let originalConsoleError: typeof console.error;
let consoleFilterRefs = 0; let consoleFilterRefs = 0;
function check(this: RendererContext, Component: any, props: Record<string, any>, children: any, ) { function check(this: RendererContext, Component: any, props: Record<string, any>, children: any) {
if (typeof Component !== 'function') return false; if (typeof Component !== 'function') return false;
if (Component.prototype != null && typeof Component.prototype.render === 'function') { if (Component.prototype != null && typeof Component.prototype.render === 'function') {
@ -49,7 +49,7 @@ function renderToStaticMarkup(
Component: any, Component: any,
props: Record<string, any>, props: Record<string, any>,
{ default: children, ...slotted }: Record<string, any>, { default: children, ...slotted }: Record<string, any>,
metadata: AstroComponentMetadata | undefined, metadata: AstroComponentMetadata | undefined
) { ) {
const ctx = getContext(this.result); const ctx = getContext(this.result);
@ -59,7 +59,7 @@ function renderToStaticMarkup(
slots[name] = h(StaticHtml, { slots[name] = h(StaticHtml, {
hydrate: shouldHydrate(metadata), hydrate: shouldHydrate(metadata),
value, value,
name name,
}); });
} }
@ -72,9 +72,16 @@ function renderToStaticMarkup(
serializeSignals(ctx, props, attrs, propsMap); serializeSignals(ctx, props, attrs, propsMap);
const html = render( const html = render(
h(Component, newProps, children != null ? h(StaticHtml, { h(
Component,
newProps,
children != null
? h(StaticHtml, {
hydrate: shouldHydrate(metadata), hydrate: shouldHydrate(metadata),
value: children}) : children) value: children,
})
: children
)
); );
return { return {
attrs, attrs,

View file

@ -4,7 +4,7 @@ type Props = {
value: string; value: string;
name?: string; name?: string;
hydrate?: boolean; hydrate?: boolean;
} };
/** /**
* Astro passes `children` as a string of HTML, so we need * Astro passes `children` as a string of HTML, so we need

View file

@ -68,7 +68,7 @@ function renderToStaticMarkup(Component, props, { default: children, ...slotted
newProps.children = React.createElement(StaticHtml, { newProps.children = React.createElement(StaticHtml, {
// Adjust how this is hydrated only when the version of Astro supports `astroStaticSlot` // Adjust how this is hydrated only when the version of Astro supports `astroStaticSlot`
hydrate: metadata.astroStaticSlot ? !!metadata.hydrate : true, hydrate: metadata.astroStaticSlot ? !!metadata.hydrate : true,
value: newChildren value: newChildren,
}); });
} }
const vnode = React.createElement(Component, newProps); const vnode = React.createElement(Component, newProps);

View file

@ -77,7 +77,7 @@ async function renderToStaticMarkup(Component, props, { default: children, ...sl
slots[name] = React.createElement(StaticHtml, { slots[name] = React.createElement(StaticHtml, {
hydrate: needsHydration(metadata), hydrate: needsHydration(metadata),
value, value,
name name,
}); });
} }
// Note: create newProps to avoid mutating `props` before they are serialized // Note: create newProps to avoid mutating `props` before they are serialized
@ -89,7 +89,7 @@ async function renderToStaticMarkup(Component, props, { default: children, ...sl
if (newChildren != null) { if (newChildren != null) {
newProps.children = React.createElement(StaticHtml, { newProps.children = React.createElement(StaticHtml, {
hydrate: needsHydration(metadata), hydrate: needsHydration(metadata),
value: newChildren value: newChildren,
}); });
} }
const vnode = React.createElement(Component, newProps); const vnode = React.createElement(Component, newProps);

View file

@ -10,7 +10,8 @@ function check(Component) {
async function renderToStaticMarkup(Component, props, slotted, metadata) { async function renderToStaticMarkup(Component, props, slotted, metadata) {
const slots = {}; const slots = {};
for (const [key, value] of Object.entries(slotted)) { for (const [key, value] of Object.entries(slotted)) {
slots[key] = () => h(StaticHtml, { slots[key] = () =>
h(StaticHtml, {
value, value,
name: key === 'default' ? undefined : key, name: key === 'default' ? undefined : key,
// Adjust how this is hydrated only when the version of Astro supports `astroStaticSlot` // Adjust how this is hydrated only when the version of Astro supports `astroStaticSlot`