-
Notifications
You must be signed in to change notification settings - Fork 0
/
@astrojs-solid-js-npm-2.0.2-bccf2155a9.patch
144 lines (138 loc) · 4.93 KB
/
@astrojs-solid-js-npm-2.0.2-bccf2155a9.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 0000000000000000000000000000000000000000..7c2feb7ef4731d430facfcafcbac59e3ea861849
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,3 @@
+{
+ "editor.formatOnSave": false
+}
diff --git a/dist/server.js b/dist/server.js
index 2cb1c0482a8bd3b79c5984f776981e028fc06d92..fd99027dfd82b113d93fafee6495636b02be1ef8 100644
--- a/dist/server.js
+++ b/dist/server.js
@@ -1,4 +1,4 @@
-import { createComponent, renderToString, ssr } from "solid-js/web";
+import { createComponent, renderToStringAsync, ssr } from "solid-js/web";
import { getContext, incrementId } from "./context.js";
const slotName = (str) => str.trim().replace(/[-_]([a-z])/g, (_, w) => w.toUpperCase());
function check(Component, props, children) {
@@ -7,9 +7,9 @@ function check(Component, props, children) {
const { html } = renderToStaticMarkup.call(this, Component, props, children);
return typeof html === "string";
}
-function renderToStaticMarkup(Component, props, { default: children, ...slotted }, metadata) {
+async function renderToStaticMarkup(Component, props, { default: children, ...slotted }, metadata) {
const renderId = (metadata == null ? void 0 : metadata.hydrate) ? incrementId(getContext(this.result)) : "";
- const html = renderToString(
+ const html = await renderToStringAsync(
() => {
const slots = {};
for (const [key, value] of Object.entries(slotted)) {
diff --git a/src/server.ts b/src/server.ts
index a4626d7523d9e0e20c5938eed5bbbe2ebc7bd0a1..16e0174c640a6a650faa5ede74402e1e74e4599c 100644
--- a/src/server.ts
+++ b/src/server.ts
@@ -1,54 +1,65 @@
-import { createComponent, renderToString, ssr } from 'solid-js/web';
-import { getContext, incrementId } from './context.js';
-import type { RendererContext } from './types';
+import { createComponent, renderToStringAsync, 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());
+const slotName = (str: string) =>
+ str.trim().replace(/[-_]([a-z])/g, (_, w) => w.toUpperCase());
-function check(this: RendererContext, Component: any, props: Record<string, any>, children: any) {
- if (typeof Component !== 'function') return false;
- const { html } = renderToStaticMarkup.call(this, Component, props, children);
- return typeof html === 'string';
+function check(
+ this: RendererContext,
+ Component: any,
+ props: Record<string, any>,
+ children: any
+) {
+ if (typeof Component !== "function") return false;
+ const { html } = renderToStaticMarkup.call(this, Component, props, children);
+ return typeof html === "string";
}
-function renderToStaticMarkup(
- this: RendererContext,
- Component: any,
- props: Record<string, any>,
- { default: children, ...slotted }: any,
- metadata?: undefined | Record<string, any>
+async 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 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 = await renderToStringAsync(
+ () => {
+ 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 {
- attrs: {
- 'data-solid-render-id': renderId,
- },
- html,
- };
+ return createComponent(Component, newProps);
+ },
+ {
+ renderId,
+ }
+ );
+ return {
+ attrs: {
+ "data-solid-render-id": renderId,
+ },
+ html,
+ };
}
export default {
- check,
- renderToStaticMarkup,
+ check,
+ renderToStaticMarkup,
};