summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar natemoo-re <natemoo-re@users.noreply.github.com> 2022-08-10 19:13:28 +0000
committerGravatar fredkbot <fred+astrobot@astro.build> 2022-08-10 19:13:28 +0000
commitd186c406b95b1e69840d136b824cbc24c86f97c2 (patch)
treeaf66066d4ba9ff7fbb8abc6bd5c665d1897ab3a2
parentbfbd32588f7e2c0a9e43cd1a571a0dc9c5f7e645 (diff)
downloadastro-d186c406b95b1e69840d136b824cbc24c86f97c2.tar.gz
astro-d186c406b95b1e69840d136b824cbc24c86f97c2.tar.zst
astro-d186c406b95b1e69840d136b824cbc24c86f97c2.zip
[ci] format
-rw-r--r--packages/astro/src/runtime/server/hydration.ts4
-rw-r--r--packages/integrations/solid/src/client.ts4
-rw-r--r--packages/integrations/solid/src/context.ts6
-rw-r--r--packages/integrations/solid/src/server.ts53
4 files changed, 38 insertions, 29 deletions
diff --git a/packages/astro/src/runtime/server/hydration.ts b/packages/astro/src/runtime/server/hydration.ts
index 5d33d54a8..f100c1d7c 100644
--- a/packages/astro/src/runtime/server/hydration.ts
+++ b/packages/astro/src/runtime/server/hydration.ts
@@ -133,8 +133,8 @@ export async function generateHydrateScript(
};
// Attach renderer-provided attributes
- if(attrs) {
- for(const [key, value] of Object.entries(attrs)) {
+ if (attrs) {
+ for (const [key, value] of Object.entries(attrs)) {
island.props[key] = value;
}
}
diff --git a/packages/integrations/solid/src/client.ts b/packages/integrations/solid/src/client.ts
index b58bdd0b8..730db0f51 100644
--- a/packages/integrations/solid/src/client.ts
+++ b/packages/integrations/solid/src/client.ts
@@ -1,5 +1,5 @@
import { sharedConfig } from 'solid-js';
-import { hydrate, render, createComponent } from 'solid-js/web';
+import { createComponent, hydrate, render } from 'solid-js/web';
export default (element: HTMLElement) =>
(Component: any, props: any, slotted: any, { client }: { client: string }) => {
@@ -39,7 +39,7 @@ export default (element: HTMLElement) =>
}),
element,
{
- renderId
+ renderId,
}
);
};
diff --git a/packages/integrations/solid/src/context.ts b/packages/integrations/solid/src/context.ts
index c7b6cc392..4846ee212 100644
--- a/packages/integrations/solid/src/context.ts
+++ b/packages/integrations/solid/src/context.ts
@@ -3,19 +3,19 @@ import type { RendererContext } from './types';
type Context = {
id: string;
c: number;
-}
+};
const contexts = new WeakMap<RendererContext['result'], Context>();
export function getContext(result: RendererContext['result']): Context {
- if(contexts.has(result)) {
+ if (contexts.has(result)) {
return contexts.get(result)!;
}
let ctx = {
c: 0,
get id() {
return 's' + this.c.toString();
- }
+ },
};
contexts.set(result, ctx);
return ctx;
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,
};
}