Skip to content

Commit

Permalink
[ci] format
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp authored and astrobot-houston committed May 17, 2023
1 parent 3d525ef commit 3420261
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 20 deletions.
12 changes: 8 additions & 4 deletions packages/astro/src/runtime/server/render/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async function renderFrameworkComponent(
const { renderers, clientDirectives } = result._metadata;
const metadata: AstroComponentMetadata = {
astroStaticSlot: true,
displayName
displayName,
};

const { hydration, isPage, props } = extractDirectives(_props, clientDirectives);
Expand Down Expand Up @@ -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') {
yield html;
} else if (html && html.length > 0) {
yield markHTMLString(removeStaticAstroSlot(html, renderer?.ssr?.supportsAstroStaticSlot ?? false));
yield markHTMLString(
removeStaticAstroSlot(html, renderer?.ssr?.supportsAstroStaticSlot ?? false)
);
} else {
yield '';
}
Expand All @@ -298,8 +300,10 @@ If you're still stuck, please open an issue on GitHub or join us at https://astr
if (html) {
if (Object.keys(children).length > 0) {
for (const key of Object.keys(children)) {
let tagName = renderer?.ssr?.supportsAstroStaticSlot ?
!!metadata.hydrate ? 'astro-slot' : 'astro-static-slot'
let tagName = renderer?.ssr?.supportsAstroStaticSlot
? !!metadata.hydrate
? 'astro-slot'
: 'astro-static-slot'
: 'astro-slot';
let expectedHTML = key === 'default' ? `<${tagName}>` : `<${tagName} name="${key}">`;
if (!html.includes(expectedHTML)) {
Expand Down
19 changes: 13 additions & 6 deletions packages/integrations/preact/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const slotName = (str: string) => str.trim().replace(/[-_]([a-z])/g, (_, w) => w
let originalConsoleError: typeof console.error;
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 (Component.prototype != null && typeof Component.prototype.render === 'function') {
Expand Down Expand Up @@ -49,7 +49,7 @@ function renderToStaticMarkup(
Component: any,
props: Record<string, any>,
{ default: children, ...slotted }: Record<string, any>,
metadata: AstroComponentMetadata | undefined,
metadata: AstroComponentMetadata | undefined
) {
const ctx = getContext(this.result);

Expand All @@ -59,7 +59,7 @@ function renderToStaticMarkup(
slots[name] = h(StaticHtml, {
hydrate: shouldHydrate(metadata),
value,
name
name,
});
}

Expand All @@ -72,9 +72,16 @@ function renderToStaticMarkup(
serializeSignals(ctx, props, attrs, propsMap);

const html = render(
h(Component, newProps, children != null ? h(StaticHtml, {
hydrate: shouldHydrate(metadata),
value: children}) : children)
h(
Component,
newProps,
children != null
? h(StaticHtml, {
hydrate: shouldHydrate(metadata),
value: children,
})
: children
)
);
return {
attrs,
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/preact/src/static-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ type Props = {
value: string;
name?: string;
hydrate?: boolean;
}
};

/**
* Astro passes `children` as a string of HTML, so we need
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/react/server-v17.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function renderToStaticMarkup(Component, props, { default: children, ...slotted
newProps.children = React.createElement(StaticHtml, {
// Adjust how this is hydrated only when the version of Astro supports `astroStaticSlot`
hydrate: metadata.astroStaticSlot ? !!metadata.hydrate : true,
value: newChildren
value: newChildren,
});
}
const vnode = React.createElement(Component, newProps);
Expand Down
4 changes: 2 additions & 2 deletions packages/integrations/react/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async function renderToStaticMarkup(Component, props, { default: children, ...sl
slots[name] = React.createElement(StaticHtml, {
hydrate: needsHydration(metadata),
value,
name
name,
});
}
// Note: create newProps to avoid mutating `props` before they are serialized
Expand All @@ -89,7 +89,7 @@ async function renderToStaticMarkup(Component, props, { default: children, ...sl
if (newChildren != null) {
newProps.children = React.createElement(StaticHtml, {
hydrate: needsHydration(metadata),
value: newChildren
value: newChildren,
});
}
const vnode = React.createElement(Component, newProps);
Expand Down
13 changes: 7 additions & 6 deletions packages/integrations/vue/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ function check(Component) {
async function renderToStaticMarkup(Component, props, slotted, metadata) {
const slots = {};
for (const [key, value] of Object.entries(slotted)) {
slots[key] = () => h(StaticHtml, {
value,
name: key === 'default' ? undefined : key,
// Adjust how this is hydrated only when the version of Astro supports `astroStaticSlot`
hydrate: metadata.astroStaticSlot ? !!metadata.hydrate : true,
});
slots[key] = () =>
h(StaticHtml, {
value,
name: key === 'default' ? undefined : key,
// Adjust how this is hydrated only when the version of Astro supports `astroStaticSlot`
hydrate: metadata.astroStaticSlot ? !!metadata.hydrate : true,
});
}
const app = createSSRApp({ render: () => h(Component, props, slots) });
await setup(app);
Expand Down

0 comments on commit 3420261

Please sign in to comment.