@solidjs/web 2.0.0-rc.5 → 2.0.0-rc.7
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/dist/server.cjs +122 -38
- package/dist/server.dev.cjs +3794 -0
- package/dist/server.dev.js +3627 -0
- package/dist/server.js +123 -39
- package/dist/web.cjs +102 -366
- package/dist/{dev.cjs → web.dev.cjs} +153 -376
- package/dist/{dev.js → web.dev.js} +155 -374
- package/dist/web.js +104 -364
- package/frames/dist/client.cjs +11 -3
- package/frames/dist/client.dev.cjs +11 -3
- package/frames/dist/client.dev.js +11 -3
- package/frames/dist/client.js +11 -3
- package/frames/dist/server.cjs +320 -53
- package/frames/dist/server.dev.cjs +4584 -0
- package/frames/dist/server.dev.js +4571 -0
- package/frames/dist/server.js +320 -53
- package/frames/package.json +10 -0
- package/package.json +78 -8
- package/serialization/dist/decode.cjs +18 -4
- package/serialization/dist/decode.js +18 -4
- package/serialization/dist/serialization.cjs +18 -4
- package/serialization/dist/serialization.js +18 -4
- package/server-functions/dist/client.cjs +27 -16
- package/server-functions/dist/client.js +27 -16
- package/server-functions/dist/server.cjs +529 -131
- package/server-functions/dist/server.dev.cjs +536 -130
- package/server-functions/dist/server.dev.js +536 -130
- package/server-functions/dist/server.js +529 -131
- package/types/client.d.ts +1 -3
- package/types/constants.d.ts +3 -1
- package/types/frames/frame-client.d.ts +1 -1
- package/types/head.d.ts +3 -0
- package/types/index.d.ts +18 -7
- package/types/index.server.d.ts +31 -9
- package/types/render.d.ts +3 -1
- package/types/server-functions/flash.d.ts +12 -3
- package/types/server-functions/server.d.ts +100 -5
- package/types/server-mock.d.ts +43 -7
- package/types/server.d.ts +47 -5
- package/types-cjs/client.d.cts +1 -3
- package/types-cjs/constants.d.cts +3 -1
- package/types-cjs/frames/frame-client.d.cts +1 -1
- package/types-cjs/head.d.cts +3 -0
- package/types-cjs/index.d.cts +18 -7
- package/types-cjs/index.server.d.cts +31 -9
- package/types-cjs/render.d.cts +3 -1
- package/types-cjs/server-functions/flash.d.cts +12 -3
- package/types-cjs/server-functions/server.d.cts +100 -5
- package/types-cjs/server-mock.d.cts +43 -7
- package/types-cjs/server.d.cts +47 -5
- package/types/patch-driver.d.ts +0 -3
- package/types-cjs/patch-driver.d.cts +0 -3
|
@@ -0,0 +1,4584 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var solidJs = require('solid-js');
|
|
4
|
+
var seroval = require('seroval');
|
|
5
|
+
var web = require('seroval-plugins/web');
|
|
6
|
+
|
|
7
|
+
const STATE = Symbol.for("solid.container-trace-state");
|
|
8
|
+
const state = globalThis[STATE] || (globalThis[STATE] = {
|
|
9
|
+
materialized: new WeakMap(),
|
|
10
|
+
materializedValues: new WeakSet()
|
|
11
|
+
});
|
|
12
|
+
function setContainerTraceResolver(fn) {
|
|
13
|
+
state.resolveTrace = fn;
|
|
14
|
+
}
|
|
15
|
+
function setContainerTraceStreamMint(fn) {
|
|
16
|
+
state.streamOf = fn;
|
|
17
|
+
}
|
|
18
|
+
function isContainerTraced(value) {
|
|
19
|
+
const resolve = state.resolveTrace;
|
|
20
|
+
return !!(resolve && value && typeof value === "object" && resolve(value));
|
|
21
|
+
}
|
|
22
|
+
const TRACE = Symbol.for("solid.container-trace");
|
|
23
|
+
function envelopeContainerTraces(value) {
|
|
24
|
+
if (!state.resolveTrace || value == null || typeof value !== "object") return value;
|
|
25
|
+
const trace = state.resolveTrace(value);
|
|
26
|
+
if (trace) return {
|
|
27
|
+
[TRACE]: trace
|
|
28
|
+
};
|
|
29
|
+
if (Array.isArray(value)) {
|
|
30
|
+
let out = value;
|
|
31
|
+
for (let i = 0; i < value.length; i++) {
|
|
32
|
+
const next = envelopeContainerTraces(value[i]);
|
|
33
|
+
if (next !== value[i]) {
|
|
34
|
+
if (out === value) out = value.slice();
|
|
35
|
+
out[i] = next;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
if (Object.getPrototypeOf(value) === Object.prototype) {
|
|
41
|
+
let out = value;
|
|
42
|
+
for (const key of Object.keys(value)) {
|
|
43
|
+
const next = envelopeContainerTraces(value[key]);
|
|
44
|
+
if (next !== value[key]) {
|
|
45
|
+
if (out === value) out = {
|
|
46
|
+
...value
|
|
47
|
+
};
|
|
48
|
+
out[key] = next;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
function materialize(marker) {
|
|
56
|
+
let value = state.materialized.get(marker.$tr);
|
|
57
|
+
if (value === undefined) {
|
|
58
|
+
value = state.materializeTrace(marker);
|
|
59
|
+
state.materialized.set(marker.$tr, value);
|
|
60
|
+
if (value !== null && typeof value === "object") state.materializedValues.add(value);
|
|
61
|
+
}
|
|
62
|
+
return value;
|
|
63
|
+
}
|
|
64
|
+
function parseTrace(value, ctx) {
|
|
65
|
+
const trace = value[TRACE];
|
|
66
|
+
const sub = trace.subscribe();
|
|
67
|
+
return {
|
|
68
|
+
a: trace.array ? 1 : 0,
|
|
69
|
+
i: ctx.parse(state.streamOf ? state.streamOf(sub) : sub)
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
const ContainerTracePlugin = {
|
|
73
|
+
tag: "solid/container-trace",
|
|
74
|
+
test(value) {
|
|
75
|
+
return value != null && typeof value === "object" && TRACE in value;
|
|
76
|
+
},
|
|
77
|
+
parse: {
|
|
78
|
+
sync() {
|
|
79
|
+
throw new Error("A reactive container can only be serialized by a streaming serializer.");
|
|
80
|
+
},
|
|
81
|
+
async async(value, ctx) {
|
|
82
|
+
const trace = value[TRACE];
|
|
83
|
+
const sub = trace.subscribe();
|
|
84
|
+
return {
|
|
85
|
+
a: trace.array ? 1 : 0,
|
|
86
|
+
i: await ctx.parse(state.streamOf ? state.streamOf(sub) : sub)
|
|
87
|
+
};
|
|
88
|
+
},
|
|
89
|
+
stream: parseTrace
|
|
90
|
+
},
|
|
91
|
+
serialize(node, ctx) {
|
|
92
|
+
return "{$tr:" + ctx.serialize(node.i) + ",$ta:" + node.a + "}";
|
|
93
|
+
},
|
|
94
|
+
deserialize(node, ctx) {
|
|
95
|
+
const iterable = ctx.deserialize(node.i);
|
|
96
|
+
const marker = {
|
|
97
|
+
$tr: iterable,
|
|
98
|
+
$ta: node.a
|
|
99
|
+
};
|
|
100
|
+
return state.materializeTrace ? materialize(marker) : marker;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const COMPOSED_BODY_FRAMING = /*#__PURE__*/new Set(["content-length", "content-encoding", "transfer-encoding"]);
|
|
105
|
+
|
|
106
|
+
setContainerTraceStreamMint(iterable => {
|
|
107
|
+
const stream = seroval.createStream();
|
|
108
|
+
(async () => {
|
|
109
|
+
try {
|
|
110
|
+
for await (const value of iterable) stream.next(value);
|
|
111
|
+
stream.return(undefined);
|
|
112
|
+
} catch (error) {
|
|
113
|
+
stream.throw(error);
|
|
114
|
+
}
|
|
115
|
+
})();
|
|
116
|
+
return stream;
|
|
117
|
+
});
|
|
118
|
+
const DEFAULT_WEB_PLUGINS = Object.freeze([web.AbortSignalPlugin,
|
|
119
|
+
web.CustomEventPlugin, web.DOMExceptionPlugin, web.EventPlugin,
|
|
120
|
+
web.FormDataPlugin, web.HeadersPlugin, web.ReadableStreamPlugin, web.RequestPlugin, web.ResponsePlugin, web.URLSearchParamsPlugin, web.URLPlugin,
|
|
121
|
+
ContainerTracePlugin]);
|
|
122
|
+
function resolveSerializerPlugins(customPlugins) {
|
|
123
|
+
return customPlugins ? [...customPlugins, ...DEFAULT_WEB_PLUGINS] : [...DEFAULT_WEB_PLUGINS];
|
|
124
|
+
}
|
|
125
|
+
const JSON_CODEC_DISABLED_FEATURES = seroval.Feature.RegExp;
|
|
126
|
+
const JSON_CODEC_DEPTH_LIMIT = 64;
|
|
127
|
+
function resolveCodecOptions({
|
|
128
|
+
plugins,
|
|
129
|
+
disabledFeatures,
|
|
130
|
+
depthLimit,
|
|
131
|
+
serializeErrorStacks
|
|
132
|
+
} = {}) {
|
|
133
|
+
return {
|
|
134
|
+
plugins: resolveSerializerPlugins(plugins),
|
|
135
|
+
disabledFeatures: disabledFeatures === undefined ? JSON_CODEC_DISABLED_FEATURES : disabledFeatures,
|
|
136
|
+
depthLimit: depthLimit === undefined ? JSON_CODEC_DEPTH_LIMIT : depthLimit,
|
|
137
|
+
serializeErrorStacks
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const DEFAULT_DISABLED_FEATURES = seroval.Feature.AggregateError | seroval.Feature.BigIntTypedArray;
|
|
142
|
+
const serializeOnlyDisabledFeatures = serializeErrorStacks => (serializeErrorStacks === undefined ? process.env.NODE_ENV === "development" : serializeErrorStacks) ? 0 : seroval.Feature.ErrorPrototypeStack;
|
|
143
|
+
const HYDRATION_GLOBAL = "_$HY.r";
|
|
144
|
+
function createSerializer(options) {
|
|
145
|
+
return new seroval.Serializer({
|
|
146
|
+
...options,
|
|
147
|
+
plugins: resolveSerializerPlugins(options.plugins),
|
|
148
|
+
disabledFeatures: (options.disabledFeatures === undefined ? DEFAULT_DISABLED_FEATURES : options.disabledFeatures) | serializeOnlyDisabledFeatures(options.serializeErrorStacks)
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
function createHydrationSerializer({
|
|
152
|
+
onData,
|
|
153
|
+
onDone,
|
|
154
|
+
scopeId,
|
|
155
|
+
onError,
|
|
156
|
+
plugins
|
|
157
|
+
}) {
|
|
158
|
+
return createSerializer({
|
|
159
|
+
scopeId,
|
|
160
|
+
plugins,
|
|
161
|
+
globalIdentifier: HYDRATION_GLOBAL,
|
|
162
|
+
onData,
|
|
163
|
+
onDone,
|
|
164
|
+
onError
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
function getLocalHeaderScript(id) {
|
|
168
|
+
return seroval.getCrossReferenceHeader(id) + ";";
|
|
169
|
+
}
|
|
170
|
+
function createJSONSerializer({
|
|
171
|
+
onData,
|
|
172
|
+
onDone,
|
|
173
|
+
onError,
|
|
174
|
+
plugins,
|
|
175
|
+
disabledFeatures,
|
|
176
|
+
depthLimit,
|
|
177
|
+
serializeErrorStacks
|
|
178
|
+
}) {
|
|
179
|
+
const resolved = resolveCodecOptions({
|
|
180
|
+
plugins,
|
|
181
|
+
disabledFeatures,
|
|
182
|
+
depthLimit,
|
|
183
|
+
serializeErrorStacks
|
|
184
|
+
});
|
|
185
|
+
const refs = new Map();
|
|
186
|
+
const cancels = new Set();
|
|
187
|
+
let pendingWrites = 0;
|
|
188
|
+
let flushed = false;
|
|
189
|
+
let done = false;
|
|
190
|
+
const maybeDone = () => {
|
|
191
|
+
if (flushed && pendingWrites === 0 && !done) {
|
|
192
|
+
done = true;
|
|
193
|
+
onDone && onDone();
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
return {
|
|
197
|
+
write(key, value) {
|
|
198
|
+
if (flushed) return;
|
|
199
|
+
pendingWrites++;
|
|
200
|
+
let settled = false;
|
|
201
|
+
let cancel = null;
|
|
202
|
+
const stream = seroval.toCrossJSONStream(value, {
|
|
203
|
+
refs,
|
|
204
|
+
plugins: resolved.plugins,
|
|
205
|
+
disabledFeatures: resolved.disabledFeatures | serializeOnlyDisabledFeatures(resolved.serializeErrorStacks),
|
|
206
|
+
onParse(node, initial) {
|
|
207
|
+
onData({
|
|
208
|
+
key,
|
|
209
|
+
node,
|
|
210
|
+
initial
|
|
211
|
+
});
|
|
212
|
+
},
|
|
213
|
+
onError,
|
|
214
|
+
onDone() {
|
|
215
|
+
settled = true;
|
|
216
|
+
if (cancel) cancels.delete(cancel);
|
|
217
|
+
pendingWrites--;
|
|
218
|
+
maybeDone();
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
if (!settled) {
|
|
222
|
+
cancel = stream;
|
|
223
|
+
cancels.add(cancel);
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
flush() {
|
|
227
|
+
flushed = true;
|
|
228
|
+
maybeDone();
|
|
229
|
+
},
|
|
230
|
+
close() {
|
|
231
|
+
flushed = true;
|
|
232
|
+
for (const cancel of cancels) cancel();
|
|
233
|
+
cancels.clear();
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const ENVELOPE = Symbol.for("solid.ResponseEnvelope");
|
|
239
|
+
function isResponseEnvelope(value) {
|
|
240
|
+
return !!(value && typeof value === "object" && value[ENVELOPE]);
|
|
241
|
+
}
|
|
242
|
+
const REVALIDATE_HEADER = "X-Revalidate";
|
|
243
|
+
|
|
244
|
+
function frameAddress(id, args) {
|
|
245
|
+
return args && args.length ? id + ":" + hashArguments(args) : id;
|
|
246
|
+
}
|
|
247
|
+
function hashArguments(args) {
|
|
248
|
+
let hash = 0;
|
|
249
|
+
const text = stableString(args);
|
|
250
|
+
for (let i = 0; i < text.length; i++) {
|
|
251
|
+
hash = (hash << 5) - hash + text.charCodeAt(i);
|
|
252
|
+
hash |= 0;
|
|
253
|
+
}
|
|
254
|
+
return (hash >>> 0).toString(36);
|
|
255
|
+
}
|
|
256
|
+
function stableString(value, seen) {
|
|
257
|
+
if (value === null || typeof value !== "object") {
|
|
258
|
+
return typeof value === "bigint" ? value + "n" : String(value);
|
|
259
|
+
}
|
|
260
|
+
if (value instanceof Date) return "Date:" + value.getTime();
|
|
261
|
+
seen || (seen = new Set());
|
|
262
|
+
if (seen.has(value)) return "~";
|
|
263
|
+
seen.add(value);
|
|
264
|
+
if (value instanceof Map) {
|
|
265
|
+
const entries = [];
|
|
266
|
+
for (const [k, v] of value) {
|
|
267
|
+
entries.push(stableString(k, seen) + "=>" + stableString(v, seen));
|
|
268
|
+
}
|
|
269
|
+
return "Map{" + entries.sort().join(",") + "}";
|
|
270
|
+
}
|
|
271
|
+
if (value instanceof Set) {
|
|
272
|
+
const members = [];
|
|
273
|
+
for (const v of value) members.push(stableString(v, seen));
|
|
274
|
+
return "Set{" + members.sort().join(",") + "}";
|
|
275
|
+
}
|
|
276
|
+
if (Array.isArray(value)) {
|
|
277
|
+
let out = "[";
|
|
278
|
+
for (let i = 0; i < value.length; i++) out += (i ? "," : "") + stableString(value[i], seen);
|
|
279
|
+
return out + "]";
|
|
280
|
+
}
|
|
281
|
+
const keys = Object.keys(value).sort();
|
|
282
|
+
let out = "{";
|
|
283
|
+
for (let i = 0; i < keys.length; i++) {
|
|
284
|
+
out += (i ? "," : "") + keys[i] + ":" + stableString(value[keys[i]], seen);
|
|
285
|
+
}
|
|
286
|
+
return out + "}";
|
|
287
|
+
}
|
|
288
|
+
const ERROR_HEADER = "X-Server-Function-Error";
|
|
289
|
+
const BODY_FORMAT_HEADER = "X-Server-Function-Format";
|
|
290
|
+
const REDIRECT_HEADER = "X-Server-Function-Redirect";
|
|
291
|
+
const SINGLE_FLIGHT_HEADER = "X-Single-Flight";
|
|
292
|
+
const BodyFormat = {
|
|
293
|
+
Serialized: "0",
|
|
294
|
+
String: "1",
|
|
295
|
+
FormData: "2",
|
|
296
|
+
URLSearchParams: "3",
|
|
297
|
+
Blob: "4",
|
|
298
|
+
File: "5",
|
|
299
|
+
ArrayBuffer: "6",
|
|
300
|
+
Uint8Array: "7",
|
|
301
|
+
Json: "8",
|
|
302
|
+
Void: "9"
|
|
303
|
+
};
|
|
304
|
+
function createChunk(data) {
|
|
305
|
+
const encoder = new TextEncoder();
|
|
306
|
+
const encodeData = encoder.encode(data);
|
|
307
|
+
const bytes = encodeData.length;
|
|
308
|
+
const chunk = new Uint8Array(12 + bytes);
|
|
309
|
+
chunk.set(encoder.encode(`;0x${bytes.toString(16).padStart(8, "0")};`));
|
|
310
|
+
chunk.set(encodeData, 12);
|
|
311
|
+
return chunk;
|
|
312
|
+
}
|
|
313
|
+
class ChunkReader {
|
|
314
|
+
constructor(stream) {
|
|
315
|
+
this.reader = stream.getReader();
|
|
316
|
+
this.store = new Uint8Array(0);
|
|
317
|
+
this.buffer = this.store;
|
|
318
|
+
this.done = false;
|
|
319
|
+
}
|
|
320
|
+
async readChunk() {
|
|
321
|
+
const chunk = await this.reader.read();
|
|
322
|
+
if (chunk.done) {
|
|
323
|
+
this.done = true;
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
const incoming = chunk.value;
|
|
327
|
+
const store = this.store;
|
|
328
|
+
const start = this.buffer.byteOffset;
|
|
329
|
+
const end = start + this.buffer.length;
|
|
330
|
+
const needed = this.buffer.length + incoming.length;
|
|
331
|
+
if (end + incoming.length <= store.length) {
|
|
332
|
+
store.set(incoming, end);
|
|
333
|
+
this.buffer = store.subarray(start, end + incoming.length);
|
|
334
|
+
} else if (needed <= store.length) {
|
|
335
|
+
store.copyWithin(0, start, end);
|
|
336
|
+
store.set(incoming, this.buffer.length);
|
|
337
|
+
this.buffer = store.subarray(0, needed);
|
|
338
|
+
} else {
|
|
339
|
+
const grown = new Uint8Array(Math.max(needed, store.length * 2));
|
|
340
|
+
grown.set(this.buffer);
|
|
341
|
+
grown.set(incoming, this.buffer.length);
|
|
342
|
+
this.store = grown;
|
|
343
|
+
this.buffer = grown.subarray(0, needed);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
async next() {
|
|
347
|
+
while (this.buffer.length < 12) {
|
|
348
|
+
if (this.done) {
|
|
349
|
+
if (this.buffer.length === 0) return {
|
|
350
|
+
done: true,
|
|
351
|
+
value: undefined
|
|
352
|
+
};
|
|
353
|
+
throw new Error("Malformed server function stream.");
|
|
354
|
+
}
|
|
355
|
+
await this.readChunk();
|
|
356
|
+
}
|
|
357
|
+
const decoder = new TextDecoder();
|
|
358
|
+
const bytes = Number.parseInt(decoder.decode(this.buffer.subarray(1, 11)), 16);
|
|
359
|
+
if (Number.isNaN(bytes)) {
|
|
360
|
+
throw new Error("Malformed server function stream.");
|
|
361
|
+
}
|
|
362
|
+
while (bytes > this.buffer.length - 12) {
|
|
363
|
+
if (this.done) {
|
|
364
|
+
throw new Error("Malformed server function stream.");
|
|
365
|
+
}
|
|
366
|
+
await this.readChunk();
|
|
367
|
+
}
|
|
368
|
+
const partial = decoder.decode(this.buffer.subarray(12, 12 + bytes));
|
|
369
|
+
this.buffer = this.buffer.subarray(12 + bytes);
|
|
370
|
+
return {
|
|
371
|
+
done: false,
|
|
372
|
+
value: partial
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
async drain(interpret) {
|
|
376
|
+
while (true) {
|
|
377
|
+
const result = await this.next();
|
|
378
|
+
if (result.done) {
|
|
379
|
+
break;
|
|
380
|
+
}
|
|
381
|
+
interpret(result.value);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
function serializeStream(value, codecOptions) {
|
|
386
|
+
return new ReadableStream({
|
|
387
|
+
async start(controller) {
|
|
388
|
+
const {
|
|
389
|
+
serializeJSON
|
|
390
|
+
} = await import('@solidjs/web/serialization');
|
|
391
|
+
serializeJSON(value, {
|
|
392
|
+
...codecOptions,
|
|
393
|
+
onParse(node) {
|
|
394
|
+
controller.enqueue(createChunk(JSON.stringify(node)));
|
|
395
|
+
},
|
|
396
|
+
onDone() {
|
|
397
|
+
controller.close();
|
|
398
|
+
},
|
|
399
|
+
onError(error) {
|
|
400
|
+
controller.error(error);
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
const HEAD_ELIGIBLE_TAGS = new Set(["title", "meta", "link", "style", "script", "base"]);
|
|
408
|
+
const HEAD_ATTR_NAME = /^[a-zA-Z_][a-zA-Z0-9_:.-]*$/;
|
|
409
|
+
const RESOURCE_LINK_RELS = new Set(["preload", "modulepreload", "prefetch", "preconnect", "dns-prefetch", "stylesheet"]);
|
|
410
|
+
const RESOURCE_QUALIFIERS = ["as", "crossorigin", "type", "media", "imagesrcset", "imagesizes"];
|
|
411
|
+
const STYLESHEET_FETCH_META = new Set(["crossorigin", "integrity", "referrerpolicy", "fetchpriority"]);
|
|
412
|
+
function evalHeadValue(v) {
|
|
413
|
+
return typeof v === "function" ? v() : v;
|
|
414
|
+
}
|
|
415
|
+
function evalHeadProps(props, presets) {
|
|
416
|
+
const out = {};
|
|
417
|
+
for (const name in props) out[name] = presets && name in presets ? presets[name] : evalHeadValue(props[name]);
|
|
418
|
+
return out;
|
|
419
|
+
}
|
|
420
|
+
function classifyHeadTag(desc) {
|
|
421
|
+
const tag = desc.tag;
|
|
422
|
+
if (tag === "link") {
|
|
423
|
+
const rel = evalHeadValue(desc.props && desc.props.rel);
|
|
424
|
+
return {
|
|
425
|
+
resource: RESOURCE_LINK_RELS.has(rel),
|
|
426
|
+
rel
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
if (tag === "style") return {
|
|
430
|
+
resource: !!(desc.props && "href" in desc.props)
|
|
431
|
+
};
|
|
432
|
+
if (tag === "script") return {
|
|
433
|
+
resource: !!(desc.props && "src" in desc.props)
|
|
434
|
+
};
|
|
435
|
+
return {
|
|
436
|
+
resource: false
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
function qualifierValue(name, value) {
|
|
440
|
+
if (value == null || value === false) return null;
|
|
441
|
+
if (name === "imagesrcset" || name === "imagesizes") return typeof value === "string" && value !== "" ? value : null;
|
|
442
|
+
const v = value === true ? "" : String(value);
|
|
443
|
+
if (name === "as") return asciiLowerCase(v);
|
|
444
|
+
if (name !== "crossorigin") return v;
|
|
445
|
+
return v.length === 15 && v.toLowerCase() === "use-credentials" ? v.toLowerCase() : "anonymous";
|
|
446
|
+
}
|
|
447
|
+
function asciiLowerCase(value) {
|
|
448
|
+
return value.replace(/[A-Z]/g, c => String.fromCharCode(c.charCodeAt(0) + 32));
|
|
449
|
+
}
|
|
450
|
+
function resourceIdentity(tag, props) {
|
|
451
|
+
const url = String(props.href || props.src || "");
|
|
452
|
+
let id = "res:" + tag + ":" + (props.rel || "") + ":" + url.length + ":" + url;
|
|
453
|
+
for (let i = 0; i < RESOURCE_QUALIFIERS.length; i++) {
|
|
454
|
+
const q = RESOURCE_QUALIFIERS[i];
|
|
455
|
+
const value = qualifierValue(q, props[q]);
|
|
456
|
+
if (value !== null) id += ":" + q + "=" + value.length + ":" + value;
|
|
457
|
+
}
|
|
458
|
+
return id;
|
|
459
|
+
}
|
|
460
|
+
function replaceableIdentity(tag, props, key, unique) {
|
|
461
|
+
if (tag === "title") return "title";
|
|
462
|
+
if (tag === "base") return "base";
|
|
463
|
+
if (tag === "meta" && props.charset != null) return "charset";
|
|
464
|
+
if (key != null) return tag + ":key:" + key;
|
|
465
|
+
if (tag === "meta") {
|
|
466
|
+
for (const ns of ["name", "property", "http-equiv"]) if (props[ns] != null) return "meta:" + ns + ":" + props[ns] + (props.media != null ? ":media=" + props.media : "");
|
|
467
|
+
return unique;
|
|
468
|
+
}
|
|
469
|
+
if (tag === "link") {
|
|
470
|
+
const rel = props.rel || "";
|
|
471
|
+
if (rel === "icon" || rel === "apple-touch-icon") return "link:" + rel + (props.sizes != null ? ":sizes=" + props.sizes : "") + (props.type != null ? ":type=" + props.type : "");
|
|
472
|
+
return "link:" + rel + ":" + (props.href || "");
|
|
473
|
+
}
|
|
474
|
+
return unique;
|
|
475
|
+
}
|
|
476
|
+
function resolveHead(groups) {
|
|
477
|
+
const winners = new Map();
|
|
478
|
+
const sorted = groups.slice().sort((a, b) => a.seq - b.seq);
|
|
479
|
+
for (let i = 0; i < sorted.length; i++) {
|
|
480
|
+
const group = sorted[i];
|
|
481
|
+
const byIdentity = new Map();
|
|
482
|
+
for (let j = 0; j < group.tags.length; j++) {
|
|
483
|
+
const t = group.tags[j];
|
|
484
|
+
let list = byIdentity.get(t.identity);
|
|
485
|
+
if (!list) byIdentity.set(t.identity, list = []);
|
|
486
|
+
list.push(t);
|
|
487
|
+
}
|
|
488
|
+
for (const [identity, tags] of byIdentity) {
|
|
489
|
+
if (identity === "title") {
|
|
490
|
+
if (tags.length > 1) console.warn("Multiple <title> tags in one head group; the last one wins.");
|
|
491
|
+
winners.set(identity, {
|
|
492
|
+
seq: group.seq,
|
|
493
|
+
tags: [tags[tags.length - 1]]
|
|
494
|
+
});
|
|
495
|
+
} else {
|
|
496
|
+
winners.set(identity, {
|
|
497
|
+
seq: group.seq,
|
|
498
|
+
tags
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
return winners;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
function joinAssetPath(base, file) {
|
|
507
|
+
if (/^(?:[a-z][a-z0-9+.-]*:)?\/\//i.test(file)) return file;
|
|
508
|
+
if (typeof base !== "string" || !base) base = "/";
|
|
509
|
+
if (base[base.length - 1] !== "/") base += "/";
|
|
510
|
+
return base + (file[0] === "/" ? file.slice(1) : file);
|
|
511
|
+
}
|
|
512
|
+
function eachCandidate(srcset, visit) {
|
|
513
|
+
let i = 0;
|
|
514
|
+
const n = srcset.length;
|
|
515
|
+
while (i < n) {
|
|
516
|
+
while (i < n && /[\s,]/.test(srcset[i])) i++;
|
|
517
|
+
const start = i;
|
|
518
|
+
while (i < n && !/\s/.test(srcset[i])) i++;
|
|
519
|
+
if (i === start) return false;
|
|
520
|
+
const raw = srcset.slice(start, i);
|
|
521
|
+
const url = raw.replace(/,+$/, "");
|
|
522
|
+
let descriptors = "";
|
|
523
|
+
if (url === raw) {
|
|
524
|
+
const from = i;
|
|
525
|
+
while (i < n && srcset[i] !== ",") i++;
|
|
526
|
+
descriptors = srcset.slice(from, i);
|
|
527
|
+
}
|
|
528
|
+
if (url && visit(url, descriptors)) return true;
|
|
529
|
+
}
|
|
530
|
+
return false;
|
|
531
|
+
}
|
|
532
|
+
function hasRelativeCandidate(srcset) {
|
|
533
|
+
return eachCandidate(srcset, url => !/^(?:[a-zA-Z][a-zA-Z0-9+.-]*:|\/)/.test(url));
|
|
534
|
+
}
|
|
535
|
+
function hasWidthDescriptor(srcset) {
|
|
536
|
+
return eachCandidate(srcset, (_, descriptors) => /(?:^|\s)\d+(?:\.\d+)?w(?=\s|$)/.test(descriptors));
|
|
537
|
+
}
|
|
538
|
+
function resolveAssets(moduleUrl, manifest) {
|
|
539
|
+
if (!manifest) return null;
|
|
540
|
+
const base = manifest._base;
|
|
541
|
+
const entry = manifest[moduleUrl];
|
|
542
|
+
if (!entry) return null;
|
|
543
|
+
const css = [];
|
|
544
|
+
const js = [];
|
|
545
|
+
let preloads;
|
|
546
|
+
const visited = new Set();
|
|
547
|
+
const walk = key => {
|
|
548
|
+
if (visited.has(key)) return;
|
|
549
|
+
visited.add(key);
|
|
550
|
+
const e = manifest[key];
|
|
551
|
+
if (!e) return;
|
|
552
|
+
js.push(joinAssetPath(base, e.file));
|
|
553
|
+
if (e.css) for (let i = 0; i < e.css.length; i++) css.push(joinAssetPath(base, e.css[i]));
|
|
554
|
+
if (e.preloads) {
|
|
555
|
+
for (let i = 0; i < e.preloads.length; i++) {
|
|
556
|
+
const link = e.preloads[i];
|
|
557
|
+
const href = link && typeof link.href === "string" && link.href;
|
|
558
|
+
const srcset = link && typeof link.imagesrcset === "string" && link.imagesrcset;
|
|
559
|
+
if (!href && !srcset) continue;
|
|
560
|
+
if (!preloads) preloads = [];
|
|
561
|
+
if (href) preloads.push({
|
|
562
|
+
...link,
|
|
563
|
+
href: joinAssetPath(base, href)
|
|
564
|
+
});else {
|
|
565
|
+
const {
|
|
566
|
+
href: bad,
|
|
567
|
+
...rest
|
|
568
|
+
} = link;
|
|
569
|
+
if (bad !== undefined) console.warn("Preload href must be a non-empty string; dropping it.", bad);
|
|
570
|
+
preloads.push(rest);
|
|
571
|
+
}
|
|
572
|
+
if (srcset && hasRelativeCandidate(srcset)) console.warn("imagesrcset candidates are not joined with the manifest base — they resolve " + "against the document URL, so a relative candidate points somewhere else " + "than the joined href; the integration should emit resolved URLs.", srcset);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
if (e.imports) for (let i = 0; i < e.imports.length; i++) walk(e.imports[i]);
|
|
576
|
+
};
|
|
577
|
+
walk(moduleUrl);
|
|
578
|
+
const assets = {
|
|
579
|
+
js,
|
|
580
|
+
css
|
|
581
|
+
};
|
|
582
|
+
if (preloads) assets.preloads = preloads;
|
|
583
|
+
return assets;
|
|
584
|
+
}
|
|
585
|
+
function registerEntryAssets(manifest) {
|
|
586
|
+
if (!manifest || typeof manifest === "function" || typeof manifest.resolve === "function") return;
|
|
587
|
+
const ctx = solidJs.sharedConfig.context;
|
|
588
|
+
if (!ctx?.registerAsset) return;
|
|
589
|
+
for (const key in manifest) {
|
|
590
|
+
if (manifest[key].isEntry) {
|
|
591
|
+
const assets = resolveAssets(key, manifest);
|
|
592
|
+
if (assets) {
|
|
593
|
+
if (assets.preloads) for (let i = 0; i < assets.preloads.length; i++) ctx.registerAsset("preload", assets.preloads[i]);
|
|
594
|
+
for (let i = 0; i < assets.css.length; i++) ctx.registerAsset("style", assets.css[i]);
|
|
595
|
+
for (let i = 1; i < assets.js.length; i++) ctx.registerAsset("module", assets.js[i]);
|
|
596
|
+
}
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
function createAssetTracking() {
|
|
602
|
+
const boundaryModules = new Map();
|
|
603
|
+
const boundaryStyles = new Map();
|
|
604
|
+
const emittedAssets = new Set();
|
|
605
|
+
const inlineStyles = new Map();
|
|
606
|
+
let currentBoundaryId = null;
|
|
607
|
+
return {
|
|
608
|
+
boundaryModules,
|
|
609
|
+
boundaryStyles,
|
|
610
|
+
emittedAssets,
|
|
611
|
+
inlineStyles,
|
|
612
|
+
preloadLinks: null,
|
|
613
|
+
registerInlineStyle(desc) {
|
|
614
|
+
let entry = inlineStyles.get(desc.id);
|
|
615
|
+
if (!entry) {
|
|
616
|
+
entry = {
|
|
617
|
+
id: desc.id,
|
|
618
|
+
content: desc.content || "",
|
|
619
|
+
attrs: desc.attrs,
|
|
620
|
+
emitted: false
|
|
621
|
+
};
|
|
622
|
+
inlineStyles.set(desc.id, entry);
|
|
623
|
+
}
|
|
624
|
+
if (currentBoundaryId) {
|
|
625
|
+
let styles = boundaryStyles.get(currentBoundaryId);
|
|
626
|
+
if (!styles) {
|
|
627
|
+
styles = new Set();
|
|
628
|
+
boundaryStyles.set(currentBoundaryId, styles);
|
|
629
|
+
}
|
|
630
|
+
styles.add(entry);
|
|
631
|
+
}
|
|
632
|
+
return entry;
|
|
633
|
+
},
|
|
634
|
+
get currentBoundaryId() {
|
|
635
|
+
return currentBoundaryId;
|
|
636
|
+
},
|
|
637
|
+
set currentBoundaryId(v) {
|
|
638
|
+
currentBoundaryId = v;
|
|
639
|
+
},
|
|
640
|
+
registerModule(key, entryUrl) {
|
|
641
|
+
const id = currentBoundaryId || "";
|
|
642
|
+
let map = boundaryModules.get(id);
|
|
643
|
+
if (!map) {
|
|
644
|
+
map = {};
|
|
645
|
+
boundaryModules.set(id, map);
|
|
646
|
+
}
|
|
647
|
+
map[key] = entryUrl;
|
|
648
|
+
},
|
|
649
|
+
getBoundaryModules(id) {
|
|
650
|
+
return boundaryModules.get(id) || null;
|
|
651
|
+
},
|
|
652
|
+
getBoundaryStyles(id) {
|
|
653
|
+
return boundaryStyles.get(id) || null;
|
|
654
|
+
}
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
function warnUnresolvedModuleAssets(moduleUrl, warned) {
|
|
658
|
+
if (warned.has(moduleUrl)) return;
|
|
659
|
+
warned.add(moduleUrl);
|
|
660
|
+
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.");
|
|
661
|
+
}
|
|
662
|
+
function guardResolvedAssets(moduleUrl, result, warned) {
|
|
663
|
+
if (result && typeof result.then === "function") {
|
|
664
|
+
return result.then(assets => {
|
|
665
|
+
if (!assets || !assets.js || !assets.js.length) warnUnresolvedModuleAssets(moduleUrl, warned);
|
|
666
|
+
return assets;
|
|
667
|
+
});
|
|
668
|
+
}
|
|
669
|
+
if (!result || !result.js || !result.js.length) warnUnresolvedModuleAssets(moduleUrl, warned);
|
|
670
|
+
return result;
|
|
671
|
+
}
|
|
672
|
+
function applyAssetTracking(context, tracking, manifest, noScripts) {
|
|
673
|
+
const warned = new Set();
|
|
674
|
+
const guard = noScripts ? resolve => resolve : resolve => moduleUrl => guardResolvedAssets(moduleUrl, resolve(moduleUrl), warned);
|
|
675
|
+
Object.defineProperty(context, "_currentBoundaryId", {
|
|
676
|
+
get() {
|
|
677
|
+
return tracking.currentBoundaryId;
|
|
678
|
+
},
|
|
679
|
+
set(v) {
|
|
680
|
+
tracking.currentBoundaryId = v;
|
|
681
|
+
},
|
|
682
|
+
configurable: true,
|
|
683
|
+
enumerable: true
|
|
684
|
+
});
|
|
685
|
+
context.registerModule = tracking.registerModule;
|
|
686
|
+
context.getBoundaryModules = tracking.getBoundaryModules;
|
|
687
|
+
if (typeof manifest === "function") {
|
|
688
|
+
context.resolveAssets = guard(manifest);
|
|
689
|
+
} else if (manifest && typeof manifest.resolve === "function") {
|
|
690
|
+
context.resolveAssets = guard(key => manifest.resolve(key));
|
|
691
|
+
if (typeof manifest.resolveSync === "function") {
|
|
692
|
+
context.resolveAssetsSync = key => manifest.resolveSync(key);
|
|
693
|
+
}
|
|
694
|
+
} else if (manifest) {
|
|
695
|
+
const resolve = moduleUrl => resolveAssets(moduleUrl, manifest);
|
|
696
|
+
context.resolveAssets = guard(resolve);
|
|
697
|
+
context.resolveAssetsSync = resolve;
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
function isCssUrl(url) {
|
|
701
|
+
const q = url.search(/[?#]/);
|
|
702
|
+
return (q === -1 ? url : url.slice(0, q)).endsWith(".css");
|
|
703
|
+
}
|
|
704
|
+
const RESPONSIVE_ATTRIBUTES = ["imagesrcset", "imagesizes"];
|
|
705
|
+
function isSetAttr(value) {
|
|
706
|
+
return value != null && value !== false && value !== "";
|
|
707
|
+
}
|
|
708
|
+
const PRELOAD_LINK_ATTRIBUTES = ["type", "crossorigin", "integrity", "referrerpolicy", "fetchpriority", "media", "imagesrcset", "imagesizes"];
|
|
709
|
+
function registerPreloadLink(tracking, headRegistry, link, nonce) {
|
|
710
|
+
if (!link || typeof link !== "object") {
|
|
711
|
+
console.warn('registerAsset("preload") requires a descriptor object.', link);
|
|
712
|
+
return null;
|
|
713
|
+
}
|
|
714
|
+
if (typeof link.as !== "string") {
|
|
715
|
+
console.warn('registerAsset("preload") requires an as destination.');
|
|
716
|
+
return null;
|
|
717
|
+
}
|
|
718
|
+
const as = asciiLowerCase(link.as);
|
|
719
|
+
let destination = null;
|
|
720
|
+
switch (as) {
|
|
721
|
+
case "script":
|
|
722
|
+
case "style":
|
|
723
|
+
destination = as;
|
|
724
|
+
break;
|
|
725
|
+
case "fetch":
|
|
726
|
+
case "font":
|
|
727
|
+
case "image":
|
|
728
|
+
case "track":
|
|
729
|
+
break;
|
|
730
|
+
default:
|
|
731
|
+
console.warn(`registerAsset("preload") received an unsupported as destination "${link.as}".`);
|
|
732
|
+
return null;
|
|
733
|
+
}
|
|
734
|
+
const responsive = as === "image";
|
|
735
|
+
if (!responsive && (isSetAttr(link.imagesrcset) || isSetAttr(link.imagesizes))) console.warn('registerAsset("preload") only supports imagesrcset and imagesizes with as="image".');
|
|
736
|
+
let srcset = null;
|
|
737
|
+
let sizes = null;
|
|
738
|
+
if (responsive) {
|
|
739
|
+
for (const name of RESPONSIVE_ATTRIBUTES) {
|
|
740
|
+
const value = link[name];
|
|
741
|
+
if (!isSetAttr(value)) continue;
|
|
742
|
+
if (typeof value !== "string") {
|
|
743
|
+
console.warn(`registerAsset("preload") expects a string ${name}.`);
|
|
744
|
+
continue;
|
|
745
|
+
}
|
|
746
|
+
if (name === "imagesrcset") srcset = value;else sizes = value;
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
const href = typeof link.href === "string" && link.href ? link.href : null;
|
|
750
|
+
if (!href && link.href != null && link.href !== false) console.warn("Preload href must be a non-empty string; dropping it.", link.href);
|
|
751
|
+
if (!href && !srcset) {
|
|
752
|
+
console.warn('registerAsset("preload") requires a non-empty string href or imagesrcset.');
|
|
753
|
+
return null;
|
|
754
|
+
}
|
|
755
|
+
if (srcset && !sizes && hasWidthDescriptor(srcset)) console.warn("imagesrcset uses a width descriptor, so imagesizes is required; without it the " + "source size defaults to 100vw and the preload may not match the image.", srcset);
|
|
756
|
+
const props = {
|
|
757
|
+
rel: "preload"
|
|
758
|
+
};
|
|
759
|
+
if (href) props.href = href;
|
|
760
|
+
props.as = as;
|
|
761
|
+
for (let i = 0; i < PRELOAD_LINK_ATTRIBUTES.length; i++) {
|
|
762
|
+
const name = PRELOAD_LINK_ATTRIBUTES[i];
|
|
763
|
+
if (RESPONSIVE_ATTRIBUTES.indexOf(name) !== -1) {
|
|
764
|
+
const value = name === "imagesrcset" ? srcset : sizes;
|
|
765
|
+
if (value !== null) props[name] = value;
|
|
766
|
+
continue;
|
|
767
|
+
}
|
|
768
|
+
const value = link[name];
|
|
769
|
+
if (value == null || value === false) continue;
|
|
770
|
+
props[name] = value === true ? "" : String(value);
|
|
771
|
+
}
|
|
772
|
+
const identity = resourceIdentity("link", props);
|
|
773
|
+
if (headRegistry.resources.has(identity)) return null;
|
|
774
|
+
if (props.crossorigin == null && (as === "font" || as === "fetch")) console.warn(`registerAsset("preload") with as="${as}" has no crossorigin and may not match the eventual request.`);
|
|
775
|
+
const attrs = headAttrRecord(props);
|
|
776
|
+
const nonceValue = destination && nonce && nonce[destination];
|
|
777
|
+
if (typeof nonceValue === "string" && nonceValue) attrs.nonce = nonceValue;
|
|
778
|
+
const entry = {
|
|
779
|
+
href: props.href,
|
|
780
|
+
attrs,
|
|
781
|
+
attrHtml: renderHeadAttrHtml(props) + nonceAttr(nonce, destination)
|
|
782
|
+
};
|
|
783
|
+
headRegistry.resources.add(identity);
|
|
784
|
+
let links = tracking.preloadLinks;
|
|
785
|
+
if (!links) tracking.preloadLinks = links = [];
|
|
786
|
+
links.push(entry);
|
|
787
|
+
return entry;
|
|
788
|
+
}
|
|
789
|
+
function createHeadRegistry() {
|
|
790
|
+
return {
|
|
791
|
+
pending: [],
|
|
792
|
+
committed: [],
|
|
793
|
+
seq: 0,
|
|
794
|
+
uniq: 0,
|
|
795
|
+
resources: new Set(),
|
|
796
|
+
eagerHtml: "",
|
|
797
|
+
flushed: null,
|
|
798
|
+
shellFlushed: false,
|
|
799
|
+
parkedResources: []
|
|
800
|
+
};
|
|
801
|
+
}
|
|
802
|
+
function registerHeadTags(registry, context, tracking, emitResource, nonce, tags) {
|
|
803
|
+
const boundary = context._currentBoundaryId || "";
|
|
804
|
+
if (typeof tags === "function") {
|
|
805
|
+
registry.pending.push({
|
|
806
|
+
boundary,
|
|
807
|
+
list: tags,
|
|
808
|
+
resource: (desc, rel) => emitHeadResource(registry, context, tracking, emitResource, nonce, desc, rel)
|
|
809
|
+
});
|
|
810
|
+
return;
|
|
811
|
+
}
|
|
812
|
+
if (!Array.isArray(tags)) tags = [tags];
|
|
813
|
+
const probe = solidJs.sharedConfig.context && solidJs.sharedConfig.context._loadingPhase;
|
|
814
|
+
let replaceable = null;
|
|
815
|
+
for (let i = 0; i < tags.length; i++) {
|
|
816
|
+
const desc = tags[i];
|
|
817
|
+
if (!desc || !HEAD_ELIGIBLE_TAGS.has(desc.tag)) {
|
|
818
|
+
console.warn(`useHead: ignoring non-head tag`, desc);
|
|
819
|
+
continue;
|
|
820
|
+
}
|
|
821
|
+
const cls = classifyHeadTag(desc);
|
|
822
|
+
if (probe && !cls.resource) {
|
|
823
|
+
try {
|
|
824
|
+
evalHeadProps(desc.props || {}, cls.rel !== undefined ? {
|
|
825
|
+
rel: cls.rel
|
|
826
|
+
} : undefined);
|
|
827
|
+
evalHeadValue(desc.key);
|
|
828
|
+
} catch (err) {
|
|
829
|
+
if (solidJs.ssrHandleError(err)) throw err;
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
if (cls.resource) {
|
|
833
|
+
emitHeadResource(registry, context, tracking, emitResource, nonce, desc, cls.rel);
|
|
834
|
+
} else {
|
|
835
|
+
(replaceable || (replaceable = [])).push(cls.rel !== undefined ? {
|
|
836
|
+
tag: desc.tag,
|
|
837
|
+
props: desc.props,
|
|
838
|
+
key: desc.key,
|
|
839
|
+
rel: cls.rel
|
|
840
|
+
} : desc);
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
if (replaceable) registry.pending.push({
|
|
844
|
+
boundary,
|
|
845
|
+
tags: replaceable
|
|
846
|
+
});
|
|
847
|
+
}
|
|
848
|
+
function headShellReady(registry, block) {
|
|
849
|
+
let ready = true;
|
|
850
|
+
const pends = err => {
|
|
851
|
+
const source = solidJs.ssrHandleError(err, true);
|
|
852
|
+
if (!source) return false;
|
|
853
|
+
block(source);
|
|
854
|
+
ready = false;
|
|
855
|
+
return true;
|
|
856
|
+
};
|
|
857
|
+
const parked = registry.parkedResources;
|
|
858
|
+
for (let i = parked.length - 1; i >= 0; i--) {
|
|
859
|
+
const {
|
|
860
|
+
desc,
|
|
861
|
+
rel,
|
|
862
|
+
emit
|
|
863
|
+
} = parked[i];
|
|
864
|
+
try {
|
|
865
|
+
evalHeadProps(desc.props || {}, rel !== undefined ? {
|
|
866
|
+
rel
|
|
867
|
+
} : undefined);
|
|
868
|
+
} catch (err) {
|
|
869
|
+
if (pends(err)) continue;
|
|
870
|
+
console.warn(`useHead: error evaluating resource tag props`, err);
|
|
871
|
+
parked.splice(i, 1);
|
|
872
|
+
continue;
|
|
873
|
+
}
|
|
874
|
+
parked.splice(i, 1);
|
|
875
|
+
emit();
|
|
876
|
+
}
|
|
877
|
+
for (let i = 0; i < registry.pending.length; i++) {
|
|
878
|
+
const reg = registry.pending[i];
|
|
879
|
+
if (reg.boundary !== "" || reg.list) continue;
|
|
880
|
+
for (let j = 0; j < reg.tags.length; j++) {
|
|
881
|
+
const desc = reg.tags[j];
|
|
882
|
+
try {
|
|
883
|
+
evalHeadProps(desc.props || {}, desc.rel !== undefined ? {
|
|
884
|
+
rel: desc.rel
|
|
885
|
+
} : undefined);
|
|
886
|
+
evalHeadValue(desc.key);
|
|
887
|
+
} catch (err) {
|
|
888
|
+
pends(err);
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
return ready;
|
|
893
|
+
}
|
|
894
|
+
function emitHeadResource(registry, context, tracking, emitResource, nonce, desc, rel) {
|
|
895
|
+
let props;
|
|
896
|
+
try {
|
|
897
|
+
props = evalHeadProps(desc.props || {}, rel !== undefined ? {
|
|
898
|
+
rel
|
|
899
|
+
} : undefined);
|
|
900
|
+
} catch (err) {
|
|
901
|
+
const loadingPhase = solidJs.sharedConfig.context && solidJs.sharedConfig.context._loadingPhase;
|
|
902
|
+
if (loadingPhase && solidJs.ssrHandleError(err)) throw err;
|
|
903
|
+
if (!loadingPhase && !context._currentBoundaryId && !registry.shellFlushed && typeof context.block === "function" && solidJs.ssrHandleError(err, true)) {
|
|
904
|
+
registry.parkedResources.push({
|
|
905
|
+
desc,
|
|
906
|
+
rel,
|
|
907
|
+
emit: () => emitHeadResource(registry, context, tracking, emitResource, nonce, desc, rel)
|
|
908
|
+
});
|
|
909
|
+
return;
|
|
910
|
+
}
|
|
911
|
+
console.warn(`useHead: error evaluating resource tag props`, err);
|
|
912
|
+
return;
|
|
913
|
+
}
|
|
914
|
+
const identity = resourceIdentity(desc.tag, props);
|
|
915
|
+
if (registry.resources.has(identity)) return;
|
|
916
|
+
registry.resources.add(identity);
|
|
917
|
+
if (desc.tag === "link" && (rel === "stylesheet" || rel === "modulepreload")) {
|
|
918
|
+
let plain = true;
|
|
919
|
+
let gateable = rel === "stylesheet";
|
|
920
|
+
for (const name in props) {
|
|
921
|
+
if (name === "rel" || name === "href") continue;
|
|
922
|
+
plain = false;
|
|
923
|
+
if (!STYLESHEET_FETCH_META.has(name)) gateable = false;
|
|
924
|
+
}
|
|
925
|
+
if (plain && props.href != null) {
|
|
926
|
+
const isCss = isCssUrl(props.href);
|
|
927
|
+
if (rel === "stylesheet" ? isCss : !isCss) {
|
|
928
|
+
context.registerAsset(rel === "stylesheet" ? "style" : "module", props.href);
|
|
929
|
+
return;
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
if (gateable && props.href != null) {
|
|
933
|
+
const attrHtml = renderHeadAttrHtml(props);
|
|
934
|
+
const entry = {
|
|
935
|
+
href: props.href,
|
|
936
|
+
attrHtml,
|
|
937
|
+
attrs: headAttrRecord(props)
|
|
938
|
+
};
|
|
939
|
+
if (tracking.currentBoundaryId) {
|
|
940
|
+
let styles = tracking.boundaryStyles.get(tracking.currentBoundaryId);
|
|
941
|
+
if (!styles) tracking.boundaryStyles.set(tracking.currentBoundaryId, styles = new Set());
|
|
942
|
+
styles.add(entry);
|
|
943
|
+
}
|
|
944
|
+
const markup = `<link${attrHtml}${nonceAttr(nonce, "style")}>`;
|
|
945
|
+
if (emitResource) emitResource(markup, entry);else {
|
|
946
|
+
registry.eagerHtml += markup;
|
|
947
|
+
entry.emitted = true;
|
|
948
|
+
}
|
|
949
|
+
return;
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
const url = props.href || props.src;
|
|
953
|
+
if (url != null && tracking.emittedAssets.has(url)) return;
|
|
954
|
+
const markup = renderHeadTagMarkup(desc.tag, props, null, nonce);
|
|
955
|
+
if (emitResource) emitResource(markup);else registry.eagerHtml += markup;
|
|
956
|
+
}
|
|
957
|
+
function commitHeadBoundary(registry, boundary, isPendingFragment) {
|
|
958
|
+
const keep = [];
|
|
959
|
+
const groups = [];
|
|
960
|
+
for (let i = 0; i < registry.pending.length; i++) {
|
|
961
|
+
const reg = registry.pending[i];
|
|
962
|
+
const mine = boundary === "" ? !(isPendingFragment && reg.boundary !== "" && isPendingFragment(reg.boundary)) : reg.boundary === boundary;
|
|
963
|
+
if (!mine) {
|
|
964
|
+
keep.push(reg);
|
|
965
|
+
continue;
|
|
966
|
+
}
|
|
967
|
+
let descs = reg.tags;
|
|
968
|
+
if (reg.list) {
|
|
969
|
+
let resolved;
|
|
970
|
+
try {
|
|
971
|
+
resolved = reg.list();
|
|
972
|
+
} catch (err) {
|
|
973
|
+
console.warn(`useHead: error evaluating head group membership`, err);
|
|
974
|
+
continue;
|
|
975
|
+
}
|
|
976
|
+
if (!Array.isArray(resolved)) resolved = [resolved];
|
|
977
|
+
descs = [];
|
|
978
|
+
for (let j = 0; j < resolved.length; j++) {
|
|
979
|
+
const desc = resolved[j];
|
|
980
|
+
if (!desc || !HEAD_ELIGIBLE_TAGS.has(desc.tag)) {
|
|
981
|
+
console.warn(`useHead: ignoring non-head tag`, desc);
|
|
982
|
+
continue;
|
|
983
|
+
}
|
|
984
|
+
const cls = classifyHeadTag(desc);
|
|
985
|
+
if (cls.resource) {
|
|
986
|
+
reg.resource(desc, cls.rel);
|
|
987
|
+
} else {
|
|
988
|
+
descs.push(cls.rel !== undefined ? {
|
|
989
|
+
tag: desc.tag,
|
|
990
|
+
props: desc.props,
|
|
991
|
+
key: desc.key,
|
|
992
|
+
rel: cls.rel
|
|
993
|
+
} : desc);
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
const tags = [];
|
|
998
|
+
for (let j = 0; j < descs.length; j++) {
|
|
999
|
+
const desc = descs[j];
|
|
1000
|
+
let props, key;
|
|
1001
|
+
try {
|
|
1002
|
+
props = evalHeadProps(desc.props || {}, desc.rel !== undefined ? {
|
|
1003
|
+
rel: desc.rel
|
|
1004
|
+
} : undefined);
|
|
1005
|
+
key = evalHeadValue(desc.key);
|
|
1006
|
+
} catch (err) {
|
|
1007
|
+
console.warn(`useHead: error evaluating tag props`, err);
|
|
1008
|
+
continue;
|
|
1009
|
+
}
|
|
1010
|
+
const identity = replaceableIdentity(desc.tag, props, key, "u:" + registry.uniq++);
|
|
1011
|
+
if ((identity === "base" || identity === "charset") && registry.shellFlushed) {
|
|
1012
|
+
console.warn(`useHead: <${desc.tag}> (${identity}) registered after shell flush is ignored`);
|
|
1013
|
+
continue;
|
|
1014
|
+
}
|
|
1015
|
+
tags.push({
|
|
1016
|
+
tag: desc.tag,
|
|
1017
|
+
props,
|
|
1018
|
+
identity
|
|
1019
|
+
});
|
|
1020
|
+
}
|
|
1021
|
+
if (tags.length) groups.push({
|
|
1022
|
+
seq: registry.seq++,
|
|
1023
|
+
tags
|
|
1024
|
+
});
|
|
1025
|
+
}
|
|
1026
|
+
registry.pending = keep;
|
|
1027
|
+
for (let i = 0; i < groups.length; i++) registry.committed.push(groups[i]);
|
|
1028
|
+
return groups;
|
|
1029
|
+
}
|
|
1030
|
+
function adoptHeadBoundary(registry, childKey, parentKey) {
|
|
1031
|
+
for (let i = 0; i < registry.pending.length; i++) {
|
|
1032
|
+
if (registry.pending[i].boundary === childKey) registry.pending[i].boundary = parentKey;
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
function dropHeadBoundary(registry, boundary) {
|
|
1036
|
+
registry.pending = registry.pending.filter(reg => reg.boundary !== boundary);
|
|
1037
|
+
}
|
|
1038
|
+
function headGroupSignature(winner) {
|
|
1039
|
+
let sig = "" + winner.seq;
|
|
1040
|
+
for (let i = 0; i < winner.tags.length; i++) {
|
|
1041
|
+
const t = winner.tags[i];
|
|
1042
|
+
sig += "|" + t.tag + JSON.stringify(t.props);
|
|
1043
|
+
}
|
|
1044
|
+
return sig;
|
|
1045
|
+
}
|
|
1046
|
+
function renderShellHead(registry, nonce, isPendingFragment, noScripts) {
|
|
1047
|
+
commitHeadBoundary(registry, "", isPendingFragment);
|
|
1048
|
+
registry.shellFlushed = true;
|
|
1049
|
+
const winners = resolveHead(registry.committed);
|
|
1050
|
+
registry.flushed = new Map();
|
|
1051
|
+
let prelude = "";
|
|
1052
|
+
let links = "";
|
|
1053
|
+
let metas = "";
|
|
1054
|
+
let others = "";
|
|
1055
|
+
let scripts = "";
|
|
1056
|
+
let title = null;
|
|
1057
|
+
for (const [identity, winner] of winners) {
|
|
1058
|
+
registry.flushed.set(identity, headGroupSignature(winner));
|
|
1059
|
+
if (identity === "title") {
|
|
1060
|
+
const children = winner.tags[0].props.children;
|
|
1061
|
+
title = children == null ? "" : String(children);
|
|
1062
|
+
continue;
|
|
1063
|
+
}
|
|
1064
|
+
for (let i = 0; i < winner.tags.length; i++) {
|
|
1065
|
+
const t = winner.tags[i];
|
|
1066
|
+
const markup = renderHeadTagMarkup(t.tag, t.props, identity, nonce);
|
|
1067
|
+
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;
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
return {
|
|
1071
|
+
prelude,
|
|
1072
|
+
html: registry.eagerHtml + links + metas + others + scripts,
|
|
1073
|
+
title,
|
|
1074
|
+
noScripts
|
|
1075
|
+
};
|
|
1076
|
+
}
|
|
1077
|
+
function flushHeadFragment(registry, boundary, nonce) {
|
|
1078
|
+
const groups = commitHeadBoundary(registry, boundary);
|
|
1079
|
+
if (!groups.length) return null;
|
|
1080
|
+
const winners = resolveHead(registry.committed);
|
|
1081
|
+
const affected = new Set();
|
|
1082
|
+
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);
|
|
1083
|
+
const ops = [];
|
|
1084
|
+
for (const identity of affected) {
|
|
1085
|
+
const winner = winners.get(identity);
|
|
1086
|
+
const sig = headGroupSignature(winner);
|
|
1087
|
+
if (registry.flushed.get(identity) === sig) continue;
|
|
1088
|
+
const existed = registry.flushed.has(identity);
|
|
1089
|
+
registry.flushed.set(identity, sig);
|
|
1090
|
+
if (identity === "title") {
|
|
1091
|
+
const children = winner.tags[0].props.children;
|
|
1092
|
+
ops.push(["t", children == null ? "" : String(children)]);
|
|
1093
|
+
continue;
|
|
1094
|
+
}
|
|
1095
|
+
if (existed) ops.push(["r", identity]);
|
|
1096
|
+
for (let i = 0; i < winner.tags.length; i++) {
|
|
1097
|
+
const t = winner.tags[i];
|
|
1098
|
+
const attrs = {};
|
|
1099
|
+
for (const name in t.props) {
|
|
1100
|
+
if (name === "children" || name === "ref" || name.slice(0, 2) === "on") continue;
|
|
1101
|
+
if (!HEAD_ATTR_NAME.test(name)) {
|
|
1102
|
+
console.warn(`useHead: ignoring invalid attribute name "${name}"`);
|
|
1103
|
+
continue;
|
|
1104
|
+
}
|
|
1105
|
+
const v = t.props[name];
|
|
1106
|
+
if (v == null || v === false) continue;
|
|
1107
|
+
attrs[name] = v === true ? "" : String(v);
|
|
1108
|
+
}
|
|
1109
|
+
if (nonce && !hasNonceProp(t.props)) {
|
|
1110
|
+
const destination = nonceDestination(t.tag, t.props);
|
|
1111
|
+
const value = destination && nonce[destination];
|
|
1112
|
+
if (value) attrs.nonce = String(value);
|
|
1113
|
+
}
|
|
1114
|
+
const children = t.props.children;
|
|
1115
|
+
ops.push(["a", identity, t.tag, attrs, children == null ? null : String(children)]);
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
return ops.length ? ops : null;
|
|
1119
|
+
}
|
|
1120
|
+
function normalizeNonce(nonce) {
|
|
1121
|
+
if (nonce == null) return undefined;
|
|
1122
|
+
if (typeof nonce === "string") {
|
|
1123
|
+
const attr = nonce ? ` nonce="${escape(nonce, true)}"` : "";
|
|
1124
|
+
return {
|
|
1125
|
+
script: nonce,
|
|
1126
|
+
style: nonce,
|
|
1127
|
+
scriptAttr: attr,
|
|
1128
|
+
styleAttr: attr
|
|
1129
|
+
};
|
|
1130
|
+
}
|
|
1131
|
+
const script = nonce.script;
|
|
1132
|
+
const style = nonce.style;
|
|
1133
|
+
if (!script && !style) return undefined;
|
|
1134
|
+
return {
|
|
1135
|
+
script,
|
|
1136
|
+
style,
|
|
1137
|
+
scriptAttr: typeof script === "string" && script ? ` nonce="${escape(script, true)}"` : "",
|
|
1138
|
+
styleAttr: typeof style === "string" && style ? ` nonce="${escape(style, true)}"` : ""
|
|
1139
|
+
};
|
|
1140
|
+
}
|
|
1141
|
+
function hasNonceProp(props) {
|
|
1142
|
+
for (const name in props) if (name.length === 5 && asciiLowerCase(name) === "nonce" && props[name] != null) return true;
|
|
1143
|
+
return false;
|
|
1144
|
+
}
|
|
1145
|
+
function nonceDestination(tag, props) {
|
|
1146
|
+
if (tag === "script") return "script";
|
|
1147
|
+
if (tag === "style") return "style";
|
|
1148
|
+
if (tag !== "link") return null;
|
|
1149
|
+
const rel = props.rel;
|
|
1150
|
+
if (typeof rel !== "string") return null;
|
|
1151
|
+
const rels = asciiLowerCase(rel).split(/[\t\n\f\r ]+/);
|
|
1152
|
+
if (rels.includes("stylesheet")) return "style";
|
|
1153
|
+
const isModulePreload = rels.includes("modulepreload");
|
|
1154
|
+
if (!isModulePreload && !rels.includes("preload")) return null;
|
|
1155
|
+
const as = typeof props.as === "string" ? asciiLowerCase(props.as) : "";
|
|
1156
|
+
if (as === "style") return "style";
|
|
1157
|
+
if (as === "script") return "script";
|
|
1158
|
+
if (!isModulePreload) return null;
|
|
1159
|
+
switch (as) {
|
|
1160
|
+
case "fetch":
|
|
1161
|
+
case "font":
|
|
1162
|
+
case "image":
|
|
1163
|
+
case "json":
|
|
1164
|
+
case "text":
|
|
1165
|
+
case "track":
|
|
1166
|
+
return null;
|
|
1167
|
+
default:
|
|
1168
|
+
return "script";
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
function nonceAttr(nonce, destination) {
|
|
1172
|
+
if (!nonce || !destination) return "";
|
|
1173
|
+
return destination === "script" ? nonce.scriptAttr : nonce.styleAttr;
|
|
1174
|
+
}
|
|
1175
|
+
function renderHeadAttrHtml(props) {
|
|
1176
|
+
let attrs = "";
|
|
1177
|
+
for (const name in props) {
|
|
1178
|
+
if (name === "children" || name === "ref" || name.slice(0, 2) === "on") continue;
|
|
1179
|
+
if (!HEAD_ATTR_NAME.test(name)) {
|
|
1180
|
+
console.warn(`useHead: ignoring invalid attribute name "${name}"`);
|
|
1181
|
+
continue;
|
|
1182
|
+
}
|
|
1183
|
+
const v = props[name];
|
|
1184
|
+
if (v == null || v === false) continue;
|
|
1185
|
+
attrs += v === true ? ` ${name}` : ` ${name}="${escape(String(v), true)}"`;
|
|
1186
|
+
}
|
|
1187
|
+
return attrs;
|
|
1188
|
+
}
|
|
1189
|
+
function headAttrRecord(props, skipRelHref) {
|
|
1190
|
+
let attrs = null;
|
|
1191
|
+
for (const name in props) {
|
|
1192
|
+
if (name === "children" || name === "ref" || name.slice(0, 2) === "on") continue;
|
|
1193
|
+
if ((name === "rel" || name === "href")) continue;
|
|
1194
|
+
if (!HEAD_ATTR_NAME.test(name)) continue;
|
|
1195
|
+
const v = props[name];
|
|
1196
|
+
if (v == null || v === false) continue;
|
|
1197
|
+
(attrs || (attrs = {}))[name] = v === true ? "" : String(v);
|
|
1198
|
+
}
|
|
1199
|
+
return attrs;
|
|
1200
|
+
}
|
|
1201
|
+
function renderHeadTagMarkup(tag, props, identity, nonce) {
|
|
1202
|
+
let attrs = renderHeadAttrHtml(props);
|
|
1203
|
+
if (identity != null) attrs += ` data-dh="${escape(identity, true)}"`;
|
|
1204
|
+
if (nonce && !hasNonceProp(props)) attrs += nonceAttr(nonce, nonceDestination(tag, props));
|
|
1205
|
+
if (tag === "meta" || tag === "link" || tag === "base") return `<${tag}${attrs}>`;
|
|
1206
|
+
let body = props.children == null ? "" : String(props.children);
|
|
1207
|
+
if (tag === "script") body = body.replace(/<\/(script)/gi, "<\\/$1");else if (tag === "style") body = escapeStyleContent(body);else body = escape(body);
|
|
1208
|
+
return `<${tag}${attrs}>${body}</${tag}>`;
|
|
1209
|
+
}
|
|
1210
|
+
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.v=_$HY.v||{})[e]=1,_$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])}`;
|
|
1211
|
+
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.hasAttribute("data-dh")||n.setAttribute("data-dhf",n.textContent):(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)}`;
|
|
1212
|
+
function renderToStream(code, options = {}) {
|
|
1213
|
+
let {
|
|
1214
|
+
onCompleteShell,
|
|
1215
|
+
onCompleteAll,
|
|
1216
|
+
renderId = "",
|
|
1217
|
+
noScripts,
|
|
1218
|
+
manifest,
|
|
1219
|
+
onHead
|
|
1220
|
+
} = options;
|
|
1221
|
+
const nonce = normalizeNonce(options.nonce);
|
|
1222
|
+
const requestEvent = peekRequestEvent();
|
|
1223
|
+
let dispose;
|
|
1224
|
+
let dead = false;
|
|
1225
|
+
const abandon = () => {
|
|
1226
|
+
if (dead) return;
|
|
1227
|
+
dead = true;
|
|
1228
|
+
completed = true;
|
|
1229
|
+
buffer = {
|
|
1230
|
+
write() {}
|
|
1231
|
+
};
|
|
1232
|
+
writable = {
|
|
1233
|
+
end() {}
|
|
1234
|
+
};
|
|
1235
|
+
if (dispose) {
|
|
1236
|
+
const d = dispose;
|
|
1237
|
+
dispose = () => {};
|
|
1238
|
+
d();
|
|
1239
|
+
}
|
|
1240
|
+
};
|
|
1241
|
+
const failRender = err => {
|
|
1242
|
+
try {
|
|
1243
|
+
options.onError ? options.onError(err) : console.error(err);
|
|
1244
|
+
} catch (_) {}
|
|
1245
|
+
abandon();
|
|
1246
|
+
};
|
|
1247
|
+
const coalesceWrites = (writeRaw, endRaw) => {
|
|
1248
|
+
let buf = "";
|
|
1249
|
+
let scheduled = false;
|
|
1250
|
+
const flush = () => {
|
|
1251
|
+
scheduled = false;
|
|
1252
|
+
if (!buf) return;
|
|
1253
|
+
const out = buf;
|
|
1254
|
+
buf = "";
|
|
1255
|
+
writeRaw(out);
|
|
1256
|
+
};
|
|
1257
|
+
return {
|
|
1258
|
+
write(payload) {
|
|
1259
|
+
buf += payload;
|
|
1260
|
+
if (buf.length >= 16384) return flush();
|
|
1261
|
+
if (!scheduled) {
|
|
1262
|
+
scheduled = true;
|
|
1263
|
+
deferFlush(flush);
|
|
1264
|
+
}
|
|
1265
|
+
},
|
|
1266
|
+
flush,
|
|
1267
|
+
end() {
|
|
1268
|
+
flush();
|
|
1269
|
+
endRaw();
|
|
1270
|
+
}
|
|
1271
|
+
};
|
|
1272
|
+
};
|
|
1273
|
+
const guardSink = w => ({
|
|
1274
|
+
write(payload) {
|
|
1275
|
+
if (dead) return;
|
|
1276
|
+
try {
|
|
1277
|
+
w.write(payload);
|
|
1278
|
+
} catch (_) {
|
|
1279
|
+
abandon();
|
|
1280
|
+
}
|
|
1281
|
+
},
|
|
1282
|
+
end() {
|
|
1283
|
+
if (dead) return;
|
|
1284
|
+
try {
|
|
1285
|
+
w.end();
|
|
1286
|
+
} catch (_) {
|
|
1287
|
+
abandon();
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
});
|
|
1291
|
+
const blockingPromises = new Set();
|
|
1292
|
+
const canBatchStubs = !options.serializer && !options.sink;
|
|
1293
|
+
let stubBatch = null;
|
|
1294
|
+
const STUB_BATCH_KEY = "$B";
|
|
1295
|
+
const flushStubBatch = () => {
|
|
1296
|
+
if (!stubBatch) return;
|
|
1297
|
+
const batch = stubBatch;
|
|
1298
|
+
stubBatch = null;
|
|
1299
|
+
if (batch.size === 1) {
|
|
1300
|
+
const [id, p] = batch.entries().next().value;
|
|
1301
|
+
serializer.write(id, p);
|
|
1302
|
+
return;
|
|
1303
|
+
}
|
|
1304
|
+
const obj = {};
|
|
1305
|
+
for (const [id, p] of batch) obj[id] = p;
|
|
1306
|
+
serializer.write(STUB_BATCH_KEY, obj);
|
|
1307
|
+
pushTask(`(b=>{for(var k in b)_$HY.r[k]=b[k];delete _$HY.r["${STUB_BATCH_KEY}"]})(_$HY.r["${STUB_BATCH_KEY}"])`);
|
|
1308
|
+
};
|
|
1309
|
+
let headerEmitted = false;
|
|
1310
|
+
const pushTask = task => {
|
|
1311
|
+
if (noScripts) return;
|
|
1312
|
+
if (!headerEmitted) {
|
|
1313
|
+
headerEmitted = true;
|
|
1314
|
+
tasks += getLocalHeaderScript(renderId);
|
|
1315
|
+
}
|
|
1316
|
+
tasks += task + ";";
|
|
1317
|
+
if (!timer && firstFlushed) {
|
|
1318
|
+
timer = true;
|
|
1319
|
+
queue(() => queue(writeTasks));
|
|
1320
|
+
}
|
|
1321
|
+
};
|
|
1322
|
+
const onDone = () => {
|
|
1323
|
+
writeTasks();
|
|
1324
|
+
lastBlockingSize = blockingPromises.size;
|
|
1325
|
+
doShell();
|
|
1326
|
+
onCompleteAll && onCompleteAll({
|
|
1327
|
+
write(v) {
|
|
1328
|
+
!completed && buffer.write(v);
|
|
1329
|
+
}
|
|
1330
|
+
});
|
|
1331
|
+
writable && writable.end();
|
|
1332
|
+
completed = true;
|
|
1333
|
+
if (firstFlushed) dispose();
|
|
1334
|
+
};
|
|
1335
|
+
const sink = {
|
|
1336
|
+
data(payload) {
|
|
1337
|
+
pushTask(payload);
|
|
1338
|
+
},
|
|
1339
|
+
fragment(key, value, meta) {
|
|
1340
|
+
const deferActivation = !!meta.revealGroup;
|
|
1341
|
+
const styles = meta.styles;
|
|
1342
|
+
for (let i = 0; i < styles.inline.length; i++) {
|
|
1343
|
+
buffer.write(renderInlineStyle(styles.inline[i], nonce));
|
|
1344
|
+
}
|
|
1345
|
+
if (styles.links.length) {
|
|
1346
|
+
const styleAttr = nonceAttr(nonce, "style");
|
|
1347
|
+
emitTask(`$dfs("${key}",${styles.links.length},${deferActivation ? 1 : 0})`);
|
|
1348
|
+
writeTasks();
|
|
1349
|
+
for (const entry of styles.links) {
|
|
1350
|
+
buffer.write(typeof entry === "string" ? `<link rel="stylesheet" href="${entry}"${styleAttr} onload="$dfc('${key}')" onerror="$dfc('${key}')">` : `<link${entry.attrHtml}${styleAttr} onload="$dfc('${key}')" onerror="$dfc('${key}')">`);
|
|
1351
|
+
}
|
|
1352
|
+
buffer.write(`<template id="${key}">${value}</template>`);
|
|
1353
|
+
} else {
|
|
1354
|
+
buffer.write(`<template id="${key}">${value}</template>`);
|
|
1355
|
+
if (!deferActivation) {
|
|
1356
|
+
emitTask(`$df("${key}")`);
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
},
|
|
1360
|
+
reveal(keys, meta) {
|
|
1361
|
+
emitTask(`${meta.fallback ? "$dflj" : "$dfj"}(${JSON.stringify(keys)})`);
|
|
1362
|
+
},
|
|
1363
|
+
asset(type, value) {
|
|
1364
|
+
if (type === "module") {
|
|
1365
|
+
buffer.write(`<link rel="modulepreload" href="${value}"${nonceAttr(nonce, "script")}>`);
|
|
1366
|
+
} else if (type === "preload") {
|
|
1367
|
+
buffer.write(`<link${value.attrHtml}>`);
|
|
1368
|
+
} else if (type === "inline-style") {
|
|
1369
|
+
buffer.write(renderInlineStyle(value, nonce));
|
|
1370
|
+
} else if (type === "head-tag") {
|
|
1371
|
+
buffer.write(value);
|
|
1372
|
+
}
|
|
1373
|
+
},
|
|
1374
|
+
shell(shellHtml, meta) {
|
|
1375
|
+
buffer.write(assembleDocument(shellHtml, meta.preloads, meta.preloadLinks, meta.inlineStyles, meta.tasks.length ? meta.tasks : "", nonce, meta.head, onHead));
|
|
1376
|
+
},
|
|
1377
|
+
...options.sink
|
|
1378
|
+
};
|
|
1379
|
+
const serializer = (options.serializer || createHydrationSerializer)({
|
|
1380
|
+
scopeId: options.renderId,
|
|
1381
|
+
plugins: options.plugins,
|
|
1382
|
+
onData: payload => sink.data(payload),
|
|
1383
|
+
onDone,
|
|
1384
|
+
onError: options.onError
|
|
1385
|
+
});
|
|
1386
|
+
let rootAssetsSerialized = false;
|
|
1387
|
+
const serializeRootAssets = () => {
|
|
1388
|
+
if (rootAssetsSerialized) return;
|
|
1389
|
+
rootAssetsSerialized = true;
|
|
1390
|
+
serializeFragmentAssets("", tracking.boundaryModules, context, renderId);
|
|
1391
|
+
};
|
|
1392
|
+
let holds = 0;
|
|
1393
|
+
const flushEnd = () => {
|
|
1394
|
+
if (!registry.size && !holds) {
|
|
1395
|
+
serializeRootAssets();
|
|
1396
|
+
queue(() => queue(() => {
|
|
1397
|
+
if (context.live.end) {
|
|
1398
|
+
const end = context.live.end;
|
|
1399
|
+
context.live.end = null;
|
|
1400
|
+
end();
|
|
1401
|
+
}
|
|
1402
|
+
flushStubBatch();
|
|
1403
|
+
serializer.flush();
|
|
1404
|
+
}));
|
|
1405
|
+
}
|
|
1406
|
+
};
|
|
1407
|
+
const registry = new Map();
|
|
1408
|
+
const pendingSerialized = new Map();
|
|
1409
|
+
const trackSerialized = (id, p) => {
|
|
1410
|
+
let settle;
|
|
1411
|
+
const raced = Promise.race([p, new Promise(r => settle = r)]);
|
|
1412
|
+
pendingSerialized.set(id, settle);
|
|
1413
|
+
const drop = () => pendingSerialized.delete(id);
|
|
1414
|
+
p.then(drop, drop);
|
|
1415
|
+
return raced;
|
|
1416
|
+
};
|
|
1417
|
+
const abandonSubtree = key => {
|
|
1418
|
+
for (const [k, entry] of registry) {
|
|
1419
|
+
if (k.length > key.length && k.startsWith(key)) {
|
|
1420
|
+
registry.delete(k);
|
|
1421
|
+
entry.resolve();
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
for (const [id, settle] of pendingSerialized) {
|
|
1425
|
+
if (id.startsWith(key)) {
|
|
1426
|
+
pendingSerialized.delete(id);
|
|
1427
|
+
settle();
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
};
|
|
1431
|
+
const writeTasks = () => {
|
|
1432
|
+
if (tasks.length && !completed && firstFlushed) {
|
|
1433
|
+
buffer.write(`<script${nonceAttr(nonce, "script")}>${tasks}</script>`);
|
|
1434
|
+
tasks = "";
|
|
1435
|
+
}
|
|
1436
|
+
timer = null;
|
|
1437
|
+
};
|
|
1438
|
+
let context;
|
|
1439
|
+
let writable;
|
|
1440
|
+
let tmp = "";
|
|
1441
|
+
let tasks = "";
|
|
1442
|
+
let firstFlushed = false;
|
|
1443
|
+
let completed = false;
|
|
1444
|
+
let shellCompleted = false;
|
|
1445
|
+
let scriptFlushed = false;
|
|
1446
|
+
let headStyles;
|
|
1447
|
+
const revealGroups = new Map();
|
|
1448
|
+
let timer = null;
|
|
1449
|
+
const emitTask = task => {
|
|
1450
|
+
pushTask(`${task}${!scriptFlushed ? ";" + REPLACE_SCRIPT : ""}`);
|
|
1451
|
+
scriptFlushed = true;
|
|
1452
|
+
};
|
|
1453
|
+
function resolveRevealKeys(groupOrKeys, release, consume) {
|
|
1454
|
+
if (Array.isArray(groupOrKeys)) return groupOrKeys.slice();
|
|
1455
|
+
let group = revealGroups.get(groupOrKeys);
|
|
1456
|
+
if (!group) {
|
|
1457
|
+
if (!release) return;
|
|
1458
|
+
group = {
|
|
1459
|
+
order: [],
|
|
1460
|
+
keys: new Set(),
|
|
1461
|
+
released: true
|
|
1462
|
+
};
|
|
1463
|
+
revealGroups.set(groupOrKeys, group);
|
|
1464
|
+
} else if (release) group.released = true;
|
|
1465
|
+
if (!group.order.length) return;
|
|
1466
|
+
const keys = group.order.slice();
|
|
1467
|
+
if (consume) revealGroups.delete(groupOrKeys);
|
|
1468
|
+
return keys;
|
|
1469
|
+
}
|
|
1470
|
+
let rootHoles = null;
|
|
1471
|
+
let nextHoleId = 0;
|
|
1472
|
+
let buffer = {
|
|
1473
|
+
write(payload) {
|
|
1474
|
+
tmp += payload;
|
|
1475
|
+
}
|
|
1476
|
+
};
|
|
1477
|
+
const tracking = createAssetTracking();
|
|
1478
|
+
const headRegistry = createHeadRegistry();
|
|
1479
|
+
let headScriptFlushed = false;
|
|
1480
|
+
const emitHeadOps = (key, ops) => {
|
|
1481
|
+
const payload = JSON.stringify(ops).replace(/</g, "\\u003C");
|
|
1482
|
+
emitTask(`${!headScriptFlushed ? HEAD_SCRIPT : ""}(_$HY.hp=_$HY.hp||{})[${JSON.stringify(key)}]=${payload}`);
|
|
1483
|
+
headScriptFlushed = true;
|
|
1484
|
+
};
|
|
1485
|
+
solidJs.sharedConfig.context = context = {
|
|
1486
|
+
async: true,
|
|
1487
|
+
nonce: options.nonce,
|
|
1488
|
+
live: {},
|
|
1489
|
+
registerHeadTags(tags) {
|
|
1490
|
+
registerHeadTags(headRegistry, context, tracking,
|
|
1491
|
+
(markup, gateEntry) => {
|
|
1492
|
+
if (!firstFlushed) {
|
|
1493
|
+
headRegistry.eagerHtml += markup;
|
|
1494
|
+
if (gateEntry) gateEntry.emitted = true;
|
|
1495
|
+
} else if (!gateEntry || !tracking.currentBoundaryId) {
|
|
1496
|
+
sink.asset("head-tag", markup);
|
|
1497
|
+
}
|
|
1498
|
+
}, nonce, tags);
|
|
1499
|
+
},
|
|
1500
|
+
registerAsset(type, value) {
|
|
1501
|
+
if (type === "preload") {
|
|
1502
|
+
const entry = registerPreloadLink(tracking, headRegistry, value, nonce);
|
|
1503
|
+
if (entry && firstFlushed) sink.asset("preload", entry);
|
|
1504
|
+
return;
|
|
1505
|
+
}
|
|
1506
|
+
if (type === "inline-style") {
|
|
1507
|
+
const entry = tracking.registerInlineStyle(value);
|
|
1508
|
+
if (firstFlushed && !tracking.currentBoundaryId && !entry.emitted) {
|
|
1509
|
+
entry.emitted = true;
|
|
1510
|
+
sink.asset("inline-style", entry);
|
|
1511
|
+
}
|
|
1512
|
+
return;
|
|
1513
|
+
}
|
|
1514
|
+
if (tracking.currentBoundaryId && type === "style") {
|
|
1515
|
+
let styles = tracking.boundaryStyles.get(tracking.currentBoundaryId);
|
|
1516
|
+
if (!styles) {
|
|
1517
|
+
styles = new Set();
|
|
1518
|
+
tracking.boundaryStyles.set(tracking.currentBoundaryId, styles);
|
|
1519
|
+
}
|
|
1520
|
+
styles.add(value);
|
|
1521
|
+
}
|
|
1522
|
+
if (!tracking.emittedAssets.has(value)) {
|
|
1523
|
+
tracking.emittedAssets.add(value);
|
|
1524
|
+
if (firstFlushed) sink.asset(type, value);
|
|
1525
|
+
}
|
|
1526
|
+
},
|
|
1527
|
+
block(p) {
|
|
1528
|
+
if (!firstFlushed) blockingPromises.add(p);
|
|
1529
|
+
},
|
|
1530
|
+
hold() {
|
|
1531
|
+
holds++;
|
|
1532
|
+
let released = false;
|
|
1533
|
+
return () => {
|
|
1534
|
+
if (released) return;
|
|
1535
|
+
released = true;
|
|
1536
|
+
holds--;
|
|
1537
|
+
if (!holds) queue(flushEnd);
|
|
1538
|
+
};
|
|
1539
|
+
},
|
|
1540
|
+
replace(id, payloadFn) {
|
|
1541
|
+
if (firstFlushed) return;
|
|
1542
|
+
const placeholder = `<!--!$${id}-->`;
|
|
1543
|
+
const first = html.indexOf(placeholder);
|
|
1544
|
+
if (first === -1) return;
|
|
1545
|
+
const last = html.indexOf(`<!--!$/${id}-->`, first + placeholder.length);
|
|
1546
|
+
html = html.slice(0, first) + resolveSSRSync(escape(payloadFn())) + html.slice(last + placeholder.length + 1);
|
|
1547
|
+
},
|
|
1548
|
+
serialize(id, p, deferStream) {
|
|
1549
|
+
if (solidJs.sharedConfig.context.noHydrate) return;
|
|
1550
|
+
if (p && typeof p === "object" && typeof p.then === "function") {
|
|
1551
|
+
if (!firstFlushed && deferStream) {
|
|
1552
|
+
blockingPromises.add(p);
|
|
1553
|
+
p.then(d => serializer.write(id, d)).catch(e => serializer.write(id, e));
|
|
1554
|
+
return;
|
|
1555
|
+
}
|
|
1556
|
+
p = trackSerialized(id, p);
|
|
1557
|
+
if (!firstFlushed && canBatchStubs && !shellCompleted) {
|
|
1558
|
+
(stubBatch ||= new Map()).set(id, p);
|
|
1559
|
+
return;
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
serializer.write(id, p);
|
|
1563
|
+
},
|
|
1564
|
+
escape: escape,
|
|
1565
|
+
resolve: resolveSSRNode,
|
|
1566
|
+
ssr: ssr,
|
|
1567
|
+
registerFragment(key, options) {
|
|
1568
|
+
const revealGroup = options && options.revealGroup;
|
|
1569
|
+
if (revealGroup) {
|
|
1570
|
+
let group = revealGroups.get(revealGroup);
|
|
1571
|
+
if (!group) {
|
|
1572
|
+
group = {
|
|
1573
|
+
order: [],
|
|
1574
|
+
keys: new Set(),
|
|
1575
|
+
released: false
|
|
1576
|
+
};
|
|
1577
|
+
revealGroups.set(revealGroup, group);
|
|
1578
|
+
}
|
|
1579
|
+
if (!group.keys.has(key)) {
|
|
1580
|
+
group.keys.add(key);
|
|
1581
|
+
group.order.push(key);
|
|
1582
|
+
}
|
|
1583
|
+
if (group.released) {
|
|
1584
|
+
throw new Error("registerFragment() for reveal group '" + revealGroup + "' was called after revealFragments(). Ensure template payload is emitted before grouped reveal.");
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
if (!registry.has(key)) {
|
|
1588
|
+
let resolve, reject;
|
|
1589
|
+
const p = new Promise((r, rej) => (resolve = r, reject = rej));
|
|
1590
|
+
registry.set(key, {
|
|
1591
|
+
resolve: err => queue(() => queue(() => {
|
|
1592
|
+
err ? reject(err) : resolve(true);
|
|
1593
|
+
queue(flushEnd);
|
|
1594
|
+
}))
|
|
1595
|
+
});
|
|
1596
|
+
if (canBatchStubs && !shellCompleted) (stubBatch ||= new Map()).set(key + "_fr", p);else serializer.write(key + "_fr", p);
|
|
1597
|
+
}
|
|
1598
|
+
return (value, error) => {
|
|
1599
|
+
if (registry.has(key)) {
|
|
1600
|
+
const item = registry.get(key);
|
|
1601
|
+
registry.delete(key);
|
|
1602
|
+
if (error) abandonSubtree(key);
|
|
1603
|
+
if (item.children) {
|
|
1604
|
+
for (const k in item.children) {
|
|
1605
|
+
value = replacePlaceholder(value, k, item.children[k]);
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
const parentKey = waitForFragments(registry, key);
|
|
1609
|
+
if (parentKey) {
|
|
1610
|
+
const parent = registry.get(parentKey);
|
|
1611
|
+
parent.children ||= {};
|
|
1612
|
+
parent.children[key] = value !== undefined ? value : "";
|
|
1613
|
+
serializeFragmentAssets(key, tracking.boundaryModules, context);
|
|
1614
|
+
propagateBoundaryStyles(key, parentKey, tracking);
|
|
1615
|
+
adoptHeadBoundary(headRegistry, key, parentKey);
|
|
1616
|
+
item.resolve();
|
|
1617
|
+
return;
|
|
1618
|
+
}
|
|
1619
|
+
if (!completed) {
|
|
1620
|
+
if (error) dropHeadBoundary(headRegistry, key);
|
|
1621
|
+
if (!firstFlushed) {
|
|
1622
|
+
queue(() => html = replacePlaceholder(html, key, value !== undefined ? value : ""));
|
|
1623
|
+
serializeFragmentAssets(key, tracking.boundaryModules, context);
|
|
1624
|
+
item.resolve(error);
|
|
1625
|
+
} else {
|
|
1626
|
+
serializeFragmentAssets(key, tracking.boundaryModules, context);
|
|
1627
|
+
const styles = collectStreamStyles(key, tracking, headStyles);
|
|
1628
|
+
const headOps = error ? null : flushHeadFragment(headRegistry, key, nonce);
|
|
1629
|
+
if (headOps) emitHeadOps(key, headOps);
|
|
1630
|
+
sink.fragment(key, resolveSSRSelectValues(value !== undefined ? value : " "), {
|
|
1631
|
+
styles,
|
|
1632
|
+
revealGroup,
|
|
1633
|
+
error
|
|
1634
|
+
});
|
|
1635
|
+
item.resolve(error);
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
return firstFlushed;
|
|
1640
|
+
};
|
|
1641
|
+
},
|
|
1642
|
+
revealFragments(groupOrKeys) {
|
|
1643
|
+
const keys = resolveRevealKeys(groupOrKeys, true, true);
|
|
1644
|
+
if (!keys) return;
|
|
1645
|
+
sink.reveal(keys, {
|
|
1646
|
+
fallback: false
|
|
1647
|
+
});
|
|
1648
|
+
},
|
|
1649
|
+
revealFallbacks(groupOrKeys) {
|
|
1650
|
+
const keys = resolveRevealKeys(groupOrKeys, false, false);
|
|
1651
|
+
if (!keys) return;
|
|
1652
|
+
sink.reveal(keys, {
|
|
1653
|
+
fallback: true
|
|
1654
|
+
});
|
|
1655
|
+
}
|
|
1656
|
+
};
|
|
1657
|
+
applyAssetTracking(context, tracking, manifest, noScripts);
|
|
1658
|
+
context.failRender = failRender;
|
|
1659
|
+
registerEntryAssets(manifest);
|
|
1660
|
+
let html = solidJs.createRoot(d => {
|
|
1661
|
+
dispose = d;
|
|
1662
|
+
const res = resolveSSRNode(escape(code()));
|
|
1663
|
+
if (!res.h.length) return res.t[0];
|
|
1664
|
+
rootHoles = [];
|
|
1665
|
+
let out = res.t[0];
|
|
1666
|
+
for (let i = 0; i < res.h.length; i++) {
|
|
1667
|
+
const id = nextHoleId++;
|
|
1668
|
+
rootHoles.push({
|
|
1669
|
+
id,
|
|
1670
|
+
fn: res.h[i]
|
|
1671
|
+
});
|
|
1672
|
+
out += `<!--rh${id}-->` + res.t[i + 1];
|
|
1673
|
+
}
|
|
1674
|
+
for (const p of res.p) blockingPromises.add(p);
|
|
1675
|
+
return out;
|
|
1676
|
+
}, {
|
|
1677
|
+
id: renderId
|
|
1678
|
+
});
|
|
1679
|
+
function resolveRootHoles() {
|
|
1680
|
+
if (!rootHoles) return true;
|
|
1681
|
+
const pending = [];
|
|
1682
|
+
for (const {
|
|
1683
|
+
id,
|
|
1684
|
+
fn
|
|
1685
|
+
} of rootHoles) {
|
|
1686
|
+
const marker = `<!--rh${id}-->`;
|
|
1687
|
+
const res = resolveSSRNode(fn);
|
|
1688
|
+
if (!res.h.length) {
|
|
1689
|
+
html = html.replace(marker, res.t[0]);
|
|
1690
|
+
} else {
|
|
1691
|
+
let out = res.t[0];
|
|
1692
|
+
for (let j = 0; j < res.h.length; j++) {
|
|
1693
|
+
const newId = nextHoleId++;
|
|
1694
|
+
pending.push({
|
|
1695
|
+
id: newId,
|
|
1696
|
+
fn: res.h[j]
|
|
1697
|
+
});
|
|
1698
|
+
out += `<!--rh${newId}-->` + res.t[j + 1];
|
|
1699
|
+
}
|
|
1700
|
+
html = html.replace(marker, out);
|
|
1701
|
+
for (const p of res.p) blockingPromises.add(p);
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
if (pending.length) {
|
|
1705
|
+
rootHoles = pending;
|
|
1706
|
+
return false;
|
|
1707
|
+
}
|
|
1708
|
+
rootHoles = null;
|
|
1709
|
+
return true;
|
|
1710
|
+
}
|
|
1711
|
+
function doShell() {
|
|
1712
|
+
if (shellCompleted) return;
|
|
1713
|
+
solidJs.sharedConfig.context = context;
|
|
1714
|
+
if (blockingPromises.size !== lastBlockingSize) return;
|
|
1715
|
+
if (!resolveRootHoles()) return;
|
|
1716
|
+
if (blockingPromises.size !== lastBlockingSize) return;
|
|
1717
|
+
if (!headShellReady(headRegistry, p => blockingPromises.add(p))) return;
|
|
1718
|
+
headStyles = new Set();
|
|
1719
|
+
for (const url of tracking.emittedAssets) {
|
|
1720
|
+
if (isCssUrl(url)) headStyles.add(url);
|
|
1721
|
+
}
|
|
1722
|
+
serializeRootAssets();
|
|
1723
|
+
flushStubBatch();
|
|
1724
|
+
const head = renderShellHead(headRegistry, nonce, k => registry.has(k), noScripts);
|
|
1725
|
+
sink.shell(resolveSSRSelectValues(html), {
|
|
1726
|
+
preloads: tracking.emittedAssets,
|
|
1727
|
+
preloadLinks: tracking.preloadLinks,
|
|
1728
|
+
inlineStyles: tracking.inlineStyles,
|
|
1729
|
+
tasks,
|
|
1730
|
+
head
|
|
1731
|
+
});
|
|
1732
|
+
tasks = "";
|
|
1733
|
+
onCompleteShell && onCompleteShell({
|
|
1734
|
+
write(v) {
|
|
1735
|
+
!completed && buffer.write(v);
|
|
1736
|
+
}
|
|
1737
|
+
});
|
|
1738
|
+
shellCompleted = true;
|
|
1739
|
+
}
|
|
1740
|
+
const MIN_DRAIN_TURNS = 8;
|
|
1741
|
+
let lastBlockingSize = -1;
|
|
1742
|
+
let lastRegistrySize = -1;
|
|
1743
|
+
let drainTurn = 0;
|
|
1744
|
+
const scheduleFlush = (fn, awaited) => {
|
|
1745
|
+
const attempt = () => {
|
|
1746
|
+
flushStubBatch();
|
|
1747
|
+
if (registry.size !== lastRegistrySize || drainTurn++ < MIN_DRAIN_TURNS) {
|
|
1748
|
+
if (registry.size !== lastRegistrySize) drainTurn = 0;
|
|
1749
|
+
lastRegistrySize = registry.size;
|
|
1750
|
+
queue(attempt);
|
|
1751
|
+
return;
|
|
1752
|
+
}
|
|
1753
|
+
fn();
|
|
1754
|
+
};
|
|
1755
|
+
const progressed = awaited !== lastBlockingSize;
|
|
1756
|
+
lastBlockingSize = awaited;
|
|
1757
|
+
lastRegistrySize = -1;
|
|
1758
|
+
drainTurn = 0;
|
|
1759
|
+
progressed ? queue(attempt) : setTimeout(attempt);
|
|
1760
|
+
};
|
|
1761
|
+
let cachedReadable;
|
|
1762
|
+
let consumer;
|
|
1763
|
+
const claimConsumer = name => {
|
|
1764
|
+
if (consumer && consumer !== name) {
|
|
1765
|
+
throw new Error(`renderToStream result was already consumed via \`${consumer}\`; cannot also consume it via \`${name}\`. Use exactly one of \`pipe\`, \`pipeTo\`, or \`readable\`.`);
|
|
1766
|
+
}
|
|
1767
|
+
consumer = name;
|
|
1768
|
+
};
|
|
1769
|
+
const pipeToImpl = w => {
|
|
1770
|
+
let resolve;
|
|
1771
|
+
const p = new Promise(r => resolve = r);
|
|
1772
|
+
function flush() {
|
|
1773
|
+
allSettled(blockingPromises).then(awaited => {
|
|
1774
|
+
scheduleFlush(() => {
|
|
1775
|
+
if (dead) return resolve();
|
|
1776
|
+
try {
|
|
1777
|
+
doShell();
|
|
1778
|
+
} catch (err) {
|
|
1779
|
+
failRender(err);
|
|
1780
|
+
return resolve();
|
|
1781
|
+
}
|
|
1782
|
+
if (!shellCompleted) return flush();
|
|
1783
|
+
const encoder = new TextEncoder();
|
|
1784
|
+
const writer = w.getWriter();
|
|
1785
|
+
let pendingWrites = Promise.resolve();
|
|
1786
|
+
let ended = false;
|
|
1787
|
+
const failed = () => {
|
|
1788
|
+
if (!ended) {
|
|
1789
|
+
abandon();
|
|
1790
|
+
resolve();
|
|
1791
|
+
}
|
|
1792
|
+
};
|
|
1793
|
+
writer.closed && writer.closed.catch(failed);
|
|
1794
|
+
buffer = writable = coalesceWrites(payload => {
|
|
1795
|
+
pendingWrites = pendingWrites.then(() => writer.write(encoder.encode(payload))).catch(failed);
|
|
1796
|
+
}, () => {
|
|
1797
|
+
pendingWrites.then(() => {
|
|
1798
|
+
ended = true;
|
|
1799
|
+
writer.releaseLock();
|
|
1800
|
+
w.close().catch(() => {});
|
|
1801
|
+
resolve();
|
|
1802
|
+
});
|
|
1803
|
+
});
|
|
1804
|
+
buffer.write(tmp);
|
|
1805
|
+
buffer.flush();
|
|
1806
|
+
firstFlushed = true;
|
|
1807
|
+
if (completed) {
|
|
1808
|
+
dispose();
|
|
1809
|
+
writable.end();
|
|
1810
|
+
} else flushEnd();
|
|
1811
|
+
}, awaited);
|
|
1812
|
+
});
|
|
1813
|
+
}
|
|
1814
|
+
flush();
|
|
1815
|
+
return p;
|
|
1816
|
+
};
|
|
1817
|
+
return {
|
|
1818
|
+
then(onFulfilled, onRejected) {
|
|
1819
|
+
const freezeHead = () => {
|
|
1820
|
+
if (requestEvent && requestEvent.response) commitResponseStub(requestEvent.response);
|
|
1821
|
+
};
|
|
1822
|
+
const p = new Promise(resolve => {
|
|
1823
|
+
function complete() {
|
|
1824
|
+
freezeHead();
|
|
1825
|
+
dispose();
|
|
1826
|
+
resolve(tmp);
|
|
1827
|
+
}
|
|
1828
|
+
if (onCompleteAll) {
|
|
1829
|
+
let ogComplete = onCompleteAll;
|
|
1830
|
+
onCompleteAll = options => {
|
|
1831
|
+
ogComplete(options);
|
|
1832
|
+
complete();
|
|
1833
|
+
};
|
|
1834
|
+
} else onCompleteAll = complete;
|
|
1835
|
+
function flush() {
|
|
1836
|
+
allSettled(blockingPromises).then(awaited => {
|
|
1837
|
+
scheduleFlush(() => {
|
|
1838
|
+
try {
|
|
1839
|
+
if (blockingPromises.size !== lastBlockingSize || !resolveRootHoles() || blockingPromises.size !== lastBlockingSize || !headShellReady(headRegistry, p => blockingPromises.add(p))) return flush();
|
|
1840
|
+
} catch (err) {
|
|
1841
|
+
failRender(err);
|
|
1842
|
+
return resolve(tmp);
|
|
1843
|
+
}
|
|
1844
|
+
queue(flushEnd);
|
|
1845
|
+
}, awaited);
|
|
1846
|
+
});
|
|
1847
|
+
}
|
|
1848
|
+
flush();
|
|
1849
|
+
});
|
|
1850
|
+
return p.then(onFulfilled, onRejected);
|
|
1851
|
+
},
|
|
1852
|
+
pipe(w) {
|
|
1853
|
+
claimConsumer("pipe");
|
|
1854
|
+
function flush() {
|
|
1855
|
+
allSettled(blockingPromises).then(awaited => {
|
|
1856
|
+
scheduleFlush(() => {
|
|
1857
|
+
if (dead) return;
|
|
1858
|
+
try {
|
|
1859
|
+
doShell();
|
|
1860
|
+
} catch (err) {
|
|
1861
|
+
failRender(err);
|
|
1862
|
+
try {
|
|
1863
|
+
w.end();
|
|
1864
|
+
} catch (_) {}
|
|
1865
|
+
return;
|
|
1866
|
+
}
|
|
1867
|
+
if (!shellCompleted) return flush();
|
|
1868
|
+
const sink = guardSink(w);
|
|
1869
|
+
buffer = writable = coalesceWrites(sink.write, sink.end);
|
|
1870
|
+
buffer.write(tmp);
|
|
1871
|
+
buffer.flush();
|
|
1872
|
+
firstFlushed = true;
|
|
1873
|
+
if (completed) {
|
|
1874
|
+
dispose();
|
|
1875
|
+
writable.end();
|
|
1876
|
+
} else flushEnd();
|
|
1877
|
+
}, awaited);
|
|
1878
|
+
});
|
|
1879
|
+
}
|
|
1880
|
+
flush();
|
|
1881
|
+
},
|
|
1882
|
+
pipeTo(w) {
|
|
1883
|
+
claimConsumer("pipeTo");
|
|
1884
|
+
return pipeToImpl(w);
|
|
1885
|
+
},
|
|
1886
|
+
get readable() {
|
|
1887
|
+
claimConsumer("readable");
|
|
1888
|
+
if (!cachedReadable) {
|
|
1889
|
+
const t = new TransformStream();
|
|
1890
|
+
pipeToImpl(t.writable);
|
|
1891
|
+
cachedReadable = t.readable;
|
|
1892
|
+
}
|
|
1893
|
+
return cachedReadable;
|
|
1894
|
+
}
|
|
1895
|
+
};
|
|
1896
|
+
}
|
|
1897
|
+
function buildAsyncWrap(err, node) {
|
|
1898
|
+
const p = solidJs.ssrHandleError(err);
|
|
1899
|
+
if (!p) return null;
|
|
1900
|
+
if (node.$rw) return {
|
|
1901
|
+
fn: node,
|
|
1902
|
+
p
|
|
1903
|
+
};
|
|
1904
|
+
const owner = solidJs.getOwner();
|
|
1905
|
+
const live = solidJs.sharedConfig.context && solidJs.sharedConfig.context.liveHoles;
|
|
1906
|
+
const suppress = node.$lhSuppress || live && (live.suppressed || live.sweeping);
|
|
1907
|
+
if (!owner) {
|
|
1908
|
+
if (suppress) node.$lhSuppress = true;
|
|
1909
|
+
return {
|
|
1910
|
+
fn: node,
|
|
1911
|
+
p
|
|
1912
|
+
};
|
|
1913
|
+
}
|
|
1914
|
+
const fn = () => solidJs.runWithOwner(owner, node);
|
|
1915
|
+
fn.$rw = true;
|
|
1916
|
+
if (suppress) fn.$lhSuppress = true;
|
|
1917
|
+
if (node.$lhSkip) fn.$lhSkip = true;
|
|
1918
|
+
if (node.$lhBinding) fn.$lhBinding = node.$lhBinding;
|
|
1919
|
+
return {
|
|
1920
|
+
fn,
|
|
1921
|
+
p
|
|
1922
|
+
};
|
|
1923
|
+
}
|
|
1924
|
+
function ssrFirstGroupHit(hole) {
|
|
1925
|
+
try {
|
|
1926
|
+
return hole();
|
|
1927
|
+
} catch (err) {
|
|
1928
|
+
return buildAsyncWrap(err, hole);
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
function tryResolveFunctionHole(hole) {
|
|
1932
|
+
let value;
|
|
1933
|
+
try {
|
|
1934
|
+
value = hole();
|
|
1935
|
+
} catch (err) {
|
|
1936
|
+
return buildAsyncWrap(err, hole) || "";
|
|
1937
|
+
}
|
|
1938
|
+
const t = typeof value;
|
|
1939
|
+
if (t === "string") return value;
|
|
1940
|
+
if (t === "number") return "" + value;
|
|
1941
|
+
if (value == null || t === "boolean") return "";
|
|
1942
|
+
return tryResolveString(value);
|
|
1943
|
+
}
|
|
1944
|
+
function mergeTemplateInto(result, node) {
|
|
1945
|
+
result.t[result.t.length - 1] += node.t[0];
|
|
1946
|
+
if (node.t.length > 1) {
|
|
1947
|
+
result.t.push(...node.t.slice(1));
|
|
1948
|
+
result.h.push(...node.h);
|
|
1949
|
+
result.p.push(...node.p);
|
|
1950
|
+
}
|
|
1951
|
+
}
|
|
1952
|
+
function appendResolvedNode(result, node) {
|
|
1953
|
+
if (node.fn !== undefined) {
|
|
1954
|
+
result.h.push(node.fn);
|
|
1955
|
+
result.p.push(node.p);
|
|
1956
|
+
result.t.push("");
|
|
1957
|
+
} else if (node.merge !== undefined) mergeTemplateInto(result, node.merge);else resolveSSRNode(node.bail, result);
|
|
1958
|
+
}
|
|
1959
|
+
let _lastGroupFn = null;
|
|
1960
|
+
let _lastGroupArr = null;
|
|
1961
|
+
let _lastGroupErr = null;
|
|
1962
|
+
function ssrGroupSlot(fn, idx) {
|
|
1963
|
+
return () => {
|
|
1964
|
+
if (idx > 0 && _lastGroupFn === fn) {
|
|
1965
|
+
if (_lastGroupArr !== null) return _lastGroupArr[idx];
|
|
1966
|
+
throw _lastGroupErr;
|
|
1967
|
+
}
|
|
1968
|
+
_lastGroupFn = fn;
|
|
1969
|
+
_lastGroupArr = null;
|
|
1970
|
+
_lastGroupErr = null;
|
|
1971
|
+
try {
|
|
1972
|
+
_lastGroupArr = fn();
|
|
1973
|
+
return _lastGroupArr[idx];
|
|
1974
|
+
} catch (err) {
|
|
1975
|
+
_lastGroupErr = err;
|
|
1976
|
+
throw err;
|
|
1977
|
+
}
|
|
1978
|
+
};
|
|
1979
|
+
}
|
|
1980
|
+
const holePositionCache = new WeakMap();
|
|
1981
|
+
function holeContentPositions(t) {
|
|
1982
|
+
let cached = holePositionCache.get(t);
|
|
1983
|
+
if (cached) return cached;
|
|
1984
|
+
const pos = [];
|
|
1985
|
+
const openOff = [];
|
|
1986
|
+
const closeOff = [];
|
|
1987
|
+
let inTag = false;
|
|
1988
|
+
let quote = "";
|
|
1989
|
+
let curOpen = null;
|
|
1990
|
+
let scanningName = false;
|
|
1991
|
+
for (let i = 0; i < t.length; i++) {
|
|
1992
|
+
const seg = t[i];
|
|
1993
|
+
let close = -1;
|
|
1994
|
+
const openAtStart = inTag;
|
|
1995
|
+
let reopened = false;
|
|
1996
|
+
for (let j = 0; j < seg.length; j++) {
|
|
1997
|
+
const ch = seg[j];
|
|
1998
|
+
if (quote) {
|
|
1999
|
+
if (ch === quote) quote = "";
|
|
2000
|
+
} else if (inTag) {
|
|
2001
|
+
if (scanningName && (ch === " " || ch === "\t" || ch === "\n" || ch === ">" || ch === "/")) {
|
|
2002
|
+
scanningName = false;
|
|
2003
|
+
curOpen = {
|
|
2004
|
+
seg: i,
|
|
2005
|
+
off: j
|
|
2006
|
+
};
|
|
2007
|
+
}
|
|
2008
|
+
if (ch === '"' || ch === "'") quote = ch;else if (ch === ">") {
|
|
2009
|
+
inTag = false;
|
|
2010
|
+
if (openAtStart && !reopened && close === -1) close = j;
|
|
2011
|
+
curOpen = null;
|
|
2012
|
+
}
|
|
2013
|
+
} else if (ch === "<") {
|
|
2014
|
+
inTag = true;
|
|
2015
|
+
scanningName = true;
|
|
2016
|
+
reopened = true;
|
|
2017
|
+
curOpen = null;
|
|
2018
|
+
}
|
|
2019
|
+
}
|
|
2020
|
+
if (inTag && scanningName) {
|
|
2021
|
+
scanningName = false;
|
|
2022
|
+
curOpen = {
|
|
2023
|
+
seg: i,
|
|
2024
|
+
off: seg.length
|
|
2025
|
+
};
|
|
2026
|
+
}
|
|
2027
|
+
closeOff.push(close);
|
|
2028
|
+
openOff.push(inTag && curOpen && curOpen.seg === i ? curOpen.off : -1);
|
|
2029
|
+
if (i < t.length - 1) pos.push(!inTag);
|
|
2030
|
+
}
|
|
2031
|
+
cached = {
|
|
2032
|
+
pos,
|
|
2033
|
+
openOff,
|
|
2034
|
+
closeOff
|
|
2035
|
+
};
|
|
2036
|
+
holePositionCache.set(t, cached);
|
|
2037
|
+
return cached;
|
|
2038
|
+
}
|
|
2039
|
+
function createLiveHoles(sink, scoped) {
|
|
2040
|
+
let nextId = 0;
|
|
2041
|
+
const stamp = typeof solidJs.creationStamp === "function" ? solidJs.creationStamp : () => 0;
|
|
2042
|
+
const inScope = scoped && typeof solidJs.inServerComponentScope === "function" ? solidJs.inServerComponentScope : null;
|
|
2043
|
+
const stripMarkers = html => html.replace(/<!--lh:\/?\d+-->/g, "");
|
|
2044
|
+
const swept = (owner, ctx, fn) => {
|
|
2045
|
+
const prev = solidJs.sharedConfig.context;
|
|
2046
|
+
solidJs.sharedConfig.context = ctx;
|
|
2047
|
+
try {
|
|
2048
|
+
return owner ? solidJs.runWithOwner(owner, fn) : fn();
|
|
2049
|
+
} finally {
|
|
2050
|
+
solidJs.sharedConfig.context = prev;
|
|
2051
|
+
}
|
|
2052
|
+
};
|
|
2053
|
+
function resolveHoleValue(hole) {
|
|
2054
|
+
const result = {
|
|
2055
|
+
t: [""],
|
|
2056
|
+
h: [],
|
|
2057
|
+
p: []
|
|
2058
|
+
};
|
|
2059
|
+
try {
|
|
2060
|
+
resolveSSRNode(hole(), result);
|
|
2061
|
+
} catch (err) {
|
|
2062
|
+
const wrap = buildAsyncWrap(err, hole);
|
|
2063
|
+
if (!wrap) throw err;
|
|
2064
|
+
result.h.push(wrap.fn);
|
|
2065
|
+
result.p.push(wrap.p);
|
|
2066
|
+
result.t.push("");
|
|
2067
|
+
}
|
|
2068
|
+
return result;
|
|
2069
|
+
}
|
|
2070
|
+
function closeChildren(b) {
|
|
2071
|
+
for (const c of b.children) {
|
|
2072
|
+
c.closed = true;
|
|
2073
|
+
if (c.key) sink.closeBinding(c.key);
|
|
2074
|
+
closeChildren(c);
|
|
2075
|
+
}
|
|
2076
|
+
b.children.length = 0;
|
|
2077
|
+
}
|
|
2078
|
+
const engine = {
|
|
2079
|
+
suppressed: 0,
|
|
2080
|
+
sweeping: false,
|
|
2081
|
+
parent: null,
|
|
2082
|
+
recordStamp: 0,
|
|
2083
|
+
gateHit: false,
|
|
2084
|
+
content(hole) {
|
|
2085
|
+
if (hole.$lhSuppress) {
|
|
2086
|
+
const r = {
|
|
2087
|
+
t: [""],
|
|
2088
|
+
h: [],
|
|
2089
|
+
p: []
|
|
2090
|
+
};
|
|
2091
|
+
engine.suppressed++;
|
|
2092
|
+
try {
|
|
2093
|
+
try {
|
|
2094
|
+
resolveSSRNode(hole(), r);
|
|
2095
|
+
} catch (err) {
|
|
2096
|
+
const wrap = buildAsyncWrap(err, hole);
|
|
2097
|
+
if (wrap) {
|
|
2098
|
+
r.h.push(wrap.fn);
|
|
2099
|
+
r.p.push(wrap.p);
|
|
2100
|
+
r.t.push("");
|
|
2101
|
+
}
|
|
2102
|
+
}
|
|
2103
|
+
} finally {
|
|
2104
|
+
engine.suppressed--;
|
|
2105
|
+
}
|
|
2106
|
+
const b = hole.$lhBinding;
|
|
2107
|
+
if (b && !b.closed && !r.h.length && !engine.sweeping) {
|
|
2108
|
+
b.last = stripMarkers(r.t[0]);
|
|
2109
|
+
}
|
|
2110
|
+
return r.h.length ? r : r.t[0];
|
|
2111
|
+
}
|
|
2112
|
+
if (engine.suppressed || engine.sweeping) return null;
|
|
2113
|
+
if (hole.$lhSkip) return null;
|
|
2114
|
+
if (inScope && !inScope()) return null;
|
|
2115
|
+
const recordsBefore = engine.recordStamp;
|
|
2116
|
+
const ownersBefore = stamp();
|
|
2117
|
+
const owner = solidJs.getOwner();
|
|
2118
|
+
const holeCtx = solidJs.sharedConfig.context;
|
|
2119
|
+
const b = {
|
|
2120
|
+
key: null,
|
|
2121
|
+
children: [],
|
|
2122
|
+
last: null,
|
|
2123
|
+
closed: false,
|
|
2124
|
+
sweep() {
|
|
2125
|
+
if (b.closed) return;
|
|
2126
|
+
const prevSweeping = engine.sweeping;
|
|
2127
|
+
engine.sweeping = true;
|
|
2128
|
+
engine.gateHit = false;
|
|
2129
|
+
const sweepOwnersBefore = stamp();
|
|
2130
|
+
let res;
|
|
2131
|
+
try {
|
|
2132
|
+
res = swept(owner, holeCtx, () => resolveHoleValue(hole));
|
|
2133
|
+
} catch (err) {
|
|
2134
|
+
b.closed = true;
|
|
2135
|
+
sink.closeBinding(b.key);
|
|
2136
|
+
sink.error(b.key, String(err && err.message || err));
|
|
2137
|
+
return;
|
|
2138
|
+
} finally {
|
|
2139
|
+
engine.sweeping = prevSweeping;
|
|
2140
|
+
}
|
|
2141
|
+
if (engine.gateHit || stamp() !== sweepOwnersBefore) {
|
|
2142
|
+
b.closed = true;
|
|
2143
|
+
sink.closeBinding(b.key);
|
|
2144
|
+
return;
|
|
2145
|
+
}
|
|
2146
|
+
if (res.h.length) return;
|
|
2147
|
+
const html = res.t[0];
|
|
2148
|
+
if (b.last === null || html === b.last) return;
|
|
2149
|
+
b.last = html;
|
|
2150
|
+
closeChildren(b);
|
|
2151
|
+
sink.hole(b.key, html);
|
|
2152
|
+
}
|
|
2153
|
+
};
|
|
2154
|
+
if (engine.parent) engine.parent.children.push(b);
|
|
2155
|
+
const prevParent = engine.parent;
|
|
2156
|
+
engine.parent = b;
|
|
2157
|
+
let value;
|
|
2158
|
+
let escalated = null;
|
|
2159
|
+
try {
|
|
2160
|
+
value = hole();
|
|
2161
|
+
} catch (err) {
|
|
2162
|
+
const wrap = buildAsyncWrap(err, hole);
|
|
2163
|
+
if (!wrap) {
|
|
2164
|
+
engine.parent = prevParent;
|
|
2165
|
+
closeChildren(b);
|
|
2166
|
+
return "";
|
|
2167
|
+
}
|
|
2168
|
+
escalated = wrap;
|
|
2169
|
+
}
|
|
2170
|
+
if (!escalated && (typeof value === "function" && value.$lhSkip || value !== null && typeof value === "object" && value.$slot)) {
|
|
2171
|
+
engine.parent = prevParent;
|
|
2172
|
+
const r = {
|
|
2173
|
+
t: [""],
|
|
2174
|
+
h: [],
|
|
2175
|
+
p: []
|
|
2176
|
+
};
|
|
2177
|
+
engine.suppressed++;
|
|
2178
|
+
try {
|
|
2179
|
+
resolveSSRNode(value, r);
|
|
2180
|
+
} finally {
|
|
2181
|
+
engine.suppressed--;
|
|
2182
|
+
}
|
|
2183
|
+
return r.h.length ? r : r.t[0];
|
|
2184
|
+
}
|
|
2185
|
+
let res;
|
|
2186
|
+
if (escalated) {
|
|
2187
|
+
closeChildren(b);
|
|
2188
|
+
escalated.fn.$lhSuppress = true;
|
|
2189
|
+
escalated.fn.$lhBinding = b;
|
|
2190
|
+
res = {
|
|
2191
|
+
t: ["", ""],
|
|
2192
|
+
h: [escalated.fn],
|
|
2193
|
+
p: [escalated.p]
|
|
2194
|
+
};
|
|
2195
|
+
} else {
|
|
2196
|
+
res = {
|
|
2197
|
+
t: [""],
|
|
2198
|
+
h: [],
|
|
2199
|
+
p: []
|
|
2200
|
+
};
|
|
2201
|
+
try {
|
|
2202
|
+
resolveSSRNode(value, res);
|
|
2203
|
+
} catch (_) {
|
|
2204
|
+
engine.parent = prevParent;
|
|
2205
|
+
closeChildren(b);
|
|
2206
|
+
return "";
|
|
2207
|
+
}
|
|
2208
|
+
}
|
|
2209
|
+
engine.parent = prevParent;
|
|
2210
|
+
if (engine.recordStamp !== recordsBefore || stamp() !== ownersBefore) {
|
|
2211
|
+
return res.h.length ? res : res.t[0];
|
|
2212
|
+
}
|
|
2213
|
+
const id = nextId++;
|
|
2214
|
+
const key = b.key = "lh:" + id;
|
|
2215
|
+
const open = `<!--lh:${id}-->`;
|
|
2216
|
+
const close = `<!--lh:/${id}-->`;
|
|
2217
|
+
if (!res.h.length) {
|
|
2218
|
+
b.last = stripMarkers(res.t[0]);
|
|
2219
|
+
sink.openBinding(key, b);
|
|
2220
|
+
return open + res.t[0] + close;
|
|
2221
|
+
}
|
|
2222
|
+
const t = res.t.slice();
|
|
2223
|
+
t[0] = open + t[0];
|
|
2224
|
+
t[t.length - 1] += close;
|
|
2225
|
+
sink.openBinding(key, b);
|
|
2226
|
+
return {
|
|
2227
|
+
t,
|
|
2228
|
+
h: res.h,
|
|
2229
|
+
p: res.p
|
|
2230
|
+
};
|
|
2231
|
+
},
|
|
2232
|
+
mint() {
|
|
2233
|
+
return nextId++;
|
|
2234
|
+
},
|
|
2235
|
+
active() {
|
|
2236
|
+
return !inScope || inScope();
|
|
2237
|
+
},
|
|
2238
|
+
attr(cap) {
|
|
2239
|
+
const owner = solidJs.getOwner();
|
|
2240
|
+
const holeCtx = solidJs.sharedConfig.context;
|
|
2241
|
+
const b = {
|
|
2242
|
+
key: "lha:" + cap.id,
|
|
2243
|
+
children: [],
|
|
2244
|
+
last: cap.base,
|
|
2245
|
+
closed: false,
|
|
2246
|
+
sweep() {
|
|
2247
|
+
if (b.closed) return;
|
|
2248
|
+
const prevSweeping = engine.sweeping;
|
|
2249
|
+
engine.sweeping = true;
|
|
2250
|
+
engine.gateHit = false;
|
|
2251
|
+
const sweepOwnersBefore = stamp();
|
|
2252
|
+
let html = "";
|
|
2253
|
+
try {
|
|
2254
|
+
let group = null;
|
|
2255
|
+
let groupVal = null;
|
|
2256
|
+
const run = () => {
|
|
2257
|
+
for (const part of cap.parts) {
|
|
2258
|
+
if (typeof part === "string") {
|
|
2259
|
+
html += part;
|
|
2260
|
+
continue;
|
|
2261
|
+
}
|
|
2262
|
+
let v;
|
|
2263
|
+
if (part.g) {
|
|
2264
|
+
if (group !== part.g) {
|
|
2265
|
+
group = part.g;
|
|
2266
|
+
groupVal = part.g();
|
|
2267
|
+
}
|
|
2268
|
+
v = groupVal[part.i];
|
|
2269
|
+
} else {
|
|
2270
|
+
v = part.f();
|
|
2271
|
+
}
|
|
2272
|
+
const vt = typeof v;
|
|
2273
|
+
if (vt === "string" || vt === "number") html += v;
|
|
2274
|
+
}
|
|
2275
|
+
};
|
|
2276
|
+
swept(owner, holeCtx, run);
|
|
2277
|
+
} catch (err) {
|
|
2278
|
+
if (solidJs.ssrHandleError(err, true)) return;
|
|
2279
|
+
b.closed = true;
|
|
2280
|
+
sink.closeBinding(b.key);
|
|
2281
|
+
sink.error("lha:" + cap.id, String(err && err.message || err));
|
|
2282
|
+
return;
|
|
2283
|
+
} finally {
|
|
2284
|
+
engine.sweeping = prevSweeping;
|
|
2285
|
+
}
|
|
2286
|
+
if (engine.gateHit || stamp() !== sweepOwnersBefore) {
|
|
2287
|
+
b.closed = true;
|
|
2288
|
+
sink.closeBinding(b.key);
|
|
2289
|
+
return;
|
|
2290
|
+
}
|
|
2291
|
+
if (html === b.last) return;
|
|
2292
|
+
const before = attrNames(b.last);
|
|
2293
|
+
const after = attrNames(html);
|
|
2294
|
+
const removed = before.filter(n => !after.includes(n));
|
|
2295
|
+
b.last = html;
|
|
2296
|
+
sink.attr(String(cap.id), html, removed);
|
|
2297
|
+
}
|
|
2298
|
+
};
|
|
2299
|
+
sink.openBinding(b.key, b);
|
|
2300
|
+
}
|
|
2301
|
+
};
|
|
2302
|
+
return engine;
|
|
2303
|
+
}
|
|
2304
|
+
function attrNames(text) {
|
|
2305
|
+
const names = [];
|
|
2306
|
+
const re = /(?:^|\s)([^\s=/>"']+)(?:="[^"]*")?/g;
|
|
2307
|
+
let m;
|
|
2308
|
+
while (m = re.exec(text)) names.push(m[1]);
|
|
2309
|
+
return names;
|
|
2310
|
+
}
|
|
2311
|
+
function ssr(t) {
|
|
2312
|
+
const len = arguments.length;
|
|
2313
|
+
if (len === 1) return {
|
|
2314
|
+
t
|
|
2315
|
+
};
|
|
2316
|
+
let s = t[0];
|
|
2317
|
+
let result = null;
|
|
2318
|
+
let lastGroup = null;
|
|
2319
|
+
let lastGroupVal = null;
|
|
2320
|
+
let lastGroupIdx = 0;
|
|
2321
|
+
const live = solidJs.sharedConfig.context && solidJs.sharedConfig.context.liveHoles;
|
|
2322
|
+
const hp = live ? holeContentPositions(t) : null;
|
|
2323
|
+
let lastOpen = null;
|
|
2324
|
+
let cap = null;
|
|
2325
|
+
if (live && hp.openOff[0] >= 0) lastOpen = {
|
|
2326
|
+
r: null,
|
|
2327
|
+
seg: -1,
|
|
2328
|
+
off: hp.openOff[0]
|
|
2329
|
+
};
|
|
2330
|
+
const captureStart = () => {
|
|
2331
|
+
if (cap) return true;
|
|
2332
|
+
if (!lastOpen || live.suppressed || live.sweeping || !live.active()) return false;
|
|
2333
|
+
if (lastOpen.r !== result || result !== null && lastOpen.seg !== result.t.length - 1) {
|
|
2334
|
+
return false;
|
|
2335
|
+
}
|
|
2336
|
+
const id = live.mint();
|
|
2337
|
+
const inject = ` data-lha="${id}"`;
|
|
2338
|
+
let prefix;
|
|
2339
|
+
if (result === null) {
|
|
2340
|
+
s = s.slice(0, lastOpen.off) + inject + s.slice(lastOpen.off);
|
|
2341
|
+
prefix = s.slice(lastOpen.off + inject.length);
|
|
2342
|
+
} else {
|
|
2343
|
+
const seg = result.t[lastOpen.seg];
|
|
2344
|
+
result.t[lastOpen.seg] = seg.slice(0, lastOpen.off) + inject + seg.slice(lastOpen.off);
|
|
2345
|
+
prefix = result.t[lastOpen.seg].slice(lastOpen.off + inject.length);
|
|
2346
|
+
}
|
|
2347
|
+
cap = {
|
|
2348
|
+
id,
|
|
2349
|
+
parts: [prefix],
|
|
2350
|
+
base: prefix
|
|
2351
|
+
};
|
|
2352
|
+
return true;
|
|
2353
|
+
};
|
|
2354
|
+
for (let i = 1; i < len; i++) {
|
|
2355
|
+
const hole = arguments[i];
|
|
2356
|
+
const ht = typeof hole;
|
|
2357
|
+
if (ht === "string") {
|
|
2358
|
+
if (result === null) s += hole;else result.t[result.t.length - 1] += hole;
|
|
2359
|
+
if (cap) {
|
|
2360
|
+
cap.parts.push(hole);
|
|
2361
|
+
cap.base += hole;
|
|
2362
|
+
}
|
|
2363
|
+
} else if (ht === "number") {
|
|
2364
|
+
if (result === null) s += hole;else result.t[result.t.length - 1] += hole;
|
|
2365
|
+
if (cap) {
|
|
2366
|
+
cap.parts.push("" + hole);
|
|
2367
|
+
cap.base += hole;
|
|
2368
|
+
}
|
|
2369
|
+
} else if (hole == null || ht === "boolean") ; else if (ht === "function" && hole.$g) {
|
|
2370
|
+
let value;
|
|
2371
|
+
let hasValue = false;
|
|
2372
|
+
if (lastGroup !== hole) {
|
|
2373
|
+
const r = ssrFirstGroupHit(hole);
|
|
2374
|
+
if (r !== null) {
|
|
2375
|
+
lastGroup = hole;
|
|
2376
|
+
lastGroupVal = r;
|
|
2377
|
+
lastGroupIdx = 0;
|
|
2378
|
+
if (!Array.isArray(r) && result === null) {
|
|
2379
|
+
result = {
|
|
2380
|
+
t: [s],
|
|
2381
|
+
h: [],
|
|
2382
|
+
p: []
|
|
2383
|
+
};
|
|
2384
|
+
s = "";
|
|
2385
|
+
}
|
|
2386
|
+
}
|
|
2387
|
+
}
|
|
2388
|
+
if (lastGroup === hole) {
|
|
2389
|
+
if (Array.isArray(lastGroupVal)) {
|
|
2390
|
+
value = lastGroupVal[lastGroupIdx++];
|
|
2391
|
+
hasValue = true;
|
|
2392
|
+
if (live && !hp.pos[i - 1] && captureStart()) {
|
|
2393
|
+
cap.parts.push({
|
|
2394
|
+
g: hole,
|
|
2395
|
+
i: lastGroupIdx - 1
|
|
2396
|
+
});
|
|
2397
|
+
}
|
|
2398
|
+
} else {
|
|
2399
|
+
cap = null;
|
|
2400
|
+
result.h.push(ssrGroupSlot(lastGroupVal.fn, lastGroupIdx++));
|
|
2401
|
+
result.p.push(lastGroupVal.p);
|
|
2402
|
+
result.t.push("");
|
|
2403
|
+
}
|
|
2404
|
+
}
|
|
2405
|
+
if (hasValue) {
|
|
2406
|
+
const vt = typeof value;
|
|
2407
|
+
if (vt === "string" || vt === "number") {
|
|
2408
|
+
if (result === null) s += value;else result.t[result.t.length - 1] += value;
|
|
2409
|
+
if (cap && !hp.pos[i - 1]) cap.base += value;
|
|
2410
|
+
} else if (value == null || vt === "boolean") ; else if (result !== null) {
|
|
2411
|
+
resolveSSRNode(value, result);
|
|
2412
|
+
} else {
|
|
2413
|
+
const rs = tryResolveString(value);
|
|
2414
|
+
if (typeof rs === "string") {
|
|
2415
|
+
s += rs;
|
|
2416
|
+
} else {
|
|
2417
|
+
result = {
|
|
2418
|
+
t: [s],
|
|
2419
|
+
h: [],
|
|
2420
|
+
p: []
|
|
2421
|
+
};
|
|
2422
|
+
s = "";
|
|
2423
|
+
if (rs.merge !== undefined) mergeTemplateInto(result, rs.merge);else resolveSSRNode(rs.bail, result);
|
|
2424
|
+
}
|
|
2425
|
+
}
|
|
2426
|
+
}
|
|
2427
|
+
} else if (ht === "function") {
|
|
2428
|
+
let liveNode = null;
|
|
2429
|
+
if (live && hp.pos[i - 1] && (liveNode = live.content(hole)) !== null) {
|
|
2430
|
+
if (typeof liveNode === "string") {
|
|
2431
|
+
if (result === null) s += liveNode;else result.t[result.t.length - 1] += liveNode;
|
|
2432
|
+
} else {
|
|
2433
|
+
if (result === null) {
|
|
2434
|
+
result = {
|
|
2435
|
+
t: [s],
|
|
2436
|
+
h: [],
|
|
2437
|
+
p: []
|
|
2438
|
+
};
|
|
2439
|
+
s = "";
|
|
2440
|
+
}
|
|
2441
|
+
resolveSSRNode(liveNode, result);
|
|
2442
|
+
}
|
|
2443
|
+
} else if (result !== null) {
|
|
2444
|
+
const inTag = live && !hp.pos[i - 1];
|
|
2445
|
+
const capturing = inTag && captureStart();
|
|
2446
|
+
const li = capturing ? result.t.length - 1 : 0;
|
|
2447
|
+
const before = capturing ? result.t[li].length : 0;
|
|
2448
|
+
if (live) live.suppressed++;
|
|
2449
|
+
try {
|
|
2450
|
+
resolveSSRNode(hole, result);
|
|
2451
|
+
} finally {
|
|
2452
|
+
if (live) live.suppressed--;
|
|
2453
|
+
}
|
|
2454
|
+
if (capturing) {
|
|
2455
|
+
if (result.t.length - 1 === li) {
|
|
2456
|
+
cap.base += result.t[li].slice(before);
|
|
2457
|
+
cap.parts.push({
|
|
2458
|
+
f: hole
|
|
2459
|
+
});
|
|
2460
|
+
} else {
|
|
2461
|
+
cap = null;
|
|
2462
|
+
}
|
|
2463
|
+
}
|
|
2464
|
+
} else {
|
|
2465
|
+
const capturing = live && !hp.pos[i - 1] && captureStart();
|
|
2466
|
+
const r = tryResolveFunctionHole(hole);
|
|
2467
|
+
if (typeof r === "string") {
|
|
2468
|
+
s += r;
|
|
2469
|
+
if (capturing) {
|
|
2470
|
+
cap.base += r;
|
|
2471
|
+
cap.parts.push({
|
|
2472
|
+
f: hole
|
|
2473
|
+
});
|
|
2474
|
+
}
|
|
2475
|
+
} else {
|
|
2476
|
+
if (capturing) cap = null;
|
|
2477
|
+
result = {
|
|
2478
|
+
t: [s],
|
|
2479
|
+
h: [],
|
|
2480
|
+
p: []
|
|
2481
|
+
};
|
|
2482
|
+
s = "";
|
|
2483
|
+
appendResolvedNode(result, r);
|
|
2484
|
+
}
|
|
2485
|
+
}
|
|
2486
|
+
} else if (result !== null) {
|
|
2487
|
+
resolveSSRNode(hole, result);
|
|
2488
|
+
} else {
|
|
2489
|
+
const r = tryResolveString(hole);
|
|
2490
|
+
if (typeof r === "string") {
|
|
2491
|
+
s += r;
|
|
2492
|
+
} else {
|
|
2493
|
+
result = {
|
|
2494
|
+
t: [s],
|
|
2495
|
+
h: [],
|
|
2496
|
+
p: []
|
|
2497
|
+
};
|
|
2498
|
+
s = "";
|
|
2499
|
+
appendResolvedNode(result, r);
|
|
2500
|
+
}
|
|
2501
|
+
}
|
|
2502
|
+
const next = t[i];
|
|
2503
|
+
if (live) {
|
|
2504
|
+
if (cap) {
|
|
2505
|
+
const co = hp.closeOff[i];
|
|
2506
|
+
if (co >= 0) {
|
|
2507
|
+
const tail = next.slice(0, co);
|
|
2508
|
+
cap.parts.push(tail);
|
|
2509
|
+
cap.base += tail;
|
|
2510
|
+
live.attr(cap);
|
|
2511
|
+
cap = null;
|
|
2512
|
+
} else {
|
|
2513
|
+
cap.parts.push(next);
|
|
2514
|
+
cap.base += next;
|
|
2515
|
+
}
|
|
2516
|
+
}
|
|
2517
|
+
if (hp.openOff[i] >= 0) {
|
|
2518
|
+
lastOpen = result === null ? {
|
|
2519
|
+
r: null,
|
|
2520
|
+
seg: -1,
|
|
2521
|
+
off: s.length + hp.openOff[i]
|
|
2522
|
+
} : {
|
|
2523
|
+
r: result,
|
|
2524
|
+
seg: result.t.length - 1,
|
|
2525
|
+
off: result.t[result.t.length - 1].length + hp.openOff[i]
|
|
2526
|
+
};
|
|
2527
|
+
}
|
|
2528
|
+
}
|
|
2529
|
+
if (result === null) s += next;else result.t[result.t.length - 1] += next;
|
|
2530
|
+
}
|
|
2531
|
+
if (result === null) return {
|
|
2532
|
+
t: s
|
|
2533
|
+
};
|
|
2534
|
+
return result;
|
|
2535
|
+
}
|
|
2536
|
+
const CLAIM_PROP = /*#__PURE__*/Symbol.for("solid.claim-prop");
|
|
2537
|
+
const CLAIMS_STREAM = 1;
|
|
2538
|
+
const CLAIMS_DOCUMENT = 2;
|
|
2539
|
+
function resolveSSRSelectValues(html) {
|
|
2540
|
+
return html;
|
|
2541
|
+
}
|
|
2542
|
+
function escape(s, attr) {
|
|
2543
|
+
const t = typeof s;
|
|
2544
|
+
if (t !== "string") {
|
|
2545
|
+
if (!attr && Array.isArray(s)) {
|
|
2546
|
+
const joined = tryJoinPlainSSRArray(s);
|
|
2547
|
+
if (joined !== undefined) return joined;
|
|
2548
|
+
s = s.slice();
|
|
2549
|
+
for (let i = 0; i < s.length; i++) s[i] = escape(s[i]);
|
|
2550
|
+
return s;
|
|
2551
|
+
}
|
|
2552
|
+
if (attr) {
|
|
2553
|
+
if (s == null || t === "boolean" || t === "number") return s;
|
|
2554
|
+
return escape(String(s), attr);
|
|
2555
|
+
}
|
|
2556
|
+
return s;
|
|
2557
|
+
}
|
|
2558
|
+
const i = s.search(attr ? ESCAPE_ATTR : ESCAPE_CONTENT);
|
|
2559
|
+
if (i < 0) return s;
|
|
2560
|
+
return escapeSlow(s, attr, i);
|
|
2561
|
+
}
|
|
2562
|
+
const ESCAPE_CONTENT = /[&<]/;
|
|
2563
|
+
const ESCAPE_ATTR = /[&"<]/;
|
|
2564
|
+
function escapeSlow(s, attr, start) {
|
|
2565
|
+
if (attr) return escapeAttrSlow(s, start);
|
|
2566
|
+
const c0 = s.charCodeAt(start);
|
|
2567
|
+
let iDelim = c0 === 60 ? start : s.indexOf("<", start);
|
|
2568
|
+
let iAmp = c0 === 38 ? start : s.indexOf("&", start);
|
|
2569
|
+
let left = 0,
|
|
2570
|
+
out = "";
|
|
2571
|
+
while (iDelim >= 0 && iAmp >= 0) {
|
|
2572
|
+
if (iDelim < iAmp) {
|
|
2573
|
+
if (left < iDelim) out += s.substring(left, iDelim);
|
|
2574
|
+
out += "<";
|
|
2575
|
+
left = iDelim + 1;
|
|
2576
|
+
iDelim = s.indexOf("<", left);
|
|
2577
|
+
} else {
|
|
2578
|
+
if (left < iAmp) out += s.substring(left, iAmp);
|
|
2579
|
+
out += "&";
|
|
2580
|
+
left = iAmp + 1;
|
|
2581
|
+
iAmp = s.indexOf("&", left);
|
|
2582
|
+
}
|
|
2583
|
+
}
|
|
2584
|
+
if (iDelim >= 0) {
|
|
2585
|
+
do {
|
|
2586
|
+
if (left < iDelim) out += s.substring(left, iDelim);
|
|
2587
|
+
out += "<";
|
|
2588
|
+
left = iDelim + 1;
|
|
2589
|
+
iDelim = s.indexOf("<", left);
|
|
2590
|
+
} while (iDelim >= 0);
|
|
2591
|
+
} else while (iAmp >= 0) {
|
|
2592
|
+
if (left < iAmp) out += s.substring(left, iAmp);
|
|
2593
|
+
out += "&";
|
|
2594
|
+
left = iAmp + 1;
|
|
2595
|
+
iAmp = s.indexOf("&", left);
|
|
2596
|
+
}
|
|
2597
|
+
return left < s.length ? out + s.substring(left) : out;
|
|
2598
|
+
}
|
|
2599
|
+
function escapeAttrSlow(s, start) {
|
|
2600
|
+
const c0 = s.charCodeAt(start);
|
|
2601
|
+
let iQuot = c0 === 34 ? start : s.indexOf('"', start);
|
|
2602
|
+
let iAmp = c0 === 38 ? start : s.indexOf("&", start);
|
|
2603
|
+
let iLt = c0 === 60 ? start : s.indexOf("<", start);
|
|
2604
|
+
let left = 0,
|
|
2605
|
+
out = "";
|
|
2606
|
+
for (;;) {
|
|
2607
|
+
let i = -1,
|
|
2608
|
+
ent;
|
|
2609
|
+
if (iQuot >= 0) {
|
|
2610
|
+
i = iQuot;
|
|
2611
|
+
ent = """;
|
|
2612
|
+
}
|
|
2613
|
+
if (iAmp >= 0 && (i < 0 || iAmp < i)) {
|
|
2614
|
+
i = iAmp;
|
|
2615
|
+
ent = "&";
|
|
2616
|
+
}
|
|
2617
|
+
if (iLt >= 0 && (i < 0 || iLt < i)) {
|
|
2618
|
+
i = iLt;
|
|
2619
|
+
ent = "<";
|
|
2620
|
+
}
|
|
2621
|
+
if (i < 0) break;
|
|
2622
|
+
if (left < i) out += s.substring(left, i);
|
|
2623
|
+
out += ent;
|
|
2624
|
+
left = i + 1;
|
|
2625
|
+
if (i === iQuot) iQuot = s.indexOf('"', left);else if (i === iAmp) iAmp = s.indexOf("&", left);else iLt = s.indexOf("<", left);
|
|
2626
|
+
}
|
|
2627
|
+
return left < s.length ? out + s.substring(left) : out;
|
|
2628
|
+
}
|
|
2629
|
+
function tryJoinPlainSSRArray(nodes) {
|
|
2630
|
+
if (nodes.length === 0) return undefined;
|
|
2631
|
+
let out = "";
|
|
2632
|
+
for (let i = 0, len = nodes.length; i < len; i++) {
|
|
2633
|
+
const node = nodes[i];
|
|
2634
|
+
if (node == null || typeof node !== "object" || node.h || typeof node.t !== "string") {
|
|
2635
|
+
return undefined;
|
|
2636
|
+
}
|
|
2637
|
+
out += node.t;
|
|
2638
|
+
}
|
|
2639
|
+
return out;
|
|
2640
|
+
}
|
|
2641
|
+
function queue(fn) {
|
|
2642
|
+
return Promise.resolve().then(fn);
|
|
2643
|
+
}
|
|
2644
|
+
const deferFlush = typeof setImmediate === "function" ? setImmediate : fn => setTimeout(fn, 0);
|
|
2645
|
+
function allSettled(promises) {
|
|
2646
|
+
let size = promises.size;
|
|
2647
|
+
return Promise.allSettled(promises).then(() => {
|
|
2648
|
+
if (promises.size !== size) return allSettled(promises);
|
|
2649
|
+
return size;
|
|
2650
|
+
});
|
|
2651
|
+
}
|
|
2652
|
+
function assembleDocument(html, emittedAssets, preloadLinks, inlineStyles, scripts, nonce, headTags, onHead) {
|
|
2653
|
+
const scriptTag = scripts ? `<script${nonceAttr(nonce, "script")}>${scripts}</script>` : "";
|
|
2654
|
+
const title = headTags ? headTags.title : null;
|
|
2655
|
+
let headTagsHtml = headTags ? headTags.html : "";
|
|
2656
|
+
const headPrelude = headTags ? headTags.prelude : "";
|
|
2657
|
+
if (!onHead && title == null && !headTagsHtml && !headPrelude && !(emittedAssets && emittedAssets.size) && !preloadLinks && !(inlineStyles && inlineStyles.size)) {
|
|
2658
|
+
if (!scriptTag) return html;
|
|
2659
|
+
const xs = html.indexOf("<!--xs-->");
|
|
2660
|
+
return xs === -1 ? html + scriptTag : html.slice(0, xs) + scriptTag + html.slice(xs);
|
|
2661
|
+
}
|
|
2662
|
+
if (headPrelude) {
|
|
2663
|
+
const open = html.match(/<head(?:\s[^>]*)?>/);
|
|
2664
|
+
if (open) {
|
|
2665
|
+
const at = open.index + open[0].length;
|
|
2666
|
+
html = html.slice(0, at) + headPrelude + html.slice(at);
|
|
2667
|
+
}
|
|
2668
|
+
}
|
|
2669
|
+
let headIdx = html.indexOf("</head>");
|
|
2670
|
+
if (headIdx === -1) {
|
|
2671
|
+
if (onHead) {
|
|
2672
|
+
let titleHtml = "";
|
|
2673
|
+
if (title != null) {
|
|
2674
|
+
titleHtml = headTags.noScripts ? `<title data-dh="title">${escape(title)}</title>` : `<script${nonceAttr(nonce, "script")}>(function(x,t){(t=document.querySelector("title"))?(t.hasAttribute("data-dh")||t.setAttribute("data-dhf",t.textContent),t.textContent=x):(document.title=x,t=document.querySelector("title"));t&&t.setAttribute("data-dh","title")})(${JSON.stringify(title).replace(/</g, "\\u003C")})</script>`;
|
|
2675
|
+
}
|
|
2676
|
+
onHead(headPrelude + headTagsHtml + titleHtml + renderHeadAssets(emittedAssets, preloadLinks, inlineStyles, nonce));
|
|
2677
|
+
}
|
|
2678
|
+
if (!scriptTag) return html;
|
|
2679
|
+
const xs = html.indexOf("<!--xs-->");
|
|
2680
|
+
return xs === -1 ? html + scriptTag : html.slice(0, xs) + scriptTag + html.slice(xs);
|
|
2681
|
+
}
|
|
2682
|
+
if (title != null) {
|
|
2683
|
+
const winner = escape(title);
|
|
2684
|
+
const open = html.match(/<head(?:\s[^>]*)?>/);
|
|
2685
|
+
const from = open ? open.index + open[0].length : 0;
|
|
2686
|
+
const m = /<title(\s[^>]*)?>([\s\S]*?)<\/title>/.exec(html.slice(from, headIdx));
|
|
2687
|
+
if (m) {
|
|
2688
|
+
const at = from + m.index;
|
|
2689
|
+
const stash = m[2].replace(/"/g, """);
|
|
2690
|
+
html = html.slice(0, at) + `<title${m[1] || ""} data-dh="title" data-dhf="${stash}">${winner}</title>` + html.slice(at + m[0].length);
|
|
2691
|
+
headIdx = html.indexOf("</head>");
|
|
2692
|
+
} else {
|
|
2693
|
+
headTagsHtml = `<title data-dh="title">${winner}</title>` + headTagsHtml;
|
|
2694
|
+
}
|
|
2695
|
+
}
|
|
2696
|
+
const head = headTagsHtml + renderHeadAssets(emittedAssets, preloadLinks, inlineStyles, nonce);
|
|
2697
|
+
if (!scriptTag) return html.slice(0, headIdx) + head + html.slice(headIdx);
|
|
2698
|
+
const xsIdx = html.indexOf("<!--xs-->");
|
|
2699
|
+
if (xsIdx === -1) return html.slice(0, headIdx) + head + html.slice(headIdx) + scriptTag;
|
|
2700
|
+
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);
|
|
2701
|
+
}
|
|
2702
|
+
function renderHeadAssets(emittedAssets, preloadLinks, inlineStyles, nonce) {
|
|
2703
|
+
let head = "";
|
|
2704
|
+
const styleAttr = nonceAttr(nonce, "style");
|
|
2705
|
+
const scriptAttr = nonceAttr(nonce, "script");
|
|
2706
|
+
if (emittedAssets && emittedAssets.size) {
|
|
2707
|
+
for (const url of emittedAssets) {
|
|
2708
|
+
head += isCssUrl(url) ? `<link rel="stylesheet" href="${url}"${styleAttr}>` : `<link rel="modulepreload" href="${url}"${scriptAttr}>`;
|
|
2709
|
+
}
|
|
2710
|
+
}
|
|
2711
|
+
if (preloadLinks) {
|
|
2712
|
+
for (const entry of preloadLinks) head += `<link${entry.attrHtml}>`;
|
|
2713
|
+
}
|
|
2714
|
+
if (inlineStyles && inlineStyles.size) {
|
|
2715
|
+
for (const entry of inlineStyles.values()) {
|
|
2716
|
+
if (entry.emitted) continue;
|
|
2717
|
+
entry.emitted = true;
|
|
2718
|
+
head += renderInlineStyle(entry, nonce);
|
|
2719
|
+
}
|
|
2720
|
+
}
|
|
2721
|
+
return head;
|
|
2722
|
+
}
|
|
2723
|
+
function serializeFragmentAssets(key, boundaryModules, context, name = key) {
|
|
2724
|
+
const map = boundaryModules.get(key);
|
|
2725
|
+
if (!map || !Object.keys(map).length) return;
|
|
2726
|
+
context.serialize(name + "_assets", {
|
|
2727
|
+
...map
|
|
2728
|
+
});
|
|
2729
|
+
}
|
|
2730
|
+
function propagateBoundaryStyles(childKey, parentKey, tracking) {
|
|
2731
|
+
const childStyles = tracking.getBoundaryStyles(childKey);
|
|
2732
|
+
if (!childStyles) return;
|
|
2733
|
+
let parentStyles = tracking.boundaryStyles.get(parentKey);
|
|
2734
|
+
if (!parentStyles) {
|
|
2735
|
+
parentStyles = new Set();
|
|
2736
|
+
tracking.boundaryStyles.set(parentKey, parentStyles);
|
|
2737
|
+
}
|
|
2738
|
+
for (const url of childStyles) {
|
|
2739
|
+
parentStyles.add(url);
|
|
2740
|
+
}
|
|
2741
|
+
}
|
|
2742
|
+
function collectStreamStyles(key, tracking, headStyles) {
|
|
2743
|
+
const styles = tracking.getBoundaryStyles(key);
|
|
2744
|
+
const links = [];
|
|
2745
|
+
const inline = [];
|
|
2746
|
+
if (!styles) return {
|
|
2747
|
+
links,
|
|
2748
|
+
inline
|
|
2749
|
+
};
|
|
2750
|
+
for (const entry of styles) {
|
|
2751
|
+
if (typeof entry === "string") {
|
|
2752
|
+
if (!headStyles || !headStyles.has(entry)) links.push(entry);
|
|
2753
|
+
} else if (entry.emitted) {
|
|
2754
|
+
continue;
|
|
2755
|
+
} else if (entry.attrHtml !== undefined) {
|
|
2756
|
+
entry.emitted = true;
|
|
2757
|
+
links.push(entry);
|
|
2758
|
+
} else {
|
|
2759
|
+
entry.emitted = true;
|
|
2760
|
+
inline.push(entry);
|
|
2761
|
+
}
|
|
2762
|
+
}
|
|
2763
|
+
return {
|
|
2764
|
+
links,
|
|
2765
|
+
inline
|
|
2766
|
+
};
|
|
2767
|
+
}
|
|
2768
|
+
function escapeStyleContent(content) {
|
|
2769
|
+
return content.replace(/<\/(style)/gi, "<\\/$1");
|
|
2770
|
+
}
|
|
2771
|
+
function renderInlineStyle(entry, nonce) {
|
|
2772
|
+
let attrs = "";
|
|
2773
|
+
let hasNonce = false;
|
|
2774
|
+
if (entry.attrs) {
|
|
2775
|
+
for (const name in entry.attrs) {
|
|
2776
|
+
if (name.length === 5 && asciiLowerCase(name) === "nonce") hasNonce = true;
|
|
2777
|
+
attrs += ` ${name}="${escape(String(entry.attrs[name]), true)}"`;
|
|
2778
|
+
}
|
|
2779
|
+
}
|
|
2780
|
+
const nonceHtml = hasNonce ? "" : nonceAttr(nonce, "style");
|
|
2781
|
+
return `<style${nonceHtml} data-asset="${escape(entry.id, true)}"${attrs}>${escapeStyleContent(entry.content)}</style>`;
|
|
2782
|
+
}
|
|
2783
|
+
function waitForFragments(registry, key) {
|
|
2784
|
+
for (const k of [...registry.keys()].reverse()) {
|
|
2785
|
+
if (key.startsWith(k)) return k;
|
|
2786
|
+
}
|
|
2787
|
+
return false;
|
|
2788
|
+
}
|
|
2789
|
+
function replacePlaceholder(html, key, value) {
|
|
2790
|
+
const marker = `<template id="pl-${key}">`;
|
|
2791
|
+
const close = `<!--pl-${key}-->`;
|
|
2792
|
+
const first = html.indexOf(marker);
|
|
2793
|
+
if (first === -1) return html;
|
|
2794
|
+
const last = html.indexOf(close, first + marker.length);
|
|
2795
|
+
return html.slice(0, first) + value + html.slice(last + close.length);
|
|
2796
|
+
}
|
|
2797
|
+
function tryResolveString(node) {
|
|
2798
|
+
const t = typeof node;
|
|
2799
|
+
if (t === "string") return node;
|
|
2800
|
+
if (t === "number") return "" + node;
|
|
2801
|
+
if (node == null || t === "boolean") return "";
|
|
2802
|
+
if (t === "object") {
|
|
2803
|
+
if (Array.isArray(node)) {
|
|
2804
|
+
const joined = tryJoinPlainSSRArray(node);
|
|
2805
|
+
if (joined !== undefined) return joined;
|
|
2806
|
+
let s = "";
|
|
2807
|
+
let prevNonObj = false;
|
|
2808
|
+
for (let i = 0, len = node.length; i < len; i++) {
|
|
2809
|
+
const item = node[i];
|
|
2810
|
+
const itemNonObj = item !== null && typeof item !== "object";
|
|
2811
|
+
if (prevNonObj && itemNonObj) s += "<!--!$-->";
|
|
2812
|
+
prevNonObj = itemNonObj;
|
|
2813
|
+
const r = tryResolveString(item);
|
|
2814
|
+
if (typeof r !== "string") return {
|
|
2815
|
+
bail: node
|
|
2816
|
+
};
|
|
2817
|
+
s += r;
|
|
2818
|
+
}
|
|
2819
|
+
return s;
|
|
2820
|
+
}
|
|
2821
|
+
if (node.h && node.h.length > 0) return {
|
|
2822
|
+
merge: node
|
|
2823
|
+
};
|
|
2824
|
+
if (node.t === undefined) {
|
|
2825
|
+
console.warn(`Unrecognized value. Skipped inserting`, node);
|
|
2826
|
+
return "";
|
|
2827
|
+
}
|
|
2828
|
+
return Array.isArray(node.t) ? node.t[0] : node.t;
|
|
2829
|
+
}
|
|
2830
|
+
if (t === "function") {
|
|
2831
|
+
let v;
|
|
2832
|
+
try {
|
|
2833
|
+
v = node();
|
|
2834
|
+
} catch (err) {
|
|
2835
|
+
return buildAsyncWrap(err, node) || "";
|
|
2836
|
+
}
|
|
2837
|
+
return tryResolveString(v);
|
|
2838
|
+
}
|
|
2839
|
+
return "";
|
|
2840
|
+
}
|
|
2841
|
+
function resolveSSRNode(node, result = {
|
|
2842
|
+
t: [""],
|
|
2843
|
+
h: [],
|
|
2844
|
+
p: []
|
|
2845
|
+
}, top) {
|
|
2846
|
+
const t = typeof node;
|
|
2847
|
+
if (t === "string" || t === "number") {
|
|
2848
|
+
result.t[result.t.length - 1] += node;
|
|
2849
|
+
} else if (node == null || t === "boolean") ; else if (Array.isArray(node)) {
|
|
2850
|
+
const slotLive = node.$slot && solidJs.sharedConfig.context && solidJs.sharedConfig.context.liveHoles;
|
|
2851
|
+
if (slotLive) slotLive.suppressed++;
|
|
2852
|
+
try {
|
|
2853
|
+
let prevNonObj = false;
|
|
2854
|
+
for (let i = 0, len = node.length; i < len; i++) {
|
|
2855
|
+
const item = node[i];
|
|
2856
|
+
const itemNonObj = item !== null && typeof item !== "object";
|
|
2857
|
+
if (!top && prevNonObj && itemNonObj) result.t[result.t.length - 1] += `<!--!$-->`;
|
|
2858
|
+
prevNonObj = itemNonObj;
|
|
2859
|
+
resolveSSRNode(item, result);
|
|
2860
|
+
}
|
|
2861
|
+
} finally {
|
|
2862
|
+
if (slotLive) slotLive.suppressed--;
|
|
2863
|
+
}
|
|
2864
|
+
} else if (t === "object") {
|
|
2865
|
+
if (node.h) {
|
|
2866
|
+
result.t[result.t.length - 1] += node.t[0];
|
|
2867
|
+
if (node.t.length > 1) {
|
|
2868
|
+
result.t.push(...node.t.slice(1));
|
|
2869
|
+
result.h.push(...node.h);
|
|
2870
|
+
result.p.push(...node.p);
|
|
2871
|
+
}
|
|
2872
|
+
} else if (node.t !== undefined) {
|
|
2873
|
+
result.t[result.t.length - 1] += node.t;
|
|
2874
|
+
} else console.warn(`Unrecognized value. Skipped inserting`, node);
|
|
2875
|
+
} else if (t === "function") {
|
|
2876
|
+
const live = solidJs.sharedConfig.context && solidJs.sharedConfig.context.liveHoles;
|
|
2877
|
+
let liveNode = null;
|
|
2878
|
+
if (live && (liveNode = live.content(node)) !== null) {
|
|
2879
|
+
if (typeof liveNode === "string") result.t[result.t.length - 1] += liveNode;else resolveSSRNode(liveNode, result);
|
|
2880
|
+
} else {
|
|
2881
|
+
try {
|
|
2882
|
+
resolveSSRNode(node(), result);
|
|
2883
|
+
} catch (err) {
|
|
2884
|
+
const wrap = buildAsyncWrap(err, node);
|
|
2885
|
+
if (wrap) {
|
|
2886
|
+
result.h.push(wrap.fn);
|
|
2887
|
+
result.p.push(wrap.p);
|
|
2888
|
+
result.t.push("");
|
|
2889
|
+
}
|
|
2890
|
+
}
|
|
2891
|
+
}
|
|
2892
|
+
}
|
|
2893
|
+
return result;
|
|
2894
|
+
}
|
|
2895
|
+
function resolveSSRSync(node) {
|
|
2896
|
+
const res = resolveSSRNode(node);
|
|
2897
|
+
if (!res.h.length) return res.t[0];
|
|
2898
|
+
throw new Error("This value cannot be rendered synchronously. Are you missing a boundary?");
|
|
2899
|
+
}
|
|
2900
|
+
const RequestContext = Symbol.for("solid.RequestContext");
|
|
2901
|
+
function peekRequestEvent() {
|
|
2902
|
+
const store = globalThis[RequestContext];
|
|
2903
|
+
return store ? store.getStore() : undefined;
|
|
2904
|
+
}
|
|
2905
|
+
function reportLostHeaderWrite(method, name) {
|
|
2906
|
+
const message = `Response header write dropped: headers.${method}(${JSON.stringify(String(name))}) ` + "ran after the response head was sent. Write headers before the shell flushes " + "(or before the handler returns).";
|
|
2907
|
+
throw new Error(message);
|
|
2908
|
+
}
|
|
2909
|
+
function commitResponseStub(stub, {
|
|
2910
|
+
allowLateLocation = false
|
|
2911
|
+
} = {}) {
|
|
2912
|
+
if (!stub || stub.committed) return stub;
|
|
2913
|
+
stub.committed = true;
|
|
2914
|
+
const headers = stub.headers;
|
|
2915
|
+
if (!headers || typeof headers.set !== "function") return stub;
|
|
2916
|
+
for (const method of ["set", "append", "delete"]) {
|
|
2917
|
+
const original = headers[method].bind(headers);
|
|
2918
|
+
headers[method] = function (name, ...rest) {
|
|
2919
|
+
if (allowLateLocation && method === "set" && String(name).toLowerCase() === "location") {
|
|
2920
|
+
return original(name, ...rest);
|
|
2921
|
+
}
|
|
2922
|
+
reportLostHeaderWrite(method, name);
|
|
2923
|
+
};
|
|
2924
|
+
}
|
|
2925
|
+
return stub;
|
|
2926
|
+
}
|
|
2927
|
+
/*#__PURE__*/new Set([ERROR_HEADER, BODY_FORMAT_HEADER, SINGLE_FLIGHT_HEADER, REVALIDATE_HEADER, REDIRECT_HEADER, "Location",
|
|
2928
|
+
...COMPOSED_BODY_FRAMING].map(header => header.toLowerCase()));
|
|
2929
|
+
|
|
2930
|
+
function scopeDeferredResult(value, scope) {
|
|
2931
|
+
const bound = bindDeferredBody(value, scope);
|
|
2932
|
+
if (bound !== value || value === null || typeof value !== "object") return bound;
|
|
2933
|
+
return scopeDeferredContents(value, scope);
|
|
2934
|
+
}
|
|
2935
|
+
class ScopeFrame {
|
|
2936
|
+
constructor(value, next, keys, descriptors) {
|
|
2937
|
+
this.value = value;
|
|
2938
|
+
this.next = next;
|
|
2939
|
+
this.keys = keys;
|
|
2940
|
+
this.descriptors = descriptors;
|
|
2941
|
+
this.i = 0;
|
|
2942
|
+
this.changed = false;
|
|
2943
|
+
}
|
|
2944
|
+
}
|
|
2945
|
+
function enterScopeCarrier(value, state) {
|
|
2946
|
+
if (value === null || typeof value !== "object" && typeof value !== "function") return value;
|
|
2947
|
+
if (state.seen.has(value)) {
|
|
2948
|
+
state.cyclic.add(value);
|
|
2949
|
+
return state.seen.get(value);
|
|
2950
|
+
}
|
|
2951
|
+
const bound = bindDeferredBody(value, state.scope);
|
|
2952
|
+
if (bound !== value) {
|
|
2953
|
+
state.seen.set(value, bound);
|
|
2954
|
+
return bound;
|
|
2955
|
+
}
|
|
2956
|
+
if (typeof value !== "object") return value;
|
|
2957
|
+
if (Array.isArray(value)) {
|
|
2958
|
+
if (Object.isFrozen(value)) {
|
|
2959
|
+
state.seen.set(value, value);
|
|
2960
|
+
return value;
|
|
2961
|
+
}
|
|
2962
|
+
const next = value.slice();
|
|
2963
|
+
state.seen.set(value, next);
|
|
2964
|
+
return new ScopeFrame(value, next, null, null);
|
|
2965
|
+
}
|
|
2966
|
+
const prototype = Object.getPrototypeOf(value);
|
|
2967
|
+
if (prototype !== Object.prototype && prototype !== null || Object.isFrozen(value)) {
|
|
2968
|
+
state.seen.set(value, value);
|
|
2969
|
+
return value;
|
|
2970
|
+
}
|
|
2971
|
+
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
2972
|
+
const next = Object.create(prototype, descriptors);
|
|
2973
|
+
state.seen.set(value, next);
|
|
2974
|
+
return new ScopeFrame(value, next, Object.keys(value), descriptors);
|
|
2975
|
+
}
|
|
2976
|
+
function scopeDeferredContents(root, scope) {
|
|
2977
|
+
const state = {
|
|
2978
|
+
seen: new Map(),
|
|
2979
|
+
cyclic: new Set(),
|
|
2980
|
+
scope
|
|
2981
|
+
};
|
|
2982
|
+
const entered = enterScopeCarrier(root, state);
|
|
2983
|
+
if (!(entered instanceof ScopeFrame)) return entered;
|
|
2984
|
+
const stack = [entered];
|
|
2985
|
+
let delivered = NOTHING;
|
|
2986
|
+
for (;;) {
|
|
2987
|
+
const top = stack[stack.length - 1];
|
|
2988
|
+
const length = top.keys ? top.keys.length : top.value.length;
|
|
2989
|
+
let pushed = null;
|
|
2990
|
+
while (top.i < length) {
|
|
2991
|
+
const i = top.i;
|
|
2992
|
+
let original;
|
|
2993
|
+
let writable = true;
|
|
2994
|
+
if (top.keys) {
|
|
2995
|
+
const descriptor = top.descriptors[top.keys[i]];
|
|
2996
|
+
writable = "value" in descriptor && descriptor.writable === true;
|
|
2997
|
+
original = writable ? descriptor.value : undefined;
|
|
2998
|
+
} else {
|
|
2999
|
+
original = top.value[i];
|
|
3000
|
+
}
|
|
3001
|
+
if (!writable) {
|
|
3002
|
+
top.i++;
|
|
3003
|
+
continue;
|
|
3004
|
+
}
|
|
3005
|
+
let bound;
|
|
3006
|
+
if (delivered !== NOTHING) {
|
|
3007
|
+
bound = delivered;
|
|
3008
|
+
delivered = NOTHING;
|
|
3009
|
+
} else {
|
|
3010
|
+
bound = enterScopeCarrier(original, state);
|
|
3011
|
+
if (bound instanceof ScopeFrame) {
|
|
3012
|
+
pushed = bound;
|
|
3013
|
+
break;
|
|
3014
|
+
}
|
|
3015
|
+
}
|
|
3016
|
+
if (bound !== original) {
|
|
3017
|
+
if (top.keys) top.next[top.keys[i]] = bound;else top.next[i] = bound;
|
|
3018
|
+
top.changed = true;
|
|
3019
|
+
}
|
|
3020
|
+
top.i++;
|
|
3021
|
+
}
|
|
3022
|
+
if (pushed !== null) {
|
|
3023
|
+
stack.push(pushed);
|
|
3024
|
+
continue;
|
|
3025
|
+
}
|
|
3026
|
+
stack.pop();
|
|
3027
|
+
let out;
|
|
3028
|
+
if (top.changed || state.cyclic.has(top.value)) {
|
|
3029
|
+
out = top.next;
|
|
3030
|
+
} else {
|
|
3031
|
+
state.seen.set(top.value, top.value);
|
|
3032
|
+
out = top.value;
|
|
3033
|
+
}
|
|
3034
|
+
if (stack.length === 0) return out;
|
|
3035
|
+
delivered = out;
|
|
3036
|
+
}
|
|
3037
|
+
}
|
|
3038
|
+
function bindDeferredBody(value, scope) {
|
|
3039
|
+
if (value === null || typeof value !== "object" && typeof value !== "function") return value;
|
|
3040
|
+
const promised = scope(() => nativePromise(value));
|
|
3041
|
+
if (promised) {
|
|
3042
|
+
return promised.then(result => scope(() => scopeDeferredResult(result, scope)));
|
|
3043
|
+
}
|
|
3044
|
+
if (typeof ReadableStream !== "undefined" && value instanceof ReadableStream) {
|
|
3045
|
+
let reader;
|
|
3046
|
+
return new ReadableStream({
|
|
3047
|
+
async pull(controller) {
|
|
3048
|
+
try {
|
|
3049
|
+
const step = await scope(() => {
|
|
3050
|
+
if (!reader) reader = value.getReader();
|
|
3051
|
+
return reader.read();
|
|
3052
|
+
});
|
|
3053
|
+
if (step.done) controller.close();else controller.enqueue(step.value);
|
|
3054
|
+
} catch (error) {
|
|
3055
|
+
controller.error(error);
|
|
3056
|
+
}
|
|
3057
|
+
},
|
|
3058
|
+
cancel(reason) {
|
|
3059
|
+
return scope(() => reader ? reader.cancel(reason) : value.cancel(reason));
|
|
3060
|
+
}
|
|
3061
|
+
}, {
|
|
3062
|
+
highWaterMark: 0
|
|
3063
|
+
});
|
|
3064
|
+
}
|
|
3065
|
+
const scopedIterator = symbol => ({
|
|
3066
|
+
[symbol]() {
|
|
3067
|
+
const iterator = scope(() => value[symbol]());
|
|
3068
|
+
return new Proxy(iterator, {
|
|
3069
|
+
get(target, property) {
|
|
3070
|
+
const member = Reflect.get(target, property, target);
|
|
3071
|
+
return typeof member === "function" && (property === "next" || property === "return" || property === "throw") ? (...args) => scope(() => member.apply(target, args)) : member;
|
|
3072
|
+
}
|
|
3073
|
+
});
|
|
3074
|
+
}
|
|
3075
|
+
});
|
|
3076
|
+
if (typeof value[Symbol.asyncIterator] === "function") {
|
|
3077
|
+
return scopedIterator(Symbol.asyncIterator);
|
|
3078
|
+
}
|
|
3079
|
+
if (typeof value[Symbol.iterator] === "function" && !Array.isArray(value) && !(value instanceof Map) && !(value instanceof Set) && !ArrayBuffer.isView(value)) {
|
|
3080
|
+
return scopedIterator(Symbol.iterator);
|
|
3081
|
+
}
|
|
3082
|
+
return value;
|
|
3083
|
+
}
|
|
3084
|
+
const INVOCATIONS = new WeakMap();
|
|
3085
|
+
function getEventServerFunctionInvocation(event) {
|
|
3086
|
+
return event && INVOCATIONS.get(event);
|
|
3087
|
+
}
|
|
3088
|
+
new Set(Object.values(BodyFormat));
|
|
3089
|
+
function guardFailures(value, state) {
|
|
3090
|
+
if (!state) state = {
|
|
3091
|
+
seen: new WeakMap(),
|
|
3092
|
+
cyclic: new WeakSet()
|
|
3093
|
+
};
|
|
3094
|
+
const entered = enterGuard(value, state);
|
|
3095
|
+
if (!(entered instanceof Frame)) return entered;
|
|
3096
|
+
const stack = [entered];
|
|
3097
|
+
let delivered = NOTHING;
|
|
3098
|
+
for (;;) {
|
|
3099
|
+
const top = stack[stack.length - 1];
|
|
3100
|
+
const items = top.items;
|
|
3101
|
+
let pushed = null;
|
|
3102
|
+
while (top.i < items.length) {
|
|
3103
|
+
const i = top.i;
|
|
3104
|
+
let original;
|
|
3105
|
+
if (top.kind === OBJECT) {
|
|
3106
|
+
const descriptor = top.descriptors[items[i]];
|
|
3107
|
+
if ("value" in descriptor) {
|
|
3108
|
+
original = descriptor.value;
|
|
3109
|
+
} else if (typeof descriptor.get === "function") {
|
|
3110
|
+
if (top.accessorRead !== i) {
|
|
3111
|
+
try {
|
|
3112
|
+
top.accessorValue = descriptor.get.call(top.value);
|
|
3113
|
+
} catch (error) {
|
|
3114
|
+
throw sanitizeServerError(error);
|
|
3115
|
+
}
|
|
3116
|
+
top.accessorRead = i;
|
|
3117
|
+
}
|
|
3118
|
+
original = top.accessorValue;
|
|
3119
|
+
} else {
|
|
3120
|
+
top.i++;
|
|
3121
|
+
continue;
|
|
3122
|
+
}
|
|
3123
|
+
} else {
|
|
3124
|
+
original = items[i];
|
|
3125
|
+
}
|
|
3126
|
+
let guarded;
|
|
3127
|
+
if (delivered !== NOTHING) {
|
|
3128
|
+
guarded = delivered;
|
|
3129
|
+
delivered = NOTHING;
|
|
3130
|
+
} else {
|
|
3131
|
+
guarded = enterGuard(original, state);
|
|
3132
|
+
if (guarded instanceof Frame) {
|
|
3133
|
+
pushed = guarded;
|
|
3134
|
+
break;
|
|
3135
|
+
}
|
|
3136
|
+
}
|
|
3137
|
+
if (top.kind === ARRAY) {
|
|
3138
|
+
if (guarded !== original) {
|
|
3139
|
+
top.next[i] = guarded;
|
|
3140
|
+
top.changed = true;
|
|
3141
|
+
}
|
|
3142
|
+
} else if (top.kind === MAP) {
|
|
3143
|
+
if ((i & 1) === 0) top.pendingKey = guarded;else top.next.set(top.pendingKey, guarded);
|
|
3144
|
+
if (guarded !== original) top.changed = true;
|
|
3145
|
+
} else if (top.kind === SET) {
|
|
3146
|
+
top.next.add(guarded);
|
|
3147
|
+
if (guarded !== original) top.changed = true;
|
|
3148
|
+
} else if (guarded !== original || top.accessorRead === i) {
|
|
3149
|
+
Object.defineProperty(top.next, items[i], {
|
|
3150
|
+
value: guarded,
|
|
3151
|
+
writable: true,
|
|
3152
|
+
configurable: true,
|
|
3153
|
+
enumerable: top.descriptors[items[i]].enumerable
|
|
3154
|
+
});
|
|
3155
|
+
top.changed = true;
|
|
3156
|
+
}
|
|
3157
|
+
top.i++;
|
|
3158
|
+
}
|
|
3159
|
+
if (pushed !== null) {
|
|
3160
|
+
stack.push(pushed);
|
|
3161
|
+
continue;
|
|
3162
|
+
}
|
|
3163
|
+
stack.pop();
|
|
3164
|
+
const out = keepGuarded(top.value, top.next, top.changed, state);
|
|
3165
|
+
if (stack.length === 0) return out;
|
|
3166
|
+
delivered = out;
|
|
3167
|
+
}
|
|
3168
|
+
}
|
|
3169
|
+
const NOTHING = Symbol();
|
|
3170
|
+
const ARRAY = 0;
|
|
3171
|
+
const MAP = 1;
|
|
3172
|
+
const SET = 2;
|
|
3173
|
+
const OBJECT = 3;
|
|
3174
|
+
class Frame {
|
|
3175
|
+
constructor(kind, value, next, items, descriptors) {
|
|
3176
|
+
this.kind = kind;
|
|
3177
|
+
this.value = value;
|
|
3178
|
+
this.next = next;
|
|
3179
|
+
this.items = items;
|
|
3180
|
+
this.descriptors = descriptors;
|
|
3181
|
+
this.i = 0;
|
|
3182
|
+
this.changed = false;
|
|
3183
|
+
this.accessorRead = -1;
|
|
3184
|
+
this.accessorValue = undefined;
|
|
3185
|
+
this.pendingKey = undefined;
|
|
3186
|
+
}
|
|
3187
|
+
}
|
|
3188
|
+
function guardOperation(state, run) {
|
|
3189
|
+
return state.scope ? state.scope(run) : run();
|
|
3190
|
+
}
|
|
3191
|
+
function enterGuard(value, state) {
|
|
3192
|
+
if (value === null || typeof value !== "object") return value;
|
|
3193
|
+
if (state.seen.has(value)) {
|
|
3194
|
+
state.cyclic.add(value);
|
|
3195
|
+
return state.seen.get(value);
|
|
3196
|
+
}
|
|
3197
|
+
if (typeof ReadableStream !== "undefined" && value instanceof ReadableStream) {
|
|
3198
|
+
let reader;
|
|
3199
|
+
const gate = state.gate;
|
|
3200
|
+
let finished = false;
|
|
3201
|
+
const close = () => {
|
|
3202
|
+
if (finished) return;
|
|
3203
|
+
finished = true;
|
|
3204
|
+
try {
|
|
3205
|
+
const cancelled = guardOperation(state, () => reader ? reader.cancel() : value.cancel());
|
|
3206
|
+
if (cancelled && typeof cancelled.then === "function") cancelled.then(undefined, () => {});
|
|
3207
|
+
} catch {}
|
|
3208
|
+
};
|
|
3209
|
+
const guardedStream = new ReadableStream({
|
|
3210
|
+
async pull(controller) {
|
|
3211
|
+
try {
|
|
3212
|
+
if (gate && !finished && !gate.wantsMore()) await gate.awaitDemand();
|
|
3213
|
+
if (finished) {
|
|
3214
|
+
controller.close();
|
|
3215
|
+
return;
|
|
3216
|
+
}
|
|
3217
|
+
if (!reader) reader = guardOperation(state, () => value.getReader());
|
|
3218
|
+
const {
|
|
3219
|
+
done,
|
|
3220
|
+
value: chunk
|
|
3221
|
+
} = await guardOperation(state, () => reader.read());
|
|
3222
|
+
done ? controller.close() : controller.enqueue(guardOperation(state, () => guardFailures(chunk, state)));
|
|
3223
|
+
} catch (error) {
|
|
3224
|
+
controller.error(guardOperation(state, () => sanitizeServerError(error)));
|
|
3225
|
+
}
|
|
3226
|
+
},
|
|
3227
|
+
cancel(reason) {
|
|
3228
|
+
finished = true;
|
|
3229
|
+
return guardOperation(state, () => reader ? reader.cancel(reason) : value.cancel(reason));
|
|
3230
|
+
}
|
|
3231
|
+
});
|
|
3232
|
+
if (gate) gate.onOpen(close);
|
|
3233
|
+
state.seen.set(value, guardedStream);
|
|
3234
|
+
return guardedStream;
|
|
3235
|
+
}
|
|
3236
|
+
if (typeof value.then === "function") {
|
|
3237
|
+
const guardedPromise = Promise.resolve(value).then(resolved => guardOperation(state, () => guardFailures(resolved, state)), error => {
|
|
3238
|
+
throw guardOperation(state, () => sanitizeServerError(error));
|
|
3239
|
+
});
|
|
3240
|
+
guardedPromise.catch(() => {});
|
|
3241
|
+
state.seen.set(value, guardedPromise);
|
|
3242
|
+
return guardedPromise;
|
|
3243
|
+
}
|
|
3244
|
+
if (typeof value[Symbol.asyncIterator] === "function") {
|
|
3245
|
+
const source = value;
|
|
3246
|
+
const gate = state.gate;
|
|
3247
|
+
const guardedIterable = {
|
|
3248
|
+
[Symbol.asyncIterator]() {
|
|
3249
|
+
const iterator = guardOperation(state, () => source[Symbol.asyncIterator]());
|
|
3250
|
+
let finished = false;
|
|
3251
|
+
const close = () => {
|
|
3252
|
+
if (finished) return;
|
|
3253
|
+
finished = true;
|
|
3254
|
+
try {
|
|
3255
|
+
const returned = iterator.return && guardOperation(state, () => iterator.return());
|
|
3256
|
+
if (returned && typeof returned.then === "function") returned.then(undefined, () => {});
|
|
3257
|
+
} catch {}
|
|
3258
|
+
};
|
|
3259
|
+
if (gate) gate.onOpen(close);
|
|
3260
|
+
const step = () => finished ? Promise.resolve({
|
|
3261
|
+
done: true,
|
|
3262
|
+
value: undefined
|
|
3263
|
+
}) : guardOperation(state, () => iterator.next()).then(step => {
|
|
3264
|
+
if (step.done) {
|
|
3265
|
+
finished = true;
|
|
3266
|
+
return step;
|
|
3267
|
+
}
|
|
3268
|
+
return {
|
|
3269
|
+
done: false,
|
|
3270
|
+
value: guardOperation(state, () => guardFailures(step.value, state))
|
|
3271
|
+
};
|
|
3272
|
+
}, error => {
|
|
3273
|
+
throw guardOperation(state, () => sanitizeServerError(error));
|
|
3274
|
+
});
|
|
3275
|
+
return {
|
|
3276
|
+
next: () => finished || !gate || gate.wantsMore() ? step() : gate.awaitDemand().then(step),
|
|
3277
|
+
return: () => {
|
|
3278
|
+
close();
|
|
3279
|
+
return Promise.resolve({
|
|
3280
|
+
done: true,
|
|
3281
|
+
value: undefined
|
|
3282
|
+
});
|
|
3283
|
+
}
|
|
3284
|
+
};
|
|
3285
|
+
}
|
|
3286
|
+
};
|
|
3287
|
+
state.seen.set(value, guardedIterable);
|
|
3288
|
+
return guardedIterable;
|
|
3289
|
+
}
|
|
3290
|
+
if (state.scope && typeof value[Symbol.iterator] === "function" && !Array.isArray(value) && !(value instanceof Map) && !(value instanceof Set) && !ArrayBuffer.isView(value)) {
|
|
3291
|
+
const scopedIterable = scopeDeferredResult(value, state.scope);
|
|
3292
|
+
state.seen.set(value, scopedIterable);
|
|
3293
|
+
return scopedIterable;
|
|
3294
|
+
}
|
|
3295
|
+
if (Array.isArray(value)) {
|
|
3296
|
+
const next = value.slice();
|
|
3297
|
+
state.seen.set(value, next);
|
|
3298
|
+
return new Frame(ARRAY, value, next, value, null);
|
|
3299
|
+
}
|
|
3300
|
+
if (value instanceof Map) {
|
|
3301
|
+
const next = new Map();
|
|
3302
|
+
state.seen.set(value, next);
|
|
3303
|
+
const items = [];
|
|
3304
|
+
for (const entry of value) items.push(entry[0], entry[1]);
|
|
3305
|
+
return new Frame(MAP, value, next, items, null);
|
|
3306
|
+
}
|
|
3307
|
+
if (value instanceof Set) {
|
|
3308
|
+
const next = new Set();
|
|
3309
|
+
state.seen.set(value, next);
|
|
3310
|
+
return new Frame(SET, value, next, [...value], null);
|
|
3311
|
+
}
|
|
3312
|
+
const prototype = Object.getPrototypeOf(value);
|
|
3313
|
+
if (prototype !== Object.prototype && prototype !== null && !(value instanceof Error)) {
|
|
3314
|
+
state.seen.set(value, value);
|
|
3315
|
+
return value;
|
|
3316
|
+
}
|
|
3317
|
+
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
3318
|
+
for (const key of Object.keys(descriptors)) {
|
|
3319
|
+
descriptors[key].configurable = true;
|
|
3320
|
+
if ("value" in descriptors[key]) descriptors[key].writable = true;
|
|
3321
|
+
}
|
|
3322
|
+
const next = Object.create(prototype, descriptors);
|
|
3323
|
+
state.seen.set(value, next);
|
|
3324
|
+
const children = !(value instanceof Error) ? Object.keys(value) : Object.getOwnPropertyNames(value).filter(key => {
|
|
3325
|
+
const descriptor = descriptors[key];
|
|
3326
|
+
return descriptor.enumerable || "value" in descriptor;
|
|
3327
|
+
});
|
|
3328
|
+
return new Frame(OBJECT, value, next, children, descriptors);
|
|
3329
|
+
}
|
|
3330
|
+
function keepGuarded(value, next, changed, state) {
|
|
3331
|
+
if (changed || state.cyclic.has(value)) return next;
|
|
3332
|
+
state.seen.set(value, value);
|
|
3333
|
+
return value;
|
|
3334
|
+
}
|
|
3335
|
+
function sanitizeServerError(value) {
|
|
3336
|
+
return value;
|
|
3337
|
+
}
|
|
3338
|
+
function nativePromise(value) {
|
|
3339
|
+
if (value instanceof Promise) return value;
|
|
3340
|
+
try {
|
|
3341
|
+
if (Object.prototype.toString.call(value) === "[object Promise]") return Promise.prototype.then.call(value, value => value);
|
|
3342
|
+
} catch {}
|
|
3343
|
+
}
|
|
3344
|
+
|
|
3345
|
+
const FRAME_STREAM_HEADER = "X-Frame-Stream";
|
|
3346
|
+
function isFrameStreamResponse(response) {
|
|
3347
|
+
return response.headers.has(FRAME_STREAM_HEADER);
|
|
3348
|
+
}
|
|
3349
|
+
const SERVER_COMPONENT = /*#__PURE__*/Symbol.for("solid.server-component");
|
|
3350
|
+
const SERVER_COMPONENT_SOURCE = /*#__PURE__*/Symbol.for("solid.server-component-source");
|
|
3351
|
+
const SERVER_COMPONENT_ADDRESS = /*#__PURE__*/Symbol.for("solid.server-component-address");
|
|
3352
|
+
let serverComponentRegistryExpr;
|
|
3353
|
+
function setServerComponentBootstrap(resolve) {
|
|
3354
|
+
serverComponentRegistryExpr = resolve;
|
|
3355
|
+
}
|
|
3356
|
+
function parseServerComponent(value, ctx) {
|
|
3357
|
+
return {
|
|
3358
|
+
id: ctx.parse(value[SERVER_COMPONENT]),
|
|
3359
|
+
address: ctx.parse(value[SERVER_COMPONENT_ADDRESS])
|
|
3360
|
+
};
|
|
3361
|
+
}
|
|
3362
|
+
const ServerComponentPlugin = {
|
|
3363
|
+
tag: "solid/server-component",
|
|
3364
|
+
test(value) {
|
|
3365
|
+
return typeof value === "function" && SERVER_COMPONENT in value;
|
|
3366
|
+
},
|
|
3367
|
+
parse: {
|
|
3368
|
+
sync: parseServerComponent,
|
|
3369
|
+
async async(value, ctx) {
|
|
3370
|
+
return {
|
|
3371
|
+
id: await ctx.parse(value[SERVER_COMPONENT]),
|
|
3372
|
+
address: await ctx.parse(value[SERVER_COMPONENT_ADDRESS])
|
|
3373
|
+
};
|
|
3374
|
+
},
|
|
3375
|
+
stream: parseServerComponent
|
|
3376
|
+
},
|
|
3377
|
+
serialize(node, ctx) {
|
|
3378
|
+
const registry = serverComponentRegistryExpr ? serverComponentRegistryExpr(ctx) : "self._$SC";
|
|
3379
|
+
return registry + ".r(" + ctx.serialize(node.id) + "," + ctx.serialize(node.address) + ")";
|
|
3380
|
+
},
|
|
3381
|
+
deserialize(node, ctx) {
|
|
3382
|
+
const id = ctx.deserialize(node.id);
|
|
3383
|
+
ctx.deserialize(node.address);
|
|
3384
|
+
return globalThis._$SC.r(id);
|
|
3385
|
+
}
|
|
3386
|
+
};
|
|
3387
|
+
function flightCodec(codec) {
|
|
3388
|
+
const plugins = codec && codec.plugins || [];
|
|
3389
|
+
if (plugins.some(plugin => plugin && plugin.tag === ServerComponentPlugin.tag)) return codec;
|
|
3390
|
+
return {
|
|
3391
|
+
...codec,
|
|
3392
|
+
plugins: [...plugins, ServerComponentPlugin]
|
|
3393
|
+
};
|
|
3394
|
+
}
|
|
3395
|
+
|
|
3396
|
+
const runWithHydrationScope = (id, fn) => solidJs.runWithOwner(solidJs.createOwner({
|
|
3397
|
+
id
|
|
3398
|
+
}), fn);
|
|
3399
|
+
const ssrAsyncValue = value => solidJs.createMemo(() => value, {
|
|
3400
|
+
serialize: false
|
|
3401
|
+
});
|
|
3402
|
+
const scopeStamp = typeof solidJs.creationStamp === "function" ? solidJs.creationStamp : () => 0;
|
|
3403
|
+
function serverOwned(render) {
|
|
3404
|
+
return solidJs.NoHydration ? solidJs.NoHydration({
|
|
3405
|
+
get children() {
|
|
3406
|
+
return render();
|
|
3407
|
+
}
|
|
3408
|
+
}) : render();
|
|
3409
|
+
}
|
|
3410
|
+
function serverComponentScope(render) {
|
|
3411
|
+
return solidJs.runInServerComponentScope ? solidJs.runInServerComponentScope(render) : render();
|
|
3412
|
+
}
|
|
3413
|
+
function wirePreload(entry) {
|
|
3414
|
+
return entry.href ? {
|
|
3415
|
+
href: entry.href,
|
|
3416
|
+
attrs: entry.attrs
|
|
3417
|
+
} : {
|
|
3418
|
+
attrs: entry.attrs
|
|
3419
|
+
};
|
|
3420
|
+
}
|
|
3421
|
+
const SERVER_COMPONENT_BOOTSTRAP_EXPR = "(self._$SC||(self._$SC={c:{},a:{},r(i,a){a&&(this.a[a]=i,this.reg&&this.reg(a,i));return this.c[i]||(this.c[i]=(p,b)=>self._$SC.impl(i,p,b))}}))";
|
|
3422
|
+
const bootstrappedScripts = new WeakSet();
|
|
3423
|
+
setServerComponentBootstrap(ctx => {
|
|
3424
|
+
if (bootstrappedScripts.has(ctx)) return "self._$SC";
|
|
3425
|
+
bootstrappedScripts.add(ctx);
|
|
3426
|
+
return SERVER_COMPONENT_BOOTSTRAP_EXPR;
|
|
3427
|
+
});
|
|
3428
|
+
const SERVER_COMPONENT_BOOTSTRAP = SERVER_COMPONENT_BOOTSTRAP_EXPR + ";";
|
|
3429
|
+
function createFrameSink(emit, frame) {
|
|
3430
|
+
const {
|
|
3431
|
+
id,
|
|
3432
|
+
version
|
|
3433
|
+
} = frame;
|
|
3434
|
+
const styledKeys = new Set();
|
|
3435
|
+
const bindings = new Map();
|
|
3436
|
+
const sweepMinted = new Set();
|
|
3437
|
+
const argRefVersions = new Map();
|
|
3438
|
+
let sweepScheduled = false;
|
|
3439
|
+
let closed = false;
|
|
3440
|
+
let epoch = 0;
|
|
3441
|
+
const sweep = () => {
|
|
3442
|
+
epoch++;
|
|
3443
|
+
for (const b of [...bindings.values()]) {
|
|
3444
|
+
try {
|
|
3445
|
+
b.sweep();
|
|
3446
|
+
} catch (_) {
|
|
3447
|
+
}
|
|
3448
|
+
}
|
|
3449
|
+
};
|
|
3450
|
+
const scheduleSweep = () => {
|
|
3451
|
+
if (closed || sweepScheduled || !bindings.size) return;
|
|
3452
|
+
sweepScheduled = true;
|
|
3453
|
+
queueMicrotask(() => {
|
|
3454
|
+
sweepScheduled = false;
|
|
3455
|
+
if (!closed) sweep();
|
|
3456
|
+
});
|
|
3457
|
+
};
|
|
3458
|
+
const regionKeys = new Map();
|
|
3459
|
+
const frameOf = key => regionKeys.get(key) || id;
|
|
3460
|
+
return {
|
|
3461
|
+
tagRegion(key, childId) {
|
|
3462
|
+
if (!regionKeys.has(key)) regionKeys.set(key, childId);
|
|
3463
|
+
},
|
|
3464
|
+
shell(html, meta = {}) {
|
|
3465
|
+
if (meta.preloads && meta.preloads.size || meta.preloadLinks) {
|
|
3466
|
+
const chunk = {
|
|
3467
|
+
type: "assets",
|
|
3468
|
+
id,
|
|
3469
|
+
version,
|
|
3470
|
+
key: ""
|
|
3471
|
+
};
|
|
3472
|
+
if (meta.preloads && meta.preloads.size) {
|
|
3473
|
+
const styles = [];
|
|
3474
|
+
const modules = [];
|
|
3475
|
+
for (const url of meta.preloads) {
|
|
3476
|
+
(url.endsWith(".css") ? styles : modules).push(url);
|
|
3477
|
+
}
|
|
3478
|
+
if (styles.length) chunk.styles = styles;
|
|
3479
|
+
if (modules.length) chunk.modules = modules;
|
|
3480
|
+
}
|
|
3481
|
+
if (meta.preloadLinks) {
|
|
3482
|
+
chunk.preloads = [];
|
|
3483
|
+
for (const entry of meta.preloadLinks) {
|
|
3484
|
+
chunk.preloads.push(wirePreload(entry));
|
|
3485
|
+
}
|
|
3486
|
+
}
|
|
3487
|
+
emit(chunk);
|
|
3488
|
+
}
|
|
3489
|
+
emit({
|
|
3490
|
+
type: "html",
|
|
3491
|
+
id,
|
|
3492
|
+
version,
|
|
3493
|
+
html
|
|
3494
|
+
});
|
|
3495
|
+
},
|
|
3496
|
+
data(record) {
|
|
3497
|
+
if (record && typeof record.key === "string" && (record.key.endsWith("_fr") || /^\d+$/.test(record.key))) {
|
|
3498
|
+
return;
|
|
3499
|
+
}
|
|
3500
|
+
if (typeof record === "string") {
|
|
3501
|
+
emit({
|
|
3502
|
+
type: "data",
|
|
3503
|
+
id,
|
|
3504
|
+
version,
|
|
3505
|
+
payload: record
|
|
3506
|
+
});
|
|
3507
|
+
scheduleSweep();
|
|
3508
|
+
} else {
|
|
3509
|
+
emit({
|
|
3510
|
+
type: "data",
|
|
3511
|
+
id,
|
|
3512
|
+
version,
|
|
3513
|
+
key: record.key,
|
|
3514
|
+
node: record.node,
|
|
3515
|
+
initial: record.initial
|
|
3516
|
+
});
|
|
3517
|
+
if (!sweepMinted.has(record.key)) scheduleSweep();
|
|
3518
|
+
}
|
|
3519
|
+
},
|
|
3520
|
+
fragment(key, value, meta = {}) {
|
|
3521
|
+
const fid = frameOf(key);
|
|
3522
|
+
const links = meta.styles && meta.styles.links || [];
|
|
3523
|
+
const inline = meta.styles && meta.styles.inline || [];
|
|
3524
|
+
if (links.length || inline.length) {
|
|
3525
|
+
if (links.length) styledKeys.add(key);
|
|
3526
|
+
const chunk = {
|
|
3527
|
+
type: "assets",
|
|
3528
|
+
id: fid,
|
|
3529
|
+
version,
|
|
3530
|
+
key
|
|
3531
|
+
};
|
|
3532
|
+
if (links.length) {
|
|
3533
|
+
chunk.styles = links.map(e => typeof e === "string" ? e : e.attrs ? {
|
|
3534
|
+
href: e.href,
|
|
3535
|
+
attrs: e.attrs
|
|
3536
|
+
} : e.href);
|
|
3537
|
+
}
|
|
3538
|
+
if (inline.length) {
|
|
3539
|
+
chunk.inlineStyles = inline.map(e => ({
|
|
3540
|
+
id: e.id,
|
|
3541
|
+
content: e.content,
|
|
3542
|
+
attrs: e.attrs
|
|
3543
|
+
}));
|
|
3544
|
+
}
|
|
3545
|
+
emit(chunk);
|
|
3546
|
+
}
|
|
3547
|
+
emit({
|
|
3548
|
+
type: "fragment",
|
|
3549
|
+
id: fid,
|
|
3550
|
+
version,
|
|
3551
|
+
key,
|
|
3552
|
+
html: value
|
|
3553
|
+
});
|
|
3554
|
+
scheduleSweep();
|
|
3555
|
+
if (meta.error) {
|
|
3556
|
+
emit({
|
|
3557
|
+
type: "error",
|
|
3558
|
+
id: fid,
|
|
3559
|
+
version,
|
|
3560
|
+
key,
|
|
3561
|
+
error: {
|
|
3562
|
+
message: String(meta.error && meta.error.message || meta.error)
|
|
3563
|
+
}
|
|
3564
|
+
});
|
|
3565
|
+
}
|
|
3566
|
+
if (!meta.revealGroup) {
|
|
3567
|
+
emit({
|
|
3568
|
+
type: "reveal",
|
|
3569
|
+
id: fid,
|
|
3570
|
+
version,
|
|
3571
|
+
keys: [key],
|
|
3572
|
+
waitForStyles: !!links.length
|
|
3573
|
+
});
|
|
3574
|
+
}
|
|
3575
|
+
},
|
|
3576
|
+
reveal(keys, meta = {}) {
|
|
3577
|
+
const byFrame = new Map();
|
|
3578
|
+
for (const key of keys) {
|
|
3579
|
+
const fid = frameOf(key);
|
|
3580
|
+
let group = byFrame.get(fid);
|
|
3581
|
+
if (!group) byFrame.set(fid, group = []);
|
|
3582
|
+
group.push(key);
|
|
3583
|
+
}
|
|
3584
|
+
for (const [fid, groupKeys] of byFrame) {
|
|
3585
|
+
let waitForStyles = false;
|
|
3586
|
+
for (const key of groupKeys) if (styledKeys.has(key)) waitForStyles = true;
|
|
3587
|
+
const chunk = {
|
|
3588
|
+
type: "reveal",
|
|
3589
|
+
id: fid,
|
|
3590
|
+
version,
|
|
3591
|
+
keys: groupKeys,
|
|
3592
|
+
waitForStyles
|
|
3593
|
+
};
|
|
3594
|
+
if (meta.fallback) chunk.fallback = true;
|
|
3595
|
+
emit(chunk);
|
|
3596
|
+
}
|
|
3597
|
+
},
|
|
3598
|
+
asset(type, value) {
|
|
3599
|
+
if (type === "module") {
|
|
3600
|
+
emit({
|
|
3601
|
+
type: "assets",
|
|
3602
|
+
id,
|
|
3603
|
+
version,
|
|
3604
|
+
key: "",
|
|
3605
|
+
modules: [value]
|
|
3606
|
+
});
|
|
3607
|
+
} else if (type === "preload") {
|
|
3608
|
+
emit({
|
|
3609
|
+
type: "assets",
|
|
3610
|
+
id,
|
|
3611
|
+
version,
|
|
3612
|
+
key: "",
|
|
3613
|
+
preloads: [wirePreload(value)]
|
|
3614
|
+
});
|
|
3615
|
+
}
|
|
3616
|
+
},
|
|
3617
|
+
end() {
|
|
3618
|
+
if (bindings.size) sweep();
|
|
3619
|
+
closed = true;
|
|
3620
|
+
emit({
|
|
3621
|
+
type: "complete",
|
|
3622
|
+
id,
|
|
3623
|
+
version
|
|
3624
|
+
});
|
|
3625
|
+
},
|
|
3626
|
+
error(errorId, error) {
|
|
3627
|
+
emit({
|
|
3628
|
+
type: "error",
|
|
3629
|
+
id,
|
|
3630
|
+
version,
|
|
3631
|
+
key: errorId,
|
|
3632
|
+
error
|
|
3633
|
+
});
|
|
3634
|
+
},
|
|
3635
|
+
slot(key, args) {
|
|
3636
|
+
emit({
|
|
3637
|
+
type: "slot",
|
|
3638
|
+
id,
|
|
3639
|
+
version,
|
|
3640
|
+
key,
|
|
3641
|
+
args
|
|
3642
|
+
});
|
|
3643
|
+
},
|
|
3644
|
+
region(childId, html) {
|
|
3645
|
+
emit({
|
|
3646
|
+
type: "html",
|
|
3647
|
+
id: childId,
|
|
3648
|
+
version,
|
|
3649
|
+
html
|
|
3650
|
+
});
|
|
3651
|
+
},
|
|
3652
|
+
hole(key, html) {
|
|
3653
|
+
emit({
|
|
3654
|
+
type: "hole",
|
|
3655
|
+
id,
|
|
3656
|
+
version,
|
|
3657
|
+
key,
|
|
3658
|
+
html
|
|
3659
|
+
});
|
|
3660
|
+
},
|
|
3661
|
+
attr(key, attrs, removed) {
|
|
3662
|
+
const chunk = {
|
|
3663
|
+
type: "attr",
|
|
3664
|
+
id,
|
|
3665
|
+
version,
|
|
3666
|
+
key,
|
|
3667
|
+
attrs
|
|
3668
|
+
};
|
|
3669
|
+
if (removed && removed.length) chunk.removed = removed;
|
|
3670
|
+
emit(chunk);
|
|
3671
|
+
},
|
|
3672
|
+
openBinding(key, b) {
|
|
3673
|
+
bindings.set(key, b);
|
|
3674
|
+
},
|
|
3675
|
+
closeBinding(key) {
|
|
3676
|
+
bindings.delete(key);
|
|
3677
|
+
},
|
|
3678
|
+
mintRef(ref) {
|
|
3679
|
+
sweepMinted.add(ref);
|
|
3680
|
+
},
|
|
3681
|
+
nextArgRef(ledgerKey) {
|
|
3682
|
+
const n = (argRefVersions.get(ledgerKey) || 0) + 1;
|
|
3683
|
+
argRefVersions.set(ledgerKey, n);
|
|
3684
|
+
return n;
|
|
3685
|
+
},
|
|
3686
|
+
commit: scheduleSweep,
|
|
3687
|
+
get epoch() {
|
|
3688
|
+
return epoch;
|
|
3689
|
+
}
|
|
3690
|
+
};
|
|
3691
|
+
}
|
|
3692
|
+
function renderToFrameStream(code, options = {}) {
|
|
3693
|
+
return frameStream(() => code, options);
|
|
3694
|
+
}
|
|
3695
|
+
function renderServerComponent(component, options = {}) {
|
|
3696
|
+
return frameStream((sink, frame) => {
|
|
3697
|
+
const props = createSlotProps(sink, frame);
|
|
3698
|
+
return () => {
|
|
3699
|
+
const ctx = solidJs.sharedConfig.context;
|
|
3700
|
+
if (ctx) {
|
|
3701
|
+
ctx.commit = sink.commit;
|
|
3702
|
+
ctx.commitEpoch = () => sink.epoch;
|
|
3703
|
+
ctx.liveHoles = createLiveHoles(sink);
|
|
3704
|
+
ctx.claims = CLAIMS_STREAM;
|
|
3705
|
+
}
|
|
3706
|
+
return serverComponentScope(() => component(props));
|
|
3707
|
+
};
|
|
3708
|
+
}, options);
|
|
3709
|
+
}
|
|
3710
|
+
function frameStream(makeCode, options) {
|
|
3711
|
+
const {
|
|
3712
|
+
id = "",
|
|
3713
|
+
version = 1
|
|
3714
|
+
} = options.frame || {};
|
|
3715
|
+
const frame = {
|
|
3716
|
+
id,
|
|
3717
|
+
version
|
|
3718
|
+
};
|
|
3719
|
+
function stream(w) {
|
|
3720
|
+
const emit = chunk => w.write(chunk);
|
|
3721
|
+
const sink = createFrameSink(emit, frame);
|
|
3722
|
+
emit({
|
|
3723
|
+
type: "start",
|
|
3724
|
+
id,
|
|
3725
|
+
version
|
|
3726
|
+
});
|
|
3727
|
+
const code = makeCode(sink, frame);
|
|
3728
|
+
try {
|
|
3729
|
+
renderToStream(() => serverOwned(code), {
|
|
3730
|
+
serializer: createJSONSerializer,
|
|
3731
|
+
...options,
|
|
3732
|
+
sink
|
|
3733
|
+
}).pipe({
|
|
3734
|
+
write() {},
|
|
3735
|
+
end() {
|
|
3736
|
+
sink.end();
|
|
3737
|
+
w.end && w.end();
|
|
3738
|
+
}
|
|
3739
|
+
});
|
|
3740
|
+
} catch (err) {
|
|
3741
|
+
sink.error("", err instanceof Error ? err.message : String(err));
|
|
3742
|
+
sink.end();
|
|
3743
|
+
w.end && w.end();
|
|
3744
|
+
}
|
|
3745
|
+
}
|
|
3746
|
+
return {
|
|
3747
|
+
pipe: stream,
|
|
3748
|
+
then(onFulfilled, onRejected) {
|
|
3749
|
+
return new Promise((resolve, reject) => {
|
|
3750
|
+
const chunks = [];
|
|
3751
|
+
try {
|
|
3752
|
+
stream({
|
|
3753
|
+
write: chunk => chunks.push(chunk),
|
|
3754
|
+
end: () => resolve(chunks)
|
|
3755
|
+
});
|
|
3756
|
+
} catch (err) {
|
|
3757
|
+
reject(err);
|
|
3758
|
+
}
|
|
3759
|
+
}).then(onFulfilled, onRejected);
|
|
3760
|
+
}
|
|
3761
|
+
};
|
|
3762
|
+
}
|
|
3763
|
+
function slotRange(occurrence) {
|
|
3764
|
+
return {
|
|
3765
|
+
t: `<!--slot:${occurrence}:start--><!--slot:${occurrence}:end-->`,
|
|
3766
|
+
$slot: true
|
|
3767
|
+
};
|
|
3768
|
+
}
|
|
3769
|
+
const OCCURRENCE_UNSAFE = /[^A-Za-z0-9_.-]/g;
|
|
3770
|
+
function encodeOccurrenceKey(key) {
|
|
3771
|
+
return String(key).replace(OCCURRENCE_UNSAFE, c => {
|
|
3772
|
+
const code = c.codePointAt(0);
|
|
3773
|
+
return "%" + (code < 16 ? "0" : "") + code.toString(16);
|
|
3774
|
+
});
|
|
3775
|
+
}
|
|
3776
|
+
function occurrenceId(prop, raw, counts) {
|
|
3777
|
+
const k = raw.$key;
|
|
3778
|
+
if (typeof k === "string" || typeof k === "number") {
|
|
3779
|
+
return `${prop}#${encodeOccurrenceKey(k)}`;
|
|
3780
|
+
}
|
|
3781
|
+
const n = counts[prop] || 0;
|
|
3782
|
+
counts[prop] = n + 1;
|
|
3783
|
+
return `${prop}#${n}`;
|
|
3784
|
+
}
|
|
3785
|
+
function isAsyncValue(v) {
|
|
3786
|
+
return !!v && typeof v === "object" && (typeof v.then === "function" || typeof v[Symbol.asyncIterator] === "function");
|
|
3787
|
+
}
|
|
3788
|
+
function tapFirstYield(iterable) {
|
|
3789
|
+
const iter = iterable[Symbol.asyncIterator]();
|
|
3790
|
+
const firstStep = Promise.resolve(iter.next());
|
|
3791
|
+
return {
|
|
3792
|
+
first: firstStep.then(r => r.done ? undefined : r.value),
|
|
3793
|
+
rest: {
|
|
3794
|
+
[Symbol.asyncIterator]() {
|
|
3795
|
+
let replayed = false;
|
|
3796
|
+
return {
|
|
3797
|
+
next: () => {
|
|
3798
|
+
if (!replayed) {
|
|
3799
|
+
replayed = true;
|
|
3800
|
+
return firstStep;
|
|
3801
|
+
}
|
|
3802
|
+
return iter.next();
|
|
3803
|
+
},
|
|
3804
|
+
return: v => iter.return ? iter.return(v) : Promise.resolve({
|
|
3805
|
+
done: true,
|
|
3806
|
+
value: v
|
|
3807
|
+
}),
|
|
3808
|
+
throw: e => iter.throw ? iter.throw(e) : Promise.reject(e)
|
|
3809
|
+
};
|
|
3810
|
+
}
|
|
3811
|
+
}
|
|
3812
|
+
};
|
|
3813
|
+
}
|
|
3814
|
+
function suppressedFill(render) {
|
|
3815
|
+
const live = solidJs.sharedConfig.context && solidJs.sharedConfig.context.liveHoles;
|
|
3816
|
+
if (!live) return render();
|
|
3817
|
+
live.suppressed++;
|
|
3818
|
+
try {
|
|
3819
|
+
return render();
|
|
3820
|
+
} finally {
|
|
3821
|
+
live.suppressed--;
|
|
3822
|
+
}
|
|
3823
|
+
}
|
|
3824
|
+
function createDocumentSlotProps(clientProps, frameId) {
|
|
3825
|
+
const counts = Object.create(null);
|
|
3826
|
+
const getters = new Map();
|
|
3827
|
+
const range = (occurrence, content) => {
|
|
3828
|
+
const r = [{
|
|
3829
|
+
t: `<!--slot:${occurrence}:start-->`
|
|
3830
|
+
}, content, {
|
|
3831
|
+
t: `<!--slot:${occurrence}:end-->`
|
|
3832
|
+
}];
|
|
3833
|
+
r.$slot = true;
|
|
3834
|
+
return r;
|
|
3835
|
+
};
|
|
3836
|
+
const zoneOwner = solidJs.getOwner ? solidJs.getOwner() : null;
|
|
3837
|
+
const scoped = (occurrence, render) => {
|
|
3838
|
+
const id = `sc-${frameId}-${occurrence}-`;
|
|
3839
|
+
const run = () => solidJs.Hydration ? solidJs.Hydration({
|
|
3840
|
+
id,
|
|
3841
|
+
get children() {
|
|
3842
|
+
return render();
|
|
3843
|
+
}
|
|
3844
|
+
}) : runWithHydrationScope(id, render);
|
|
3845
|
+
return zoneOwner ? solidJs.runWithOwner(zoneOwner, run) : run();
|
|
3846
|
+
};
|
|
3847
|
+
return new Proxy(Object.create(null), {
|
|
3848
|
+
has() {
|
|
3849
|
+
return true;
|
|
3850
|
+
},
|
|
3851
|
+
get(_, prop) {
|
|
3852
|
+
if (typeof prop !== "string") return undefined;
|
|
3853
|
+
if (prop === "then") return undefined;
|
|
3854
|
+
let fn = getters.get(prop);
|
|
3855
|
+
if (!fn) {
|
|
3856
|
+
fn = (...callArgs) => {
|
|
3857
|
+
if (callArgs.length === 0 || callArgs[0] === undefined) {
|
|
3858
|
+
return suppressedFill(() => scoped(prop, () => {
|
|
3859
|
+
const value = clientProps[prop];
|
|
3860
|
+
return range(prop, typeof value === "function" ? value() : value);
|
|
3861
|
+
}));
|
|
3862
|
+
}
|
|
3863
|
+
const raw = callArgs[0];
|
|
3864
|
+
const occurrence = occurrenceId(prop, raw, counts);
|
|
3865
|
+
const slot = clientProps[prop];
|
|
3866
|
+
if (typeof slot !== "function") return range(occurrence, undefined);
|
|
3867
|
+
const resolved = {};
|
|
3868
|
+
const liveArgs = solidJs.sharedConfig.context && solidJs.sharedConfig.context.live && solidJs.sharedConfig.context.live.args;
|
|
3869
|
+
const vals = {};
|
|
3870
|
+
const evals = {};
|
|
3871
|
+
const states = {};
|
|
3872
|
+
const minted = {};
|
|
3873
|
+
for (const key of Object.keys(raw)) {
|
|
3874
|
+
if (key === "$key") continue;
|
|
3875
|
+
const desc = Object.getOwnPropertyDescriptor(raw, key);
|
|
3876
|
+
let evaluate = null;
|
|
3877
|
+
let value;
|
|
3878
|
+
if (desc.get) {
|
|
3879
|
+
const get = desc.get;
|
|
3880
|
+
evaluate = () => unwrapThunks(get.call(raw));
|
|
3881
|
+
} else {
|
|
3882
|
+
value = desc.value;
|
|
3883
|
+
if (typeof value === "function") {
|
|
3884
|
+
const fn = value;
|
|
3885
|
+
evaluate = () => unwrapThunks(fn);
|
|
3886
|
+
}
|
|
3887
|
+
}
|
|
3888
|
+
if (evaluate) {
|
|
3889
|
+
evals[key] = evaluate;
|
|
3890
|
+
const stampBefore = scopeStamp();
|
|
3891
|
+
try {
|
|
3892
|
+
value = evaluate();
|
|
3893
|
+
states[key] = {
|
|
3894
|
+
settled: true,
|
|
3895
|
+
last: value
|
|
3896
|
+
};
|
|
3897
|
+
} catch (err) {
|
|
3898
|
+
const blocked = solidJs.ssrHandleError && solidJs.ssrHandleError(err);
|
|
3899
|
+
if (!blocked) throw err;
|
|
3900
|
+
const state = states[key] = {
|
|
3901
|
+
settled: false,
|
|
3902
|
+
last: undefined
|
|
3903
|
+
};
|
|
3904
|
+
value = retryArgUntilSettled(evaluate, blocked, key, occurrence, v => {
|
|
3905
|
+
state.settled = true;
|
|
3906
|
+
state.last = v;
|
|
3907
|
+
if (liveArgs) liveArgs.commit();
|
|
3908
|
+
});
|
|
3909
|
+
}
|
|
3910
|
+
if (scopeStamp() !== stampBefore) minted[key] = true;
|
|
3911
|
+
}
|
|
3912
|
+
vals[key] = value;
|
|
3913
|
+
}
|
|
3914
|
+
const regions = [];
|
|
3915
|
+
for (const key of Object.keys(vals)) {
|
|
3916
|
+
const value = vals[key];
|
|
3917
|
+
if (isContainerTraced(value)) {
|
|
3918
|
+
resolved[key] = value;
|
|
3919
|
+
} else if (isServerContent(value)) {
|
|
3920
|
+
const childId = `${frameId}.${occurrence}.${key}`;
|
|
3921
|
+
const region = {
|
|
3922
|
+
key,
|
|
3923
|
+
childId,
|
|
3924
|
+
value,
|
|
3925
|
+
used: false,
|
|
3926
|
+
locked: false
|
|
3927
|
+
};
|
|
3928
|
+
regions.push(region);
|
|
3929
|
+
resolved[key] = () => {
|
|
3930
|
+
if (region.locked) return [];
|
|
3931
|
+
region.used = true;
|
|
3932
|
+
return [{
|
|
3933
|
+
t: frameElementOpen(childId)
|
|
3934
|
+
}, value, {
|
|
3935
|
+
t: FRAME_ELEMENT_CLOSE
|
|
3936
|
+
}];
|
|
3937
|
+
};
|
|
3938
|
+
} else if (ssrAsyncValue && isAsyncValue(value)) {
|
|
3939
|
+
let readable = value;
|
|
3940
|
+
if (typeof value.then !== "function") {
|
|
3941
|
+
const {
|
|
3942
|
+
first,
|
|
3943
|
+
rest
|
|
3944
|
+
} = tapFirstYield(value);
|
|
3945
|
+
readable = first;
|
|
3946
|
+
vals[key] = rest;
|
|
3947
|
+
}
|
|
3948
|
+
const read = ssrAsyncValue(readable);
|
|
3949
|
+
Object.defineProperty(resolved, key, {
|
|
3950
|
+
get: read,
|
|
3951
|
+
enumerable: true,
|
|
3952
|
+
configurable: true
|
|
3953
|
+
});
|
|
3954
|
+
} else {
|
|
3955
|
+
resolved[key] = value;
|
|
3956
|
+
}
|
|
3957
|
+
}
|
|
3958
|
+
const out = suppressedFill(() => scoped(occurrence, () => range(occurrence, slot(resolved))));
|
|
3959
|
+
const unused = regions.filter(r => !r.used);
|
|
3960
|
+
if (solidJs.sharedConfig.context) {
|
|
3961
|
+
const args = {};
|
|
3962
|
+
for (const key of Object.keys(vals)) {
|
|
3963
|
+
const value = vals[key];
|
|
3964
|
+
const region = regions.find(r => r.key === key);
|
|
3965
|
+
if (region) {
|
|
3966
|
+
args[key] = {
|
|
3967
|
+
$frame: region.childId
|
|
3968
|
+
};
|
|
3969
|
+
continue;
|
|
3970
|
+
}
|
|
3971
|
+
if (!isContainerTraced(value) && isServerContent(value)) continue;
|
|
3972
|
+
args[key] = envelopeContainerTraces(value);
|
|
3973
|
+
}
|
|
3974
|
+
solidJs.sharedConfig.context.serialize(`sc:slot:${frameId}:${occurrence}`, {
|
|
3975
|
+
...args
|
|
3976
|
+
});
|
|
3977
|
+
for (const region of unused) {
|
|
3978
|
+
region.locked = true;
|
|
3979
|
+
solidJs.sharedConfig.context.serialize(`sc:region:${region.childId}`, resolveRegionHtml(solidJs.sharedConfig.context, region.value));
|
|
3980
|
+
}
|
|
3981
|
+
if (liveArgs) {
|
|
3982
|
+
for (const key of Object.keys(evals)) {
|
|
3983
|
+
if (regions.some(r => r.key === key)) continue;
|
|
3984
|
+
if (minted[key]) continue;
|
|
3985
|
+
const ledgerKey = `${frameId}:${occurrence}:${key}`;
|
|
3986
|
+
openArgBinding(liveArgs, ledgerKey, occurrence, key, evals[key], states[key], value => {
|
|
3987
|
+
args[key] = envelopeContainerTraces(value);
|
|
3988
|
+
liveArgs.slot(frameId, occurrence, {
|
|
3989
|
+
...args
|
|
3990
|
+
});
|
|
3991
|
+
});
|
|
3992
|
+
}
|
|
3993
|
+
}
|
|
3994
|
+
}
|
|
3995
|
+
return out;
|
|
3996
|
+
};
|
|
3997
|
+
fn.$lhSkip = true;
|
|
3998
|
+
fn[CLAIM_PROP] = prop;
|
|
3999
|
+
getters.set(prop, fn);
|
|
4000
|
+
}
|
|
4001
|
+
return fn;
|
|
4002
|
+
}
|
|
4003
|
+
});
|
|
4004
|
+
}
|
|
4005
|
+
const FRAME_TAG = "solid-frame";
|
|
4006
|
+
const FRAME_ID_ATTR = "data-fid";
|
|
4007
|
+
function frameElementOpen(id) {
|
|
4008
|
+
const escaped = solidJs.sharedConfig.context ? solidJs.sharedConfig.context.escape(String(id), true) : String(id);
|
|
4009
|
+
return `<${FRAME_TAG} ${FRAME_ID_ATTR}="${escaped}" style="display:contents">`;
|
|
4010
|
+
}
|
|
4011
|
+
const FRAME_ELEMENT_CLOSE = `</${FRAME_TAG}>`;
|
|
4012
|
+
function armDocumentLiveHoles(ctx) {
|
|
4013
|
+
if (!ctx || ctx.liveHoles !== undefined) return;
|
|
4014
|
+
const live = ctx.live;
|
|
4015
|
+
if (live && live.holes !== undefined) {
|
|
4016
|
+
ctx.liveHoles = live.holes;
|
|
4017
|
+
if (live.holes) {
|
|
4018
|
+
ctx.commit = live.commit;
|
|
4019
|
+
ctx.commitEpoch = live.commitEpoch;
|
|
4020
|
+
}
|
|
4021
|
+
return;
|
|
4022
|
+
}
|
|
4023
|
+
if (!live || !ctx.async || ctx.noHydrate || !ctx.serialize || typeof ReadableStream !== "function") {
|
|
4024
|
+
ctx.liveHoles = null;
|
|
4025
|
+
if (live) live.holes = null;
|
|
4026
|
+
return;
|
|
4027
|
+
}
|
|
4028
|
+
const bindings = new Map();
|
|
4029
|
+
let epoch = 0;
|
|
4030
|
+
let sweepScheduled = false;
|
|
4031
|
+
let closed = false;
|
|
4032
|
+
const sweep = () => {
|
|
4033
|
+
epoch++;
|
|
4034
|
+
for (const b of [...bindings.values()]) {
|
|
4035
|
+
try {
|
|
4036
|
+
b.sweep();
|
|
4037
|
+
} catch (_) {
|
|
4038
|
+
}
|
|
4039
|
+
}
|
|
4040
|
+
};
|
|
4041
|
+
const scheduleSweep = () => {
|
|
4042
|
+
if (closed || sweepScheduled || !bindings.size) return;
|
|
4043
|
+
sweepScheduled = true;
|
|
4044
|
+
queueMicrotask(() => {
|
|
4045
|
+
sweepScheduled = false;
|
|
4046
|
+
if (!closed) sweep();
|
|
4047
|
+
});
|
|
4048
|
+
};
|
|
4049
|
+
let channel;
|
|
4050
|
+
ctx.serialize("sc:live", new ReadableStream({
|
|
4051
|
+
start(c) {
|
|
4052
|
+
channel = c;
|
|
4053
|
+
}
|
|
4054
|
+
}));
|
|
4055
|
+
const push = op => {
|
|
4056
|
+
if (!closed) channel.enqueue(op);
|
|
4057
|
+
};
|
|
4058
|
+
ctx.liveHoles = live.holes = createLiveHoles({
|
|
4059
|
+
openBinding(key, b) {
|
|
4060
|
+
bindings.set(key, b);
|
|
4061
|
+
},
|
|
4062
|
+
closeBinding(key) {
|
|
4063
|
+
bindings.delete(key);
|
|
4064
|
+
},
|
|
4065
|
+
hole(key, html) {
|
|
4066
|
+
push({
|
|
4067
|
+
type: "hole",
|
|
4068
|
+
key,
|
|
4069
|
+
html
|
|
4070
|
+
});
|
|
4071
|
+
},
|
|
4072
|
+
attr(key, attrs, removed) {
|
|
4073
|
+
const op = {
|
|
4074
|
+
type: "attr",
|
|
4075
|
+
key,
|
|
4076
|
+
attrs
|
|
4077
|
+
};
|
|
4078
|
+
if (removed && removed.length) op.removed = removed;
|
|
4079
|
+
push(op);
|
|
4080
|
+
},
|
|
4081
|
+
error(key, error) {
|
|
4082
|
+
push({
|
|
4083
|
+
type: "error",
|
|
4084
|
+
key,
|
|
4085
|
+
error
|
|
4086
|
+
});
|
|
4087
|
+
},
|
|
4088
|
+
commit: scheduleSweep,
|
|
4089
|
+
get epoch() {
|
|
4090
|
+
return epoch;
|
|
4091
|
+
}
|
|
4092
|
+
}, true);
|
|
4093
|
+
ctx.commit = live.commit = scheduleSweep;
|
|
4094
|
+
ctx.commitEpoch = live.commitEpoch = () => epoch;
|
|
4095
|
+
live.args = {
|
|
4096
|
+
openBinding(key, b) {
|
|
4097
|
+
bindings.set(key, b);
|
|
4098
|
+
},
|
|
4099
|
+
closeBinding(key) {
|
|
4100
|
+
bindings.delete(key);
|
|
4101
|
+
},
|
|
4102
|
+
slot(fid, occurrence, args) {
|
|
4103
|
+
push({
|
|
4104
|
+
type: "slot",
|
|
4105
|
+
fid,
|
|
4106
|
+
key: occurrence,
|
|
4107
|
+
args
|
|
4108
|
+
});
|
|
4109
|
+
},
|
|
4110
|
+
commit: scheduleSweep
|
|
4111
|
+
};
|
|
4112
|
+
live.end = () => {
|
|
4113
|
+
if (closed) return;
|
|
4114
|
+
if (bindings.size) sweep();
|
|
4115
|
+
closed = true;
|
|
4116
|
+
channel.close();
|
|
4117
|
+
};
|
|
4118
|
+
}
|
|
4119
|
+
function frameTransformDirectResult(value, {
|
|
4120
|
+
id,
|
|
4121
|
+
args
|
|
4122
|
+
}) {
|
|
4123
|
+
if (typeof value !== "function") return value;
|
|
4124
|
+
const component = value;
|
|
4125
|
+
const wrapped = props => [{
|
|
4126
|
+
t: frameElementOpen(id)
|
|
4127
|
+
},
|
|
4128
|
+
serverOwned(() => {
|
|
4129
|
+
armDocumentLiveHoles(solidJs.sharedConfig.context);
|
|
4130
|
+
solidJs.sharedConfig.context.claims = CLAIMS_DOCUMENT;
|
|
4131
|
+
const slotProps = createDocumentSlotProps(props, id);
|
|
4132
|
+
return serverComponentScope(() => component(slotProps));
|
|
4133
|
+
}), {
|
|
4134
|
+
t: FRAME_ELEMENT_CLOSE
|
|
4135
|
+
}];
|
|
4136
|
+
wrapped[SERVER_COMPONENT] = id;
|
|
4137
|
+
wrapped[SERVER_COMPONENT_SOURCE] = component;
|
|
4138
|
+
wrapped[SERVER_COMPONENT_ADDRESS] = frameAddress(id, args);
|
|
4139
|
+
return wrapped;
|
|
4140
|
+
}
|
|
4141
|
+
function resolveRegionHtml(ctx, node) {
|
|
4142
|
+
const res = ctx.resolve(node);
|
|
4143
|
+
if (!res || !res.t) return String(res ?? "");
|
|
4144
|
+
if (!res.h || !res.h.length) return res.t[0];
|
|
4145
|
+
return Promise.all(res.p).then(() => {
|
|
4146
|
+
let out = Promise.resolve(res.t[0]);
|
|
4147
|
+
for (let i = 0; i < res.h.length; i++) {
|
|
4148
|
+
const hole = res.h[i];
|
|
4149
|
+
const tail = res.t[i + 1];
|
|
4150
|
+
out = out.then(acc => Promise.resolve(resolveRegionHtml(ctx, hole)).then(part => acc + part + tail));
|
|
4151
|
+
}
|
|
4152
|
+
return out;
|
|
4153
|
+
});
|
|
4154
|
+
}
|
|
4155
|
+
function isServerContent(value) {
|
|
4156
|
+
if (value && typeof value === "object") {
|
|
4157
|
+
if ("t" in value) return true;
|
|
4158
|
+
if (Array.isArray(value) && value.length > 0) {
|
|
4159
|
+
for (const item of value) {
|
|
4160
|
+
if (!(item && typeof item === "object" && "t" in item)) return false;
|
|
4161
|
+
}
|
|
4162
|
+
return true;
|
|
4163
|
+
}
|
|
4164
|
+
}
|
|
4165
|
+
return false;
|
|
4166
|
+
}
|
|
4167
|
+
function unwrapThunks(value) {
|
|
4168
|
+
for (let d = 0; typeof value === "function" && d < 16; d++) value = value();
|
|
4169
|
+
return value;
|
|
4170
|
+
}
|
|
4171
|
+
function contentArgError(key, occurrence) {
|
|
4172
|
+
return new Error("Async slot arg resolved to JSX (arg '" + key + "' of " + occurrence + "). Async args must resolve to serializable values; render async content through a boundary instead.");
|
|
4173
|
+
}
|
|
4174
|
+
function retryArgUntilSettled(evaluate, blocked, key, occurrence, onSettle) {
|
|
4175
|
+
const owner = solidJs.getOwner();
|
|
4176
|
+
return new Promise((resolve, reject) => {
|
|
4177
|
+
const retry = () => {
|
|
4178
|
+
try {
|
|
4179
|
+
const value = owner ? solidJs.runWithOwner(owner, evaluate) : evaluate();
|
|
4180
|
+
if (isServerContent(value)) {
|
|
4181
|
+
reject(contentArgError(key, occurrence));
|
|
4182
|
+
return;
|
|
4183
|
+
}
|
|
4184
|
+
if (onSettle) onSettle(value);
|
|
4185
|
+
resolve(value);
|
|
4186
|
+
} catch (err) {
|
|
4187
|
+
const next = solidJs.ssrHandleError && solidJs.ssrHandleError(err);
|
|
4188
|
+
if (next) next.then(retry, retry);else reject(err);
|
|
4189
|
+
}
|
|
4190
|
+
};
|
|
4191
|
+
blocked.then(retry, retry);
|
|
4192
|
+
});
|
|
4193
|
+
}
|
|
4194
|
+
function openArgBinding(sink, ledgerKey, occurrence, key, evaluate, state, emit) {
|
|
4195
|
+
const owner = solidJs.getOwner();
|
|
4196
|
+
sink.openBinding(ledgerKey, {
|
|
4197
|
+
sweep() {
|
|
4198
|
+
if (!state.settled) return;
|
|
4199
|
+
let value;
|
|
4200
|
+
const stampBefore = scopeStamp();
|
|
4201
|
+
try {
|
|
4202
|
+
value = owner ? solidJs.runWithOwner(owner, evaluate) : evaluate();
|
|
4203
|
+
} catch (err) {
|
|
4204
|
+
const blocked = solidJs.ssrHandleError && solidJs.ssrHandleError(err);
|
|
4205
|
+
if (!blocked) {
|
|
4206
|
+
sink.closeBinding(ledgerKey);
|
|
4207
|
+
emit(Promise.reject(err instanceof Error ? err : new Error(String(err))));
|
|
4208
|
+
return;
|
|
4209
|
+
}
|
|
4210
|
+
if (scopeStamp() !== stampBefore) {
|
|
4211
|
+
sink.closeBinding(ledgerKey);
|
|
4212
|
+
return;
|
|
4213
|
+
}
|
|
4214
|
+
state.settled = false;
|
|
4215
|
+
emit(retryArgUntilSettled(evaluate, blocked, key, occurrence, v => {
|
|
4216
|
+
state.settled = true;
|
|
4217
|
+
state.last = v;
|
|
4218
|
+
sink.commit();
|
|
4219
|
+
}));
|
|
4220
|
+
return;
|
|
4221
|
+
}
|
|
4222
|
+
if (scopeStamp() !== stampBefore) {
|
|
4223
|
+
sink.closeBinding(ledgerKey);
|
|
4224
|
+
return;
|
|
4225
|
+
}
|
|
4226
|
+
if (value === state.last) return;
|
|
4227
|
+
state.last = value;
|
|
4228
|
+
if (isServerContent(value)) {
|
|
4229
|
+
sink.closeBinding(ledgerKey);
|
|
4230
|
+
emit(Promise.reject(contentArgError(key, occurrence)));
|
|
4231
|
+
return;
|
|
4232
|
+
}
|
|
4233
|
+
emit(value);
|
|
4234
|
+
}
|
|
4235
|
+
});
|
|
4236
|
+
}
|
|
4237
|
+
function createSlotProps(sink, frame) {
|
|
4238
|
+
const counts = Object.create(null);
|
|
4239
|
+
const getters = new Map();
|
|
4240
|
+
return new Proxy(Object.create(null), {
|
|
4241
|
+
has() {
|
|
4242
|
+
return true;
|
|
4243
|
+
},
|
|
4244
|
+
get(_, prop) {
|
|
4245
|
+
if (typeof prop !== "string") return undefined;
|
|
4246
|
+
if (prop === "then") return undefined;
|
|
4247
|
+
let fn = getters.get(prop);
|
|
4248
|
+
if (!fn) {
|
|
4249
|
+
fn = (...callArgs) => {
|
|
4250
|
+
if (callArgs.length === 0 || callArgs[0] === undefined) {
|
|
4251
|
+
return slotRange(prop);
|
|
4252
|
+
}
|
|
4253
|
+
const live = solidJs.sharedConfig.context && solidJs.sharedConfig.context.liveHoles;
|
|
4254
|
+
if (live) {
|
|
4255
|
+
if (live.sweeping) {
|
|
4256
|
+
live.gateHit = true;
|
|
4257
|
+
return {
|
|
4258
|
+
t: "",
|
|
4259
|
+
$slot: true
|
|
4260
|
+
};
|
|
4261
|
+
}
|
|
4262
|
+
live.recordStamp++;
|
|
4263
|
+
}
|
|
4264
|
+
const raw = callArgs[0];
|
|
4265
|
+
const occurrence = occurrenceId(prop, raw, counts);
|
|
4266
|
+
const args = {};
|
|
4267
|
+
const opened = [];
|
|
4268
|
+
for (const key of Object.keys(raw)) {
|
|
4269
|
+
if (key === "$key") continue;
|
|
4270
|
+
const childId = `${frame.id}.${occurrence}.${key}`;
|
|
4271
|
+
const ctx = solidJs.sharedConfig.context;
|
|
4272
|
+
const origRegister = ctx.registerFragment;
|
|
4273
|
+
ctx.registerFragment = (fragKey, fragOptions) => {
|
|
4274
|
+
sink.tagRegion(fragKey, childId);
|
|
4275
|
+
return origRegister.call(ctx, fragKey, fragOptions);
|
|
4276
|
+
};
|
|
4277
|
+
try {
|
|
4278
|
+
const desc = Object.getOwnPropertyDescriptor(raw, key);
|
|
4279
|
+
let evaluate = null;
|
|
4280
|
+
let value;
|
|
4281
|
+
let state = null;
|
|
4282
|
+
const stampBefore = scopeStamp();
|
|
4283
|
+
try {
|
|
4284
|
+
if (desc.get) {
|
|
4285
|
+
const get = desc.get;
|
|
4286
|
+
evaluate = () => unwrapThunks(get.call(raw));
|
|
4287
|
+
value = evaluate();
|
|
4288
|
+
} else {
|
|
4289
|
+
value = desc.value;
|
|
4290
|
+
if (typeof value === "function") {
|
|
4291
|
+
const fn = value;
|
|
4292
|
+
evaluate = () => unwrapThunks(fn);
|
|
4293
|
+
value = evaluate();
|
|
4294
|
+
}
|
|
4295
|
+
}
|
|
4296
|
+
} catch (err) {
|
|
4297
|
+
const blocked = solidJs.ssrHandleError && solidJs.ssrHandleError(err);
|
|
4298
|
+
if (!blocked) throw err;
|
|
4299
|
+
state = {
|
|
4300
|
+
settled: false,
|
|
4301
|
+
last: undefined
|
|
4302
|
+
};
|
|
4303
|
+
const pendingState = state;
|
|
4304
|
+
value = retryArgUntilSettled(evaluate, blocked, key, occurrence, v => {
|
|
4305
|
+
pendingState.settled = true;
|
|
4306
|
+
pendingState.last = v;
|
|
4307
|
+
sink.commit();
|
|
4308
|
+
});
|
|
4309
|
+
}
|
|
4310
|
+
const mintedEval = scopeStamp() !== stampBefore;
|
|
4311
|
+
const t = typeof value;
|
|
4312
|
+
if (value == null || t === "string" || t === "number" || t === "boolean") {
|
|
4313
|
+
args[key] = value;
|
|
4314
|
+
if (evaluate) state = {
|
|
4315
|
+
settled: true,
|
|
4316
|
+
last: value
|
|
4317
|
+
};
|
|
4318
|
+
} else if (!isContainerTraced(value) && isServerContent(value)) {
|
|
4319
|
+
const resolved = ctx.resolve(value);
|
|
4320
|
+
if (resolved.h.length) {
|
|
4321
|
+
throw new Error("Async server content in a slot arg needs a boundary (arg '" + key + "' of " + occurrence + "). Wrap the async read in a <Suspense>, or move it above the slot.");
|
|
4322
|
+
}
|
|
4323
|
+
sink.region(childId, resolved.t[0]);
|
|
4324
|
+
args[key] = {
|
|
4325
|
+
$frame: childId
|
|
4326
|
+
};
|
|
4327
|
+
} else {
|
|
4328
|
+
const ref = `arg:${occurrence}:${key}`;
|
|
4329
|
+
ctx.serialize(ref, envelopeContainerTraces(value));
|
|
4330
|
+
args[key] = {
|
|
4331
|
+
$ref: ref
|
|
4332
|
+
};
|
|
4333
|
+
if (evaluate && !state) state = {
|
|
4334
|
+
settled: true,
|
|
4335
|
+
last: value
|
|
4336
|
+
};
|
|
4337
|
+
}
|
|
4338
|
+
if (evaluate && state && !mintedEval) opened.push({
|
|
4339
|
+
key,
|
|
4340
|
+
evaluate,
|
|
4341
|
+
state
|
|
4342
|
+
});
|
|
4343
|
+
} finally {
|
|
4344
|
+
ctx.registerFragment = origRegister;
|
|
4345
|
+
}
|
|
4346
|
+
}
|
|
4347
|
+
sink.slot(occurrence, {
|
|
4348
|
+
...args
|
|
4349
|
+
});
|
|
4350
|
+
const ctx = solidJs.sharedConfig.context;
|
|
4351
|
+
for (const b of opened) {
|
|
4352
|
+
const key = b.key;
|
|
4353
|
+
const ledgerKey = `${occurrence}:${key}`;
|
|
4354
|
+
openArgBinding(sink, ledgerKey, occurrence, key, b.evaluate, b.state, value => {
|
|
4355
|
+
const t = typeof value;
|
|
4356
|
+
if (value == null || t === "string" || t === "number" || t === "boolean") {
|
|
4357
|
+
args[key] = value;
|
|
4358
|
+
} else {
|
|
4359
|
+
const ref = `arg:${occurrence}:${key}@${sink.nextArgRef(ledgerKey)}`;
|
|
4360
|
+
sink.mintRef(ref);
|
|
4361
|
+
ctx.serialize(ref, envelopeContainerTraces(value));
|
|
4362
|
+
args[key] = {
|
|
4363
|
+
$ref: ref
|
|
4364
|
+
};
|
|
4365
|
+
}
|
|
4366
|
+
sink.slot(occurrence, {
|
|
4367
|
+
...args
|
|
4368
|
+
});
|
|
4369
|
+
});
|
|
4370
|
+
}
|
|
4371
|
+
return slotRange(occurrence);
|
|
4372
|
+
};
|
|
4373
|
+
fn.$lhSkip = true;
|
|
4374
|
+
fn[CLAIM_PROP] = prop;
|
|
4375
|
+
getters.set(prop, fn);
|
|
4376
|
+
}
|
|
4377
|
+
return fn;
|
|
4378
|
+
}
|
|
4379
|
+
});
|
|
4380
|
+
}
|
|
4381
|
+
function copyInitHeaders(init) {
|
|
4382
|
+
if (!init || !init.getSetCookie) return new Headers(init);
|
|
4383
|
+
const headers = new Headers();
|
|
4384
|
+
init.forEach((value, key) => {
|
|
4385
|
+
if (key !== "set-cookie") headers.append(key, value);
|
|
4386
|
+
});
|
|
4387
|
+
for (const cookie of init.getSetCookie()) headers.append("Set-Cookie", cookie);
|
|
4388
|
+
return headers;
|
|
4389
|
+
}
|
|
4390
|
+
function serverComponentResponse(component, options = {}, init = {}) {
|
|
4391
|
+
const {
|
|
4392
|
+
id = "",
|
|
4393
|
+
version = 1
|
|
4394
|
+
} = options.frame || {};
|
|
4395
|
+
const headers = copyInitHeaders(init.headers);
|
|
4396
|
+
headers.set("Content-Type", "application/x-frame-stream");
|
|
4397
|
+
headers.set(FRAME_STREAM_HEADER, id);
|
|
4398
|
+
headers.set("X-Content-Raw", "1");
|
|
4399
|
+
const stream = renderServerComponent(component, {
|
|
4400
|
+
...options,
|
|
4401
|
+
frame: {
|
|
4402
|
+
id,
|
|
4403
|
+
version
|
|
4404
|
+
}
|
|
4405
|
+
});
|
|
4406
|
+
let closed = false;
|
|
4407
|
+
const body = new ReadableStream({
|
|
4408
|
+
start(controller) {
|
|
4409
|
+
stream.pipe({
|
|
4410
|
+
write(chunk) {
|
|
4411
|
+
if (closed) return;
|
|
4412
|
+
try {
|
|
4413
|
+
controller.enqueue(createChunk(JSON.stringify(chunk)));
|
|
4414
|
+
} catch (_) {
|
|
4415
|
+
closed = true;
|
|
4416
|
+
}
|
|
4417
|
+
},
|
|
4418
|
+
end() {
|
|
4419
|
+
if (closed) return;
|
|
4420
|
+
closed = true;
|
|
4421
|
+
controller.close();
|
|
4422
|
+
}
|
|
4423
|
+
});
|
|
4424
|
+
},
|
|
4425
|
+
cancel() {
|
|
4426
|
+
closed = true;
|
|
4427
|
+
}
|
|
4428
|
+
});
|
|
4429
|
+
return new Response(body, {
|
|
4430
|
+
status: init.status || 200,
|
|
4431
|
+
headers
|
|
4432
|
+
});
|
|
4433
|
+
}
|
|
4434
|
+
function frameTransformResult(event, result, context) {
|
|
4435
|
+
let init;
|
|
4436
|
+
if (isResponseEnvelope(result)) {
|
|
4437
|
+
const {
|
|
4438
|
+
response,
|
|
4439
|
+
value
|
|
4440
|
+
} = result;
|
|
4441
|
+
if (typeof value !== "function") return result;
|
|
4442
|
+
init = response ? {
|
|
4443
|
+
headers: response.headers,
|
|
4444
|
+
status: response.status
|
|
4445
|
+
} : undefined;
|
|
4446
|
+
result = value;
|
|
4447
|
+
}
|
|
4448
|
+
if (typeof result !== "function") return result;
|
|
4449
|
+
if (context && context.collectsFlight) return init ? {
|
|
4450
|
+
response: init,
|
|
4451
|
+
value: result
|
|
4452
|
+
} : result;
|
|
4453
|
+
const invocation = getEventServerFunctionInvocation(event);
|
|
4454
|
+
return serverComponentResponse(result, {
|
|
4455
|
+
frame: {
|
|
4456
|
+
id: invocation && invocation.id || ""
|
|
4457
|
+
}
|
|
4458
|
+
}, init);
|
|
4459
|
+
}
|
|
4460
|
+
async function frameTransformFlightResult(event, outcome, context) {
|
|
4461
|
+
const {
|
|
4462
|
+
value,
|
|
4463
|
+
data
|
|
4464
|
+
} = outcome;
|
|
4465
|
+
const regions = [];
|
|
4466
|
+
let serialized = data;
|
|
4467
|
+
if (data && typeof data === "object") {
|
|
4468
|
+
serialized = {};
|
|
4469
|
+
const keys = Object.keys(data);
|
|
4470
|
+
const values = await Promise.all(keys.map(key => data[key]));
|
|
4471
|
+
for (let i = 0; i < keys.length; i++) {
|
|
4472
|
+
const entry = values[i];
|
|
4473
|
+
serialized[keys[i]] = entry;
|
|
4474
|
+
if (typeof entry === "function") {
|
|
4475
|
+
regions.push({
|
|
4476
|
+
id: entry[SERVER_COMPONENT_ADDRESS] || keys[i],
|
|
4477
|
+
component: entry[SERVER_COMPONENT_SOURCE] || entry
|
|
4478
|
+
});
|
|
4479
|
+
}
|
|
4480
|
+
}
|
|
4481
|
+
}
|
|
4482
|
+
const invocation = getEventServerFunctionInvocation(event);
|
|
4483
|
+
const primary = typeof value === "function" ? {
|
|
4484
|
+
id: invocation && invocation.id || "",
|
|
4485
|
+
component: value
|
|
4486
|
+
} : undefined;
|
|
4487
|
+
if (!primary && !regions.length) return undefined;
|
|
4488
|
+
return frameFlightResponse({
|
|
4489
|
+
primary,
|
|
4490
|
+
regions,
|
|
4491
|
+
outcome: {
|
|
4492
|
+
value: primary ? undefined : value,
|
|
4493
|
+
data: serialized
|
|
4494
|
+
},
|
|
4495
|
+
codec: context && context.codec
|
|
4496
|
+
});
|
|
4497
|
+
}
|
|
4498
|
+
function frameFlightResponse({
|
|
4499
|
+
primary,
|
|
4500
|
+
regions = [],
|
|
4501
|
+
outcome,
|
|
4502
|
+
codec
|
|
4503
|
+
}, init = {}) {
|
|
4504
|
+
const frames = primary ? [primary, ...regions] : regions;
|
|
4505
|
+
const headers = copyInitHeaders(init.headers);
|
|
4506
|
+
headers.set("Content-Type", "application/x-frame-stream");
|
|
4507
|
+
headers.set(FRAME_STREAM_HEADER, primary ? primary.id : "");
|
|
4508
|
+
headers.set("X-Content-Raw", "1");
|
|
4509
|
+
headers.set(SINGLE_FLIGHT_HEADER, "true");
|
|
4510
|
+
let closed = false;
|
|
4511
|
+
const body = new ReadableStream({
|
|
4512
|
+
async start(controller) {
|
|
4513
|
+
const write = chunk => {
|
|
4514
|
+
if (closed) return;
|
|
4515
|
+
try {
|
|
4516
|
+
controller.enqueue(createChunk(JSON.stringify(chunk)));
|
|
4517
|
+
} catch (_) {
|
|
4518
|
+
closed = true;
|
|
4519
|
+
}
|
|
4520
|
+
};
|
|
4521
|
+
try {
|
|
4522
|
+
for (const {
|
|
4523
|
+
id,
|
|
4524
|
+
component
|
|
4525
|
+
} of frames) {
|
|
4526
|
+
await new Promise(resolve => {
|
|
4527
|
+
renderServerComponent(component, {
|
|
4528
|
+
frame: {
|
|
4529
|
+
id,
|
|
4530
|
+
version: 1
|
|
4531
|
+
}
|
|
4532
|
+
}).pipe({
|
|
4533
|
+
write,
|
|
4534
|
+
end: resolve
|
|
4535
|
+
});
|
|
4536
|
+
});
|
|
4537
|
+
}
|
|
4538
|
+
if (outcome) {
|
|
4539
|
+
const reader = new ChunkReader(serializeStream(guardFailures(outcome), flightCodec(codec)));
|
|
4540
|
+
for (let node = await reader.next(); !node.done; node = await reader.next()) {
|
|
4541
|
+
write({
|
|
4542
|
+
type: "outcome",
|
|
4543
|
+
payload: node.value
|
|
4544
|
+
});
|
|
4545
|
+
}
|
|
4546
|
+
}
|
|
4547
|
+
if (!closed) {
|
|
4548
|
+
closed = true;
|
|
4549
|
+
controller.close();
|
|
4550
|
+
}
|
|
4551
|
+
} catch (err) {
|
|
4552
|
+
if (!closed) {
|
|
4553
|
+
closed = true;
|
|
4554
|
+
controller.error(err);
|
|
4555
|
+
}
|
|
4556
|
+
}
|
|
4557
|
+
},
|
|
4558
|
+
cancel() {
|
|
4559
|
+
closed = true;
|
|
4560
|
+
}
|
|
4561
|
+
});
|
|
4562
|
+
return new Response(body, {
|
|
4563
|
+
status: init.status || 200,
|
|
4564
|
+
headers
|
|
4565
|
+
});
|
|
4566
|
+
}
|
|
4567
|
+
|
|
4568
|
+
setContainerTraceResolver(solidJs.getProjectionTrace);
|
|
4569
|
+
function asyncArg(value) {
|
|
4570
|
+
return value;
|
|
4571
|
+
}
|
|
4572
|
+
|
|
4573
|
+
exports.FRAME_STREAM_HEADER = FRAME_STREAM_HEADER;
|
|
4574
|
+
exports.SERVER_COMPONENT_BOOTSTRAP = SERVER_COMPONENT_BOOTSTRAP;
|
|
4575
|
+
exports.ServerComponentPlugin = ServerComponentPlugin;
|
|
4576
|
+
exports.asyncArg = asyncArg;
|
|
4577
|
+
exports.createFrameSink = createFrameSink;
|
|
4578
|
+
exports.frameTransformDirectResult = frameTransformDirectResult;
|
|
4579
|
+
exports.frameTransformFlightResult = frameTransformFlightResult;
|
|
4580
|
+
exports.frameTransformResult = frameTransformResult;
|
|
4581
|
+
exports.isFrameStreamResponse = isFrameStreamResponse;
|
|
4582
|
+
exports.renderServerComponent = renderServerComponent;
|
|
4583
|
+
exports.renderToFrameStream = renderToFrameStream;
|
|
4584
|
+
exports.serverComponentResponse = serverComponentResponse;
|