summaryrefslogtreecommitdiff
path: root/packages/integrations/solid/src/server.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/integrations/solid/src/server.ts')
-rw-r--r--packages/integrations/solid/src/server.ts53
1 files changed, 31 insertions, 22 deletions
diff --git a/packages/integrations/solid/src/server.ts b/packages/integrations/solid/src/server.ts
index bd50d8d77..a4626d752 100644
--- a/packages/integrations/solid/src/server.ts
+++ b/packages/integrations/solid/src/server.ts
@@ -1,6 +1,6 @@
-import type { RendererContext } from './types';
-import { renderToString, ssr, createComponent } from 'solid-js/web';
+import { createComponent, renderToString, ssr } from 'solid-js/web';
import { getContext, incrementId } from './context.js';
+import type { RendererContext } from './types';
const slotName = (str: string) => str.trim().replace(/[-_]([a-z])/g, (_, w) => w.toUpperCase());
@@ -10,32 +10,41 @@ function check(this: RendererContext, Component: any, props: Record<string, any>
return typeof html === 'string';
}
-function renderToStaticMarkup(this: RendererContext, Component: any, props: Record<string, any>, { default: children, ...slotted }: any, metadata?: undefined | Record<string, any>) {
+function renderToStaticMarkup(
+ this: RendererContext,
+ Component: any,
+ props: Record<string, any>,
+ { default: children, ...slotted }: any,
+ metadata?: undefined | Record<string, any>
+) {
const renderId = metadata?.hydrate ? incrementId(getContext(this.result)) : '';
- const html = renderToString(() => {
- const slots: Record<string, any> = {};
- for (const [key, value] of Object.entries(slotted)) {
- const name = slotName(key);
- slots[name] = ssr(`<astro-slot name="${name}">${value}</astro-slot>`);
- }
- // Note: create newProps to avoid mutating `props` before they are serialized
- const newProps = {
- ...props,
- ...slots,
- // In Solid SSR mode, `ssr` creates the expected structure for `children`.
- children: children != null ? ssr(`<astro-slot>${children}</astro-slot>`) : children,
- };
+ const html = renderToString(
+ () => {
+ const slots: Record<string, any> = {};
+ for (const [key, value] of Object.entries(slotted)) {
+ const name = slotName(key);
+ slots[name] = ssr(`<astro-slot name="${name}">${value}</astro-slot>`);
+ }
+ // Note: create newProps to avoid mutating `props` before they are serialized
+ const newProps = {
+ ...props,
+ ...slots,
+ // In Solid SSR mode, `ssr` creates the expected structure for `children`.
+ children: children != null ? ssr(`<astro-slot>${children}</astro-slot>`) : children,
+ };
- return createComponent(Component, newProps);
- }, {
- renderId
- });
+ return createComponent(Component, newProps);
+ },
+ {
+ renderId,
+ }
+ );
return {
attrs: {
- 'data-solid-render-id': renderId
+ 'data-solid-render-id': renderId,
},
- html
+ html,
};
}