@solidjs/web 2.0.0-beta.3 → 2.0.0-beta.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -4
- package/dist/dev.cjs +1211 -205
- package/dist/dev.js +1175 -199
- package/dist/server.cjs +1342 -234
- package/dist/server.js +1304 -231
- package/dist/web.cjs +1195 -196
- package/dist/web.js +1159 -190
- package/frames/dist/client.cjs +1746 -0
- package/frames/dist/client.dev.cjs +1759 -0
- package/frames/dist/client.dev.js +1747 -0
- package/frames/dist/client.js +1734 -0
- package/frames/dist/server.cjs +2426 -0
- package/frames/dist/server.js +2414 -0
- package/frames/package.json +30 -0
- package/package.json +287 -38
- package/serialization/dist/serialization.cjs +169 -0
- package/serialization/dist/serialization.js +159 -0
- package/serialization/package.json +20 -0
- package/serialization/types/index.d.ts +157 -0
- package/serialization/types-cjs/index.d.cts +157 -0
- package/serialization/types-cjs/package.json +3 -0
- package/server-functions/dist/client.cjs +613 -0
- package/server-functions/dist/client.js +585 -0
- package/server-functions/dist/server.cjs +904 -0
- package/server-functions/dist/server.js +875 -0
- package/server-functions/package.json +30 -0
- package/storage/package.json +8 -3
- package/storage/types/index.d.ts +26 -0
- package/storage/types-cjs/index.d.cts +28 -0
- package/storage/types-cjs/package.json +3 -0
- package/types/client.d.ts +125 -21
- package/types/core.d.ts +4 -3
- package/types/frames/client.d.ts +20 -0
- package/types/frames/frame-client.d.ts +270 -0
- package/types/frames/frame-sink.d.ts +168 -0
- package/types/frames/frame-transport.d.ts +196 -0
- package/types/frames/serializer.d.ts +157 -0
- package/types/frames/server.d.ts +30 -0
- package/types/index.d.ts +211 -26
- package/types/jsx-properties.d.ts +93 -0
- package/types/jsx.d.ts +4150 -1
- package/types/response.d.ts +129 -0
- package/types/serializer.d.ts +157 -0
- package/types/server-functions/client.d.ts +200 -0
- package/types/server-functions/flash.d.ts +38 -0
- package/types/server-functions/server.d.ts +490 -0
- package/types/server-functions/shared.d.ts +445 -0
- package/types/server-mock.d.ts +93 -0
- package/types/server.d.ts +221 -28
- package/types-cjs/client.d.cts +192 -0
- package/types-cjs/core.d.cts +4 -0
- package/types-cjs/frames/client.d.cts +20 -0
- package/types-cjs/frames/frame-client.d.cts +270 -0
- package/types-cjs/frames/frame-sink.d.cts +168 -0
- package/types-cjs/frames/frame-transport.d.cts +196 -0
- package/types-cjs/frames/serializer.d.cts +157 -0
- package/types-cjs/frames/server.d.cts +30 -0
- package/types-cjs/index.d.cts +231 -0
- package/types-cjs/jsx-properties.d.cts +93 -0
- package/types-cjs/jsx.d.cts +4150 -0
- package/types-cjs/package.json +3 -0
- package/types-cjs/response.d.cts +129 -0
- package/types-cjs/serializer.d.cts +157 -0
- package/types-cjs/server-functions/client.d.cts +200 -0
- package/types-cjs/server-functions/flash.d.cts +38 -0
- package/types-cjs/server-functions/server.d.cts +490 -0
- package/types-cjs/server-functions/shared.d.cts +445 -0
- package/types-cjs/server-mock.d.cts +165 -0
- package/types-cjs/server.d.cts +349 -0
- package/storage/types/src/client.d.ts +0 -1
- package/storage/types/src/index.d.ts +0 -46
- package/storage/types/src/server-mock.d.ts +0 -72
- package/storage/types/storage/src/index.d.ts +0 -2
package/dist/server.js
CHANGED
|
@@ -1,11 +1,36 @@
|
|
|
1
|
-
import { createRenderEffect, createMemo
|
|
2
|
-
export { Errored, For, Hydration, Loading, Match, NoHydration, Repeat, Show, Switch, createComponent, getOwner,
|
|
3
|
-
import { Serializer,
|
|
1
|
+
import { createRenderEffect, createMemo, sharedConfig, createRoot, ssrHandleError, getOwner, runWithOwner, createComponent, omit, getNextChildId, onCleanup } from 'solid-js';
|
|
2
|
+
export { Errored, For, Hydration, Loading, Match, NoHydration, Repeat, Reveal, Show, Switch, createComponent, getOwner, merge as mergeProps, ssrScope as scope, untrack } from 'solid-js';
|
|
3
|
+
import { Serializer, getCrossReferenceHeader, Feature } from 'seroval';
|
|
4
4
|
import { AbortSignalPlugin, CustomEventPlugin, DOMExceptionPlugin, EventPlugin, FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin } from 'seroval-plugins/web';
|
|
5
|
-
import { createMemo } from '@solidjs/signals';
|
|
6
5
|
|
|
7
|
-
const
|
|
8
|
-
|
|
6
|
+
const DOMWithState = {
|
|
7
|
+
INPUT: {
|
|
8
|
+
value: 1,
|
|
9
|
+
defaultValue: 2,
|
|
10
|
+
checked: 1,
|
|
11
|
+
defaultChecked: 2
|
|
12
|
+
},
|
|
13
|
+
SELECT: {
|
|
14
|
+
value: 1
|
|
15
|
+
},
|
|
16
|
+
OPTION: {
|
|
17
|
+
value: 1,
|
|
18
|
+
selected: 1,
|
|
19
|
+
defaultSelected: 2
|
|
20
|
+
},
|
|
21
|
+
TEXTAREA: {
|
|
22
|
+
value: 1,
|
|
23
|
+
defaultValue: 2
|
|
24
|
+
},
|
|
25
|
+
VIDEO: {
|
|
26
|
+
muted: 1,
|
|
27
|
+
defaultMuted: 2
|
|
28
|
+
},
|
|
29
|
+
AUDIO: {
|
|
30
|
+
muted: 1,
|
|
31
|
+
defaultMuted: 2
|
|
32
|
+
}
|
|
33
|
+
};
|
|
9
34
|
const ChildProperties = /*#__PURE__*/new Set(["innerHTML", "textContent", "innerText", "children"]);
|
|
10
35
|
const DelegatedEvents = /*#__PURE__*/new Set(["beforeinput", "click", "dblclick", "contextmenu", "focusin", "focusout", "input", "keydown", "keyup", "mousedown", "mousemove", "mouseout", "mouseover", "mouseup", "pointerdown", "pointermove", "pointerout", "pointerover", "pointerup", "touchend", "touchmove", "touchstart"]);
|
|
11
36
|
const SVGElements = /*#__PURE__*/new Set([
|
|
@@ -13,52 +38,161 @@ const SVGElements = /*#__PURE__*/new Set([
|
|
|
13
38
|
"set", "stop",
|
|
14
39
|
"svg", "switch", "symbol", "text", "textPath",
|
|
15
40
|
"tref", "tspan", "use", "view", "vkern"]);
|
|
16
|
-
const
|
|
41
|
+
const MathMLElements = /*#__PURE__*/new Set(["annotation", "annotation-xml", "maction", "math", "menclose", "merror", "mfenced", "mfrac", "mi", "mmultiscripts", "mn", "mo", "mover", "mpadded", "mphantom", "mprescripts", "mroot", "mrow", "ms", "mspace", "msqrt", "mstyle", "msub", "msubsup", "msup", "mtable", "mtd", "mtext", "mtr", "munder", "munderover", "semantics"]);
|
|
42
|
+
const Namespaces = {
|
|
43
|
+
svg: "http://www.w3.org/2000/svg",
|
|
44
|
+
mathml: "http://www.w3.org/1998/Math/MathML",
|
|
17
45
|
xlink: "http://www.w3.org/1999/xlink",
|
|
18
46
|
xml: "http://www.w3.org/XML/1998/namespace"
|
|
19
47
|
};
|
|
20
|
-
const
|
|
21
|
-
"
|
|
22
|
-
"isindex
|
|
48
|
+
const VoidElements = /*#__PURE__*/new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"]);
|
|
49
|
+
const RawTextElements = /*#__PURE__*/new Set(["style", "script", "noscript", "template", "textarea", "title"]);
|
|
50
|
+
const DOMElements = /*#__PURE__*/new Set(/*#__PURE__*/"a,abbr,acronym,address,applet,area,article,aside,audio,b,base,basefont,bdi,bdo,bgsound,big,blink,blockquote,body,br,button,canvas,caption,center,cite,code,col,colgroup,content,data,datalist,dd,del,details,dfn,dialog,dir,div,dl,dt,em,embed,fieldset,figcaption,figure,font,footer,form,frame,frameset,h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,i,iframe,image,img,input,ins,isindex,kbd,keygen,label,legend,li,link,listing,main,map,mark,marquee,math,menu,menuitem,meta,meter,multicol,nav,nextid,nobr,noembed,noframes,noindex,noscript,object,ol,optgroup,option,output,p,param,picture,plaintext,portal,pre,progress,q,rb,rp,rt,rtc,ruby,s,samp,script,search,section,select,shadow,slot,small,source,spacer,span,strike,strong,style,sub,summary,sup,svg,table,tbody,td,template,textarea,tfoot,th,thead,time,title,tr,track,tt,u,ul,var,video,wbr,webview,xmp".split(","));
|
|
23
51
|
|
|
24
|
-
const
|
|
25
|
-
transparent: true
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
52
|
+
const transparentOptions = {
|
|
53
|
+
transparent: true,
|
|
54
|
+
sync: true
|
|
55
|
+
};
|
|
56
|
+
const syncOptions = {
|
|
57
|
+
sync: true
|
|
58
|
+
};
|
|
59
|
+
const effect = (fn, effectFn, options) => createRenderEffect(fn, effectFn, options ? {
|
|
60
|
+
sync: true,
|
|
61
|
+
...options,
|
|
62
|
+
transparent: !options.scope
|
|
63
|
+
} : transparentOptions);
|
|
64
|
+
const memo = fn => createMemo(() => fn(), syncOptions);
|
|
30
65
|
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
66
|
+
const DEFAULT_DISABLED_FEATURES = Feature.AggregateError | Feature.BigIntTypedArray;
|
|
67
|
+
const serializeOnlyDisabledFeatures = () => process.env.NODE_ENV === "development" ? 0 : Feature.ErrorPrototypeStack;
|
|
68
|
+
const HYDRATION_GLOBAL = "_$HY.r";
|
|
69
|
+
const DEFAULT_WEB_PLUGINS = Object.freeze([AbortSignalPlugin,
|
|
70
|
+
CustomEventPlugin, DOMExceptionPlugin, EventPlugin,
|
|
71
|
+
FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin]);
|
|
72
|
+
function resolveSerializerPlugins(customPlugins) {
|
|
73
|
+
return customPlugins ? [...customPlugins, ...DEFAULT_WEB_PLUGINS] : [...DEFAULT_WEB_PLUGINS];
|
|
74
|
+
}
|
|
75
|
+
function createSerializer(options) {
|
|
76
|
+
return new Serializer({
|
|
77
|
+
...options,
|
|
78
|
+
plugins: resolveSerializerPlugins(options.plugins),
|
|
79
|
+
disabledFeatures: (options.disabledFeatures === undefined ? DEFAULT_DISABLED_FEATURES : options.disabledFeatures) | serializeOnlyDisabledFeatures()
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
function createHydrationSerializer({
|
|
35
83
|
onData,
|
|
36
84
|
onDone,
|
|
37
85
|
scopeId,
|
|
38
86
|
onError,
|
|
39
|
-
plugins
|
|
87
|
+
plugins
|
|
40
88
|
}) {
|
|
41
|
-
|
|
42
|
-
CustomEventPlugin, DOMExceptionPlugin, EventPlugin,
|
|
43
|
-
FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin];
|
|
44
|
-
const allPlugins = customPlugins ? [...customPlugins, ...defaultPlugins] : defaultPlugins;
|
|
45
|
-
return new Serializer({
|
|
89
|
+
return createSerializer({
|
|
46
90
|
scopeId,
|
|
47
|
-
plugins
|
|
48
|
-
globalIdentifier:
|
|
49
|
-
disabledFeatures: ES2017FLAG,
|
|
91
|
+
plugins,
|
|
92
|
+
globalIdentifier: HYDRATION_GLOBAL,
|
|
50
93
|
onData,
|
|
51
94
|
onDone,
|
|
52
95
|
onError
|
|
53
96
|
});
|
|
54
97
|
}
|
|
55
98
|
function getLocalHeaderScript(id) {
|
|
56
|
-
return getCrossReferenceHeader(id) +
|
|
99
|
+
return getCrossReferenceHeader(id) + ";";
|
|
57
100
|
}
|
|
101
|
+
Feature.RegExp;
|
|
58
102
|
|
|
103
|
+
const HEAD_ELIGIBLE_TAGS = new Set(["title", "meta", "link", "style", "script", "base"]);
|
|
104
|
+
const HEAD_ATTR_NAME = /^[a-zA-Z_][a-zA-Z0-9_:.-]*$/;
|
|
105
|
+
const RESOURCE_LINK_RELS = new Set(["preload", "modulepreload", "prefetch", "preconnect", "dns-prefetch", "icon", "stylesheet"]);
|
|
106
|
+
const RESOURCE_QUALIFIERS = ["as", "crossorigin", "type", "media", "imagesrcset", "imagesizes"];
|
|
107
|
+
const STYLESHEET_FETCH_META = new Set(["crossorigin", "integrity", "referrerpolicy", "fetchpriority"]);
|
|
108
|
+
function evalHeadValue(v) {
|
|
109
|
+
return typeof v === "function" ? v() : v;
|
|
110
|
+
}
|
|
111
|
+
function evalHeadProps(props, presets) {
|
|
112
|
+
const out = {};
|
|
113
|
+
for (const name in props) out[name] = presets && name in presets ? presets[name] : evalHeadValue(props[name]);
|
|
114
|
+
return out;
|
|
115
|
+
}
|
|
116
|
+
function classifyHeadTag(desc) {
|
|
117
|
+
const tag = desc.tag;
|
|
118
|
+
if (tag === "link") {
|
|
119
|
+
const rel = evalHeadValue(desc.props && desc.props.rel);
|
|
120
|
+
return {
|
|
121
|
+
resource: RESOURCE_LINK_RELS.has(rel),
|
|
122
|
+
rel
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
if (tag === "style") return {
|
|
126
|
+
resource: !!(desc.props && "href" in desc.props)
|
|
127
|
+
};
|
|
128
|
+
if (tag === "script") return {
|
|
129
|
+
resource: !!(desc.props && "src" in desc.props)
|
|
130
|
+
};
|
|
131
|
+
return {
|
|
132
|
+
resource: false
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
function resourceIdentity(tag, props) {
|
|
136
|
+
let id = "res:" + tag + ":" + (props.rel || "") + ":" + (props.href || props.src || "");
|
|
137
|
+
for (let i = 0; i < RESOURCE_QUALIFIERS.length; i++) {
|
|
138
|
+
const q = RESOURCE_QUALIFIERS[i];
|
|
139
|
+
if (props[q] != null) id += ":" + q + "=" + props[q];
|
|
140
|
+
}
|
|
141
|
+
return id;
|
|
142
|
+
}
|
|
143
|
+
function replaceableIdentity(tag, props, key, unique) {
|
|
144
|
+
if (tag === "title") return "title";
|
|
145
|
+
if (tag === "base") return "base";
|
|
146
|
+
if (tag === "meta" && props.charset != null) return "charset";
|
|
147
|
+
if (key != null) return tag + ":key:" + key;
|
|
148
|
+
if (tag === "meta") {
|
|
149
|
+
if (props.name != null) return "meta:name:" + props.name;
|
|
150
|
+
if (props.property != null) return "meta:property:" + props.property;
|
|
151
|
+
if (props["http-equiv"] != null) return "meta:http-equiv:" + props["http-equiv"];
|
|
152
|
+
return unique;
|
|
153
|
+
}
|
|
154
|
+
if (tag === "link") return "link:" + (props.rel || "") + ":" + (props.href || "");
|
|
155
|
+
return unique;
|
|
156
|
+
}
|
|
157
|
+
function resolveHead(groups) {
|
|
158
|
+
const winners = new Map();
|
|
159
|
+
const sorted = groups.slice().sort((a, b) => a.seq - b.seq);
|
|
160
|
+
for (let i = 0; i < sorted.length; i++) {
|
|
161
|
+
const group = sorted[i];
|
|
162
|
+
const byIdentity = new Map();
|
|
163
|
+
for (let j = 0; j < group.tags.length; j++) {
|
|
164
|
+
const t = group.tags[j];
|
|
165
|
+
let list = byIdentity.get(t.identity);
|
|
166
|
+
if (!list) byIdentity.set(t.identity, list = []);
|
|
167
|
+
list.push(t);
|
|
168
|
+
}
|
|
169
|
+
for (const [identity, tags] of byIdentity) {
|
|
170
|
+
if (identity === "title") {
|
|
171
|
+
if (tags.length > 1) console.warn("Multiple <title> tags in one head group; the last one wins.");
|
|
172
|
+
winners.set(identity, {
|
|
173
|
+
seq: group.seq,
|
|
174
|
+
tags: [tags[tags.length - 1]]
|
|
175
|
+
});
|
|
176
|
+
} else {
|
|
177
|
+
winners.set(identity, {
|
|
178
|
+
seq: group.seq,
|
|
179
|
+
tags
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return winners;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function joinAssetPath(base, file) {
|
|
188
|
+
if (/^(?:[a-z][a-z0-9+.-]*:)?\/\//i.test(file)) return file;
|
|
189
|
+
if (typeof base !== "string" || !base) base = "/";
|
|
190
|
+
if (base[base.length - 1] !== "/") base += "/";
|
|
191
|
+
return base + (file[0] === "/" ? file.slice(1) : file);
|
|
192
|
+
}
|
|
59
193
|
function resolveAssets(moduleUrl, manifest) {
|
|
60
194
|
if (!manifest) return null;
|
|
61
|
-
const base = manifest._base
|
|
195
|
+
const base = manifest._base;
|
|
62
196
|
const entry = manifest[moduleUrl];
|
|
63
197
|
if (!entry) return null;
|
|
64
198
|
const css = [];
|
|
@@ -69,8 +203,8 @@ function resolveAssets(moduleUrl, manifest) {
|
|
|
69
203
|
visited.add(key);
|
|
70
204
|
const e = manifest[key];
|
|
71
205
|
if (!e) return;
|
|
72
|
-
js.push(base
|
|
73
|
-
if (e.css) for (let i = 0; i < e.css.length; i++) css.push(base
|
|
206
|
+
js.push(joinAssetPath(base, e.file));
|
|
207
|
+
if (e.css) for (let i = 0; i < e.css.length; i++) css.push(joinAssetPath(base, e.css[i]));
|
|
74
208
|
if (e.imports) for (let i = 0; i < e.imports.length; i++) walk(e.imports[i]);
|
|
75
209
|
};
|
|
76
210
|
walk(moduleUrl);
|
|
@@ -80,7 +214,7 @@ function resolveAssets(moduleUrl, manifest) {
|
|
|
80
214
|
};
|
|
81
215
|
}
|
|
82
216
|
function registerEntryAssets(manifest) {
|
|
83
|
-
if (!manifest) return;
|
|
217
|
+
if (!manifest || typeof manifest === "function" || typeof manifest.resolve === "function") return;
|
|
84
218
|
const ctx = sharedConfig.context;
|
|
85
219
|
if (!ctx?.registerAsset) return;
|
|
86
220
|
for (const key in manifest) {
|
|
@@ -97,25 +231,48 @@ function createAssetTracking() {
|
|
|
97
231
|
const boundaryModules = new Map();
|
|
98
232
|
const boundaryStyles = new Map();
|
|
99
233
|
const emittedAssets = new Set();
|
|
234
|
+
const inlineStyles = new Map();
|
|
100
235
|
let currentBoundaryId = null;
|
|
101
236
|
return {
|
|
102
237
|
boundaryModules,
|
|
103
238
|
boundaryStyles,
|
|
104
239
|
emittedAssets,
|
|
240
|
+
inlineStyles,
|
|
241
|
+
registerInlineStyle(desc) {
|
|
242
|
+
let entry = inlineStyles.get(desc.id);
|
|
243
|
+
if (!entry) {
|
|
244
|
+
entry = {
|
|
245
|
+
id: desc.id,
|
|
246
|
+
content: desc.content || "",
|
|
247
|
+
attrs: desc.attrs,
|
|
248
|
+
emitted: false
|
|
249
|
+
};
|
|
250
|
+
inlineStyles.set(desc.id, entry);
|
|
251
|
+
}
|
|
252
|
+
if (currentBoundaryId) {
|
|
253
|
+
let styles = boundaryStyles.get(currentBoundaryId);
|
|
254
|
+
if (!styles) {
|
|
255
|
+
styles = new Set();
|
|
256
|
+
boundaryStyles.set(currentBoundaryId, styles);
|
|
257
|
+
}
|
|
258
|
+
styles.add(entry);
|
|
259
|
+
}
|
|
260
|
+
return entry;
|
|
261
|
+
},
|
|
105
262
|
get currentBoundaryId() {
|
|
106
263
|
return currentBoundaryId;
|
|
107
264
|
},
|
|
108
265
|
set currentBoundaryId(v) {
|
|
109
266
|
currentBoundaryId = v;
|
|
110
267
|
},
|
|
111
|
-
registerModule(
|
|
112
|
-
|
|
113
|
-
let map = boundaryModules.get(
|
|
268
|
+
registerModule(key, entryUrl) {
|
|
269
|
+
const id = currentBoundaryId || "";
|
|
270
|
+
let map = boundaryModules.get(id);
|
|
114
271
|
if (!map) {
|
|
115
272
|
map = {};
|
|
116
|
-
boundaryModules.set(
|
|
273
|
+
boundaryModules.set(id, map);
|
|
117
274
|
}
|
|
118
|
-
map[
|
|
275
|
+
map[key] = entryUrl;
|
|
119
276
|
},
|
|
120
277
|
getBoundaryModules(id) {
|
|
121
278
|
return boundaryModules.get(id) || null;
|
|
@@ -125,7 +282,24 @@ function createAssetTracking() {
|
|
|
125
282
|
}
|
|
126
283
|
};
|
|
127
284
|
}
|
|
128
|
-
function
|
|
285
|
+
function warnUnresolvedModuleAssets(moduleUrl, warned) {
|
|
286
|
+
if (warned.has(moduleUrl)) return;
|
|
287
|
+
warned.add(moduleUrl);
|
|
288
|
+
console.error(`Asset manifest returned no client assets for module "${moduleUrl}". ` + "If this module is a server-rendered lazy() component, its entry will be missing from " + "the serialized hydration asset map, the client will be unable to preload it, and " + "hydration will fail with 'lazy() module \"…\" was not preloaded before hydration'. " + "This means the integration's asset resolver (dev manifest bridge or build client " + "manifest) failed to answer for this module — check the integration's server logs, " + "restart the dev server, or verify the module is included in the client build.");
|
|
289
|
+
}
|
|
290
|
+
function guardResolvedAssets(moduleUrl, result, warned) {
|
|
291
|
+
if (result && typeof result.then === "function") {
|
|
292
|
+
return result.then(assets => {
|
|
293
|
+
if (!assets || !assets.js || !assets.js.length) warnUnresolvedModuleAssets(moduleUrl, warned);
|
|
294
|
+
return assets;
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
if (!result || !result.js || !result.js.length) warnUnresolvedModuleAssets(moduleUrl, warned);
|
|
298
|
+
return result;
|
|
299
|
+
}
|
|
300
|
+
function applyAssetTracking(context, tracking, manifest, noScripts) {
|
|
301
|
+
const warned = new Set();
|
|
302
|
+
const guard = noScripts ? resolve => resolve : resolve => moduleUrl => guardResolvedAssets(moduleUrl, resolve(moduleUrl), warned);
|
|
129
303
|
Object.defineProperty(context, "_currentBoundaryId", {
|
|
130
304
|
get() {
|
|
131
305
|
return tracking.currentBoundaryId;
|
|
@@ -138,19 +312,290 @@ function applyAssetTracking(context, tracking, manifest) {
|
|
|
138
312
|
});
|
|
139
313
|
context.registerModule = tracking.registerModule;
|
|
140
314
|
context.getBoundaryModules = tracking.getBoundaryModules;
|
|
141
|
-
if (manifest
|
|
315
|
+
if (typeof manifest === "function") {
|
|
316
|
+
context.resolveAssets = guard(manifest);
|
|
317
|
+
} else if (manifest && typeof manifest.resolve === "function") {
|
|
318
|
+
context.resolveAssets = guard(key => manifest.resolve(key));
|
|
319
|
+
if (typeof manifest.resolveSync === "function") {
|
|
320
|
+
context.resolveAssetsSync = key => manifest.resolveSync(key);
|
|
321
|
+
}
|
|
322
|
+
} else if (manifest) {
|
|
323
|
+
const resolve = moduleUrl => resolveAssets(moduleUrl, manifest);
|
|
324
|
+
context.resolveAssets = guard(resolve);
|
|
325
|
+
context.resolveAssetsSync = resolve;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
function isCssUrl(url) {
|
|
329
|
+
const q = url.search(/[?#]/);
|
|
330
|
+
return (q === -1 ? url : url.slice(0, q)).endsWith(".css");
|
|
331
|
+
}
|
|
332
|
+
function createHeadRegistry() {
|
|
333
|
+
return {
|
|
334
|
+
pending: [],
|
|
335
|
+
committed: [],
|
|
336
|
+
seq: 0,
|
|
337
|
+
uniq: 0,
|
|
338
|
+
resources: new Set(),
|
|
339
|
+
eagerHtml: "",
|
|
340
|
+
flushed: null,
|
|
341
|
+
shellFlushed: false
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
function registerHeadTags(registry, context, tracking, emitResource, nonce, tags) {
|
|
345
|
+
const boundary = context._currentBoundaryId || "";
|
|
346
|
+
let replaceable = null;
|
|
347
|
+
for (let i = 0; i < tags.length; i++) {
|
|
348
|
+
const desc = tags[i];
|
|
349
|
+
if (!desc || !HEAD_ELIGIBLE_TAGS.has(desc.tag)) {
|
|
350
|
+
console.warn(`useHead: ignoring non-head tag`, desc);
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
const cls = classifyHeadTag(desc);
|
|
354
|
+
if (cls.resource) {
|
|
355
|
+
emitHeadResource(registry, context, tracking, emitResource, nonce, desc, cls.rel);
|
|
356
|
+
} else {
|
|
357
|
+
(replaceable || (replaceable = [])).push(cls.rel !== undefined ? {
|
|
358
|
+
tag: desc.tag,
|
|
359
|
+
props: desc.props,
|
|
360
|
+
key: desc.key,
|
|
361
|
+
rel: cls.rel
|
|
362
|
+
} : desc);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
if (replaceable) registry.pending.push({
|
|
366
|
+
boundary,
|
|
367
|
+
tags: replaceable
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
function emitHeadResource(registry, context, tracking, emitResource, nonce, desc, rel) {
|
|
371
|
+
let props;
|
|
372
|
+
try {
|
|
373
|
+
props = evalHeadProps(desc.props || {}, rel !== undefined ? {
|
|
374
|
+
rel
|
|
375
|
+
} : undefined);
|
|
376
|
+
} catch (err) {
|
|
377
|
+
console.warn(`useHead: error evaluating resource tag props`, err);
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
const identity = resourceIdentity(desc.tag, props);
|
|
381
|
+
if (registry.resources.has(identity)) return;
|
|
382
|
+
registry.resources.add(identity);
|
|
383
|
+
if (desc.tag === "link" && (rel === "stylesheet" || rel === "modulepreload")) {
|
|
384
|
+
let plain = true;
|
|
385
|
+
let gateable = rel === "stylesheet";
|
|
386
|
+
for (const name in props) {
|
|
387
|
+
if (name === "rel" || name === "href") continue;
|
|
388
|
+
plain = false;
|
|
389
|
+
if (!STYLESHEET_FETCH_META.has(name)) gateable = false;
|
|
390
|
+
}
|
|
391
|
+
if (plain && props.href != null) {
|
|
392
|
+
const isCss = isCssUrl(props.href);
|
|
393
|
+
if (rel === "stylesheet" ? isCss : !isCss) {
|
|
394
|
+
context.registerAsset(rel === "stylesheet" ? "style" : "module", props.href);
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
if (gateable && props.href != null) {
|
|
399
|
+
const attrHtml = renderHeadAttrHtml(props);
|
|
400
|
+
const entry = {
|
|
401
|
+
href: props.href,
|
|
402
|
+
attrHtml,
|
|
403
|
+
attrs: headAttrRecord(props)
|
|
404
|
+
};
|
|
405
|
+
if (tracking.currentBoundaryId) {
|
|
406
|
+
let styles = tracking.boundaryStyles.get(tracking.currentBoundaryId);
|
|
407
|
+
if (!styles) tracking.boundaryStyles.set(tracking.currentBoundaryId, styles = new Set());
|
|
408
|
+
styles.add(entry);
|
|
409
|
+
}
|
|
410
|
+
const markup = `<link${attrHtml}>`;
|
|
411
|
+
if (emitResource) emitResource(markup, entry);else {
|
|
412
|
+
registry.eagerHtml += markup;
|
|
413
|
+
entry.emitted = true;
|
|
414
|
+
}
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
const url = props.href || props.src;
|
|
419
|
+
if (url != null && tracking.emittedAssets.has(url)) return;
|
|
420
|
+
const markup = renderHeadTagMarkup(desc.tag, props, null, nonce);
|
|
421
|
+
if (emitResource) emitResource(markup);else registry.eagerHtml += markup;
|
|
422
|
+
}
|
|
423
|
+
function commitHeadBoundary(registry, boundary, isPendingFragment) {
|
|
424
|
+
const keep = [];
|
|
425
|
+
const groups = [];
|
|
426
|
+
for (let i = 0; i < registry.pending.length; i++) {
|
|
427
|
+
const reg = registry.pending[i];
|
|
428
|
+
const mine = boundary === "" ? !(isPendingFragment && reg.boundary !== "" && isPendingFragment(reg.boundary)) : reg.boundary === boundary;
|
|
429
|
+
if (!mine) {
|
|
430
|
+
keep.push(reg);
|
|
431
|
+
continue;
|
|
432
|
+
}
|
|
433
|
+
const tags = [];
|
|
434
|
+
for (let j = 0; j < reg.tags.length; j++) {
|
|
435
|
+
const desc = reg.tags[j];
|
|
436
|
+
let props, key;
|
|
437
|
+
try {
|
|
438
|
+
props = evalHeadProps(desc.props || {}, desc.rel !== undefined ? {
|
|
439
|
+
rel: desc.rel
|
|
440
|
+
} : undefined);
|
|
441
|
+
key = evalHeadValue(desc.key);
|
|
442
|
+
} catch (err) {
|
|
443
|
+
console.warn(`useHead: error evaluating tag props`, err);
|
|
444
|
+
continue;
|
|
445
|
+
}
|
|
446
|
+
const identity = replaceableIdentity(desc.tag, props, key, "u:" + registry.uniq++);
|
|
447
|
+
if ((identity === "base" || identity === "charset") && registry.shellFlushed) {
|
|
448
|
+
console.warn(`useHead: <${desc.tag}> (${identity}) registered after shell flush is ignored`);
|
|
449
|
+
continue;
|
|
450
|
+
}
|
|
451
|
+
tags.push({
|
|
452
|
+
tag: desc.tag,
|
|
453
|
+
props,
|
|
454
|
+
identity
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
if (tags.length) groups.push({
|
|
458
|
+
seq: registry.seq++,
|
|
459
|
+
tags
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
registry.pending = keep;
|
|
463
|
+
for (let i = 0; i < groups.length; i++) registry.committed.push(groups[i]);
|
|
464
|
+
return groups;
|
|
465
|
+
}
|
|
466
|
+
function adoptHeadBoundary(registry, childKey, parentKey) {
|
|
467
|
+
for (let i = 0; i < registry.pending.length; i++) {
|
|
468
|
+
if (registry.pending[i].boundary === childKey) registry.pending[i].boundary = parentKey;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
function dropHeadBoundary(registry, boundary) {
|
|
472
|
+
registry.pending = registry.pending.filter(reg => reg.boundary !== boundary);
|
|
473
|
+
}
|
|
474
|
+
function headGroupSignature(winner) {
|
|
475
|
+
let sig = "" + winner.seq;
|
|
476
|
+
for (let i = 0; i < winner.tags.length; i++) {
|
|
477
|
+
const t = winner.tags[i];
|
|
478
|
+
sig += "|" + t.tag + JSON.stringify(t.props);
|
|
479
|
+
}
|
|
480
|
+
return sig;
|
|
481
|
+
}
|
|
482
|
+
function renderShellHead(registry, nonce, isPendingFragment) {
|
|
483
|
+
commitHeadBoundary(registry, "", isPendingFragment);
|
|
484
|
+
registry.shellFlushed = true;
|
|
485
|
+
const winners = resolveHead(registry.committed);
|
|
486
|
+
registry.flushed = new Map();
|
|
487
|
+
let prelude = "";
|
|
488
|
+
let links = "";
|
|
489
|
+
let metas = "";
|
|
490
|
+
let others = "";
|
|
491
|
+
let scripts = "";
|
|
492
|
+
for (const [identity, winner] of winners) {
|
|
493
|
+
registry.flushed.set(identity, headGroupSignature(winner));
|
|
494
|
+
for (let i = 0; i < winner.tags.length; i++) {
|
|
495
|
+
const t = winner.tags[i];
|
|
496
|
+
const markup = renderHeadTagMarkup(t.tag, t.props, identity, nonce);
|
|
497
|
+
if (identity === "charset" || identity === "base") prelude += markup;else if (t.tag === "link" || t.tag === "style") links += markup;else if (t.tag === "meta") metas += markup;else if (t.tag === "script") scripts += markup;else others += markup;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
return {
|
|
501
|
+
prelude,
|
|
502
|
+
html: registry.eagerHtml + links + metas + others + scripts
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
function flushHeadFragment(registry, boundary) {
|
|
506
|
+
const groups = commitHeadBoundary(registry, boundary);
|
|
507
|
+
if (!groups.length) return null;
|
|
508
|
+
const winners = resolveHead(registry.committed);
|
|
509
|
+
const affected = new Set();
|
|
510
|
+
for (let i = 0; i < groups.length; i++) for (let j = 0; j < groups[i].tags.length; j++) affected.add(groups[i].tags[j].identity);
|
|
511
|
+
const ops = [];
|
|
512
|
+
for (const identity of affected) {
|
|
513
|
+
const winner = winners.get(identity);
|
|
514
|
+
const sig = headGroupSignature(winner);
|
|
515
|
+
if (registry.flushed.get(identity) === sig) continue;
|
|
516
|
+
const existed = registry.flushed.has(identity);
|
|
517
|
+
registry.flushed.set(identity, sig);
|
|
518
|
+
if (identity === "title") {
|
|
519
|
+
const children = winner.tags[0].props.children;
|
|
520
|
+
ops.push(["t", children == null ? "" : String(children)]);
|
|
521
|
+
continue;
|
|
522
|
+
}
|
|
523
|
+
if (existed) ops.push(["r", identity]);
|
|
524
|
+
for (let i = 0; i < winner.tags.length; i++) {
|
|
525
|
+
const t = winner.tags[i];
|
|
526
|
+
const attrs = {};
|
|
527
|
+
for (const name in t.props) {
|
|
528
|
+
if (name === "children" || name === "ref" || name.slice(0, 2) === "on") continue;
|
|
529
|
+
if (!HEAD_ATTR_NAME.test(name)) {
|
|
530
|
+
console.warn(`useHead: ignoring invalid attribute name "${name}"`);
|
|
531
|
+
continue;
|
|
532
|
+
}
|
|
533
|
+
const v = t.props[name];
|
|
534
|
+
if (v == null || v === false) continue;
|
|
535
|
+
attrs[name] = v === true ? "" : String(v);
|
|
536
|
+
}
|
|
537
|
+
const children = t.props.children;
|
|
538
|
+
ops.push(["a", identity, t.tag, attrs, children == null ? null : String(children)]);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
return ops.length ? ops : null;
|
|
542
|
+
}
|
|
543
|
+
function renderHeadAttrHtml(props) {
|
|
544
|
+
let attrs = "";
|
|
545
|
+
for (const name in props) {
|
|
546
|
+
if (name === "children" || name === "ref" || name.slice(0, 2) === "on") continue;
|
|
547
|
+
if (!HEAD_ATTR_NAME.test(name)) {
|
|
548
|
+
console.warn(`useHead: ignoring invalid attribute name "${name}"`);
|
|
549
|
+
continue;
|
|
550
|
+
}
|
|
551
|
+
const v = props[name];
|
|
552
|
+
if (v == null || v === false) continue;
|
|
553
|
+
attrs += v === true ? ` ${name}` : ` ${name}="${escape(String(v), true)}"`;
|
|
554
|
+
}
|
|
555
|
+
return attrs;
|
|
556
|
+
}
|
|
557
|
+
function headAttrRecord(props, skipRelHref) {
|
|
558
|
+
let attrs = null;
|
|
559
|
+
for (const name in props) {
|
|
560
|
+
if (name === "children" || name === "ref" || name.slice(0, 2) === "on") continue;
|
|
561
|
+
if ((name === "rel" || name === "href")) continue;
|
|
562
|
+
if (!HEAD_ATTR_NAME.test(name)) continue;
|
|
563
|
+
const v = props[name];
|
|
564
|
+
if (v == null || v === false) continue;
|
|
565
|
+
(attrs || (attrs = {}))[name] = v === true ? "" : String(v);
|
|
566
|
+
}
|
|
567
|
+
return attrs;
|
|
568
|
+
}
|
|
569
|
+
function renderHeadTagMarkup(tag, props, identity, nonce) {
|
|
570
|
+
let attrs = renderHeadAttrHtml(props);
|
|
571
|
+
if (identity != null) attrs += ` data-dh="${escape(identity, true)}"`;
|
|
572
|
+
if (nonce && (tag === "script" || tag === "style")) attrs += ` nonce="${nonce}"`;
|
|
573
|
+
if (tag === "meta" || tag === "link" || tag === "base") return `<${tag}${attrs}>`;
|
|
574
|
+
let body = props.children == null ? "" : String(props.children);
|
|
575
|
+
if (tag === "script") body = body.replace(/<\/(script)/gi, "<\\/$1");else if (tag === "style") body = escapeStyleContent(body);else body = escape(body);
|
|
576
|
+
return `<${tag}${attrs}>${body}</${tag}>`;
|
|
577
|
+
}
|
|
578
|
+
function useHead(tags) {
|
|
579
|
+
const ctx = sharedConfig.context;
|
|
580
|
+
if (!ctx || !ctx.registerHeadTags) {
|
|
581
|
+
console.warn("useHead() called outside of a server render; registration ignored.");
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
ctx.registerHeadTags(Array.isArray(tags) ? tags : [tags]);
|
|
142
585
|
}
|
|
143
586
|
const VOID_ELEMENTS = /^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i;
|
|
144
|
-
const REPLACE_SCRIPT = `function $df(e,n,o,t){if(n=document.getElementById(e)
|
|
587
|
+
const REPLACE_SCRIPT = `function $df(e){return _$HY.f?_$HY.f(e):$dfr(e)}function $dfr(e,n,o,t){if(!(n=document.getElementById(e)))return 0;if(!(o=document.getElementById("pl-"+e)))return(_$HY.dq=_$HY.dq||{})[e]=1,0;for(;o&&(8!==o.nodeType||o.nodeValue!=="pl-"+e);)t=o.nextSibling,o.remove(),o=t;t=o.parentNode,o.replaceWith(n.content),n.remove(),_$HY.fe(e,t),_$HY.hp&&_$HY.hp[e]&&($dh(_$HY.hp[e]),delete _$HY.hp[e]),$dfd();return 1}function $dfl(e,o,n){if(!(o=document.getElementById("pl-"+e)))return(_$HY.dlq=_$HY.dlq||{})[e]=1,0;if(o._$fl)return 1;for(n=o.nextSibling;n;){if(8===n.nodeType&&n.nodeValue==="pl-"+e){o.parentNode&&o.parentNode.insertBefore(o.content.cloneNode(!0),n),o._$fl=1,$dfd();return 1}n=n.nextSibling}return 0}function $dflj(e,i){for(i=0;i<e.length;i++)$dfl(e[i])}function $dfd(e,i){if(e=_$HY.dq){_$HY.dq=0;for(i in e)$df(i)}if(e=_$HY.dlq){_$HY.dlq=0;for(i in e)$dfl(i)}}function $dfs(e,c,d){(_$HY.sc=_$HY.sc||{})[e]=c,d&&((_$HY.sd=_$HY.sd||{})[e]=1)}function $dfg(e,g,i,k){if(!(g=_$HY.sg&&_$HY.sg[e]))return;for(i=0;i<g.length;i++)if(_$HY.sc&&_$HY.sc[g[i]]>0)return;for(i=0;i<g.length;i++)k=g[i],delete _$HY.sg[k],$df(k)}function $dfc(e){if(--_$HY.sc[e]<=0){delete _$HY.sc[e],_$HY.sg&&_$HY.sg[e]?$dfg(e):!(_$HY.sd&&_$HY.sd[e])&&$df(e);_$HY.sd&&delete _$HY.sd[e]}}function $dfj(e,i,n){for(i=0;i<e.length;i++)if(_$HY.sc&&_$HY.sc[e[i]]>0){for(n=0;n<e.length;n++)(_$HY.sg=_$HY.sg||{})[e[n]]=e;return}for(i=0;i<e.length;i++)$df(e[i])}`;
|
|
588
|
+
const HEAD_SCRIPT = `function $dha(o,i,e,n){for(i=0;i<o.length;i++)e=o[i],"t"==e[0]?((n=document.querySelector("title"))||(n=document.createElement("title"),document.head.appendChild(n)),n.textContent=e[1],n.setAttribute("data-dh","title")):"r"==e[0]?$dhr(e[1]):(n=document.createElement(e[2]),Object.keys(e[3]).forEach(function(a){n.setAttribute(a,e[3][a])}),null!=e[4]&&(n.textContent=e[4]),n.setAttribute("data-dh",e[1]),document.head.appendChild(n))}function $dhr(v,l,i){for(l=document.head.querySelectorAll("[data-dh]"),i=0;i<l.length;i++)l[i].getAttribute("data-dh")==v&&l[i].remove()}function $dh(o){_$HY.h?_$HY.h(o):$dha(o)}`;
|
|
145
589
|
function renderToString(code, options = {}) {
|
|
146
590
|
const {
|
|
147
591
|
renderId = "",
|
|
148
592
|
nonce,
|
|
149
593
|
noScripts,
|
|
150
|
-
manifest
|
|
594
|
+
manifest,
|
|
595
|
+
onHead
|
|
151
596
|
} = options;
|
|
152
597
|
let scripts = "";
|
|
153
|
-
const serializer =
|
|
598
|
+
const serializer = createHydrationSerializer({
|
|
154
599
|
scopeId: renderId,
|
|
155
600
|
plugins: options.plugins,
|
|
156
601
|
onData(script) {
|
|
@@ -163,12 +608,16 @@ function renderToString(code, options = {}) {
|
|
|
163
608
|
onError: options.onError
|
|
164
609
|
});
|
|
165
610
|
const tracking = createAssetTracking();
|
|
611
|
+
const headRegistry = createHeadRegistry();
|
|
166
612
|
sharedConfig.context = {
|
|
167
613
|
assets: [],
|
|
168
614
|
nonce,
|
|
169
615
|
escape: escape,
|
|
170
616
|
resolve: resolveSSRNode,
|
|
171
617
|
ssr: ssr,
|
|
618
|
+
registerHeadTags(tags) {
|
|
619
|
+
registerHeadTags(headRegistry, sharedConfig.context, tracking, null, nonce, tags);
|
|
620
|
+
},
|
|
172
621
|
serialize(id, p) {
|
|
173
622
|
if (sharedConfig.context.noHydrate) return;
|
|
174
623
|
if (p != null && typeof p === "object" && (typeof p.then === "function" || typeof p[Symbol.asyncIterator] === "function")) {
|
|
@@ -176,19 +625,23 @@ function renderToString(code, options = {}) {
|
|
|
176
625
|
}
|
|
177
626
|
serializer.write(id, p);
|
|
178
627
|
},
|
|
179
|
-
registerAsset(type,
|
|
628
|
+
registerAsset(type, value) {
|
|
629
|
+
if (type === "inline-style") {
|
|
630
|
+
tracking.registerInlineStyle(value);
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
180
633
|
if (tracking.currentBoundaryId && type === "style") {
|
|
181
634
|
let styles = tracking.boundaryStyles.get(tracking.currentBoundaryId);
|
|
182
635
|
if (!styles) {
|
|
183
636
|
styles = new Set();
|
|
184
637
|
tracking.boundaryStyles.set(tracking.currentBoundaryId, styles);
|
|
185
638
|
}
|
|
186
|
-
styles.add(
|
|
639
|
+
styles.add(value);
|
|
187
640
|
}
|
|
188
|
-
tracking.emittedAssets.add(
|
|
641
|
+
tracking.emittedAssets.add(value);
|
|
189
642
|
}
|
|
190
643
|
};
|
|
191
|
-
applyAssetTracking(sharedConfig.context, tracking, manifest);
|
|
644
|
+
applyAssetTracking(sharedConfig.context, tracking, manifest, noScripts);
|
|
192
645
|
registerEntryAssets(manifest);
|
|
193
646
|
let html = createRoot(d => {
|
|
194
647
|
setTimeout(d);
|
|
@@ -196,12 +649,12 @@ function renderToString(code, options = {}) {
|
|
|
196
649
|
}, {
|
|
197
650
|
id: renderId
|
|
198
651
|
});
|
|
652
|
+
serializeFragmentAssets("", tracking.boundaryModules, sharedConfig.context);
|
|
199
653
|
sharedConfig.context.noHydrate = true;
|
|
200
654
|
serializer.close();
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
return html;
|
|
655
|
+
const assetsHtml = resolveAssetsHtml(sharedConfig.context.assets);
|
|
656
|
+
const head = renderShellHead(headRegistry, nonce, null);
|
|
657
|
+
return assembleDocument(html, assetsHtml, tracking.emittedAssets, tracking.inlineStyles, scripts.length ? scripts : "", nonce, head, onHead);
|
|
205
658
|
}
|
|
206
659
|
function renderToStream(code, options = {}) {
|
|
207
660
|
let {
|
|
@@ -210,18 +663,22 @@ function renderToStream(code, options = {}) {
|
|
|
210
663
|
onCompleteAll,
|
|
211
664
|
renderId = "",
|
|
212
665
|
noScripts,
|
|
213
|
-
manifest
|
|
666
|
+
manifest,
|
|
667
|
+
onHead
|
|
214
668
|
} = options;
|
|
215
669
|
let dispose;
|
|
216
670
|
const blockingPromises = new Set();
|
|
671
|
+
let headerEmitted = false;
|
|
217
672
|
const pushTask = task => {
|
|
218
673
|
if (noScripts) return;
|
|
219
|
-
if (!
|
|
220
|
-
|
|
674
|
+
if (!headerEmitted) {
|
|
675
|
+
headerEmitted = true;
|
|
676
|
+
tasks += getLocalHeaderScript(renderId);
|
|
221
677
|
}
|
|
222
678
|
tasks += task + ";";
|
|
223
679
|
if (!timer && firstFlushed) {
|
|
224
|
-
timer =
|
|
680
|
+
timer = true;
|
|
681
|
+
queue(() => queue(writeTasks));
|
|
225
682
|
}
|
|
226
683
|
};
|
|
227
684
|
const onDone = () => {
|
|
@@ -236,15 +693,63 @@ function renderToStream(code, options = {}) {
|
|
|
236
693
|
completed = true;
|
|
237
694
|
if (firstFlushed) dispose();
|
|
238
695
|
};
|
|
239
|
-
const
|
|
696
|
+
const sink = {
|
|
697
|
+
data(payload) {
|
|
698
|
+
pushTask(payload);
|
|
699
|
+
},
|
|
700
|
+
fragment(key, value, meta) {
|
|
701
|
+
const deferActivation = !!meta.revealGroup;
|
|
702
|
+
const styles = meta.styles;
|
|
703
|
+
for (let i = 0; i < styles.inline.length; i++) {
|
|
704
|
+
buffer.write(renderInlineStyle(styles.inline[i], nonce));
|
|
705
|
+
}
|
|
706
|
+
if (styles.links.length) {
|
|
707
|
+
emitTask(`$dfs("${key}",${styles.links.length},${deferActivation ? 1 : 0})`);
|
|
708
|
+
writeTasks();
|
|
709
|
+
for (const entry of styles.links) {
|
|
710
|
+
buffer.write(typeof entry === "string" ? `<link rel="stylesheet" href="${entry}" onload="$dfc('${key}')" onerror="$dfc('${key}')">` : `<link${entry.attrHtml} onload="$dfc('${key}')" onerror="$dfc('${key}')">`);
|
|
711
|
+
}
|
|
712
|
+
buffer.write(`<template id="${key}">${value}</template>`);
|
|
713
|
+
} else {
|
|
714
|
+
buffer.write(`<template id="${key}">${value}</template>`);
|
|
715
|
+
if (!deferActivation) {
|
|
716
|
+
emitTask(`$df("${key}")`);
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
},
|
|
720
|
+
reveal(keys, meta) {
|
|
721
|
+
emitTask(`${meta.fallback ? "$dflj" : "$dfj"}(${JSON.stringify(keys)})`);
|
|
722
|
+
},
|
|
723
|
+
asset(type, value) {
|
|
724
|
+
if (type === "module") {
|
|
725
|
+
buffer.write(`<link rel="modulepreload" href="${value}">`);
|
|
726
|
+
} else if (type === "inline-style") {
|
|
727
|
+
buffer.write(renderInlineStyle(value, nonce));
|
|
728
|
+
} else if (type === "head-tag") {
|
|
729
|
+
buffer.write(value);
|
|
730
|
+
}
|
|
731
|
+
},
|
|
732
|
+
shell(shellHtml, meta) {
|
|
733
|
+
buffer.write(assembleDocument(shellHtml, meta.assets, meta.preloads, meta.inlineStyles, meta.tasks.length ? meta.tasks : "", nonce, meta.head, onHead));
|
|
734
|
+
},
|
|
735
|
+
...options.sink
|
|
736
|
+
};
|
|
737
|
+
const serializer = (options.serializer || createHydrationSerializer)({
|
|
240
738
|
scopeId: options.renderId,
|
|
241
739
|
plugins: options.plugins,
|
|
242
|
-
onData:
|
|
740
|
+
onData: payload => sink.data(payload),
|
|
243
741
|
onDone,
|
|
244
742
|
onError: options.onError
|
|
245
743
|
});
|
|
744
|
+
let rootAssetsSerialized = false;
|
|
745
|
+
const serializeRootAssets = () => {
|
|
746
|
+
if (rootAssetsSerialized) return;
|
|
747
|
+
rootAssetsSerialized = true;
|
|
748
|
+
serializeFragmentAssets("", tracking.boundaryModules, context);
|
|
749
|
+
};
|
|
246
750
|
const flushEnd = () => {
|
|
247
751
|
if (!registry.size) {
|
|
752
|
+
serializeRootAssets();
|
|
248
753
|
queue(() => queue(() => serializer.flush()));
|
|
249
754
|
}
|
|
250
755
|
};
|
|
@@ -254,7 +759,6 @@ function renderToStream(code, options = {}) {
|
|
|
254
759
|
buffer.write(`<script${nonce ? ` nonce="${nonce}"` : ""}>${tasks}</script>`);
|
|
255
760
|
tasks = "";
|
|
256
761
|
}
|
|
257
|
-
timer && clearTimeout(timer);
|
|
258
762
|
timer = null;
|
|
259
763
|
};
|
|
260
764
|
let context;
|
|
@@ -266,7 +770,29 @@ function renderToStream(code, options = {}) {
|
|
|
266
770
|
let shellCompleted = false;
|
|
267
771
|
let scriptFlushed = false;
|
|
268
772
|
let headStyles;
|
|
773
|
+
const revealGroups = new Map();
|
|
269
774
|
let timer = null;
|
|
775
|
+
const emitTask = task => {
|
|
776
|
+
pushTask(`${task}${!scriptFlushed ? ";" + REPLACE_SCRIPT : ""}`);
|
|
777
|
+
scriptFlushed = true;
|
|
778
|
+
};
|
|
779
|
+
function resolveRevealKeys(groupOrKeys, release, consume) {
|
|
780
|
+
if (Array.isArray(groupOrKeys)) return groupOrKeys.slice();
|
|
781
|
+
let group = revealGroups.get(groupOrKeys);
|
|
782
|
+
if (!group) {
|
|
783
|
+
if (!release) return;
|
|
784
|
+
group = {
|
|
785
|
+
order: [],
|
|
786
|
+
keys: new Set(),
|
|
787
|
+
released: true
|
|
788
|
+
};
|
|
789
|
+
revealGroups.set(groupOrKeys, group);
|
|
790
|
+
} else if (release) group.released = true;
|
|
791
|
+
if (!group.order.length) return;
|
|
792
|
+
const keys = group.order.slice();
|
|
793
|
+
if (consume) revealGroups.delete(groupOrKeys);
|
|
794
|
+
return keys;
|
|
795
|
+
}
|
|
270
796
|
let rootHoles = null;
|
|
271
797
|
let nextHoleId = 0;
|
|
272
798
|
let buffer = {
|
|
@@ -275,24 +801,48 @@ function renderToStream(code, options = {}) {
|
|
|
275
801
|
}
|
|
276
802
|
};
|
|
277
803
|
const tracking = createAssetTracking();
|
|
804
|
+
const headRegistry = createHeadRegistry();
|
|
805
|
+
let headScriptFlushed = false;
|
|
806
|
+
const emitHeadOps = (key, ops) => {
|
|
807
|
+
const payload = JSON.stringify(ops).replace(/</g, "\\u003C");
|
|
808
|
+
emitTask(`${!headScriptFlushed ? HEAD_SCRIPT : ""}(_$HY.hp=_$HY.hp||{})[${JSON.stringify(key)}]=${payload}`);
|
|
809
|
+
headScriptFlushed = true;
|
|
810
|
+
};
|
|
278
811
|
sharedConfig.context = context = {
|
|
279
812
|
async: true,
|
|
280
813
|
assets: [],
|
|
281
814
|
nonce,
|
|
282
|
-
|
|
815
|
+
registerHeadTags(tags) {
|
|
816
|
+
registerHeadTags(headRegistry, context, tracking,
|
|
817
|
+
(markup, gateEntry) => {
|
|
818
|
+
if (!firstFlushed) {
|
|
819
|
+
headRegistry.eagerHtml += markup;
|
|
820
|
+
if (gateEntry) gateEntry.emitted = true;
|
|
821
|
+
} else if (!gateEntry || !tracking.currentBoundaryId) {
|
|
822
|
+
sink.asset("head-tag", markup);
|
|
823
|
+
}
|
|
824
|
+
}, nonce, tags);
|
|
825
|
+
},
|
|
826
|
+
registerAsset(type, value) {
|
|
827
|
+
if (type === "inline-style") {
|
|
828
|
+
const entry = tracking.registerInlineStyle(value);
|
|
829
|
+
if (firstFlushed && !tracking.currentBoundaryId && !entry.emitted) {
|
|
830
|
+
entry.emitted = true;
|
|
831
|
+
sink.asset("inline-style", entry);
|
|
832
|
+
}
|
|
833
|
+
return;
|
|
834
|
+
}
|
|
283
835
|
if (tracking.currentBoundaryId && type === "style") {
|
|
284
836
|
let styles = tracking.boundaryStyles.get(tracking.currentBoundaryId);
|
|
285
837
|
if (!styles) {
|
|
286
838
|
styles = new Set();
|
|
287
839
|
tracking.boundaryStyles.set(tracking.currentBoundaryId, styles);
|
|
288
840
|
}
|
|
289
|
-
styles.add(
|
|
841
|
+
styles.add(value);
|
|
290
842
|
}
|
|
291
|
-
if (!tracking.emittedAssets.has(
|
|
292
|
-
tracking.emittedAssets.add(
|
|
293
|
-
if (firstFlushed
|
|
294
|
-
buffer.write(`<link rel="modulepreload" href="${url}">`);
|
|
295
|
-
}
|
|
843
|
+
if (!tracking.emittedAssets.has(value)) {
|
|
844
|
+
tracking.emittedAssets.add(value);
|
|
845
|
+
if (firstFlushed) sink.asset(type, value);
|
|
296
846
|
}
|
|
297
847
|
},
|
|
298
848
|
block(p) {
|
|
@@ -316,7 +866,26 @@ function renderToStream(code, options = {}) {
|
|
|
316
866
|
escape: escape,
|
|
317
867
|
resolve: resolveSSRNode,
|
|
318
868
|
ssr: ssr,
|
|
319
|
-
registerFragment(key) {
|
|
869
|
+
registerFragment(key, options) {
|
|
870
|
+
const revealGroup = options && options.revealGroup;
|
|
871
|
+
if (revealGroup) {
|
|
872
|
+
let group = revealGroups.get(revealGroup);
|
|
873
|
+
if (!group) {
|
|
874
|
+
group = {
|
|
875
|
+
order: [],
|
|
876
|
+
keys: new Set(),
|
|
877
|
+
released: false
|
|
878
|
+
};
|
|
879
|
+
revealGroups.set(revealGroup, group);
|
|
880
|
+
}
|
|
881
|
+
if (!group.keys.has(key)) {
|
|
882
|
+
group.keys.add(key);
|
|
883
|
+
group.order.push(key);
|
|
884
|
+
}
|
|
885
|
+
if (group.released) {
|
|
886
|
+
throw new Error("registerFragment() for reveal group '" + revealGroup + "' was called after revealFragments(). Ensure template payload is emitted before grouped reveal.");
|
|
887
|
+
}
|
|
888
|
+
}
|
|
320
889
|
if (!registry.has(key)) {
|
|
321
890
|
let resolve, reject;
|
|
322
891
|
const p = new Promise((r, rej) => (resolve = r, reject = rej));
|
|
@@ -326,7 +895,7 @@ function renderToStream(code, options = {}) {
|
|
|
326
895
|
queue(flushEnd);
|
|
327
896
|
}))
|
|
328
897
|
});
|
|
329
|
-
serializer.write(key, p);
|
|
898
|
+
serializer.write(key + "_fr", p);
|
|
330
899
|
}
|
|
331
900
|
return (value, error) => {
|
|
332
901
|
if (registry.has(key)) {
|
|
@@ -344,10 +913,12 @@ function renderToStream(code, options = {}) {
|
|
|
344
913
|
parent.children[key] = value !== undefined ? value : "";
|
|
345
914
|
serializeFragmentAssets(key, tracking.boundaryModules, context);
|
|
346
915
|
propagateBoundaryStyles(key, parentKey, tracking);
|
|
916
|
+
adoptHeadBoundary(headRegistry, key, parentKey);
|
|
347
917
|
item.resolve();
|
|
348
918
|
return;
|
|
349
919
|
}
|
|
350
920
|
if (!completed) {
|
|
921
|
+
if (error) dropHeadBoundary(headRegistry, key);
|
|
351
922
|
if (!firstFlushed) {
|
|
352
923
|
queue(() => html = replacePlaceholder(html, key, value !== undefined ? value : ""));
|
|
353
924
|
serializeFragmentAssets(key, tracking.boundaryModules, context);
|
|
@@ -355,28 +926,36 @@ function renderToStream(code, options = {}) {
|
|
|
355
926
|
} else {
|
|
356
927
|
serializeFragmentAssets(key, tracking.boundaryModules, context);
|
|
357
928
|
const styles = collectStreamStyles(key, tracking, headStyles);
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
buffer.write(`<template id="${key}">${value !== undefined ? value : " "}</template>`);
|
|
366
|
-
} else {
|
|
367
|
-
buffer.write(`<template id="${key}">${value !== undefined ? value : " "}</template>`);
|
|
368
|
-
pushTask(`$df("${key}")${!scriptFlushed ? ";" + REPLACE_SCRIPT : ""}`);
|
|
369
|
-
scriptFlushed = true;
|
|
370
|
-
}
|
|
929
|
+
const headOps = error ? null : flushHeadFragment(headRegistry, key);
|
|
930
|
+
if (headOps) emitHeadOps(key, headOps);
|
|
931
|
+
sink.fragment(key, value !== undefined ? value : " ", {
|
|
932
|
+
styles,
|
|
933
|
+
revealGroup,
|
|
934
|
+
error
|
|
935
|
+
});
|
|
371
936
|
item.resolve(error);
|
|
372
937
|
}
|
|
373
938
|
}
|
|
374
939
|
}
|
|
375
940
|
return firstFlushed;
|
|
376
941
|
};
|
|
942
|
+
},
|
|
943
|
+
revealFragments(groupOrKeys) {
|
|
944
|
+
const keys = resolveRevealKeys(groupOrKeys, true, true);
|
|
945
|
+
if (!keys) return;
|
|
946
|
+
sink.reveal(keys, {
|
|
947
|
+
fallback: false
|
|
948
|
+
});
|
|
949
|
+
},
|
|
950
|
+
revealFallbacks(groupOrKeys) {
|
|
951
|
+
const keys = resolveRevealKeys(groupOrKeys, false, false);
|
|
952
|
+
if (!keys) return;
|
|
953
|
+
sink.reveal(keys, {
|
|
954
|
+
fallback: true
|
|
955
|
+
});
|
|
377
956
|
}
|
|
378
957
|
};
|
|
379
|
-
applyAssetTracking(context, tracking, manifest);
|
|
958
|
+
applyAssetTracking(context, tracking, manifest, noScripts);
|
|
380
959
|
registerEntryAssets(manifest);
|
|
381
960
|
let html = createRoot(d => {
|
|
382
961
|
dispose = d;
|
|
@@ -397,28 +976,56 @@ function renderToStream(code, options = {}) {
|
|
|
397
976
|
}, {
|
|
398
977
|
id: renderId
|
|
399
978
|
});
|
|
400
|
-
function
|
|
401
|
-
if (
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
979
|
+
function resolveRootHoles() {
|
|
980
|
+
if (!rootHoles) return true;
|
|
981
|
+
const pending = [];
|
|
982
|
+
for (const {
|
|
983
|
+
id,
|
|
984
|
+
fn
|
|
985
|
+
} of rootHoles) {
|
|
986
|
+
const marker = `<!--rh${id}-->`;
|
|
987
|
+
const res = resolveSSRNode(fn);
|
|
988
|
+
if (!res.h.length) {
|
|
989
|
+
html = html.replace(marker, res.t[0]);
|
|
990
|
+
} else {
|
|
991
|
+
let out = res.t[0];
|
|
992
|
+
for (let j = 0; j < res.h.length; j++) {
|
|
993
|
+
const newId = nextHoleId++;
|
|
994
|
+
pending.push({
|
|
995
|
+
id: newId,
|
|
996
|
+
fn: res.h[j]
|
|
997
|
+
});
|
|
998
|
+
out += `<!--rh${newId}-->` + res.t[j + 1];
|
|
999
|
+
}
|
|
1000
|
+
html = html.replace(marker, out);
|
|
1001
|
+
for (const p of res.p) blockingPromises.add(p);
|
|
410
1002
|
}
|
|
411
|
-
rootHoles = null;
|
|
412
1003
|
}
|
|
1004
|
+
if (pending.length) {
|
|
1005
|
+
rootHoles = pending;
|
|
1006
|
+
return false;
|
|
1007
|
+
}
|
|
1008
|
+
rootHoles = null;
|
|
1009
|
+
return true;
|
|
1010
|
+
}
|
|
1011
|
+
function doShell() {
|
|
1012
|
+
if (shellCompleted) return;
|
|
1013
|
+
if (!resolveRootHoles()) return;
|
|
413
1014
|
sharedConfig.context = context;
|
|
414
|
-
|
|
1015
|
+
const assetsHtml = resolveAssetsHtml(context.assets);
|
|
415
1016
|
headStyles = new Set();
|
|
416
1017
|
for (const url of tracking.emittedAssets) {
|
|
417
|
-
if (url
|
|
1018
|
+
if (isCssUrl(url)) headStyles.add(url);
|
|
418
1019
|
}
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
1020
|
+
serializeRootAssets();
|
|
1021
|
+
const head = renderShellHead(headRegistry, nonce, k => registry.has(k));
|
|
1022
|
+
sink.shell(html, {
|
|
1023
|
+
assets: assetsHtml,
|
|
1024
|
+
preloads: tracking.emittedAssets,
|
|
1025
|
+
inlineStyles: tracking.inlineStyles,
|
|
1026
|
+
tasks,
|
|
1027
|
+
head
|
|
1028
|
+
});
|
|
422
1029
|
tasks = "";
|
|
423
1030
|
onCompleteShell && onCompleteShell({
|
|
424
1031
|
write(v) {
|
|
@@ -427,53 +1034,57 @@ function renderToStream(code, options = {}) {
|
|
|
427
1034
|
});
|
|
428
1035
|
shellCompleted = true;
|
|
429
1036
|
}
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
1037
|
+
const MIN_DRAIN_TURNS = 8;
|
|
1038
|
+
let lastBlockingSize = -1;
|
|
1039
|
+
let lastRegistrySize = -1;
|
|
1040
|
+
let drainTurn = 0;
|
|
1041
|
+
const scheduleFlush = fn => {
|
|
1042
|
+
const attempt = () => {
|
|
1043
|
+
if (registry.size !== lastRegistrySize || drainTurn++ < MIN_DRAIN_TURNS) {
|
|
1044
|
+
if (registry.size !== lastRegistrySize) drainTurn = 0;
|
|
1045
|
+
lastRegistrySize = registry.size;
|
|
1046
|
+
queue(attempt);
|
|
1047
|
+
return;
|
|
435
1048
|
}
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
1049
|
+
fn();
|
|
1050
|
+
};
|
|
1051
|
+
const progressed = blockingPromises.size !== lastBlockingSize;
|
|
1052
|
+
lastBlockingSize = blockingPromises.size;
|
|
1053
|
+
lastRegistrySize = -1;
|
|
1054
|
+
drainTurn = 0;
|
|
1055
|
+
progressed ? queue(attempt) : setTimeout(attempt);
|
|
1056
|
+
};
|
|
1057
|
+
let cachedReadable;
|
|
1058
|
+
let consumer;
|
|
1059
|
+
const claimConsumer = name => {
|
|
1060
|
+
if (consumer && consumer !== name) {
|
|
1061
|
+
throw new Error(`renderToStream result was already consumed via \`${consumer}\`; cannot also consume it via \`${name}\`. Use exactly one of \`pipe\`, \`pipeTo\`, or \`readable\`.`);
|
|
1062
|
+
}
|
|
1063
|
+
consumer = name;
|
|
1064
|
+
};
|
|
1065
|
+
const pipeToImpl = w => {
|
|
1066
|
+
let resolve;
|
|
1067
|
+
const p = new Promise(r => resolve = r);
|
|
1068
|
+
function flush() {
|
|
446
1069
|
allSettled(blockingPromises).then(() => {
|
|
447
|
-
|
|
448
|
-
doShell();
|
|
449
|
-
buffer = writable = w;
|
|
450
|
-
buffer.write(tmp);
|
|
451
|
-
firstFlushed = true;
|
|
452
|
-
if (completed) {
|
|
453
|
-
dispose();
|
|
454
|
-
writable.end();
|
|
455
|
-
} else flushEnd();
|
|
456
|
-
});
|
|
457
|
-
});
|
|
458
|
-
},
|
|
459
|
-
pipeTo(w) {
|
|
460
|
-
return allSettled(blockingPromises).then(() => {
|
|
461
|
-
let resolve;
|
|
462
|
-
const p = new Promise(r => resolve = r);
|
|
463
|
-
setTimeout(() => {
|
|
1070
|
+
scheduleFlush(() => {
|
|
464
1071
|
doShell();
|
|
1072
|
+
if (!shellCompleted) return flush();
|
|
465
1073
|
const encoder = new TextEncoder();
|
|
466
1074
|
const writer = w.getWriter();
|
|
1075
|
+
let pendingWrites = Promise.resolve();
|
|
467
1076
|
writable = {
|
|
468
1077
|
end() {
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
1078
|
+
pendingWrites.then(() => {
|
|
1079
|
+
writer.releaseLock();
|
|
1080
|
+
w.close().catch(() => {});
|
|
1081
|
+
resolve();
|
|
1082
|
+
});
|
|
472
1083
|
}
|
|
473
1084
|
};
|
|
474
1085
|
buffer = {
|
|
475
1086
|
write(payload) {
|
|
476
|
-
writer.write(encoder.encode(payload)).catch(() => {});
|
|
1087
|
+
pendingWrites = pendingWrites.then(() => writer.write(encoder.encode(payload))).catch(() => {});
|
|
477
1088
|
}
|
|
478
1089
|
};
|
|
479
1090
|
buffer.write(tmp);
|
|
@@ -483,9 +1094,66 @@ function renderToStream(code, options = {}) {
|
|
|
483
1094
|
writable.end();
|
|
484
1095
|
} else flushEnd();
|
|
485
1096
|
});
|
|
486
|
-
return p;
|
|
487
1097
|
});
|
|
488
1098
|
}
|
|
1099
|
+
flush();
|
|
1100
|
+
return p;
|
|
1101
|
+
};
|
|
1102
|
+
return {
|
|
1103
|
+
then(fn) {
|
|
1104
|
+
function complete() {
|
|
1105
|
+
dispose();
|
|
1106
|
+
fn(tmp);
|
|
1107
|
+
}
|
|
1108
|
+
if (onCompleteAll) {
|
|
1109
|
+
let ogComplete = onCompleteAll;
|
|
1110
|
+
onCompleteAll = options => {
|
|
1111
|
+
ogComplete(options);
|
|
1112
|
+
complete();
|
|
1113
|
+
};
|
|
1114
|
+
} else onCompleteAll = complete;
|
|
1115
|
+
function flush() {
|
|
1116
|
+
allSettled(blockingPromises).then(() => {
|
|
1117
|
+
scheduleFlush(() => {
|
|
1118
|
+
if (!resolveRootHoles()) return flush();
|
|
1119
|
+
queue(flushEnd);
|
|
1120
|
+
});
|
|
1121
|
+
});
|
|
1122
|
+
}
|
|
1123
|
+
flush();
|
|
1124
|
+
},
|
|
1125
|
+
pipe(w) {
|
|
1126
|
+
claimConsumer("pipe");
|
|
1127
|
+
function flush() {
|
|
1128
|
+
allSettled(blockingPromises).then(() => {
|
|
1129
|
+
scheduleFlush(() => {
|
|
1130
|
+
doShell();
|
|
1131
|
+
if (!shellCompleted) return flush();
|
|
1132
|
+
buffer = writable = w;
|
|
1133
|
+
buffer.write(tmp);
|
|
1134
|
+
firstFlushed = true;
|
|
1135
|
+
if (completed) {
|
|
1136
|
+
dispose();
|
|
1137
|
+
writable.end();
|
|
1138
|
+
} else flushEnd();
|
|
1139
|
+
});
|
|
1140
|
+
});
|
|
1141
|
+
}
|
|
1142
|
+
flush();
|
|
1143
|
+
},
|
|
1144
|
+
pipeTo(w) {
|
|
1145
|
+
claimConsumer("pipeTo");
|
|
1146
|
+
return pipeToImpl(w);
|
|
1147
|
+
},
|
|
1148
|
+
get readable() {
|
|
1149
|
+
claimConsumer("readable");
|
|
1150
|
+
if (!cachedReadable) {
|
|
1151
|
+
const t = new TransformStream();
|
|
1152
|
+
pipeToImpl(t.writable);
|
|
1153
|
+
cachedReadable = t.readable;
|
|
1154
|
+
}
|
|
1155
|
+
return cachedReadable;
|
|
1156
|
+
}
|
|
489
1157
|
};
|
|
490
1158
|
}
|
|
491
1159
|
function HydrationScript(props) {
|
|
@@ -497,11 +1165,176 @@ function HydrationScript(props) {
|
|
|
497
1165
|
...props
|
|
498
1166
|
}));
|
|
499
1167
|
}
|
|
500
|
-
function
|
|
501
|
-
|
|
1168
|
+
function ssrGroup(fn, n) {
|
|
1169
|
+
fn.$g = n;
|
|
1170
|
+
return fn;
|
|
1171
|
+
}
|
|
1172
|
+
function buildAsyncWrap(err, node) {
|
|
1173
|
+
const p = ssrHandleError(err);
|
|
1174
|
+
if (!p) return null;
|
|
1175
|
+
const owner = getOwner();
|
|
502
1176
|
return {
|
|
1177
|
+
fn: owner ? () => runWithOwner(owner, node) : node,
|
|
1178
|
+
p
|
|
1179
|
+
};
|
|
1180
|
+
}
|
|
1181
|
+
function ssrFirstGroupHit(hole) {
|
|
1182
|
+
try {
|
|
1183
|
+
return hole();
|
|
1184
|
+
} catch (err) {
|
|
1185
|
+
return buildAsyncWrap(err, hole);
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
function tryResolveFunctionHole(hole) {
|
|
1189
|
+
let value;
|
|
1190
|
+
try {
|
|
1191
|
+
value = hole();
|
|
1192
|
+
} catch (err) {
|
|
1193
|
+
return buildAsyncWrap(err, hole) || "";
|
|
1194
|
+
}
|
|
1195
|
+
const t = typeof value;
|
|
1196
|
+
if (t === "string") return value;
|
|
1197
|
+
if (t === "number") return "" + value;
|
|
1198
|
+
if (value == null || t === "boolean") return "";
|
|
1199
|
+
return tryResolveString(value);
|
|
1200
|
+
}
|
|
1201
|
+
function mergeTemplateInto(result, node) {
|
|
1202
|
+
result.t[result.t.length - 1] += node.t[0];
|
|
1203
|
+
if (node.t.length > 1) {
|
|
1204
|
+
result.t.push(...node.t.slice(1));
|
|
1205
|
+
result.h.push(...node.h);
|
|
1206
|
+
result.p.push(...node.p);
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
function appendResolvedNode(result, node) {
|
|
1210
|
+
if (node.fn !== undefined) {
|
|
1211
|
+
result.h.push(node.fn);
|
|
1212
|
+
result.p.push(node.p);
|
|
1213
|
+
result.t.push("");
|
|
1214
|
+
} else if (node.merge !== undefined) mergeTemplateInto(result, node.merge);else resolveSSRNode(node.bail, result);
|
|
1215
|
+
}
|
|
1216
|
+
let _lastGroupFn = null;
|
|
1217
|
+
let _lastGroupArr = null;
|
|
1218
|
+
let _lastGroupErr = null;
|
|
1219
|
+
function ssrGroupSlot(fn, idx) {
|
|
1220
|
+
return () => {
|
|
1221
|
+
if (idx > 0 && _lastGroupFn === fn) {
|
|
1222
|
+
if (_lastGroupArr !== null) return _lastGroupArr[idx];
|
|
1223
|
+
throw _lastGroupErr;
|
|
1224
|
+
}
|
|
1225
|
+
_lastGroupFn = fn;
|
|
1226
|
+
_lastGroupArr = null;
|
|
1227
|
+
_lastGroupErr = null;
|
|
1228
|
+
try {
|
|
1229
|
+
_lastGroupArr = fn();
|
|
1230
|
+
return _lastGroupArr[idx];
|
|
1231
|
+
} catch (err) {
|
|
1232
|
+
_lastGroupErr = err;
|
|
1233
|
+
throw err;
|
|
1234
|
+
}
|
|
1235
|
+
};
|
|
1236
|
+
}
|
|
1237
|
+
function ssr(t) {
|
|
1238
|
+
const len = arguments.length;
|
|
1239
|
+
if (len === 1) return {
|
|
503
1240
|
t
|
|
504
1241
|
};
|
|
1242
|
+
let s = t[0];
|
|
1243
|
+
let result = null;
|
|
1244
|
+
let lastGroup = null;
|
|
1245
|
+
let lastGroupVal = null;
|
|
1246
|
+
let lastGroupIdx = 0;
|
|
1247
|
+
for (let i = 1; i < len; i++) {
|
|
1248
|
+
const hole = arguments[i];
|
|
1249
|
+
const ht = typeof hole;
|
|
1250
|
+
if (ht === "string") {
|
|
1251
|
+
if (result === null) s += hole;else result.t[result.t.length - 1] += hole;
|
|
1252
|
+
} else if (ht === "number") {
|
|
1253
|
+
if (result === null) s += hole;else result.t[result.t.length - 1] += hole;
|
|
1254
|
+
} else if (hole == null || ht === "boolean") ; else if (ht === "function" && hole.$g) {
|
|
1255
|
+
let value;
|
|
1256
|
+
let hasValue = false;
|
|
1257
|
+
if (lastGroup !== hole) {
|
|
1258
|
+
const r = ssrFirstGroupHit(hole);
|
|
1259
|
+
if (r !== null) {
|
|
1260
|
+
lastGroup = hole;
|
|
1261
|
+
lastGroupVal = r;
|
|
1262
|
+
lastGroupIdx = 0;
|
|
1263
|
+
if (!Array.isArray(r) && result === null) {
|
|
1264
|
+
result = {
|
|
1265
|
+
t: [s],
|
|
1266
|
+
h: [],
|
|
1267
|
+
p: []
|
|
1268
|
+
};
|
|
1269
|
+
s = "";
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
if (lastGroup === hole) {
|
|
1274
|
+
if (Array.isArray(lastGroupVal)) {
|
|
1275
|
+
value = lastGroupVal[lastGroupIdx++];
|
|
1276
|
+
hasValue = true;
|
|
1277
|
+
} else {
|
|
1278
|
+
result.h.push(ssrGroupSlot(lastGroupVal.fn, lastGroupIdx++));
|
|
1279
|
+
result.p.push(lastGroupVal.p);
|
|
1280
|
+
result.t.push("");
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
if (hasValue) {
|
|
1284
|
+
const vt = typeof value;
|
|
1285
|
+
if (vt === "string" || vt === "number") {
|
|
1286
|
+
if (result === null) s += value;else result.t[result.t.length - 1] += value;
|
|
1287
|
+
} else if (value == null || vt === "boolean") ; else if (result !== null) {
|
|
1288
|
+
resolveSSRNode(value, result);
|
|
1289
|
+
} else {
|
|
1290
|
+
const rs = tryResolveString(value);
|
|
1291
|
+
if (typeof rs === "string") {
|
|
1292
|
+
s += rs;
|
|
1293
|
+
} else {
|
|
1294
|
+
result = {
|
|
1295
|
+
t: [s],
|
|
1296
|
+
h: [],
|
|
1297
|
+
p: []
|
|
1298
|
+
};
|
|
1299
|
+
s = "";
|
|
1300
|
+
if (rs.merge !== undefined) mergeTemplateInto(result, rs.merge);else resolveSSRNode(rs.bail, result);
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
} else if (result !== null) {
|
|
1305
|
+
resolveSSRNode(hole, result);
|
|
1306
|
+
} else if (ht === "function") {
|
|
1307
|
+
const r = tryResolveFunctionHole(hole);
|
|
1308
|
+
if (typeof r === "string") s += r;else {
|
|
1309
|
+
result = {
|
|
1310
|
+
t: [s],
|
|
1311
|
+
h: [],
|
|
1312
|
+
p: []
|
|
1313
|
+
};
|
|
1314
|
+
s = "";
|
|
1315
|
+
appendResolvedNode(result, r);
|
|
1316
|
+
}
|
|
1317
|
+
} else {
|
|
1318
|
+
const r = tryResolveString(hole);
|
|
1319
|
+
if (typeof r === "string") {
|
|
1320
|
+
s += r;
|
|
1321
|
+
} else {
|
|
1322
|
+
result = {
|
|
1323
|
+
t: [s],
|
|
1324
|
+
h: [],
|
|
1325
|
+
p: []
|
|
1326
|
+
};
|
|
1327
|
+
s = "";
|
|
1328
|
+
appendResolvedNode(result, r);
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
const next = t[i];
|
|
1332
|
+
if (result === null) s += next;else result.t[result.t.length - 1] += next;
|
|
1333
|
+
}
|
|
1334
|
+
if (result === null) return {
|
|
1335
|
+
t: s
|
|
1336
|
+
};
|
|
1337
|
+
return result;
|
|
505
1338
|
}
|
|
506
1339
|
function ssrClassName(value) {
|
|
507
1340
|
if (!value) return "";
|
|
@@ -514,7 +1347,7 @@ function ssrClassName(value) {
|
|
|
514
1347
|
classValue = !!value[key];
|
|
515
1348
|
if (!key || key === "undefined" || !classValue) continue;
|
|
516
1349
|
i && (result += " ");
|
|
517
|
-
result += escape(key);
|
|
1350
|
+
result += escape(key, true);
|
|
518
1351
|
}
|
|
519
1352
|
return result;
|
|
520
1353
|
}
|
|
@@ -524,8 +1357,8 @@ function ssrStyle(value) {
|
|
|
524
1357
|
let result = "";
|
|
525
1358
|
const k = Object.keys(value);
|
|
526
1359
|
for (let i = 0; i < k.length; i++) {
|
|
527
|
-
const s = k[i];
|
|
528
|
-
const v = value[
|
|
1360
|
+
const s = escape(k[i], true);
|
|
1361
|
+
const v = value[k[i]];
|
|
529
1362
|
if (v != undefined) {
|
|
530
1363
|
if (i) result += ";";
|
|
531
1364
|
const r = escape(v, true);
|
|
@@ -540,10 +1373,11 @@ function ssrStyleProperty(name, value) {
|
|
|
540
1373
|
return value != null ? name + value : "";
|
|
541
1374
|
}
|
|
542
1375
|
function ssrElement(tag, props, children, needsId) {
|
|
1376
|
+
const hk = needsId ? ssrHydrationKey() : "";
|
|
543
1377
|
if (props == null) props = {};else if (typeof props === "function") props = props();
|
|
544
1378
|
const skipChildren = VOID_ELEMENTS.test(tag);
|
|
545
1379
|
const keys = Object.keys(props);
|
|
546
|
-
let result = `<${tag}${
|
|
1380
|
+
let result = `<${tag}${hk} `;
|
|
547
1381
|
for (let i = 0; i < keys.length; i++) {
|
|
548
1382
|
const prop = keys[i];
|
|
549
1383
|
if (ChildProperties.has(prop)) {
|
|
@@ -582,18 +1416,31 @@ function escape(s, attr) {
|
|
|
582
1416
|
const t = typeof s;
|
|
583
1417
|
if (t !== "string") {
|
|
584
1418
|
if (!attr && Array.isArray(s)) {
|
|
1419
|
+
const joined = tryJoinPlainSSRArray(s);
|
|
1420
|
+
if (joined !== undefined) return joined;
|
|
585
1421
|
s = s.slice();
|
|
586
1422
|
for (let i = 0; i < s.length; i++) s[i] = escape(s[i]);
|
|
587
1423
|
return s;
|
|
588
1424
|
}
|
|
589
|
-
if (attr
|
|
1425
|
+
if (attr) {
|
|
1426
|
+
if (s == null || t === "boolean" || t === "number") return s;
|
|
1427
|
+
return escape(String(s), attr);
|
|
1428
|
+
}
|
|
590
1429
|
return s;
|
|
591
1430
|
}
|
|
1431
|
+
const i = s.search(attr ? ESCAPE_ATTR : ESCAPE_CONTENT);
|
|
1432
|
+
if (i < 0) return s;
|
|
1433
|
+
return escapeSlow(s, attr, i);
|
|
1434
|
+
}
|
|
1435
|
+
const ESCAPE_CONTENT = /[&<]/;
|
|
1436
|
+
const ESCAPE_ATTR = /[&"]/;
|
|
1437
|
+
function escapeSlow(s, attr, start) {
|
|
592
1438
|
const delim = attr ? '"' : "<";
|
|
1439
|
+
const delimCode = attr ? 34 : 60;
|
|
593
1440
|
const escDelim = attr ? """ : "<";
|
|
594
|
-
|
|
595
|
-
let
|
|
596
|
-
|
|
1441
|
+
const c0 = s.charCodeAt(start);
|
|
1442
|
+
let iDelim = c0 === delimCode ? start : s.indexOf(delim, start);
|
|
1443
|
+
let iAmp = c0 === 38 ? start : s.indexOf("&", start);
|
|
597
1444
|
let left = 0,
|
|
598
1445
|
out = "";
|
|
599
1446
|
while (iDelim >= 0 && iAmp >= 0) {
|
|
@@ -624,28 +1471,17 @@ function escape(s, attr) {
|
|
|
624
1471
|
}
|
|
625
1472
|
return left < s.length ? out + s.substring(left) : out;
|
|
626
1473
|
}
|
|
627
|
-
function
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
if (
|
|
633
|
-
|
|
634
|
-
for (const key in descriptors) {
|
|
635
|
-
if (key in target) continue;
|
|
636
|
-
Object.defineProperty(target, key, {
|
|
637
|
-
enumerable: true,
|
|
638
|
-
get() {
|
|
639
|
-
for (let i = sources.length - 1; i >= 0; i--) {
|
|
640
|
-
const v = (sources[i] || {})[key];
|
|
641
|
-
if (v !== undefined) return v;
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
});
|
|
645
|
-
}
|
|
1474
|
+
function tryJoinPlainSSRArray(nodes) {
|
|
1475
|
+
if (nodes.length === 0) return undefined;
|
|
1476
|
+
let out = "";
|
|
1477
|
+
for (let i = 0, len = nodes.length; i < len; i++) {
|
|
1478
|
+
const node = nodes[i];
|
|
1479
|
+
if (node == null || typeof node !== "object" || node.h || typeof node.t !== "string") {
|
|
1480
|
+
return undefined;
|
|
646
1481
|
}
|
|
1482
|
+
out += node.t;
|
|
647
1483
|
}
|
|
648
|
-
return
|
|
1484
|
+
return out;
|
|
649
1485
|
}
|
|
650
1486
|
function getHydrationKey() {
|
|
651
1487
|
const hydrate = sharedConfig.context;
|
|
@@ -663,11 +1499,14 @@ function getAssets() {
|
|
|
663
1499
|
for (let i = 0, len = assets.length; i < len; i++) out += assets[i]();
|
|
664
1500
|
return out;
|
|
665
1501
|
}
|
|
1502
|
+
function Assets(props) {
|
|
1503
|
+
useAssets(() => props.children);
|
|
1504
|
+
}
|
|
666
1505
|
function generateHydrationScript({
|
|
667
1506
|
eventNames = ["click", "input"],
|
|
668
1507
|
nonce
|
|
669
1508
|
} = {}) {
|
|
670
|
-
return `<script${nonce ? ` nonce="${nonce}"` : ""}>window._$HY||(e=>{let t=e=>e&&e.hasAttribute&&(e.hasAttribute("_hk")?e:t(e.host&&e.host.nodeType?e.host:e.parentNode));["${eventNames.join('",
|
|
1509
|
+
return `<script${nonce ? ` nonce="${nonce}"` : ""}>window._$HY||(e=>{let t=e=>e&&e.hasAttribute&&(e.hasAttribute("_hk")?e:t(e.host&&e.host.nodeType?e.host:e.parentNode));["${eventNames.join('","')}"].forEach((o=>document.addEventListener(o,(o=>{if(!e.events)return;let s=t(o.composedPath&&o.composedPath()[0]||o.target);s&&!e.completed.has(s)&&e.events.push([s,o])}))))})(_$HY={events:[],completed:new WeakSet,r:{},fe(){}});</script><!--xs-->`;
|
|
671
1510
|
}
|
|
672
1511
|
function queue(fn) {
|
|
673
1512
|
return Promise.resolve().then(fn);
|
|
@@ -679,27 +1518,58 @@ function allSettled(promises) {
|
|
|
679
1518
|
return;
|
|
680
1519
|
});
|
|
681
1520
|
}
|
|
682
|
-
function
|
|
683
|
-
if (!assets || !assets.length) return
|
|
1521
|
+
function resolveAssetsHtml(assets) {
|
|
1522
|
+
if (!assets || !assets.length) return "";
|
|
684
1523
|
let out = "";
|
|
685
1524
|
for (let i = 0, len = assets.length; i < len; i++) out += assets[i]();
|
|
686
|
-
|
|
687
|
-
if (index === -1) return html;
|
|
688
|
-
return html.slice(0, index) + out + html.slice(index);
|
|
1525
|
+
return out;
|
|
689
1526
|
}
|
|
690
|
-
function
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
1527
|
+
function assembleDocument(html, assetsHtml, emittedAssets, inlineStyles, scripts, nonce, headTags, onHead) {
|
|
1528
|
+
const scriptTag = scripts ? `<script${nonce ? ` nonce="${nonce}"` : ""}>${scripts}</script>` : "";
|
|
1529
|
+
const headTagsHtml = headTags ? headTags.html : "";
|
|
1530
|
+
const headPrelude = headTags ? headTags.prelude : "";
|
|
1531
|
+
if (!onHead && !assetsHtml && !headTagsHtml && !headPrelude && !(emittedAssets && emittedAssets.size) && !(inlineStyles && inlineStyles.size)) {
|
|
1532
|
+
if (!scriptTag) return html;
|
|
1533
|
+
const xs = html.indexOf("<!--xs-->");
|
|
1534
|
+
return xs === -1 ? html + scriptTag : html.slice(0, xs) + scriptTag + html.slice(xs);
|
|
1535
|
+
}
|
|
1536
|
+
if (headPrelude) {
|
|
1537
|
+
const open = html.match(/<head(?:\s[^>]*)?>/);
|
|
1538
|
+
if (open) {
|
|
1539
|
+
const at = open.index + open[0].length;
|
|
1540
|
+
html = html.slice(0, at) + headPrelude + html.slice(at);
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
const headIdx = html.indexOf("</head>");
|
|
1544
|
+
if (headIdx === -1) {
|
|
1545
|
+
if (onHead) {
|
|
1546
|
+
onHead(headPrelude + headTagsHtml + (assetsHtml || "") + renderHeadAssets(emittedAssets, inlineStyles, nonce));
|
|
1547
|
+
}
|
|
1548
|
+
if (!scriptTag) return html;
|
|
1549
|
+
const xs = html.indexOf("<!--xs-->");
|
|
1550
|
+
return xs === -1 ? html + scriptTag : html.slice(0, xs) + scriptTag + html.slice(xs);
|
|
1551
|
+
}
|
|
1552
|
+
const head = headTagsHtml + (assetsHtml || "") + renderHeadAssets(emittedAssets, inlineStyles, nonce);
|
|
1553
|
+
if (!scriptTag) return html.slice(0, headIdx) + head + html.slice(headIdx);
|
|
1554
|
+
const xsIdx = html.indexOf("<!--xs-->");
|
|
1555
|
+
if (xsIdx === -1) return html.slice(0, headIdx) + head + html.slice(headIdx) + scriptTag;
|
|
1556
|
+
return xsIdx < headIdx ? html.slice(0, xsIdx) + scriptTag + html.slice(xsIdx, headIdx) + head + html.slice(headIdx) : html.slice(0, headIdx) + head + html.slice(headIdx, xsIdx) + scriptTag + html.slice(xsIdx);
|
|
1557
|
+
}
|
|
1558
|
+
function renderHeadAssets(emittedAssets, inlineStyles, nonce) {
|
|
1559
|
+
let head = "";
|
|
1560
|
+
if (emittedAssets && emittedAssets.size) {
|
|
1561
|
+
for (const url of emittedAssets) {
|
|
1562
|
+
head += isCssUrl(url) ? `<link rel="stylesheet" href="${url}">` : `<link rel="modulepreload" href="${url}">`;
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
if (inlineStyles && inlineStyles.size) {
|
|
1566
|
+
for (const entry of inlineStyles.values()) {
|
|
1567
|
+
if (entry.emitted) continue;
|
|
1568
|
+
entry.emitted = true;
|
|
1569
|
+
head += renderInlineStyle(entry, nonce);
|
|
698
1570
|
}
|
|
699
1571
|
}
|
|
700
|
-
|
|
701
|
-
if (index === -1) return html;
|
|
702
|
-
return html.slice(0, index) + links + html.slice(index);
|
|
1572
|
+
return head;
|
|
703
1573
|
}
|
|
704
1574
|
function serializeFragmentAssets(key, boundaryModules, context) {
|
|
705
1575
|
const map = boundaryModules.get(key);
|
|
@@ -720,22 +1590,41 @@ function propagateBoundaryStyles(childKey, parentKey, tracking) {
|
|
|
720
1590
|
}
|
|
721
1591
|
function collectStreamStyles(key, tracking, headStyles) {
|
|
722
1592
|
const styles = tracking.getBoundaryStyles(key);
|
|
723
|
-
|
|
724
|
-
const
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
1593
|
+
const links = [];
|
|
1594
|
+
const inline = [];
|
|
1595
|
+
if (!styles) return {
|
|
1596
|
+
links,
|
|
1597
|
+
inline
|
|
1598
|
+
};
|
|
1599
|
+
for (const entry of styles) {
|
|
1600
|
+
if (typeof entry === "string") {
|
|
1601
|
+
if (!headStyles || !headStyles.has(entry)) links.push(entry);
|
|
1602
|
+
} else if (entry.emitted) {
|
|
1603
|
+
continue;
|
|
1604
|
+
} else if (entry.attrHtml !== undefined) {
|
|
1605
|
+
entry.emitted = true;
|
|
1606
|
+
links.push(entry);
|
|
1607
|
+
} else {
|
|
1608
|
+
entry.emitted = true;
|
|
1609
|
+
inline.push(entry);
|
|
728
1610
|
}
|
|
729
1611
|
}
|
|
730
|
-
return
|
|
1612
|
+
return {
|
|
1613
|
+
links,
|
|
1614
|
+
inline
|
|
1615
|
+
};
|
|
1616
|
+
}
|
|
1617
|
+
function escapeStyleContent(content) {
|
|
1618
|
+
return content.replace(/<\/(style)/gi, "<\\/$1");
|
|
731
1619
|
}
|
|
732
|
-
function
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
1620
|
+
function renderInlineStyle(entry, nonce) {
|
|
1621
|
+
let attrs = "";
|
|
1622
|
+
if (entry.attrs) {
|
|
1623
|
+
for (const name in entry.attrs) {
|
|
1624
|
+
attrs += ` ${name}="${escape(String(entry.attrs[name]), true)}"`;
|
|
1625
|
+
}
|
|
737
1626
|
}
|
|
738
|
-
return
|
|
1627
|
+
return `<style${nonce ? ` nonce="${nonce}"` : ""} data-asset="${escape(entry.id, true)}"${attrs}>${escapeStyleContent(entry.content)}</style>`;
|
|
739
1628
|
}
|
|
740
1629
|
function waitForFragments(registry, key) {
|
|
741
1630
|
for (const k of [...registry.keys()].reverse()) {
|
|
@@ -765,19 +1654,49 @@ function flattenClassList(list, result) {
|
|
|
765
1654
|
if (Array.isArray(item)) flattenClassList(item, result);else if (typeof item === "object" && item != null) Object.assign(result, item);else if (item || item === 0) result[item] = true;
|
|
766
1655
|
}
|
|
767
1656
|
}
|
|
768
|
-
function
|
|
769
|
-
t
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
1657
|
+
function tryResolveString(node) {
|
|
1658
|
+
const t = typeof node;
|
|
1659
|
+
if (t === "string") return node;
|
|
1660
|
+
if (t === "number") return "" + node;
|
|
1661
|
+
if (node == null || t === "boolean") return "";
|
|
1662
|
+
if (t === "object") {
|
|
1663
|
+
if (Array.isArray(node)) {
|
|
1664
|
+
const joined = tryJoinPlainSSRArray(node);
|
|
1665
|
+
if (joined !== undefined) return joined;
|
|
1666
|
+
let s = "";
|
|
1667
|
+
let prevNonObj = false;
|
|
1668
|
+
for (let i = 0, len = node.length; i < len; i++) {
|
|
1669
|
+
const item = node[i];
|
|
1670
|
+
const itemNonObj = item !== null && typeof item !== "object";
|
|
1671
|
+
if (prevNonObj && itemNonObj) s += "<!--!$-->";
|
|
1672
|
+
prevNonObj = itemNonObj;
|
|
1673
|
+
const r = tryResolveString(item);
|
|
1674
|
+
if (typeof r !== "string") return {
|
|
1675
|
+
bail: node
|
|
1676
|
+
};
|
|
1677
|
+
s += r;
|
|
1678
|
+
}
|
|
1679
|
+
return s;
|
|
1680
|
+
}
|
|
1681
|
+
if (node.h && node.h.length > 0) return {
|
|
1682
|
+
merge: node
|
|
1683
|
+
};
|
|
1684
|
+
if (node.t === undefined) {
|
|
1685
|
+
console.warn(`Unrecognized value. Skipped inserting`, node);
|
|
1686
|
+
return "";
|
|
1687
|
+
}
|
|
1688
|
+
return Array.isArray(node.t) ? node.t[0] : node.t;
|
|
778
1689
|
}
|
|
779
|
-
|
|
780
|
-
|
|
1690
|
+
if (t === "function") {
|
|
1691
|
+
let v;
|
|
1692
|
+
try {
|
|
1693
|
+
v = node();
|
|
1694
|
+
} catch (err) {
|
|
1695
|
+
return buildAsyncWrap(err, node) || "";
|
|
1696
|
+
}
|
|
1697
|
+
return tryResolveString(v);
|
|
1698
|
+
}
|
|
1699
|
+
return "";
|
|
781
1700
|
}
|
|
782
1701
|
function resolveSSRNode(node, result = {
|
|
783
1702
|
t: [""],
|
|
@@ -788,10 +1707,13 @@ function resolveSSRNode(node, result = {
|
|
|
788
1707
|
if (t === "string" || t === "number") {
|
|
789
1708
|
result.t[result.t.length - 1] += node;
|
|
790
1709
|
} else if (node == null || t === "boolean") ; else if (Array.isArray(node)) {
|
|
791
|
-
let
|
|
1710
|
+
let prevNonObj = false;
|
|
792
1711
|
for (let i = 0, len = node.length; i < len; i++) {
|
|
793
|
-
|
|
794
|
-
|
|
1712
|
+
const item = node[i];
|
|
1713
|
+
const itemNonObj = item !== null && typeof item !== "object";
|
|
1714
|
+
if (!top && prevNonObj && itemNonObj) result.t[result.t.length - 1] += `<!--!$-->`;
|
|
1715
|
+
prevNonObj = itemNonObj;
|
|
1716
|
+
resolveSSRNode(item, result);
|
|
795
1717
|
}
|
|
796
1718
|
} else if (t === "object") {
|
|
797
1719
|
if (node.h) {
|
|
@@ -801,15 +1723,17 @@ function resolveSSRNode(node, result = {
|
|
|
801
1723
|
result.h.push(...node.h);
|
|
802
1724
|
result.p.push(...node.p);
|
|
803
1725
|
}
|
|
804
|
-
} else
|
|
1726
|
+
} else if (node.t !== undefined) {
|
|
1727
|
+
result.t[result.t.length - 1] += node.t;
|
|
1728
|
+
} else console.warn(`Unrecognized value. Skipped inserting`, node);
|
|
805
1729
|
} else if (t === "function") {
|
|
806
1730
|
try {
|
|
807
1731
|
resolveSSRNode(node(), result);
|
|
808
1732
|
} catch (err) {
|
|
809
|
-
const
|
|
810
|
-
if (
|
|
811
|
-
result.h.push(
|
|
812
|
-
result.p.push(p);
|
|
1733
|
+
const wrap = buildAsyncWrap(err, node);
|
|
1734
|
+
if (wrap) {
|
|
1735
|
+
result.h.push(wrap.fn);
|
|
1736
|
+
result.p.push(wrap.p);
|
|
813
1737
|
result.t.push("");
|
|
814
1738
|
}
|
|
815
1739
|
}
|
|
@@ -821,39 +1745,188 @@ function resolveSSRSync(node) {
|
|
|
821
1745
|
if (!res.h.length) return res.t[0];
|
|
822
1746
|
throw new Error("This value cannot be rendered synchronously. Are you missing a boundary?");
|
|
823
1747
|
}
|
|
824
|
-
const RequestContext = Symbol();
|
|
1748
|
+
const RequestContext = Symbol.for("solid.RequestContext");
|
|
825
1749
|
function getRequestEvent() {
|
|
826
1750
|
return globalThis[RequestContext] ? globalThis[RequestContext].getStore() || sharedConfig.context && sharedConfig.context.event || console.warn("RequestEvent is missing. This is most likely due to accessing `getRequestEvent` non-managed async scope in a partially polyfilled environment. Try moving it above all `await` calls.") : undefined;
|
|
827
1751
|
}
|
|
828
1752
|
function renderToStringAsync(code, options = {}) {
|
|
829
1753
|
return new Promise(resolve => renderToStream(code, options).then(resolve));
|
|
830
1754
|
}
|
|
1755
|
+
function registerElementClaim() {
|
|
1756
|
+
return noopCleanup;
|
|
1757
|
+
}
|
|
1758
|
+
function noopCleanup() {}
|
|
1759
|
+
function claimElement(node) {
|
|
1760
|
+
return node;
|
|
1761
|
+
}
|
|
1762
|
+
function claimElementTree(root) {
|
|
1763
|
+
return root;
|
|
1764
|
+
}
|
|
831
1765
|
function notSup() {
|
|
832
1766
|
throw new Error("Client-only API called on the server side. Run client-only code in onMount, or conditionally run client-only component with <Show>.");
|
|
833
1767
|
}
|
|
834
1768
|
|
|
1769
|
+
const ENVELOPE = Symbol.for("solid.ResponseEnvelope");
|
|
1770
|
+
class ResponseEnvelope {
|
|
1771
|
+
constructor(response, value) {
|
|
1772
|
+
this.response = response;
|
|
1773
|
+
this.value = value;
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1776
|
+
ResponseEnvelope.prototype[ENVELOPE] = true;
|
|
1777
|
+
function isResponseEnvelope(value) {
|
|
1778
|
+
return !!(value && typeof value === "object" && value[ENVELOPE]);
|
|
1779
|
+
}
|
|
1780
|
+
const HREF = Symbol.for("solid.Href");
|
|
1781
|
+
function isHref(value) {
|
|
1782
|
+
return !!(value && (typeof value === "object" || typeof value === "function") && value[HREF]);
|
|
1783
|
+
}
|
|
1784
|
+
const REVALIDATE_HEADER = "X-Revalidate";
|
|
1785
|
+
function initWithRevalidate(init) {
|
|
1786
|
+
const {
|
|
1787
|
+
revalidate,
|
|
1788
|
+
...responseInit
|
|
1789
|
+
} = init;
|
|
1790
|
+
const headers = new Headers(responseInit.headers);
|
|
1791
|
+
revalidate !== undefined && headers.set(REVALIDATE_HEADER, revalidate.toString());
|
|
1792
|
+
return {
|
|
1793
|
+
responseInit,
|
|
1794
|
+
headers
|
|
1795
|
+
};
|
|
1796
|
+
}
|
|
1797
|
+
function redirect(url, init = 302) {
|
|
1798
|
+
if (typeof url !== "string" && !isHref(url)) {
|
|
1799
|
+
throw new TypeError("redirect() expects a string URL or an Href-branded value (Symbol.for('solid.Href')).");
|
|
1800
|
+
}
|
|
1801
|
+
const {
|
|
1802
|
+
responseInit,
|
|
1803
|
+
headers
|
|
1804
|
+
} = initWithRevalidate(typeof init === "number" ? {
|
|
1805
|
+
status: init
|
|
1806
|
+
} : init);
|
|
1807
|
+
if (responseInit.status === undefined) {
|
|
1808
|
+
responseInit.status = 302;
|
|
1809
|
+
}
|
|
1810
|
+
headers.set("Location", String(url));
|
|
1811
|
+
return new Response(null, {
|
|
1812
|
+
...responseInit,
|
|
1813
|
+
headers
|
|
1814
|
+
});
|
|
1815
|
+
}
|
|
1816
|
+
function reload(init = {}) {
|
|
1817
|
+
const {
|
|
1818
|
+
responseInit,
|
|
1819
|
+
headers
|
|
1820
|
+
} = initWithRevalidate(init);
|
|
1821
|
+
return new Response(null, {
|
|
1822
|
+
...responseInit,
|
|
1823
|
+
headers
|
|
1824
|
+
});
|
|
1825
|
+
}
|
|
1826
|
+
function respond(value, init = {}) {
|
|
1827
|
+
const {
|
|
1828
|
+
responseInit,
|
|
1829
|
+
headers
|
|
1830
|
+
} = initWithRevalidate(init);
|
|
1831
|
+
headers.set("Content-Type", "application/json");
|
|
1832
|
+
return new ResponseEnvelope(new Response(JSON.stringify(value), {
|
|
1833
|
+
...responseInit,
|
|
1834
|
+
headers
|
|
1835
|
+
}), value);
|
|
1836
|
+
}
|
|
1837
|
+
|
|
835
1838
|
const isServer = true;
|
|
836
1839
|
const isDev = false;
|
|
837
|
-
function
|
|
838
|
-
const
|
|
839
|
-
|
|
840
|
-
const memoOwner = createOwner();
|
|
841
|
-
return runWithOwner(memoOwner, () => {
|
|
842
|
-
const comp = component(),
|
|
843
|
-
t = typeof comp;
|
|
844
|
-
if (comp) {
|
|
845
|
-
if (t === "function") return comp(props);else if (t === "string") {
|
|
846
|
-
return ssrElement(comp, props, undefined, true);
|
|
847
|
-
}
|
|
848
|
-
}
|
|
1840
|
+
function dynamic(source) {
|
|
1841
|
+
const cached = createMemo(source, {
|
|
1842
|
+
serialize: false
|
|
849
1843
|
});
|
|
1844
|
+
return props => {
|
|
1845
|
+
return createMemo(() => {
|
|
1846
|
+
const c = cached();
|
|
1847
|
+
if (c) {
|
|
1848
|
+
if (typeof c === "function") return c(props);
|
|
1849
|
+
if (typeof c === "string") {
|
|
1850
|
+
return ssrElement(c, props, undefined, true);
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
}, {
|
|
1854
|
+
sync: true
|
|
1855
|
+
});
|
|
1856
|
+
};
|
|
850
1857
|
}
|
|
851
1858
|
function Dynamic(props) {
|
|
852
|
-
const
|
|
853
|
-
return
|
|
1859
|
+
const Comp = dynamic(() => props.component);
|
|
1860
|
+
return createComponent(Comp, omit(props, "component"));
|
|
854
1861
|
}
|
|
855
1862
|
function Portal(props) {
|
|
856
|
-
|
|
1863
|
+
const o = getOwner();
|
|
1864
|
+
if (o?.id != null) getNextChildId(o);
|
|
1865
|
+
return undefined;
|
|
1866
|
+
}
|
|
1867
|
+
function registerClientOnlyPreload(moduleUrl) {
|
|
1868
|
+
const ctx = sharedConfig.context;
|
|
1869
|
+
if (!ctx?.registerAsset || !ctx.resolveAssets) return;
|
|
1870
|
+
const registerAsset = ctx.registerAsset;
|
|
1871
|
+
const resolve = ctx.resolveAssets;
|
|
1872
|
+
const apply = assets => {
|
|
1873
|
+
if (!assets) return;
|
|
1874
|
+
for (let i = 0; i < assets.css.length; i++) {
|
|
1875
|
+
const css = assets.css[i];
|
|
1876
|
+
if (typeof css === "string") registerAsset("style", css);else registerAsset("inline-style", css);
|
|
1877
|
+
}
|
|
1878
|
+
for (let i = 0; i < assets.js.length; i++) registerAsset("module", assets.js[i]);
|
|
1879
|
+
};
|
|
1880
|
+
const assets = resolve(moduleUrl);
|
|
1881
|
+
if (assets && typeof assets.then === "function") {
|
|
1882
|
+
const boundary = ctx._currentBoundaryId;
|
|
1883
|
+
assets.then(resolved => {
|
|
1884
|
+
const current = ctx._currentBoundaryId;
|
|
1885
|
+
ctx._currentBoundaryId = boundary;
|
|
1886
|
+
try {
|
|
1887
|
+
apply(resolved);
|
|
1888
|
+
} finally {
|
|
1889
|
+
ctx._currentBoundaryId = current;
|
|
1890
|
+
}
|
|
1891
|
+
},
|
|
1892
|
+
() => {});
|
|
1893
|
+
} else {
|
|
1894
|
+
apply(assets);
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
function clientOnly(_fn, _options = {}, moduleUrl) {
|
|
1898
|
+
return props => {
|
|
1899
|
+
if (moduleUrl) registerClientOnlyPreload(moduleUrl);
|
|
1900
|
+
return createMemo(() => props.fallback);
|
|
1901
|
+
};
|
|
1902
|
+
}
|
|
1903
|
+
function httpStatus(code, text) {
|
|
1904
|
+
const event = getRequestEvent();
|
|
1905
|
+
const response = event && event.response;
|
|
1906
|
+
if (response && !response.committed) {
|
|
1907
|
+
const prevStatus = response.status;
|
|
1908
|
+
const prevStatusText = response.statusText;
|
|
1909
|
+
response.status = code;
|
|
1910
|
+
response.statusText = text;
|
|
1911
|
+
onCleanup(() => {
|
|
1912
|
+
if (response.committed) return;
|
|
1913
|
+
response.status = prevStatus;
|
|
1914
|
+
response.statusText = prevStatusText;
|
|
1915
|
+
});
|
|
1916
|
+
}
|
|
1917
|
+
}
|
|
1918
|
+
function httpHeader(name, value, options) {
|
|
1919
|
+
const event = getRequestEvent();
|
|
1920
|
+
const response = event && event.response;
|
|
1921
|
+
if (response && !response.committed) {
|
|
1922
|
+
const headers = response.headers;
|
|
1923
|
+
const prev = headers.get(name);
|
|
1924
|
+
if (options && options.append) headers.append(name, value);else headers.set(name, value);
|
|
1925
|
+
onCleanup(() => {
|
|
1926
|
+
if (response.committed) return;
|
|
1927
|
+
if (prev === null) headers.delete(name);else headers.set(name, prev);
|
|
1928
|
+
});
|
|
1929
|
+
}
|
|
857
1930
|
}
|
|
858
1931
|
|
|
859
|
-
export { ChildProperties, DOMElements, DelegatedEvents, Dynamic, HydrationScript, Portal,
|
|
1932
|
+
export { Assets, ChildProperties, DOMElements, DOMWithState, DelegatedEvents, Dynamic, HREF, HydrationScript, MathMLElements, Namespaces, Portal, REVALIDATE_HEADER, RawTextElements, RequestContext, ResponseEnvelope, SVGElements, VoidElements, notSup as acquireAsset, notSup as addEvent, applyRef, notSup as assign, claimElement, claimElementTree, notSup as className, clientOnly, notSup as delegateEvents, dynamic, notSup as dynamicProperty, effect, escape, generateHydrationScript, getAssets, notSup as getDelegatedRoot, getHydrationKey, notSup as getNextElement, notSup as getNextMarker, notSup as getNextMatch, getRequestEvent, httpHeader, httpStatus, notSup as hydrate, notSup as insert, isDev, isHref, isResponseEnvelope, isServer, memo, redirect, notSup as ref, notSup as registerDelegatedContainer, notSup as registerDelegatedRoot, registerElementClaim, reload, notSup as render, renderToStream, renderToString, renderToStringAsync, respond, notSup as runHydrationEvents, notSup as setAttribute, notSup as setAttributeNS, notSup as setProperty, notSup as setStyleProperty, notSup as spread, ssr, ssrAttribute, ssrClassName, ssrElement, ssrGroup, ssrHydrationKey, ssrStyle, ssrStyleProperty, notSup as style, notSup as template, notSup as unregisterDelegatedContainer, notSup as unregisterDelegatedRoot, useAssets, useHead };
|