@solidjs/web 2.0.0-rc.0 → 2.0.0-rc.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/server.dev.js +4472 -0
- package/dist/server.js +1363 -224
- package/dist/{server.cjs → server.observe.js} +1563 -424
- package/dist/{dev.cjs → web.dev.js} +708 -365
- package/dist/web.js +460 -144
- package/dist/{dev.js → web.observe.js} +511 -213
- package/frames/dist/client.dev.js +464 -72
- package/frames/dist/client.js +364 -71
- package/frames/dist/{client.dev.cjs → client.observe.js} +487 -134
- package/frames/dist/server.dev.js +1713 -0
- package/frames/dist/server.js +553 -2495
- package/frames/dist/server.observe.js +1713 -0
- package/frames/package.json +2 -25
- package/package.json +214 -254
- package/performance-tracks/dist/performance-tracks.dev.js +678 -0
- package/performance-tracks/dist/performance-tracks.js +6 -0
- package/performance-tracks/dist/performance-tracks.observe.js +666 -0
- package/performance-tracks/package.json +7 -0
- package/performance-tracks/types/index.d.ts +67 -0
- package/serialization/decode/package.json +2 -15
- package/serialization/dist/decode.js +101 -12
- package/serialization/dist/serialization.js +112 -20
- package/serialization/package.json +2 -15
- package/serialization/types/index.d.ts +76 -157
- package/serialization/types/serializer-decode.d.ts +149 -112
- package/serialization/types/serializer.d.ts +101 -0
- package/server-functions/dist/client.dev.js +1364 -0
- package/server-functions/dist/client.js +745 -85
- package/server-functions/dist/client.observe.js +1343 -0
- package/server-functions/dist/server.dev.js +2203 -175
- package/server-functions/dist/server.js +2111 -176
- package/server-functions/dist/server.observe.js +3043 -0
- package/server-functions/package.json +2 -35
- package/server-functions/rich-args/package.json +2 -15
- package/storage/package.json +2 -15
- package/types/client.d.ts +193 -288
- package/types/constants.d.ts +20 -0
- package/types/cookies.d.ts +32 -84
- package/types/diagnostics.d.ts +56 -0
- package/types/frames/client.d.ts +1 -1
- package/types/frames/frame-client.d.ts +323 -259
- package/types/frames/frame-container-plugin.d.ts +72 -0
- package/types/frames/frame-sink.d.ts +101 -158
- package/types/frames/frame-transport.d.ts +192 -190
- package/types/frames/serializer-decode.d.ts +219 -0
- package/types/frames/serializer.d.ts +76 -157
- package/types/frames/server.d.ts +1 -1
- package/types/head.d.ts +19 -0
- package/types/index.d.ts +62 -76
- package/types/index.server.d.ts +174 -0
- package/types/jsx.d.ts +33 -26
- package/types/observe.d.ts +358 -0
- package/types/reconcile.d.ts +1 -0
- package/types/render.d.ts +9 -0
- package/types/response.d.ts +75 -150
- package/types/serializer-decode.d.ts +149 -112
- package/types/serializer.d.ts +76 -157
- package/types/server-functions/client.d.ts +202 -174
- package/types/server-functions/flash.d.ts +28 -30
- package/types/server-functions/registry.d.ts +102 -0
- package/types/server-functions/rich-args.d.ts +1 -10
- package/types/server-functions/server.d.ts +518 -454
- package/types/server-functions/shared.d.ts +366 -425
- package/types/server-mock.d.ts +110 -13
- package/types/server-observe.d.ts +77 -0
- package/types/server.d.ts +425 -425
- package/types/trace.d.ts +127 -0
- package/LICENSE +0 -21
- package/dist/web.cjs +0 -2007
- package/frames/dist/client.cjs +0 -1916
- package/frames/dist/server.cjs +0 -3667
- package/serialization/dist/decode.cjs +0 -110
- package/serialization/dist/serialization.cjs +0 -232
- package/serialization/types-cjs/index.d.cts +0 -182
- package/serialization/types-cjs/package.json +0 -3
- package/serialization/types-cjs/serializer-decode.d.cts +0 -182
- package/server-functions/dist/client.cjs +0 -646
- package/server-functions/dist/rich-args.cjs +0 -11
- package/server-functions/dist/server.cjs +0 -1077
- package/server-functions/dist/server.dev.cjs +0 -1077
- package/storage/dist/storage.cjs +0 -12
- package/storage/types-cjs/index.d.cts +0 -28
- package/storage/types-cjs/package.json +0 -3
- package/types/core.d.ts +0 -6
- package/types-cjs/client.d.cts +0 -337
- package/types-cjs/cookies.d.cts +0 -93
- package/types-cjs/core.d.cts +0 -6
- package/types-cjs/frames/client.d.cts +0 -36
- package/types-cjs/frames/frame-client.d.cts +0 -338
- package/types-cjs/frames/frame-sink.d.cts +0 -194
- package/types-cjs/frames/frame-transport.d.cts +0 -222
- package/types-cjs/frames/serializer.d.cts +0 -182
- package/types-cjs/frames/server.d.cts +0 -52
- package/types-cjs/index.d.cts +0 -230
- package/types-cjs/jsx-properties.d.cts +0 -93
- package/types-cjs/jsx.d.cts +0 -4150
- package/types-cjs/package.json +0 -3
- package/types-cjs/response.d.cts +0 -174
- package/types-cjs/serializer-decode.d.cts +0 -182
- package/types-cjs/serializer.d.cts +0 -182
- package/types-cjs/server-functions/client.d.cts +0 -201
- package/types-cjs/server-functions/flash.d.cts +0 -38
- package/types-cjs/server-functions/rich-args.d.cts +0 -10
- package/types-cjs/server-functions/server.d.cts +0 -588
- package/types-cjs/server-functions/shared.d.cts +0 -523
- package/types-cjs/server-mock.d.cts +0 -277
- package/types-cjs/server.d.cts +0 -523
package/frames/dist/server.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ssrSanitizeError, creationStamp, ssrHandleError, runInServerComponentScope, shareAsyncIterable, getProjectionTrace } from 'solid-js/internal';
|
|
2
|
+
import { sharedConfig, NoHydration, getOwner, runWithOwner, createMemo, Hydration, createOwner } from 'solid-js';
|
|
3
|
+
import { isResponseEnvelope, renderToStream, createLiveHoles, CLAIMS_STREAM, CLAIMS_DOCUMENT, CLAIM_PROP } from '@solidjs/web';
|
|
4
|
+
import { Feature, createStream, toCrossJSONStream } from 'seroval';
|
|
3
5
|
import { AbortSignalPlugin, CustomEventPlugin, DOMExceptionPlugin, EventPlugin, FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin } from 'seroval-plugins/web';
|
|
6
|
+
import { textDigest, frameAddress, getEventServerFunctionInvocation, armLiveBody, createEventChunk, createChunk, ChunkReader, serializeStream, guardFailures } from '@solidjs/web/server-functions/server';
|
|
4
7
|
|
|
5
|
-
const STATE = Symbol.for("
|
|
8
|
+
const STATE = Symbol.for("solid.container-trace-state");
|
|
6
9
|
const state = globalThis[STATE] || (globalThis[STATE] = {
|
|
7
10
|
materialized: new WeakMap(),
|
|
8
11
|
materializedValues: new WeakSet()
|
|
@@ -10,21 +13,33 @@ const state = globalThis[STATE] || (globalThis[STATE] = {
|
|
|
10
13
|
function setContainerTraceResolver(fn) {
|
|
11
14
|
state.resolveTrace = fn;
|
|
12
15
|
}
|
|
16
|
+
function setAsyncIterableSharer(fn) {
|
|
17
|
+
state.shareIterable = fn;
|
|
18
|
+
}
|
|
19
|
+
function setContainerTraceStreamMint(fn) {
|
|
20
|
+
state.streamOf = fn;
|
|
21
|
+
}
|
|
13
22
|
function isContainerTraced(value) {
|
|
14
23
|
const resolve = state.resolveTrace;
|
|
15
24
|
return !!(resolve && value && typeof value === "object" && resolve(value));
|
|
16
25
|
}
|
|
17
|
-
const TRACE = Symbol.for("
|
|
18
|
-
function
|
|
19
|
-
if (
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
const TRACE = Symbol.for("solid.container-trace");
|
|
27
|
+
function toBorderForm(value, envelopeContainers) {
|
|
28
|
+
if (value == null || typeof value !== "object") return value;
|
|
29
|
+
const resolve = state.resolveTrace ;
|
|
30
|
+
const share = state.shareIterable;
|
|
31
|
+
if (!resolve && !share) return value;
|
|
32
|
+
if (resolve) {
|
|
33
|
+
const trace = resolve(value);
|
|
34
|
+
if (trace) return {
|
|
35
|
+
[TRACE]: trace
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
if (share && isShareableIterable(value)) return share(value);
|
|
24
39
|
if (Array.isArray(value)) {
|
|
25
40
|
let out = value;
|
|
26
41
|
for (let i = 0; i < value.length; i++) {
|
|
27
|
-
const next =
|
|
42
|
+
const next = toBorderForm(value[i]);
|
|
28
43
|
if (next !== value[i]) {
|
|
29
44
|
if (out === value) out = value.slice();
|
|
30
45
|
out[i] = next;
|
|
@@ -35,2436 +50,259 @@ function envelopeContainerTraces(value) {
|
|
|
35
50
|
if (Object.getPrototypeOf(value) === Object.prototype) {
|
|
36
51
|
let out = value;
|
|
37
52
|
for (const key of Object.keys(value)) {
|
|
38
|
-
const next =
|
|
53
|
+
const next = toBorderForm(value[key]);
|
|
39
54
|
if (next !== value[key]) {
|
|
40
55
|
if (out === value) out = {
|
|
41
56
|
...value
|
|
42
|
-
};
|
|
43
|
-
out[key] = next;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return out;
|
|
47
|
-
}
|
|
48
|
-
return value;
|
|
49
|
-
}
|
|
50
|
-
function materialize(marker) {
|
|
51
|
-
let value = state.materialized.get(marker.$tr);
|
|
52
|
-
if (value === undefined) {
|
|
53
|
-
value = state.materializeTrace(marker);
|
|
54
|
-
state.materialized.set(marker.$tr, value);
|
|
55
|
-
if (value !== null && typeof value === "object") state.materializedValues.add(value);
|
|
56
|
-
}
|
|
57
|
-
return value;
|
|
58
|
-
}
|
|
59
|
-
function parseTrace(value, ctx) {
|
|
60
|
-
const trace = value[TRACE];
|
|
61
|
-
return {
|
|
62
|
-
a: trace.array ? 1 : 0,
|
|
63
|
-
i: ctx.parse(trace.subscribe())
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
const ContainerTracePlugin = {
|
|
67
|
-
tag: "dom-expressions/container-trace",
|
|
68
|
-
test(value) {
|
|
69
|
-
return value != null && typeof value === "object" && TRACE in value;
|
|
70
|
-
},
|
|
71
|
-
parse: {
|
|
72
|
-
sync() {
|
|
73
|
-
throw new Error("A reactive container can only be serialized by a streaming serializer.");
|
|
74
|
-
},
|
|
75
|
-
async async(value, ctx) {
|
|
76
|
-
const trace = value[TRACE];
|
|
77
|
-
return {
|
|
78
|
-
a: trace.array ? 1 : 0,
|
|
79
|
-
i: await ctx.parse(trace.subscribe())
|
|
80
|
-
};
|
|
81
|
-
},
|
|
82
|
-
stream: parseTrace
|
|
83
|
-
},
|
|
84
|
-
serialize(node, ctx) {
|
|
85
|
-
return "{$tr:" + ctx.serialize(node.i) + ",$ta:" + node.a + "}";
|
|
86
|
-
},
|
|
87
|
-
deserialize(node, ctx) {
|
|
88
|
-
const iterable = ctx.deserialize(node.i);
|
|
89
|
-
const marker = {
|
|
90
|
-
$tr: iterable,
|
|
91
|
-
$ta: node.a
|
|
92
|
-
};
|
|
93
|
-
return state.materializeTrace ? materialize(marker) : marker;
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const runWithHydrationScope = (id, fn) => runWithOwner(createOwner({
|
|
98
|
-
id
|
|
99
|
-
}), fn);
|
|
100
|
-
const ssrAsyncValue = value => createMemo(() => value, {
|
|
101
|
-
serialize: false
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
const DEFAULT_WEB_PLUGINS = Object.freeze([AbortSignalPlugin,
|
|
105
|
-
CustomEventPlugin, DOMExceptionPlugin, EventPlugin,
|
|
106
|
-
FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin,
|
|
107
|
-
ContainerTracePlugin]);
|
|
108
|
-
function resolveSerializerPlugins(customPlugins) {
|
|
109
|
-
return customPlugins ? [...customPlugins, ...DEFAULT_WEB_PLUGINS] : [...DEFAULT_WEB_PLUGINS];
|
|
110
|
-
}
|
|
111
|
-
const JSON_CODEC_DISABLED_FEATURES = Feature.RegExp;
|
|
112
|
-
const JSON_CODEC_DEPTH_LIMIT = 64;
|
|
113
|
-
function resolveCodecOptions({
|
|
114
|
-
plugins,
|
|
115
|
-
disabledFeatures,
|
|
116
|
-
depthLimit
|
|
117
|
-
} = {}) {
|
|
118
|
-
return {
|
|
119
|
-
plugins: resolveSerializerPlugins(plugins),
|
|
120
|
-
disabledFeatures: disabledFeatures === undefined ? JSON_CODEC_DISABLED_FEATURES : disabledFeatures,
|
|
121
|
-
depthLimit: depthLimit === undefined ? JSON_CODEC_DEPTH_LIMIT : depthLimit
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const DEFAULT_DISABLED_FEATURES = Feature.AggregateError | Feature.BigIntTypedArray;
|
|
126
|
-
const serializeOnlyDisabledFeatures = () => process.env.NODE_ENV === "development" ? 0 : Feature.ErrorPrototypeStack;
|
|
127
|
-
const HYDRATION_GLOBAL = "_$HY.r";
|
|
128
|
-
function createSerializer(options) {
|
|
129
|
-
return new Serializer({
|
|
130
|
-
...options,
|
|
131
|
-
plugins: resolveSerializerPlugins(options.plugins),
|
|
132
|
-
disabledFeatures: (options.disabledFeatures === undefined ? DEFAULT_DISABLED_FEATURES : options.disabledFeatures) | serializeOnlyDisabledFeatures()
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
function createHydrationSerializer({
|
|
136
|
-
onData,
|
|
137
|
-
onDone,
|
|
138
|
-
scopeId,
|
|
139
|
-
onError,
|
|
140
|
-
plugins
|
|
141
|
-
}) {
|
|
142
|
-
return createSerializer({
|
|
143
|
-
scopeId,
|
|
144
|
-
plugins,
|
|
145
|
-
globalIdentifier: HYDRATION_GLOBAL,
|
|
146
|
-
onData,
|
|
147
|
-
onDone,
|
|
148
|
-
onError
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
function getLocalHeaderScript(id) {
|
|
152
|
-
return getCrossReferenceHeader(id) + ";";
|
|
153
|
-
}
|
|
154
|
-
function createJSONSerializer({
|
|
155
|
-
onData,
|
|
156
|
-
onDone,
|
|
157
|
-
onError,
|
|
158
|
-
plugins,
|
|
159
|
-
disabledFeatures,
|
|
160
|
-
depthLimit
|
|
161
|
-
}) {
|
|
162
|
-
const resolved = resolveCodecOptions({
|
|
163
|
-
plugins,
|
|
164
|
-
disabledFeatures,
|
|
165
|
-
depthLimit
|
|
166
|
-
});
|
|
167
|
-
const refs = new Map();
|
|
168
|
-
const cancels = new Set();
|
|
169
|
-
let pendingWrites = 0;
|
|
170
|
-
let flushed = false;
|
|
171
|
-
let done = false;
|
|
172
|
-
const maybeDone = () => {
|
|
173
|
-
if (flushed && pendingWrites === 0 && !done) {
|
|
174
|
-
done = true;
|
|
175
|
-
onDone && onDone();
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
return {
|
|
179
|
-
write(key, value) {
|
|
180
|
-
if (flushed) return;
|
|
181
|
-
pendingWrites++;
|
|
182
|
-
let settled = false;
|
|
183
|
-
let cancel = null;
|
|
184
|
-
const stream = toCrossJSONStream(value, {
|
|
185
|
-
refs,
|
|
186
|
-
plugins: resolved.plugins,
|
|
187
|
-
disabledFeatures: resolved.disabledFeatures | serializeOnlyDisabledFeatures(),
|
|
188
|
-
onParse(node, initial) {
|
|
189
|
-
onData({
|
|
190
|
-
key,
|
|
191
|
-
node,
|
|
192
|
-
initial
|
|
193
|
-
});
|
|
194
|
-
},
|
|
195
|
-
onError,
|
|
196
|
-
onDone() {
|
|
197
|
-
settled = true;
|
|
198
|
-
if (cancel) cancels.delete(cancel);
|
|
199
|
-
pendingWrites--;
|
|
200
|
-
maybeDone();
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
if (!settled) {
|
|
204
|
-
cancel = stream;
|
|
205
|
-
cancels.add(cancel);
|
|
206
|
-
}
|
|
207
|
-
},
|
|
208
|
-
flush() {
|
|
209
|
-
flushed = true;
|
|
210
|
-
maybeDone();
|
|
211
|
-
},
|
|
212
|
-
close() {
|
|
213
|
-
flushed = true;
|
|
214
|
-
for (const cancel of cancels) cancel();
|
|
215
|
-
cancels.clear();
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
const ENVELOPE = Symbol.for("solid.ResponseEnvelope");
|
|
221
|
-
function isResponseEnvelope(value) {
|
|
222
|
-
return !!(value && typeof value === "object" && value[ENVELOPE]);
|
|
223
|
-
}
|
|
224
|
-
const REVALIDATE_HEADER = "X-Revalidate";
|
|
225
|
-
|
|
226
|
-
function frameAddress(id, args) {
|
|
227
|
-
return args && args.length ? id + ":" + hashArguments(args) : id;
|
|
228
|
-
}
|
|
229
|
-
function hashArguments(args) {
|
|
230
|
-
let hash = 0;
|
|
231
|
-
const text = stableString(args);
|
|
232
|
-
for (let i = 0; i < text.length; i++) {
|
|
233
|
-
hash = (hash << 5) - hash + text.charCodeAt(i);
|
|
234
|
-
hash |= 0;
|
|
235
|
-
}
|
|
236
|
-
return (hash >>> 0).toString(36);
|
|
237
|
-
}
|
|
238
|
-
function stableString(value, seen) {
|
|
239
|
-
if (value === null || typeof value !== "object") {
|
|
240
|
-
return typeof value === "bigint" ? value + "n" : String(value);
|
|
241
|
-
}
|
|
242
|
-
if (value instanceof Date) return "Date:" + value.getTime();
|
|
243
|
-
seen || (seen = new Set());
|
|
244
|
-
if (seen.has(value)) return "~";
|
|
245
|
-
seen.add(value);
|
|
246
|
-
if (value instanceof Map) {
|
|
247
|
-
const entries = [];
|
|
248
|
-
for (const [k, v] of value) {
|
|
249
|
-
entries.push(stableString(k, seen) + "=>" + stableString(v, seen));
|
|
250
|
-
}
|
|
251
|
-
return "Map{" + entries.sort().join(",") + "}";
|
|
252
|
-
}
|
|
253
|
-
if (value instanceof Set) {
|
|
254
|
-
const members = [];
|
|
255
|
-
for (const v of value) members.push(stableString(v, seen));
|
|
256
|
-
return "Set{" + members.sort().join(",") + "}";
|
|
257
|
-
}
|
|
258
|
-
if (Array.isArray(value)) {
|
|
259
|
-
let out = "[";
|
|
260
|
-
for (let i = 0; i < value.length; i++) out += (i ? "," : "") + stableString(value[i], seen);
|
|
261
|
-
return out + "]";
|
|
262
|
-
}
|
|
263
|
-
const keys = Object.keys(value).sort();
|
|
264
|
-
let out = "{";
|
|
265
|
-
for (let i = 0; i < keys.length; i++) {
|
|
266
|
-
out += (i ? "," : "") + keys[i] + ":" + stableString(value[keys[i]], seen);
|
|
267
|
-
}
|
|
268
|
-
return out + "}";
|
|
269
|
-
}
|
|
270
|
-
const ERROR_HEADER = "X-Server-Function-Error";
|
|
271
|
-
const BODY_FORMAT_HEADER = "X-Server-Function-Format";
|
|
272
|
-
const SINGLE_FLIGHT_HEADER = "X-Single-Flight";
|
|
273
|
-
function createChunk(data) {
|
|
274
|
-
const encoder = new TextEncoder();
|
|
275
|
-
const encodeData = encoder.encode(data);
|
|
276
|
-
const bytes = encodeData.length;
|
|
277
|
-
const chunk = new Uint8Array(12 + bytes);
|
|
278
|
-
chunk.set(encoder.encode(`;0x${bytes.toString(16).padStart(8, "0")};`));
|
|
279
|
-
chunk.set(encodeData, 12);
|
|
280
|
-
return chunk;
|
|
281
|
-
}
|
|
282
|
-
class ChunkReader {
|
|
283
|
-
constructor(stream) {
|
|
284
|
-
this.reader = stream.getReader();
|
|
285
|
-
this.buffer = new Uint8Array(0);
|
|
286
|
-
this.done = false;
|
|
287
|
-
}
|
|
288
|
-
async readChunk() {
|
|
289
|
-
const chunk = await this.reader.read();
|
|
290
|
-
if (!chunk.done) {
|
|
291
|
-
const newBuffer = new Uint8Array(this.buffer.length + chunk.value.length);
|
|
292
|
-
newBuffer.set(this.buffer);
|
|
293
|
-
newBuffer.set(chunk.value, this.buffer.length);
|
|
294
|
-
this.buffer = newBuffer;
|
|
295
|
-
} else {
|
|
296
|
-
this.done = true;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
async next() {
|
|
300
|
-
while (this.buffer.length < 12) {
|
|
301
|
-
if (this.done) {
|
|
302
|
-
if (this.buffer.length === 0) return {
|
|
303
|
-
done: true,
|
|
304
|
-
value: undefined
|
|
305
|
-
};
|
|
306
|
-
throw new Error("Malformed server function stream.");
|
|
307
|
-
}
|
|
308
|
-
await this.readChunk();
|
|
309
|
-
}
|
|
310
|
-
const decoder = new TextDecoder();
|
|
311
|
-
const bytes = Number.parseInt(decoder.decode(this.buffer.subarray(1, 11)), 16);
|
|
312
|
-
if (Number.isNaN(bytes)) {
|
|
313
|
-
throw new Error("Malformed server function stream.");
|
|
314
|
-
}
|
|
315
|
-
while (bytes > this.buffer.length - 12) {
|
|
316
|
-
if (this.done) {
|
|
317
|
-
throw new Error("Malformed server function stream.");
|
|
318
|
-
}
|
|
319
|
-
await this.readChunk();
|
|
320
|
-
}
|
|
321
|
-
const partial = decoder.decode(this.buffer.subarray(12, 12 + bytes));
|
|
322
|
-
this.buffer = this.buffer.subarray(12 + bytes);
|
|
323
|
-
return {
|
|
324
|
-
done: false,
|
|
325
|
-
value: partial
|
|
326
|
-
};
|
|
327
|
-
}
|
|
328
|
-
async drain(interpret) {
|
|
329
|
-
while (true) {
|
|
330
|
-
const result = await this.next();
|
|
331
|
-
if (result.done) {
|
|
332
|
-
break;
|
|
333
|
-
}
|
|
334
|
-
interpret(result.value);
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
function serializeStream(value, codecOptions) {
|
|
339
|
-
return new ReadableStream({
|
|
340
|
-
async start(controller) {
|
|
341
|
-
const {
|
|
342
|
-
serializeJSON
|
|
343
|
-
} = await import('@solidjs/web/serialization');
|
|
344
|
-
serializeJSON(value, {
|
|
345
|
-
...codecOptions,
|
|
346
|
-
onParse(node) {
|
|
347
|
-
controller.enqueue(createChunk(JSON.stringify(node)));
|
|
348
|
-
},
|
|
349
|
-
onDone() {
|
|
350
|
-
controller.close();
|
|
351
|
-
},
|
|
352
|
-
onError(error) {
|
|
353
|
-
controller.error(error);
|
|
354
|
-
}
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
const HEAD_ELIGIBLE_TAGS = new Set(["title", "meta", "link", "style", "script", "base"]);
|
|
361
|
-
const HEAD_ATTR_NAME = /^[a-zA-Z_][a-zA-Z0-9_:.-]*$/;
|
|
362
|
-
const RESOURCE_LINK_RELS = new Set(["preload", "modulepreload", "prefetch", "preconnect", "dns-prefetch", "stylesheet"]);
|
|
363
|
-
const RESOURCE_QUALIFIERS = ["as", "crossorigin", "type", "media", "imagesrcset", "imagesizes"];
|
|
364
|
-
const STYLESHEET_FETCH_META = new Set(["crossorigin", "integrity", "referrerpolicy", "fetchpriority"]);
|
|
365
|
-
function evalHeadValue(v) {
|
|
366
|
-
return typeof v === "function" ? v() : v;
|
|
367
|
-
}
|
|
368
|
-
function evalHeadProps(props, presets) {
|
|
369
|
-
const out = {};
|
|
370
|
-
for (const name in props) out[name] = presets && name in presets ? presets[name] : evalHeadValue(props[name]);
|
|
371
|
-
return out;
|
|
372
|
-
}
|
|
373
|
-
function classifyHeadTag(desc) {
|
|
374
|
-
const tag = desc.tag;
|
|
375
|
-
if (tag === "link") {
|
|
376
|
-
const rel = evalHeadValue(desc.props && desc.props.rel);
|
|
377
|
-
return {
|
|
378
|
-
resource: RESOURCE_LINK_RELS.has(rel),
|
|
379
|
-
rel
|
|
380
|
-
};
|
|
381
|
-
}
|
|
382
|
-
if (tag === "style") return {
|
|
383
|
-
resource: !!(desc.props && "href" in desc.props)
|
|
384
|
-
};
|
|
385
|
-
if (tag === "script") return {
|
|
386
|
-
resource: !!(desc.props && "src" in desc.props)
|
|
387
|
-
};
|
|
388
|
-
return {
|
|
389
|
-
resource: false
|
|
390
|
-
};
|
|
391
|
-
}
|
|
392
|
-
function resourceIdentity(tag, props) {
|
|
393
|
-
let id = "res:" + tag + ":" + (props.rel || "") + ":" + (props.href || props.src || "");
|
|
394
|
-
for (let i = 0; i < RESOURCE_QUALIFIERS.length; i++) {
|
|
395
|
-
const q = RESOURCE_QUALIFIERS[i];
|
|
396
|
-
if (props[q] != null) id += ":" + q + "=" + props[q];
|
|
397
|
-
}
|
|
398
|
-
return id;
|
|
399
|
-
}
|
|
400
|
-
function replaceableIdentity(tag, props, key, unique) {
|
|
401
|
-
if (tag === "title") return "title";
|
|
402
|
-
if (tag === "base") return "base";
|
|
403
|
-
if (tag === "meta" && props.charset != null) return "charset";
|
|
404
|
-
if (key != null) return tag + ":key:" + key;
|
|
405
|
-
if (tag === "meta") {
|
|
406
|
-
for (const ns of ["name", "property", "http-equiv"]) if (props[ns] != null) return "meta:" + ns + ":" + props[ns] + (props.media != null ? ":media=" + props.media : "");
|
|
407
|
-
return unique;
|
|
408
|
-
}
|
|
409
|
-
if (tag === "link") {
|
|
410
|
-
const rel = props.rel || "";
|
|
411
|
-
if (rel === "icon" || rel === "apple-touch-icon") return "link:" + rel + (props.sizes != null ? ":sizes=" + props.sizes : "") + (props.type != null ? ":type=" + props.type : "");
|
|
412
|
-
return "link:" + rel + ":" + (props.href || "");
|
|
413
|
-
}
|
|
414
|
-
return unique;
|
|
415
|
-
}
|
|
416
|
-
function resolveHead(groups) {
|
|
417
|
-
const winners = new Map();
|
|
418
|
-
const sorted = groups.slice().sort((a, b) => a.seq - b.seq);
|
|
419
|
-
for (let i = 0; i < sorted.length; i++) {
|
|
420
|
-
const group = sorted[i];
|
|
421
|
-
const byIdentity = new Map();
|
|
422
|
-
for (let j = 0; j < group.tags.length; j++) {
|
|
423
|
-
const t = group.tags[j];
|
|
424
|
-
let list = byIdentity.get(t.identity);
|
|
425
|
-
if (!list) byIdentity.set(t.identity, list = []);
|
|
426
|
-
list.push(t);
|
|
427
|
-
}
|
|
428
|
-
for (const [identity, tags] of byIdentity) {
|
|
429
|
-
if (identity === "title") {
|
|
430
|
-
winners.set(identity, {
|
|
431
|
-
seq: group.seq,
|
|
432
|
-
tags: [tags[tags.length - 1]]
|
|
433
|
-
});
|
|
434
|
-
} else {
|
|
435
|
-
winners.set(identity, {
|
|
436
|
-
seq: group.seq,
|
|
437
|
-
tags
|
|
438
|
-
});
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
return winners;
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
function joinAssetPath(base, file) {
|
|
446
|
-
if (/^(?:[a-z][a-z0-9+.-]*:)?\/\//i.test(file)) return file;
|
|
447
|
-
if (typeof base !== "string" || !base) base = "/";
|
|
448
|
-
if (base[base.length - 1] !== "/") base += "/";
|
|
449
|
-
return base + (file[0] === "/" ? file.slice(1) : file);
|
|
450
|
-
}
|
|
451
|
-
function resolveAssets(moduleUrl, manifest) {
|
|
452
|
-
if (!manifest) return null;
|
|
453
|
-
const base = manifest._base;
|
|
454
|
-
const entry = manifest[moduleUrl];
|
|
455
|
-
if (!entry) return null;
|
|
456
|
-
const css = [];
|
|
457
|
-
const js = [];
|
|
458
|
-
const visited = new Set();
|
|
459
|
-
const walk = key => {
|
|
460
|
-
if (visited.has(key)) return;
|
|
461
|
-
visited.add(key);
|
|
462
|
-
const e = manifest[key];
|
|
463
|
-
if (!e) return;
|
|
464
|
-
js.push(joinAssetPath(base, e.file));
|
|
465
|
-
if (e.css) for (let i = 0; i < e.css.length; i++) css.push(joinAssetPath(base, e.css[i]));
|
|
466
|
-
if (e.imports) for (let i = 0; i < e.imports.length; i++) walk(e.imports[i]);
|
|
467
|
-
};
|
|
468
|
-
walk(moduleUrl);
|
|
469
|
-
return {
|
|
470
|
-
js,
|
|
471
|
-
css
|
|
472
|
-
};
|
|
473
|
-
}
|
|
474
|
-
function registerEntryAssets(manifest) {
|
|
475
|
-
if (!manifest || typeof manifest === "function" || typeof manifest.resolve === "function") return;
|
|
476
|
-
const ctx = sharedConfig.context;
|
|
477
|
-
if (!ctx?.registerAsset) return;
|
|
478
|
-
for (const key in manifest) {
|
|
479
|
-
if (manifest[key].isEntry) {
|
|
480
|
-
const assets = resolveAssets(key, manifest);
|
|
481
|
-
if (assets) {
|
|
482
|
-
for (let i = 0; i < assets.css.length; i++) ctx.registerAsset("style", assets.css[i]);
|
|
483
|
-
}
|
|
484
|
-
return;
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
function createAssetTracking() {
|
|
489
|
-
const boundaryModules = new Map();
|
|
490
|
-
const boundaryStyles = new Map();
|
|
491
|
-
const emittedAssets = new Set();
|
|
492
|
-
const inlineStyles = new Map();
|
|
493
|
-
let currentBoundaryId = null;
|
|
494
|
-
return {
|
|
495
|
-
boundaryModules,
|
|
496
|
-
boundaryStyles,
|
|
497
|
-
emittedAssets,
|
|
498
|
-
inlineStyles,
|
|
499
|
-
registerInlineStyle(desc) {
|
|
500
|
-
let entry = inlineStyles.get(desc.id);
|
|
501
|
-
if (!entry) {
|
|
502
|
-
entry = {
|
|
503
|
-
id: desc.id,
|
|
504
|
-
content: desc.content || "",
|
|
505
|
-
attrs: desc.attrs,
|
|
506
|
-
emitted: false
|
|
507
|
-
};
|
|
508
|
-
inlineStyles.set(desc.id, entry);
|
|
509
|
-
}
|
|
510
|
-
if (currentBoundaryId) {
|
|
511
|
-
let styles = boundaryStyles.get(currentBoundaryId);
|
|
512
|
-
if (!styles) {
|
|
513
|
-
styles = new Set();
|
|
514
|
-
boundaryStyles.set(currentBoundaryId, styles);
|
|
515
|
-
}
|
|
516
|
-
styles.add(entry);
|
|
517
|
-
}
|
|
518
|
-
return entry;
|
|
519
|
-
},
|
|
520
|
-
get currentBoundaryId() {
|
|
521
|
-
return currentBoundaryId;
|
|
522
|
-
},
|
|
523
|
-
set currentBoundaryId(v) {
|
|
524
|
-
currentBoundaryId = v;
|
|
525
|
-
},
|
|
526
|
-
registerModule(key, entryUrl) {
|
|
527
|
-
const id = currentBoundaryId || "";
|
|
528
|
-
let map = boundaryModules.get(id);
|
|
529
|
-
if (!map) {
|
|
530
|
-
map = {};
|
|
531
|
-
boundaryModules.set(id, map);
|
|
532
|
-
}
|
|
533
|
-
map[key] = entryUrl;
|
|
534
|
-
},
|
|
535
|
-
getBoundaryModules(id) {
|
|
536
|
-
return boundaryModules.get(id) || null;
|
|
537
|
-
},
|
|
538
|
-
getBoundaryStyles(id) {
|
|
539
|
-
return boundaryStyles.get(id) || null;
|
|
540
|
-
}
|
|
541
|
-
};
|
|
542
|
-
}
|
|
543
|
-
function warnUnresolvedModuleAssets(moduleUrl, warned) {
|
|
544
|
-
if (warned.has(moduleUrl)) return;
|
|
545
|
-
warned.add(moduleUrl);
|
|
546
|
-
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.");
|
|
547
|
-
}
|
|
548
|
-
function guardResolvedAssets(moduleUrl, result, warned) {
|
|
549
|
-
if (result && typeof result.then === "function") {
|
|
550
|
-
return result.then(assets => {
|
|
551
|
-
if (!assets || !assets.js || !assets.js.length) warnUnresolvedModuleAssets(moduleUrl, warned);
|
|
552
|
-
return assets;
|
|
553
|
-
});
|
|
554
|
-
}
|
|
555
|
-
if (!result || !result.js || !result.js.length) warnUnresolvedModuleAssets(moduleUrl, warned);
|
|
556
|
-
return result;
|
|
557
|
-
}
|
|
558
|
-
function applyAssetTracking(context, tracking, manifest, noScripts) {
|
|
559
|
-
const warned = new Set();
|
|
560
|
-
const guard = noScripts ? resolve => resolve : resolve => moduleUrl => guardResolvedAssets(moduleUrl, resolve(moduleUrl), warned);
|
|
561
|
-
Object.defineProperty(context, "_currentBoundaryId", {
|
|
562
|
-
get() {
|
|
563
|
-
return tracking.currentBoundaryId;
|
|
564
|
-
},
|
|
565
|
-
set(v) {
|
|
566
|
-
tracking.currentBoundaryId = v;
|
|
567
|
-
},
|
|
568
|
-
configurable: true,
|
|
569
|
-
enumerable: true
|
|
570
|
-
});
|
|
571
|
-
context.registerModule = tracking.registerModule;
|
|
572
|
-
context.getBoundaryModules = tracking.getBoundaryModules;
|
|
573
|
-
if (typeof manifest === "function") {
|
|
574
|
-
context.resolveAssets = guard(manifest);
|
|
575
|
-
} else if (manifest && typeof manifest.resolve === "function") {
|
|
576
|
-
context.resolveAssets = guard(key => manifest.resolve(key));
|
|
577
|
-
if (typeof manifest.resolveSync === "function") {
|
|
578
|
-
context.resolveAssetsSync = key => manifest.resolveSync(key);
|
|
579
|
-
}
|
|
580
|
-
} else if (manifest) {
|
|
581
|
-
const resolve = moduleUrl => resolveAssets(moduleUrl, manifest);
|
|
582
|
-
context.resolveAssets = guard(resolve);
|
|
583
|
-
context.resolveAssetsSync = resolve;
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
function isCssUrl(url) {
|
|
587
|
-
const q = url.search(/[?#]/);
|
|
588
|
-
return (q === -1 ? url : url.slice(0, q)).endsWith(".css");
|
|
589
|
-
}
|
|
590
|
-
function createHeadRegistry() {
|
|
591
|
-
return {
|
|
592
|
-
pending: [],
|
|
593
|
-
committed: [],
|
|
594
|
-
seq: 0,
|
|
595
|
-
uniq: 0,
|
|
596
|
-
resources: new Set(),
|
|
597
|
-
eagerHtml: "",
|
|
598
|
-
flushed: null,
|
|
599
|
-
shellFlushed: false,
|
|
600
|
-
parkedResources: []
|
|
601
|
-
};
|
|
602
|
-
}
|
|
603
|
-
function registerHeadTags(registry, context, tracking, emitResource, nonce, tags) {
|
|
604
|
-
const boundary = context._currentBoundaryId || "";
|
|
605
|
-
if (typeof tags === "function") {
|
|
606
|
-
registry.pending.push({
|
|
607
|
-
boundary,
|
|
608
|
-
list: tags,
|
|
609
|
-
resource: (desc, rel) => emitHeadResource(registry, context, tracking, emitResource, nonce, desc, rel)
|
|
610
|
-
});
|
|
611
|
-
return;
|
|
612
|
-
}
|
|
613
|
-
if (!Array.isArray(tags)) tags = [tags];
|
|
614
|
-
const probe = sharedConfig.context && sharedConfig.context._loadingPhase;
|
|
615
|
-
let replaceable = null;
|
|
616
|
-
for (let i = 0; i < tags.length; i++) {
|
|
617
|
-
const desc = tags[i];
|
|
618
|
-
if (!desc || !HEAD_ELIGIBLE_TAGS.has(desc.tag)) {
|
|
619
|
-
continue;
|
|
620
|
-
}
|
|
621
|
-
const cls = classifyHeadTag(desc);
|
|
622
|
-
if (probe && !cls.resource) {
|
|
623
|
-
try {
|
|
624
|
-
evalHeadProps(desc.props || {}, cls.rel !== undefined ? {
|
|
625
|
-
rel: cls.rel
|
|
626
|
-
} : undefined);
|
|
627
|
-
evalHeadValue(desc.key);
|
|
628
|
-
} catch (err) {
|
|
629
|
-
if (ssrHandleError(err)) throw err;
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
if (cls.resource) {
|
|
633
|
-
emitHeadResource(registry, context, tracking, emitResource, nonce, desc, cls.rel);
|
|
634
|
-
} else {
|
|
635
|
-
(replaceable || (replaceable = [])).push(cls.rel !== undefined ? {
|
|
636
|
-
tag: desc.tag,
|
|
637
|
-
props: desc.props,
|
|
638
|
-
key: desc.key,
|
|
639
|
-
rel: cls.rel
|
|
640
|
-
} : desc);
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
if (replaceable) registry.pending.push({
|
|
644
|
-
boundary,
|
|
645
|
-
tags: replaceable
|
|
646
|
-
});
|
|
647
|
-
}
|
|
648
|
-
function headShellReady(registry, block) {
|
|
649
|
-
let ready = true;
|
|
650
|
-
const pends = err => {
|
|
651
|
-
const source = ssrHandleError(err, true);
|
|
652
|
-
if (!source) return false;
|
|
653
|
-
block(source);
|
|
654
|
-
ready = false;
|
|
655
|
-
return true;
|
|
656
|
-
};
|
|
657
|
-
const parked = registry.parkedResources;
|
|
658
|
-
for (let i = parked.length - 1; i >= 0; i--) {
|
|
659
|
-
const {
|
|
660
|
-
desc,
|
|
661
|
-
rel,
|
|
662
|
-
emit
|
|
663
|
-
} = parked[i];
|
|
664
|
-
try {
|
|
665
|
-
evalHeadProps(desc.props || {}, rel !== undefined ? {
|
|
666
|
-
rel
|
|
667
|
-
} : undefined);
|
|
668
|
-
} catch (err) {
|
|
669
|
-
if (pends(err)) continue;
|
|
670
|
-
parked.splice(i, 1);
|
|
671
|
-
continue;
|
|
672
|
-
}
|
|
673
|
-
parked.splice(i, 1);
|
|
674
|
-
emit();
|
|
675
|
-
}
|
|
676
|
-
for (let i = 0; i < registry.pending.length; i++) {
|
|
677
|
-
const reg = registry.pending[i];
|
|
678
|
-
if (reg.boundary !== "" || reg.list) continue;
|
|
679
|
-
for (let j = 0; j < reg.tags.length; j++) {
|
|
680
|
-
const desc = reg.tags[j];
|
|
681
|
-
try {
|
|
682
|
-
evalHeadProps(desc.props || {}, desc.rel !== undefined ? {
|
|
683
|
-
rel: desc.rel
|
|
684
|
-
} : undefined);
|
|
685
|
-
evalHeadValue(desc.key);
|
|
686
|
-
} catch (err) {
|
|
687
|
-
pends(err);
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
return ready;
|
|
692
|
-
}
|
|
693
|
-
function emitHeadResource(registry, context, tracking, emitResource, nonce, desc, rel) {
|
|
694
|
-
let props;
|
|
695
|
-
try {
|
|
696
|
-
props = evalHeadProps(desc.props || {}, rel !== undefined ? {
|
|
697
|
-
rel
|
|
698
|
-
} : undefined);
|
|
699
|
-
} catch (err) {
|
|
700
|
-
const loadingPhase = sharedConfig.context && sharedConfig.context._loadingPhase;
|
|
701
|
-
if (loadingPhase && ssrHandleError(err)) throw err;
|
|
702
|
-
if (!loadingPhase && !context._currentBoundaryId && !registry.shellFlushed && typeof context.block === "function" && ssrHandleError(err, true)) {
|
|
703
|
-
registry.parkedResources.push({
|
|
704
|
-
desc,
|
|
705
|
-
rel,
|
|
706
|
-
emit: () => emitHeadResource(registry, context, tracking, emitResource, nonce, desc, rel)
|
|
707
|
-
});
|
|
708
|
-
return;
|
|
709
|
-
}
|
|
710
|
-
return;
|
|
711
|
-
}
|
|
712
|
-
const identity = resourceIdentity(desc.tag, props);
|
|
713
|
-
if (registry.resources.has(identity)) return;
|
|
714
|
-
registry.resources.add(identity);
|
|
715
|
-
if (desc.tag === "link" && (rel === "stylesheet" || rel === "modulepreload")) {
|
|
716
|
-
let plain = true;
|
|
717
|
-
let gateable = rel === "stylesheet";
|
|
718
|
-
for (const name in props) {
|
|
719
|
-
if (name === "rel" || name === "href") continue;
|
|
720
|
-
plain = false;
|
|
721
|
-
if (!STYLESHEET_FETCH_META.has(name)) gateable = false;
|
|
722
|
-
}
|
|
723
|
-
if (plain && props.href != null) {
|
|
724
|
-
const isCss = isCssUrl(props.href);
|
|
725
|
-
if (rel === "stylesheet" ? isCss : !isCss) {
|
|
726
|
-
context.registerAsset(rel === "stylesheet" ? "style" : "module", props.href);
|
|
727
|
-
return;
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
if (gateable && props.href != null) {
|
|
731
|
-
const attrHtml = renderHeadAttrHtml(props);
|
|
732
|
-
const entry = {
|
|
733
|
-
href: props.href,
|
|
734
|
-
attrHtml,
|
|
735
|
-
attrs: headAttrRecord(props)
|
|
736
|
-
};
|
|
737
|
-
if (tracking.currentBoundaryId) {
|
|
738
|
-
let styles = tracking.boundaryStyles.get(tracking.currentBoundaryId);
|
|
739
|
-
if (!styles) tracking.boundaryStyles.set(tracking.currentBoundaryId, styles = new Set());
|
|
740
|
-
styles.add(entry);
|
|
741
|
-
}
|
|
742
|
-
const markup = `<link${attrHtml}>`;
|
|
743
|
-
if (emitResource) emitResource(markup, entry);else {
|
|
744
|
-
registry.eagerHtml += markup;
|
|
745
|
-
entry.emitted = true;
|
|
746
|
-
}
|
|
747
|
-
return;
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
const url = props.href || props.src;
|
|
751
|
-
if (url != null && tracking.emittedAssets.has(url)) return;
|
|
752
|
-
const markup = renderHeadTagMarkup(desc.tag, props, null, nonce);
|
|
753
|
-
if (emitResource) emitResource(markup);else registry.eagerHtml += markup;
|
|
754
|
-
}
|
|
755
|
-
function commitHeadBoundary(registry, boundary, isPendingFragment) {
|
|
756
|
-
const keep = [];
|
|
757
|
-
const groups = [];
|
|
758
|
-
for (let i = 0; i < registry.pending.length; i++) {
|
|
759
|
-
const reg = registry.pending[i];
|
|
760
|
-
const mine = boundary === "" ? !(isPendingFragment && reg.boundary !== "" && isPendingFragment(reg.boundary)) : reg.boundary === boundary;
|
|
761
|
-
if (!mine) {
|
|
762
|
-
keep.push(reg);
|
|
763
|
-
continue;
|
|
764
|
-
}
|
|
765
|
-
let descs = reg.tags;
|
|
766
|
-
if (reg.list) {
|
|
767
|
-
let resolved;
|
|
768
|
-
try {
|
|
769
|
-
resolved = reg.list();
|
|
770
|
-
} catch (err) {
|
|
771
|
-
continue;
|
|
772
|
-
}
|
|
773
|
-
if (!Array.isArray(resolved)) resolved = [resolved];
|
|
774
|
-
descs = [];
|
|
775
|
-
for (let j = 0; j < resolved.length; j++) {
|
|
776
|
-
const desc = resolved[j];
|
|
777
|
-
if (!desc || !HEAD_ELIGIBLE_TAGS.has(desc.tag)) {
|
|
778
|
-
continue;
|
|
779
|
-
}
|
|
780
|
-
const cls = classifyHeadTag(desc);
|
|
781
|
-
if (cls.resource) {
|
|
782
|
-
reg.resource(desc, cls.rel);
|
|
783
|
-
} else {
|
|
784
|
-
descs.push(cls.rel !== undefined ? {
|
|
785
|
-
tag: desc.tag,
|
|
786
|
-
props: desc.props,
|
|
787
|
-
key: desc.key,
|
|
788
|
-
rel: cls.rel
|
|
789
|
-
} : desc);
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
}
|
|
793
|
-
const tags = [];
|
|
794
|
-
for (let j = 0; j < descs.length; j++) {
|
|
795
|
-
const desc = descs[j];
|
|
796
|
-
let props, key;
|
|
797
|
-
try {
|
|
798
|
-
props = evalHeadProps(desc.props || {}, desc.rel !== undefined ? {
|
|
799
|
-
rel: desc.rel
|
|
800
|
-
} : undefined);
|
|
801
|
-
key = evalHeadValue(desc.key);
|
|
802
|
-
} catch (err) {
|
|
803
|
-
continue;
|
|
804
|
-
}
|
|
805
|
-
const identity = replaceableIdentity(desc.tag, props, key, "u:" + registry.uniq++);
|
|
806
|
-
if ((identity === "base" || identity === "charset") && registry.shellFlushed) {
|
|
807
|
-
continue;
|
|
808
|
-
}
|
|
809
|
-
tags.push({
|
|
810
|
-
tag: desc.tag,
|
|
811
|
-
props,
|
|
812
|
-
identity
|
|
813
|
-
});
|
|
814
|
-
}
|
|
815
|
-
if (tags.length) groups.push({
|
|
816
|
-
seq: registry.seq++,
|
|
817
|
-
tags
|
|
818
|
-
});
|
|
819
|
-
}
|
|
820
|
-
registry.pending = keep;
|
|
821
|
-
for (let i = 0; i < groups.length; i++) registry.committed.push(groups[i]);
|
|
822
|
-
return groups;
|
|
823
|
-
}
|
|
824
|
-
function adoptHeadBoundary(registry, childKey, parentKey) {
|
|
825
|
-
for (let i = 0; i < registry.pending.length; i++) {
|
|
826
|
-
if (registry.pending[i].boundary === childKey) registry.pending[i].boundary = parentKey;
|
|
827
|
-
}
|
|
828
|
-
}
|
|
829
|
-
function dropHeadBoundary(registry, boundary) {
|
|
830
|
-
registry.pending = registry.pending.filter(reg => reg.boundary !== boundary);
|
|
831
|
-
}
|
|
832
|
-
function headGroupSignature(winner) {
|
|
833
|
-
let sig = "" + winner.seq;
|
|
834
|
-
for (let i = 0; i < winner.tags.length; i++) {
|
|
835
|
-
const t = winner.tags[i];
|
|
836
|
-
sig += "|" + t.tag + JSON.stringify(t.props);
|
|
837
|
-
}
|
|
838
|
-
return sig;
|
|
839
|
-
}
|
|
840
|
-
function renderShellHead(registry, nonce, isPendingFragment) {
|
|
841
|
-
commitHeadBoundary(registry, "", isPendingFragment);
|
|
842
|
-
registry.shellFlushed = true;
|
|
843
|
-
const winners = resolveHead(registry.committed);
|
|
844
|
-
registry.flushed = new Map();
|
|
845
|
-
let prelude = "";
|
|
846
|
-
let links = "";
|
|
847
|
-
let metas = "";
|
|
848
|
-
let others = "";
|
|
849
|
-
let scripts = "";
|
|
850
|
-
for (const [identity, winner] of winners) {
|
|
851
|
-
registry.flushed.set(identity, headGroupSignature(winner));
|
|
852
|
-
for (let i = 0; i < winner.tags.length; i++) {
|
|
853
|
-
const t = winner.tags[i];
|
|
854
|
-
const markup = renderHeadTagMarkup(t.tag, t.props, identity, nonce);
|
|
855
|
-
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;
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
return {
|
|
859
|
-
prelude,
|
|
860
|
-
html: registry.eagerHtml + links + metas + others + scripts
|
|
861
|
-
};
|
|
862
|
-
}
|
|
863
|
-
function flushHeadFragment(registry, boundary) {
|
|
864
|
-
const groups = commitHeadBoundary(registry, boundary);
|
|
865
|
-
if (!groups.length) return null;
|
|
866
|
-
const winners = resolveHead(registry.committed);
|
|
867
|
-
const affected = new Set();
|
|
868
|
-
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);
|
|
869
|
-
const ops = [];
|
|
870
|
-
for (const identity of affected) {
|
|
871
|
-
const winner = winners.get(identity);
|
|
872
|
-
const sig = headGroupSignature(winner);
|
|
873
|
-
if (registry.flushed.get(identity) === sig) continue;
|
|
874
|
-
const existed = registry.flushed.has(identity);
|
|
875
|
-
registry.flushed.set(identity, sig);
|
|
876
|
-
if (identity === "title") {
|
|
877
|
-
const children = winner.tags[0].props.children;
|
|
878
|
-
ops.push(["t", children == null ? "" : String(children)]);
|
|
879
|
-
continue;
|
|
880
|
-
}
|
|
881
|
-
if (existed) ops.push(["r", identity]);
|
|
882
|
-
for (let i = 0; i < winner.tags.length; i++) {
|
|
883
|
-
const t = winner.tags[i];
|
|
884
|
-
const attrs = {};
|
|
885
|
-
for (const name in t.props) {
|
|
886
|
-
if (name === "children" || name === "ref" || name.slice(0, 2) === "on") continue;
|
|
887
|
-
if (!HEAD_ATTR_NAME.test(name)) {
|
|
888
|
-
continue;
|
|
889
|
-
}
|
|
890
|
-
const v = t.props[name];
|
|
891
|
-
if (v == null || v === false) continue;
|
|
892
|
-
attrs[name] = v === true ? "" : String(v);
|
|
893
|
-
}
|
|
894
|
-
const children = t.props.children;
|
|
895
|
-
ops.push(["a", identity, t.tag, attrs, children == null ? null : String(children)]);
|
|
896
|
-
}
|
|
897
|
-
}
|
|
898
|
-
return ops.length ? ops : null;
|
|
899
|
-
}
|
|
900
|
-
function renderHeadAttrHtml(props) {
|
|
901
|
-
let attrs = "";
|
|
902
|
-
for (const name in props) {
|
|
903
|
-
if (name === "children" || name === "ref" || name.slice(0, 2) === "on") continue;
|
|
904
|
-
if (!HEAD_ATTR_NAME.test(name)) {
|
|
905
|
-
continue;
|
|
906
|
-
}
|
|
907
|
-
const v = props[name];
|
|
908
|
-
if (v == null || v === false) continue;
|
|
909
|
-
attrs += v === true ? ` ${name}` : ` ${name}="${escape(String(v), true)}"`;
|
|
910
|
-
}
|
|
911
|
-
return attrs;
|
|
912
|
-
}
|
|
913
|
-
function headAttrRecord(props, skipRelHref) {
|
|
914
|
-
let attrs = null;
|
|
915
|
-
for (const name in props) {
|
|
916
|
-
if (name === "children" || name === "ref" || name.slice(0, 2) === "on") continue;
|
|
917
|
-
if ((name === "rel" || name === "href")) continue;
|
|
918
|
-
if (!HEAD_ATTR_NAME.test(name)) continue;
|
|
919
|
-
const v = props[name];
|
|
920
|
-
if (v == null || v === false) continue;
|
|
921
|
-
(attrs || (attrs = {}))[name] = v === true ? "" : String(v);
|
|
922
|
-
}
|
|
923
|
-
return attrs;
|
|
924
|
-
}
|
|
925
|
-
function renderHeadTagMarkup(tag, props, identity, nonce) {
|
|
926
|
-
let attrs = renderHeadAttrHtml(props);
|
|
927
|
-
if (identity != null) attrs += ` data-dh="${escape(identity, true)}"`;
|
|
928
|
-
if (nonce && (tag === "script" || tag === "style")) attrs += ` nonce="${nonce}"`;
|
|
929
|
-
if (tag === "meta" || tag === "link" || tag === "base") return `<${tag}${attrs}>`;
|
|
930
|
-
let body = props.children == null ? "" : String(props.children);
|
|
931
|
-
if (tag === "script") body = body.replace(/<\/(script)/gi, "<\\/$1");else if (tag === "style") body = escapeStyleContent(body);else body = escape(body);
|
|
932
|
-
return `<${tag}${attrs}>${body}</${tag}>`;
|
|
933
|
-
}
|
|
934
|
-
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])}`;
|
|
935
|
-
const HEAD_SCRIPT = `function $dha(o,i,e,n){for(i=0;i<o.length;i++)e=o[i],"t"==e[0]?((n=document.querySelector("title"))||(n=document.createElement("title"),document.head.appendChild(n)),n.textContent=e[1],n.setAttribute("data-dh","title")):"r"==e[0]?$dhr(e[1]):(n=document.createElement(e[2]),Object.keys(e[3]).forEach(function(a){n.setAttribute(a,e[3][a])}),null!=e[4]&&(n.textContent=e[4]),n.setAttribute("data-dh",e[1]),document.head.appendChild(n))}function $dhr(v,l,i){for(l=document.head.querySelectorAll("[data-dh]"),i=0;i<l.length;i++)l[i].getAttribute("data-dh")==v&&l[i].remove()}function $dh(o){_$HY.h?_$HY.h(o):$dha(o)}`;
|
|
936
|
-
function renderToStream(code, options = {}) {
|
|
937
|
-
let {
|
|
938
|
-
nonce,
|
|
939
|
-
onCompleteShell,
|
|
940
|
-
onCompleteAll,
|
|
941
|
-
renderId = "",
|
|
942
|
-
noScripts,
|
|
943
|
-
manifest,
|
|
944
|
-
onHead
|
|
945
|
-
} = options;
|
|
946
|
-
let dispose;
|
|
947
|
-
let dead = false;
|
|
948
|
-
const abandon = () => {
|
|
949
|
-
if (dead) return;
|
|
950
|
-
dead = true;
|
|
951
|
-
completed = true;
|
|
952
|
-
buffer = {
|
|
953
|
-
write() {}
|
|
954
|
-
};
|
|
955
|
-
writable = {
|
|
956
|
-
end() {}
|
|
957
|
-
};
|
|
958
|
-
if (dispose) {
|
|
959
|
-
const d = dispose;
|
|
960
|
-
dispose = () => {};
|
|
961
|
-
d();
|
|
962
|
-
}
|
|
963
|
-
};
|
|
964
|
-
const failRender = err => {
|
|
965
|
-
try {
|
|
966
|
-
options.onError ? options.onError(err) : console.error(err);
|
|
967
|
-
} catch (_) {}
|
|
968
|
-
abandon();
|
|
969
|
-
};
|
|
970
|
-
const guardSink = w => ({
|
|
971
|
-
write(payload) {
|
|
972
|
-
if (dead) return;
|
|
973
|
-
try {
|
|
974
|
-
w.write(payload);
|
|
975
|
-
} catch (_) {
|
|
976
|
-
abandon();
|
|
977
|
-
}
|
|
978
|
-
},
|
|
979
|
-
end() {
|
|
980
|
-
if (dead) return;
|
|
981
|
-
try {
|
|
982
|
-
w.end();
|
|
983
|
-
} catch (_) {
|
|
984
|
-
abandon();
|
|
985
|
-
}
|
|
986
|
-
}
|
|
987
|
-
});
|
|
988
|
-
const blockingPromises = new Set();
|
|
989
|
-
let headerEmitted = false;
|
|
990
|
-
const pushTask = task => {
|
|
991
|
-
if (noScripts) return;
|
|
992
|
-
if (!headerEmitted) {
|
|
993
|
-
headerEmitted = true;
|
|
994
|
-
tasks += getLocalHeaderScript(renderId);
|
|
995
|
-
}
|
|
996
|
-
tasks += task + ";";
|
|
997
|
-
if (!timer && firstFlushed) {
|
|
998
|
-
timer = true;
|
|
999
|
-
queue(() => queue(writeTasks));
|
|
1000
|
-
}
|
|
1001
|
-
};
|
|
1002
|
-
const onDone = () => {
|
|
1003
|
-
writeTasks();
|
|
1004
|
-
doShell();
|
|
1005
|
-
onCompleteAll && onCompleteAll({
|
|
1006
|
-
write(v) {
|
|
1007
|
-
!completed && buffer.write(v);
|
|
1008
|
-
}
|
|
1009
|
-
});
|
|
1010
|
-
writable && writable.end();
|
|
1011
|
-
completed = true;
|
|
1012
|
-
if (firstFlushed) dispose();
|
|
1013
|
-
};
|
|
1014
|
-
const sink = {
|
|
1015
|
-
data(payload) {
|
|
1016
|
-
pushTask(payload);
|
|
1017
|
-
},
|
|
1018
|
-
fragment(key, value, meta) {
|
|
1019
|
-
const deferActivation = !!meta.revealGroup;
|
|
1020
|
-
const styles = meta.styles;
|
|
1021
|
-
for (let i = 0; i < styles.inline.length; i++) {
|
|
1022
|
-
buffer.write(renderInlineStyle(styles.inline[i], nonce));
|
|
1023
|
-
}
|
|
1024
|
-
if (styles.links.length) {
|
|
1025
|
-
emitTask(`$dfs("${key}",${styles.links.length},${deferActivation ? 1 : 0})`);
|
|
1026
|
-
writeTasks();
|
|
1027
|
-
for (const entry of styles.links) {
|
|
1028
|
-
buffer.write(typeof entry === "string" ? `<link rel="stylesheet" href="${entry}" onload="$dfc('${key}')" onerror="$dfc('${key}')">` : `<link${entry.attrHtml} onload="$dfc('${key}')" onerror="$dfc('${key}')">`);
|
|
1029
|
-
}
|
|
1030
|
-
buffer.write(`<template id="${key}">${value}</template>`);
|
|
1031
|
-
} else {
|
|
1032
|
-
buffer.write(`<template id="${key}">${value}</template>`);
|
|
1033
|
-
if (!deferActivation) {
|
|
1034
|
-
emitTask(`$df("${key}")`);
|
|
1035
|
-
}
|
|
1036
|
-
}
|
|
1037
|
-
},
|
|
1038
|
-
reveal(keys, meta) {
|
|
1039
|
-
emitTask(`${meta.fallback ? "$dflj" : "$dfj"}(${JSON.stringify(keys)})`);
|
|
1040
|
-
},
|
|
1041
|
-
asset(type, value) {
|
|
1042
|
-
if (type === "module") {
|
|
1043
|
-
buffer.write(`<link rel="modulepreload" href="${value}">`);
|
|
1044
|
-
} else if (type === "inline-style") {
|
|
1045
|
-
buffer.write(renderInlineStyle(value, nonce));
|
|
1046
|
-
} else if (type === "head-tag") {
|
|
1047
|
-
buffer.write(value);
|
|
1048
|
-
}
|
|
1049
|
-
},
|
|
1050
|
-
shell(shellHtml, meta) {
|
|
1051
|
-
buffer.write(assembleDocument(shellHtml, meta.preloads, meta.inlineStyles, meta.tasks.length ? meta.tasks : "", nonce, meta.head, onHead));
|
|
1052
|
-
},
|
|
1053
|
-
...options.sink
|
|
1054
|
-
};
|
|
1055
|
-
const serializer = (options.serializer || createHydrationSerializer)({
|
|
1056
|
-
scopeId: options.renderId,
|
|
1057
|
-
plugins: options.plugins,
|
|
1058
|
-
onData: payload => sink.data(payload),
|
|
1059
|
-
onDone,
|
|
1060
|
-
onError: options.onError
|
|
1061
|
-
});
|
|
1062
|
-
let rootAssetsSerialized = false;
|
|
1063
|
-
const serializeRootAssets = () => {
|
|
1064
|
-
if (rootAssetsSerialized) return;
|
|
1065
|
-
rootAssetsSerialized = true;
|
|
1066
|
-
serializeFragmentAssets("", tracking.boundaryModules, context, renderId);
|
|
1067
|
-
};
|
|
1068
|
-
let holds = 0;
|
|
1069
|
-
const flushEnd = () => {
|
|
1070
|
-
if (!registry.size && !holds) {
|
|
1071
|
-
serializeRootAssets();
|
|
1072
|
-
queue(() => queue(() => {
|
|
1073
|
-
if (context.live.end) {
|
|
1074
|
-
const end = context.live.end;
|
|
1075
|
-
context.live.end = null;
|
|
1076
|
-
end();
|
|
1077
|
-
}
|
|
1078
|
-
serializer.flush();
|
|
1079
|
-
}));
|
|
1080
|
-
}
|
|
1081
|
-
};
|
|
1082
|
-
const registry = new Map();
|
|
1083
|
-
const writeTasks = () => {
|
|
1084
|
-
if (tasks.length && !completed && firstFlushed) {
|
|
1085
|
-
buffer.write(`<script${nonce ? ` nonce="${nonce}"` : ""}>${tasks}</script>`);
|
|
1086
|
-
tasks = "";
|
|
1087
|
-
}
|
|
1088
|
-
timer = null;
|
|
1089
|
-
};
|
|
1090
|
-
let context;
|
|
1091
|
-
let writable;
|
|
1092
|
-
let tmp = "";
|
|
1093
|
-
let tasks = "";
|
|
1094
|
-
let firstFlushed = false;
|
|
1095
|
-
let completed = false;
|
|
1096
|
-
let shellCompleted = false;
|
|
1097
|
-
let scriptFlushed = false;
|
|
1098
|
-
let headStyles;
|
|
1099
|
-
const revealGroups = new Map();
|
|
1100
|
-
let timer = null;
|
|
1101
|
-
const emitTask = task => {
|
|
1102
|
-
pushTask(`${task}${!scriptFlushed ? ";" + REPLACE_SCRIPT : ""}`);
|
|
1103
|
-
scriptFlushed = true;
|
|
1104
|
-
};
|
|
1105
|
-
function resolveRevealKeys(groupOrKeys, release, consume) {
|
|
1106
|
-
if (Array.isArray(groupOrKeys)) return groupOrKeys.slice();
|
|
1107
|
-
let group = revealGroups.get(groupOrKeys);
|
|
1108
|
-
if (!group) {
|
|
1109
|
-
if (!release) return;
|
|
1110
|
-
group = {
|
|
1111
|
-
order: [],
|
|
1112
|
-
keys: new Set(),
|
|
1113
|
-
released: true
|
|
1114
|
-
};
|
|
1115
|
-
revealGroups.set(groupOrKeys, group);
|
|
1116
|
-
} else if (release) group.released = true;
|
|
1117
|
-
if (!group.order.length) return;
|
|
1118
|
-
const keys = group.order.slice();
|
|
1119
|
-
if (consume) revealGroups.delete(groupOrKeys);
|
|
1120
|
-
return keys;
|
|
1121
|
-
}
|
|
1122
|
-
let rootHoles = null;
|
|
1123
|
-
let nextHoleId = 0;
|
|
1124
|
-
let buffer = {
|
|
1125
|
-
write(payload) {
|
|
1126
|
-
tmp += payload;
|
|
1127
|
-
}
|
|
1128
|
-
};
|
|
1129
|
-
const tracking = createAssetTracking();
|
|
1130
|
-
const headRegistry = createHeadRegistry();
|
|
1131
|
-
let headScriptFlushed = false;
|
|
1132
|
-
const emitHeadOps = (key, ops) => {
|
|
1133
|
-
const payload = JSON.stringify(ops).replace(/</g, "\\u003C");
|
|
1134
|
-
emitTask(`${!headScriptFlushed ? HEAD_SCRIPT : ""}(_$HY.hp=_$HY.hp||{})[${JSON.stringify(key)}]=${payload}`);
|
|
1135
|
-
headScriptFlushed = true;
|
|
1136
|
-
};
|
|
1137
|
-
sharedConfig.context = context = {
|
|
1138
|
-
async: true,
|
|
1139
|
-
nonce,
|
|
1140
|
-
live: {},
|
|
1141
|
-
registerHeadTags(tags) {
|
|
1142
|
-
registerHeadTags(headRegistry, context, tracking,
|
|
1143
|
-
(markup, gateEntry) => {
|
|
1144
|
-
if (!firstFlushed) {
|
|
1145
|
-
headRegistry.eagerHtml += markup;
|
|
1146
|
-
if (gateEntry) gateEntry.emitted = true;
|
|
1147
|
-
} else if (!gateEntry || !tracking.currentBoundaryId) {
|
|
1148
|
-
sink.asset("head-tag", markup);
|
|
1149
|
-
}
|
|
1150
|
-
}, nonce, tags);
|
|
1151
|
-
},
|
|
1152
|
-
registerAsset(type, value) {
|
|
1153
|
-
if (type === "inline-style") {
|
|
1154
|
-
const entry = tracking.registerInlineStyle(value);
|
|
1155
|
-
if (firstFlushed && !tracking.currentBoundaryId && !entry.emitted) {
|
|
1156
|
-
entry.emitted = true;
|
|
1157
|
-
sink.asset("inline-style", entry);
|
|
1158
|
-
}
|
|
1159
|
-
return;
|
|
1160
|
-
}
|
|
1161
|
-
if (tracking.currentBoundaryId && type === "style") {
|
|
1162
|
-
let styles = tracking.boundaryStyles.get(tracking.currentBoundaryId);
|
|
1163
|
-
if (!styles) {
|
|
1164
|
-
styles = new Set();
|
|
1165
|
-
tracking.boundaryStyles.set(tracking.currentBoundaryId, styles);
|
|
1166
|
-
}
|
|
1167
|
-
styles.add(value);
|
|
1168
|
-
}
|
|
1169
|
-
if (!tracking.emittedAssets.has(value)) {
|
|
1170
|
-
tracking.emittedAssets.add(value);
|
|
1171
|
-
if (firstFlushed) sink.asset(type, value);
|
|
1172
|
-
}
|
|
1173
|
-
},
|
|
1174
|
-
block(p) {
|
|
1175
|
-
if (!firstFlushed) blockingPromises.add(p);
|
|
1176
|
-
},
|
|
1177
|
-
hold() {
|
|
1178
|
-
holds++;
|
|
1179
|
-
let released = false;
|
|
1180
|
-
return () => {
|
|
1181
|
-
if (released) return;
|
|
1182
|
-
released = true;
|
|
1183
|
-
holds--;
|
|
1184
|
-
if (!holds) queue(flushEnd);
|
|
1185
|
-
};
|
|
1186
|
-
},
|
|
1187
|
-
replace(id, payloadFn) {
|
|
1188
|
-
if (firstFlushed) return;
|
|
1189
|
-
const placeholder = `<!--!$${id}-->`;
|
|
1190
|
-
const first = html.indexOf(placeholder);
|
|
1191
|
-
if (first === -1) return;
|
|
1192
|
-
const last = html.indexOf(`<!--!$/${id}-->`, first + placeholder.length);
|
|
1193
|
-
html = html.slice(0, first) + resolveSSRSync(escape(payloadFn())) + html.slice(last + placeholder.length + 1);
|
|
1194
|
-
},
|
|
1195
|
-
serialize(id, p, deferStream) {
|
|
1196
|
-
if (sharedConfig.context.noHydrate) return;
|
|
1197
|
-
if (!firstFlushed && deferStream && typeof p === "object" && "then" in p) {
|
|
1198
|
-
blockingPromises.add(p);
|
|
1199
|
-
p.then(d => serializer.write(id, d)).catch(e => serializer.write(id, e));
|
|
1200
|
-
} else serializer.write(id, p);
|
|
1201
|
-
},
|
|
1202
|
-
escape: escape,
|
|
1203
|
-
resolve: resolveSSRNode,
|
|
1204
|
-
ssr: ssr,
|
|
1205
|
-
registerFragment(key, options) {
|
|
1206
|
-
const revealGroup = options && options.revealGroup;
|
|
1207
|
-
if (revealGroup) {
|
|
1208
|
-
let group = revealGroups.get(revealGroup);
|
|
1209
|
-
if (!group) {
|
|
1210
|
-
group = {
|
|
1211
|
-
order: [],
|
|
1212
|
-
keys: new Set(),
|
|
1213
|
-
released: false
|
|
1214
|
-
};
|
|
1215
|
-
revealGroups.set(revealGroup, group);
|
|
1216
|
-
}
|
|
1217
|
-
if (!group.keys.has(key)) {
|
|
1218
|
-
group.keys.add(key);
|
|
1219
|
-
group.order.push(key);
|
|
1220
|
-
}
|
|
1221
|
-
if (group.released) {
|
|
1222
|
-
throw new Error("registerFragment() for reveal group '" + revealGroup + "' was called after revealFragments(). Ensure template payload is emitted before grouped reveal.");
|
|
1223
|
-
}
|
|
1224
|
-
}
|
|
1225
|
-
if (!registry.has(key)) {
|
|
1226
|
-
let resolve, reject;
|
|
1227
|
-
const p = new Promise((r, rej) => (resolve = r, reject = rej));
|
|
1228
|
-
registry.set(key, {
|
|
1229
|
-
resolve: err => queue(() => queue(() => {
|
|
1230
|
-
err ? reject(err) : resolve(true);
|
|
1231
|
-
queue(flushEnd);
|
|
1232
|
-
}))
|
|
1233
|
-
});
|
|
1234
|
-
serializer.write(key + "_fr", p);
|
|
1235
|
-
}
|
|
1236
|
-
return (value, error) => {
|
|
1237
|
-
if (registry.has(key)) {
|
|
1238
|
-
const item = registry.get(key);
|
|
1239
|
-
registry.delete(key);
|
|
1240
|
-
if (item.children) {
|
|
1241
|
-
for (const k in item.children) {
|
|
1242
|
-
value = replacePlaceholder(value, k, item.children[k]);
|
|
1243
|
-
}
|
|
1244
|
-
}
|
|
1245
|
-
const parentKey = waitForFragments(registry, key);
|
|
1246
|
-
if (parentKey) {
|
|
1247
|
-
const parent = registry.get(parentKey);
|
|
1248
|
-
parent.children ||= {};
|
|
1249
|
-
parent.children[key] = value !== undefined ? value : "";
|
|
1250
|
-
serializeFragmentAssets(key, tracking.boundaryModules, context);
|
|
1251
|
-
propagateBoundaryStyles(key, parentKey, tracking);
|
|
1252
|
-
adoptHeadBoundary(headRegistry, key, parentKey);
|
|
1253
|
-
item.resolve();
|
|
1254
|
-
return;
|
|
1255
|
-
}
|
|
1256
|
-
if (!completed) {
|
|
1257
|
-
if (error) dropHeadBoundary(headRegistry, key);
|
|
1258
|
-
if (!firstFlushed) {
|
|
1259
|
-
queue(() => html = replacePlaceholder(html, key, value !== undefined ? value : ""));
|
|
1260
|
-
serializeFragmentAssets(key, tracking.boundaryModules, context);
|
|
1261
|
-
item.resolve(error);
|
|
1262
|
-
} else {
|
|
1263
|
-
serializeFragmentAssets(key, tracking.boundaryModules, context);
|
|
1264
|
-
const styles = collectStreamStyles(key, tracking, headStyles);
|
|
1265
|
-
const headOps = error ? null : flushHeadFragment(headRegistry, key);
|
|
1266
|
-
if (headOps) emitHeadOps(key, headOps);
|
|
1267
|
-
sink.fragment(key, value !== undefined ? value : " ", {
|
|
1268
|
-
styles,
|
|
1269
|
-
revealGroup,
|
|
1270
|
-
error
|
|
1271
|
-
});
|
|
1272
|
-
item.resolve(error);
|
|
1273
|
-
}
|
|
1274
|
-
}
|
|
1275
|
-
}
|
|
1276
|
-
return firstFlushed;
|
|
1277
|
-
};
|
|
1278
|
-
},
|
|
1279
|
-
revealFragments(groupOrKeys) {
|
|
1280
|
-
const keys = resolveRevealKeys(groupOrKeys, true, true);
|
|
1281
|
-
if (!keys) return;
|
|
1282
|
-
sink.reveal(keys, {
|
|
1283
|
-
fallback: false
|
|
1284
|
-
});
|
|
1285
|
-
},
|
|
1286
|
-
revealFallbacks(groupOrKeys) {
|
|
1287
|
-
const keys = resolveRevealKeys(groupOrKeys, false, false);
|
|
1288
|
-
if (!keys) return;
|
|
1289
|
-
sink.reveal(keys, {
|
|
1290
|
-
fallback: true
|
|
1291
|
-
});
|
|
1292
|
-
}
|
|
1293
|
-
};
|
|
1294
|
-
applyAssetTracking(context, tracking, manifest, noScripts);
|
|
1295
|
-
context.failRender = failRender;
|
|
1296
|
-
registerEntryAssets(manifest);
|
|
1297
|
-
let html = createRoot(d => {
|
|
1298
|
-
dispose = d;
|
|
1299
|
-
const res = resolveSSRNode(escape(code()));
|
|
1300
|
-
if (!res.h.length) return res.t[0];
|
|
1301
|
-
rootHoles = [];
|
|
1302
|
-
let out = res.t[0];
|
|
1303
|
-
for (let i = 0; i < res.h.length; i++) {
|
|
1304
|
-
const id = nextHoleId++;
|
|
1305
|
-
rootHoles.push({
|
|
1306
|
-
id,
|
|
1307
|
-
fn: res.h[i]
|
|
1308
|
-
});
|
|
1309
|
-
out += `<!--rh${id}-->` + res.t[i + 1];
|
|
1310
|
-
}
|
|
1311
|
-
for (const p of res.p) blockingPromises.add(p);
|
|
1312
|
-
return out;
|
|
1313
|
-
}, {
|
|
1314
|
-
id: renderId
|
|
1315
|
-
});
|
|
1316
|
-
function resolveRootHoles() {
|
|
1317
|
-
if (!rootHoles) return true;
|
|
1318
|
-
const pending = [];
|
|
1319
|
-
for (const {
|
|
1320
|
-
id,
|
|
1321
|
-
fn
|
|
1322
|
-
} of rootHoles) {
|
|
1323
|
-
const marker = `<!--rh${id}-->`;
|
|
1324
|
-
const res = resolveSSRNode(fn);
|
|
1325
|
-
if (!res.h.length) {
|
|
1326
|
-
html = html.replace(marker, res.t[0]);
|
|
1327
|
-
} else {
|
|
1328
|
-
let out = res.t[0];
|
|
1329
|
-
for (let j = 0; j < res.h.length; j++) {
|
|
1330
|
-
const newId = nextHoleId++;
|
|
1331
|
-
pending.push({
|
|
1332
|
-
id: newId,
|
|
1333
|
-
fn: res.h[j]
|
|
1334
|
-
});
|
|
1335
|
-
out += `<!--rh${newId}-->` + res.t[j + 1];
|
|
1336
|
-
}
|
|
1337
|
-
html = html.replace(marker, out);
|
|
1338
|
-
for (const p of res.p) blockingPromises.add(p);
|
|
1339
|
-
}
|
|
1340
|
-
}
|
|
1341
|
-
if (pending.length) {
|
|
1342
|
-
rootHoles = pending;
|
|
1343
|
-
return false;
|
|
1344
|
-
}
|
|
1345
|
-
rootHoles = null;
|
|
1346
|
-
return true;
|
|
1347
|
-
}
|
|
1348
|
-
function doShell() {
|
|
1349
|
-
if (shellCompleted) return;
|
|
1350
|
-
sharedConfig.context = context;
|
|
1351
|
-
if (!resolveRootHoles()) return;
|
|
1352
|
-
if (!headShellReady(headRegistry, p => blockingPromises.add(p))) return;
|
|
1353
|
-
headStyles = new Set();
|
|
1354
|
-
for (const url of tracking.emittedAssets) {
|
|
1355
|
-
if (isCssUrl(url)) headStyles.add(url);
|
|
1356
|
-
}
|
|
1357
|
-
serializeRootAssets();
|
|
1358
|
-
const head = renderShellHead(headRegistry, nonce, k => registry.has(k));
|
|
1359
|
-
sink.shell(html, {
|
|
1360
|
-
preloads: tracking.emittedAssets,
|
|
1361
|
-
inlineStyles: tracking.inlineStyles,
|
|
1362
|
-
tasks,
|
|
1363
|
-
head
|
|
1364
|
-
});
|
|
1365
|
-
tasks = "";
|
|
1366
|
-
onCompleteShell && onCompleteShell({
|
|
1367
|
-
write(v) {
|
|
1368
|
-
!completed && buffer.write(v);
|
|
1369
|
-
}
|
|
1370
|
-
});
|
|
1371
|
-
shellCompleted = true;
|
|
1372
|
-
}
|
|
1373
|
-
const MIN_DRAIN_TURNS = 8;
|
|
1374
|
-
let lastBlockingSize = -1;
|
|
1375
|
-
let lastRegistrySize = -1;
|
|
1376
|
-
let drainTurn = 0;
|
|
1377
|
-
const scheduleFlush = fn => {
|
|
1378
|
-
const attempt = () => {
|
|
1379
|
-
if (registry.size !== lastRegistrySize || drainTurn++ < MIN_DRAIN_TURNS) {
|
|
1380
|
-
if (registry.size !== lastRegistrySize) drainTurn = 0;
|
|
1381
|
-
lastRegistrySize = registry.size;
|
|
1382
|
-
queue(attempt);
|
|
1383
|
-
return;
|
|
1384
|
-
}
|
|
1385
|
-
fn();
|
|
1386
|
-
};
|
|
1387
|
-
const progressed = blockingPromises.size !== lastBlockingSize;
|
|
1388
|
-
lastBlockingSize = blockingPromises.size;
|
|
1389
|
-
lastRegistrySize = -1;
|
|
1390
|
-
drainTurn = 0;
|
|
1391
|
-
progressed ? queue(attempt) : setTimeout(attempt);
|
|
1392
|
-
};
|
|
1393
|
-
let cachedReadable;
|
|
1394
|
-
let consumer;
|
|
1395
|
-
const claimConsumer = name => {
|
|
1396
|
-
if (consumer && consumer !== name) {
|
|
1397
|
-
throw new Error(`renderToStream result was already consumed via \`${consumer}\`; cannot also consume it via \`${name}\`. Use exactly one of \`pipe\`, \`pipeTo\`, or \`readable\`.`);
|
|
1398
|
-
}
|
|
1399
|
-
consumer = name;
|
|
1400
|
-
};
|
|
1401
|
-
const pipeToImpl = w => {
|
|
1402
|
-
let resolve;
|
|
1403
|
-
const p = new Promise(r => resolve = r);
|
|
1404
|
-
function flush() {
|
|
1405
|
-
allSettled(blockingPromises).then(() => {
|
|
1406
|
-
scheduleFlush(() => {
|
|
1407
|
-
if (dead) return resolve();
|
|
1408
|
-
try {
|
|
1409
|
-
doShell();
|
|
1410
|
-
} catch (err) {
|
|
1411
|
-
failRender(err);
|
|
1412
|
-
return resolve();
|
|
1413
|
-
}
|
|
1414
|
-
if (!shellCompleted) return flush();
|
|
1415
|
-
const encoder = new TextEncoder();
|
|
1416
|
-
const writer = w.getWriter();
|
|
1417
|
-
let pendingWrites = Promise.resolve();
|
|
1418
|
-
let ended = false;
|
|
1419
|
-
const failed = () => {
|
|
1420
|
-
if (!ended) {
|
|
1421
|
-
abandon();
|
|
1422
|
-
resolve();
|
|
1423
|
-
}
|
|
1424
|
-
};
|
|
1425
|
-
writer.closed && writer.closed.catch(failed);
|
|
1426
|
-
writable = {
|
|
1427
|
-
end() {
|
|
1428
|
-
pendingWrites.then(() => {
|
|
1429
|
-
ended = true;
|
|
1430
|
-
writer.releaseLock();
|
|
1431
|
-
w.close().catch(() => {});
|
|
1432
|
-
resolve();
|
|
1433
|
-
});
|
|
1434
|
-
}
|
|
1435
|
-
};
|
|
1436
|
-
buffer = {
|
|
1437
|
-
write(payload) {
|
|
1438
|
-
pendingWrites = pendingWrites.then(() => writer.write(encoder.encode(payload))).catch(failed);
|
|
1439
|
-
}
|
|
1440
|
-
};
|
|
1441
|
-
buffer.write(tmp);
|
|
1442
|
-
firstFlushed = true;
|
|
1443
|
-
if (completed) {
|
|
1444
|
-
dispose();
|
|
1445
|
-
writable.end();
|
|
1446
|
-
} else flushEnd();
|
|
1447
|
-
});
|
|
1448
|
-
});
|
|
1449
|
-
}
|
|
1450
|
-
flush();
|
|
1451
|
-
return p;
|
|
1452
|
-
};
|
|
1453
|
-
return {
|
|
1454
|
-
then(onFulfilled, onRejected) {
|
|
1455
|
-
const p = new Promise(resolve => {
|
|
1456
|
-
function complete() {
|
|
1457
|
-
dispose();
|
|
1458
|
-
resolve(tmp);
|
|
1459
|
-
}
|
|
1460
|
-
if (onCompleteAll) {
|
|
1461
|
-
let ogComplete = onCompleteAll;
|
|
1462
|
-
onCompleteAll = options => {
|
|
1463
|
-
ogComplete(options);
|
|
1464
|
-
complete();
|
|
1465
|
-
};
|
|
1466
|
-
} else onCompleteAll = complete;
|
|
1467
|
-
function flush() {
|
|
1468
|
-
allSettled(blockingPromises).then(() => {
|
|
1469
|
-
scheduleFlush(() => {
|
|
1470
|
-
try {
|
|
1471
|
-
if (!resolveRootHoles() || !headShellReady(headRegistry, p => blockingPromises.add(p))) return flush();
|
|
1472
|
-
} catch (err) {
|
|
1473
|
-
failRender(err);
|
|
1474
|
-
return resolve(tmp);
|
|
1475
|
-
}
|
|
1476
|
-
queue(flushEnd);
|
|
1477
|
-
});
|
|
1478
|
-
});
|
|
1479
|
-
}
|
|
1480
|
-
flush();
|
|
1481
|
-
});
|
|
1482
|
-
return p.then(onFulfilled, onRejected);
|
|
1483
|
-
},
|
|
1484
|
-
pipe(w) {
|
|
1485
|
-
claimConsumer("pipe");
|
|
1486
|
-
function flush() {
|
|
1487
|
-
allSettled(blockingPromises).then(() => {
|
|
1488
|
-
scheduleFlush(() => {
|
|
1489
|
-
if (dead) return;
|
|
1490
|
-
try {
|
|
1491
|
-
doShell();
|
|
1492
|
-
} catch (err) {
|
|
1493
|
-
failRender(err);
|
|
1494
|
-
try {
|
|
1495
|
-
w.end();
|
|
1496
|
-
} catch (_) {}
|
|
1497
|
-
return;
|
|
1498
|
-
}
|
|
1499
|
-
if (!shellCompleted) return flush();
|
|
1500
|
-
buffer = writable = guardSink(w);
|
|
1501
|
-
buffer.write(tmp);
|
|
1502
|
-
firstFlushed = true;
|
|
1503
|
-
if (completed) {
|
|
1504
|
-
dispose();
|
|
1505
|
-
writable.end();
|
|
1506
|
-
} else flushEnd();
|
|
1507
|
-
});
|
|
1508
|
-
});
|
|
1509
|
-
}
|
|
1510
|
-
flush();
|
|
1511
|
-
},
|
|
1512
|
-
pipeTo(w) {
|
|
1513
|
-
claimConsumer("pipeTo");
|
|
1514
|
-
return pipeToImpl(w);
|
|
1515
|
-
},
|
|
1516
|
-
get readable() {
|
|
1517
|
-
claimConsumer("readable");
|
|
1518
|
-
if (!cachedReadable) {
|
|
1519
|
-
const t = new TransformStream();
|
|
1520
|
-
pipeToImpl(t.writable);
|
|
1521
|
-
cachedReadable = t.readable;
|
|
1522
|
-
}
|
|
1523
|
-
return cachedReadable;
|
|
1524
|
-
}
|
|
1525
|
-
};
|
|
1526
|
-
}
|
|
1527
|
-
function buildAsyncWrap(err, node) {
|
|
1528
|
-
const p = ssrHandleError(err);
|
|
1529
|
-
if (!p) return null;
|
|
1530
|
-
if (node.$rw) return {
|
|
1531
|
-
fn: node,
|
|
1532
|
-
p
|
|
1533
|
-
};
|
|
1534
|
-
const owner = getOwner();
|
|
1535
|
-
const live = sharedConfig.context && sharedConfig.context.liveHoles;
|
|
1536
|
-
const suppress = node.$lhSuppress || live && (live.suppressed || live.sweeping);
|
|
1537
|
-
if (!owner) {
|
|
1538
|
-
if (suppress) node.$lhSuppress = true;
|
|
1539
|
-
return {
|
|
1540
|
-
fn: node,
|
|
1541
|
-
p
|
|
1542
|
-
};
|
|
1543
|
-
}
|
|
1544
|
-
const fn = () => runWithOwner(owner, node);
|
|
1545
|
-
fn.$rw = true;
|
|
1546
|
-
if (suppress) fn.$lhSuppress = true;
|
|
1547
|
-
if (node.$lhSkip) fn.$lhSkip = true;
|
|
1548
|
-
if (node.$lhBinding) fn.$lhBinding = node.$lhBinding;
|
|
1549
|
-
return {
|
|
1550
|
-
fn,
|
|
1551
|
-
p
|
|
1552
|
-
};
|
|
1553
|
-
}
|
|
1554
|
-
function ssrFirstGroupHit(hole) {
|
|
1555
|
-
try {
|
|
1556
|
-
return hole();
|
|
1557
|
-
} catch (err) {
|
|
1558
|
-
return buildAsyncWrap(err, hole);
|
|
1559
|
-
}
|
|
1560
|
-
}
|
|
1561
|
-
function tryResolveFunctionHole(hole) {
|
|
1562
|
-
let value;
|
|
1563
|
-
try {
|
|
1564
|
-
value = hole();
|
|
1565
|
-
} catch (err) {
|
|
1566
|
-
return buildAsyncWrap(err, hole) || "";
|
|
1567
|
-
}
|
|
1568
|
-
const t = typeof value;
|
|
1569
|
-
if (t === "string") return value;
|
|
1570
|
-
if (t === "number") return "" + value;
|
|
1571
|
-
if (value == null || t === "boolean") return "";
|
|
1572
|
-
return tryResolveString(value);
|
|
1573
|
-
}
|
|
1574
|
-
function mergeTemplateInto(result, node) {
|
|
1575
|
-
result.t[result.t.length - 1] += node.t[0];
|
|
1576
|
-
if (node.t.length > 1) {
|
|
1577
|
-
result.t.push(...node.t.slice(1));
|
|
1578
|
-
result.h.push(...node.h);
|
|
1579
|
-
result.p.push(...node.p);
|
|
1580
|
-
}
|
|
1581
|
-
}
|
|
1582
|
-
function appendResolvedNode(result, node) {
|
|
1583
|
-
if (node.fn !== undefined) {
|
|
1584
|
-
result.h.push(node.fn);
|
|
1585
|
-
result.p.push(node.p);
|
|
1586
|
-
result.t.push("");
|
|
1587
|
-
} else if (node.merge !== undefined) mergeTemplateInto(result, node.merge);else resolveSSRNode(node.bail, result);
|
|
1588
|
-
}
|
|
1589
|
-
let _lastGroupFn = null;
|
|
1590
|
-
let _lastGroupArr = null;
|
|
1591
|
-
let _lastGroupErr = null;
|
|
1592
|
-
function ssrGroupSlot(fn, idx) {
|
|
1593
|
-
return () => {
|
|
1594
|
-
if (idx > 0 && _lastGroupFn === fn) {
|
|
1595
|
-
if (_lastGroupArr !== null) return _lastGroupArr[idx];
|
|
1596
|
-
throw _lastGroupErr;
|
|
1597
|
-
}
|
|
1598
|
-
_lastGroupFn = fn;
|
|
1599
|
-
_lastGroupArr = null;
|
|
1600
|
-
_lastGroupErr = null;
|
|
1601
|
-
try {
|
|
1602
|
-
_lastGroupArr = fn();
|
|
1603
|
-
return _lastGroupArr[idx];
|
|
1604
|
-
} catch (err) {
|
|
1605
|
-
_lastGroupErr = err;
|
|
1606
|
-
throw err;
|
|
1607
|
-
}
|
|
1608
|
-
};
|
|
1609
|
-
}
|
|
1610
|
-
const holePositionCache = new WeakMap();
|
|
1611
|
-
function holeContentPositions(t) {
|
|
1612
|
-
let cached = holePositionCache.get(t);
|
|
1613
|
-
if (cached) return cached;
|
|
1614
|
-
const pos = [];
|
|
1615
|
-
const openOff = [];
|
|
1616
|
-
const closeOff = [];
|
|
1617
|
-
let inTag = false;
|
|
1618
|
-
let quote = "";
|
|
1619
|
-
let curOpen = null;
|
|
1620
|
-
let scanningName = false;
|
|
1621
|
-
for (let i = 0; i < t.length; i++) {
|
|
1622
|
-
const seg = t[i];
|
|
1623
|
-
let close = -1;
|
|
1624
|
-
const openAtStart = inTag;
|
|
1625
|
-
let reopened = false;
|
|
1626
|
-
for (let j = 0; j < seg.length; j++) {
|
|
1627
|
-
const ch = seg[j];
|
|
1628
|
-
if (quote) {
|
|
1629
|
-
if (ch === quote) quote = "";
|
|
1630
|
-
} else if (inTag) {
|
|
1631
|
-
if (scanningName && (ch === " " || ch === "\t" || ch === "\n" || ch === ">" || ch === "/")) {
|
|
1632
|
-
scanningName = false;
|
|
1633
|
-
curOpen = {
|
|
1634
|
-
seg: i,
|
|
1635
|
-
off: j
|
|
1636
|
-
};
|
|
1637
|
-
}
|
|
1638
|
-
if (ch === '"' || ch === "'") quote = ch;else if (ch === ">") {
|
|
1639
|
-
inTag = false;
|
|
1640
|
-
if (openAtStart && !reopened && close === -1) close = j;
|
|
1641
|
-
curOpen = null;
|
|
1642
|
-
}
|
|
1643
|
-
} else if (ch === "<") {
|
|
1644
|
-
inTag = true;
|
|
1645
|
-
scanningName = true;
|
|
1646
|
-
reopened = true;
|
|
1647
|
-
curOpen = null;
|
|
1648
|
-
}
|
|
1649
|
-
}
|
|
1650
|
-
if (inTag && scanningName) {
|
|
1651
|
-
scanningName = false;
|
|
1652
|
-
curOpen = {
|
|
1653
|
-
seg: i,
|
|
1654
|
-
off: seg.length
|
|
1655
|
-
};
|
|
1656
|
-
}
|
|
1657
|
-
closeOff.push(close);
|
|
1658
|
-
openOff.push(inTag && curOpen && curOpen.seg === i ? curOpen.off : -1);
|
|
1659
|
-
if (i < t.length - 1) pos.push(!inTag);
|
|
1660
|
-
}
|
|
1661
|
-
cached = {
|
|
1662
|
-
pos,
|
|
1663
|
-
openOff,
|
|
1664
|
-
closeOff
|
|
1665
|
-
};
|
|
1666
|
-
holePositionCache.set(t, cached);
|
|
1667
|
-
return cached;
|
|
1668
|
-
}
|
|
1669
|
-
function createLiveHoles(sink, scoped) {
|
|
1670
|
-
let nextId = 0;
|
|
1671
|
-
const stamp = typeof creationStamp === "function" ? creationStamp : () => 0;
|
|
1672
|
-
const inScope = scoped && typeof inServerComponentScope === "function" ? inServerComponentScope : null;
|
|
1673
|
-
const stripMarkers = html => html.replace(/<!--lh:\/?\d+-->/g, "");
|
|
1674
|
-
function resolveHoleValue(hole) {
|
|
1675
|
-
const result = {
|
|
1676
|
-
t: [""],
|
|
1677
|
-
h: [],
|
|
1678
|
-
p: []
|
|
1679
|
-
};
|
|
1680
|
-
try {
|
|
1681
|
-
resolveSSRNode(hole(), result);
|
|
1682
|
-
} catch (err) {
|
|
1683
|
-
const wrap = buildAsyncWrap(err, hole);
|
|
1684
|
-
if (!wrap) throw err;
|
|
1685
|
-
result.h.push(wrap.fn);
|
|
1686
|
-
result.p.push(wrap.p);
|
|
1687
|
-
result.t.push("");
|
|
1688
|
-
}
|
|
1689
|
-
return result;
|
|
1690
|
-
}
|
|
1691
|
-
function closeChildren(b) {
|
|
1692
|
-
for (const c of b.children) {
|
|
1693
|
-
c.closed = true;
|
|
1694
|
-
if (c.key) sink.closeBinding(c.key);
|
|
1695
|
-
closeChildren(c);
|
|
1696
|
-
}
|
|
1697
|
-
b.children.length = 0;
|
|
1698
|
-
}
|
|
1699
|
-
const engine = {
|
|
1700
|
-
suppressed: 0,
|
|
1701
|
-
sweeping: false,
|
|
1702
|
-
parent: null,
|
|
1703
|
-
recordStamp: 0,
|
|
1704
|
-
gateHit: false,
|
|
1705
|
-
content(hole) {
|
|
1706
|
-
if (hole.$lhSuppress) {
|
|
1707
|
-
const r = {
|
|
1708
|
-
t: [""],
|
|
1709
|
-
h: [],
|
|
1710
|
-
p: []
|
|
1711
|
-
};
|
|
1712
|
-
engine.suppressed++;
|
|
1713
|
-
try {
|
|
1714
|
-
try {
|
|
1715
|
-
resolveSSRNode(hole(), r);
|
|
1716
|
-
} catch (err) {
|
|
1717
|
-
const wrap = buildAsyncWrap(err, hole);
|
|
1718
|
-
if (wrap) {
|
|
1719
|
-
r.h.push(wrap.fn);
|
|
1720
|
-
r.p.push(wrap.p);
|
|
1721
|
-
r.t.push("");
|
|
1722
|
-
}
|
|
1723
|
-
}
|
|
1724
|
-
} finally {
|
|
1725
|
-
engine.suppressed--;
|
|
1726
|
-
}
|
|
1727
|
-
const b = hole.$lhBinding;
|
|
1728
|
-
if (b && !b.closed && !r.h.length && !engine.sweeping) {
|
|
1729
|
-
b.last = stripMarkers(r.t[0]);
|
|
1730
|
-
}
|
|
1731
|
-
return r.h.length ? r : r.t[0];
|
|
1732
|
-
}
|
|
1733
|
-
if (engine.suppressed || engine.sweeping) return null;
|
|
1734
|
-
if (hole.$lhSkip) return null;
|
|
1735
|
-
if (inScope && !inScope()) return null;
|
|
1736
|
-
const recordsBefore = engine.recordStamp;
|
|
1737
|
-
const ownersBefore = stamp();
|
|
1738
|
-
const owner = getOwner();
|
|
1739
|
-
const b = {
|
|
1740
|
-
key: null,
|
|
1741
|
-
children: [],
|
|
1742
|
-
last: null,
|
|
1743
|
-
closed: false,
|
|
1744
|
-
sweep() {
|
|
1745
|
-
if (b.closed) return;
|
|
1746
|
-
const prevSweeping = engine.sweeping;
|
|
1747
|
-
engine.sweeping = true;
|
|
1748
|
-
engine.gateHit = false;
|
|
1749
|
-
const sweepOwnersBefore = stamp();
|
|
1750
|
-
let res;
|
|
1751
|
-
try {
|
|
1752
|
-
res = owner ? runWithOwner(owner, () => resolveHoleValue(hole)) : resolveHoleValue(hole);
|
|
1753
|
-
} catch (err) {
|
|
1754
|
-
b.closed = true;
|
|
1755
|
-
sink.closeBinding(b.key);
|
|
1756
|
-
sink.error(b.key, String(err && err.message || err));
|
|
1757
|
-
return;
|
|
1758
|
-
} finally {
|
|
1759
|
-
engine.sweeping = prevSweeping;
|
|
1760
|
-
}
|
|
1761
|
-
if (engine.gateHit || stamp() !== sweepOwnersBefore) {
|
|
1762
|
-
b.closed = true;
|
|
1763
|
-
sink.closeBinding(b.key);
|
|
1764
|
-
return;
|
|
1765
|
-
}
|
|
1766
|
-
if (res.h.length) return;
|
|
1767
|
-
const html = res.t[0];
|
|
1768
|
-
if (b.last === null || html === b.last) return;
|
|
1769
|
-
b.last = html;
|
|
1770
|
-
closeChildren(b);
|
|
1771
|
-
sink.hole(b.key, html);
|
|
1772
|
-
}
|
|
1773
|
-
};
|
|
1774
|
-
if (engine.parent) engine.parent.children.push(b);
|
|
1775
|
-
const prevParent = engine.parent;
|
|
1776
|
-
engine.parent = b;
|
|
1777
|
-
let value;
|
|
1778
|
-
let escalated = null;
|
|
1779
|
-
try {
|
|
1780
|
-
value = hole();
|
|
1781
|
-
} catch (err) {
|
|
1782
|
-
const wrap = buildAsyncWrap(err, hole);
|
|
1783
|
-
if (!wrap) {
|
|
1784
|
-
engine.parent = prevParent;
|
|
1785
|
-
closeChildren(b);
|
|
1786
|
-
return "";
|
|
1787
|
-
}
|
|
1788
|
-
escalated = wrap;
|
|
1789
|
-
}
|
|
1790
|
-
if (!escalated && (typeof value === "function" && value.$lhSkip || value !== null && typeof value === "object" && value.$slot)) {
|
|
1791
|
-
engine.parent = prevParent;
|
|
1792
|
-
const r = {
|
|
1793
|
-
t: [""],
|
|
1794
|
-
h: [],
|
|
1795
|
-
p: []
|
|
1796
|
-
};
|
|
1797
|
-
engine.suppressed++;
|
|
1798
|
-
try {
|
|
1799
|
-
resolveSSRNode(value, r);
|
|
1800
|
-
} finally {
|
|
1801
|
-
engine.suppressed--;
|
|
1802
|
-
}
|
|
1803
|
-
return r.h.length ? r : r.t[0];
|
|
1804
|
-
}
|
|
1805
|
-
let res;
|
|
1806
|
-
if (escalated) {
|
|
1807
|
-
closeChildren(b);
|
|
1808
|
-
escalated.fn.$lhSuppress = true;
|
|
1809
|
-
escalated.fn.$lhBinding = b;
|
|
1810
|
-
res = {
|
|
1811
|
-
t: ["", ""],
|
|
1812
|
-
h: [escalated.fn],
|
|
1813
|
-
p: [escalated.p]
|
|
1814
|
-
};
|
|
1815
|
-
} else {
|
|
1816
|
-
res = {
|
|
1817
|
-
t: [""],
|
|
1818
|
-
h: [],
|
|
1819
|
-
p: []
|
|
1820
|
-
};
|
|
1821
|
-
try {
|
|
1822
|
-
resolveSSRNode(value, res);
|
|
1823
|
-
} catch (_) {
|
|
1824
|
-
engine.parent = prevParent;
|
|
1825
|
-
closeChildren(b);
|
|
1826
|
-
return "";
|
|
1827
|
-
}
|
|
1828
|
-
}
|
|
1829
|
-
engine.parent = prevParent;
|
|
1830
|
-
if (engine.recordStamp !== recordsBefore || stamp() !== ownersBefore) {
|
|
1831
|
-
return res.h.length ? res : res.t[0];
|
|
1832
|
-
}
|
|
1833
|
-
const id = nextId++;
|
|
1834
|
-
const key = b.key = "lh:" + id;
|
|
1835
|
-
const open = `<!--lh:${id}-->`;
|
|
1836
|
-
const close = `<!--lh:/${id}-->`;
|
|
1837
|
-
if (!res.h.length) {
|
|
1838
|
-
b.last = stripMarkers(res.t[0]);
|
|
1839
|
-
sink.openBinding(key, b);
|
|
1840
|
-
return open + res.t[0] + close;
|
|
1841
|
-
}
|
|
1842
|
-
const t = res.t.slice();
|
|
1843
|
-
t[0] = open + t[0];
|
|
1844
|
-
t[t.length - 1] += close;
|
|
1845
|
-
sink.openBinding(key, b);
|
|
1846
|
-
return {
|
|
1847
|
-
t,
|
|
1848
|
-
h: res.h,
|
|
1849
|
-
p: res.p
|
|
1850
|
-
};
|
|
1851
|
-
},
|
|
1852
|
-
mint() {
|
|
1853
|
-
return nextId++;
|
|
1854
|
-
},
|
|
1855
|
-
active() {
|
|
1856
|
-
return !inScope || inScope();
|
|
1857
|
-
},
|
|
1858
|
-
attr(cap) {
|
|
1859
|
-
const owner = getOwner();
|
|
1860
|
-
const b = {
|
|
1861
|
-
key: "lha:" + cap.id,
|
|
1862
|
-
children: [],
|
|
1863
|
-
last: cap.base,
|
|
1864
|
-
closed: false,
|
|
1865
|
-
sweep() {
|
|
1866
|
-
if (b.closed) return;
|
|
1867
|
-
const prevSweeping = engine.sweeping;
|
|
1868
|
-
engine.sweeping = true;
|
|
1869
|
-
engine.gateHit = false;
|
|
1870
|
-
const sweepOwnersBefore = stamp();
|
|
1871
|
-
let html = "";
|
|
1872
|
-
try {
|
|
1873
|
-
let group = null;
|
|
1874
|
-
let groupVal = null;
|
|
1875
|
-
const run = () => {
|
|
1876
|
-
for (const part of cap.parts) {
|
|
1877
|
-
if (typeof part === "string") {
|
|
1878
|
-
html += part;
|
|
1879
|
-
continue;
|
|
1880
|
-
}
|
|
1881
|
-
let v;
|
|
1882
|
-
if (part.g) {
|
|
1883
|
-
if (group !== part.g) {
|
|
1884
|
-
group = part.g;
|
|
1885
|
-
groupVal = part.g();
|
|
1886
|
-
}
|
|
1887
|
-
v = groupVal[part.i];
|
|
1888
|
-
} else {
|
|
1889
|
-
v = part.f();
|
|
1890
|
-
}
|
|
1891
|
-
const vt = typeof v;
|
|
1892
|
-
if (vt === "string" || vt === "number") html += v;
|
|
1893
|
-
}
|
|
1894
|
-
};
|
|
1895
|
-
owner ? runWithOwner(owner, run) : run();
|
|
1896
|
-
} catch (err) {
|
|
1897
|
-
if (ssrHandleError(err, true)) return;
|
|
1898
|
-
b.closed = true;
|
|
1899
|
-
sink.closeBinding(b.key);
|
|
1900
|
-
sink.error("lha:" + cap.id, String(err && err.message || err));
|
|
1901
|
-
return;
|
|
1902
|
-
} finally {
|
|
1903
|
-
engine.sweeping = prevSweeping;
|
|
1904
|
-
}
|
|
1905
|
-
if (engine.gateHit || stamp() !== sweepOwnersBefore) {
|
|
1906
|
-
b.closed = true;
|
|
1907
|
-
sink.closeBinding(b.key);
|
|
1908
|
-
return;
|
|
1909
|
-
}
|
|
1910
|
-
if (html === b.last) return;
|
|
1911
|
-
const before = attrNames(b.last);
|
|
1912
|
-
const after = attrNames(html);
|
|
1913
|
-
const removed = before.filter(n => !after.includes(n));
|
|
1914
|
-
b.last = html;
|
|
1915
|
-
sink.attr(String(cap.id), html, removed);
|
|
1916
|
-
}
|
|
1917
|
-
};
|
|
1918
|
-
sink.openBinding(b.key, b);
|
|
1919
|
-
}
|
|
1920
|
-
};
|
|
1921
|
-
return engine;
|
|
1922
|
-
}
|
|
1923
|
-
function attrNames(text) {
|
|
1924
|
-
const names = [];
|
|
1925
|
-
const re = /(?:^|\s)([^\s=/>"']+)(?:="[^"]*")?/g;
|
|
1926
|
-
let m;
|
|
1927
|
-
while (m = re.exec(text)) names.push(m[1]);
|
|
1928
|
-
return names;
|
|
1929
|
-
}
|
|
1930
|
-
function ssr(t) {
|
|
1931
|
-
const len = arguments.length;
|
|
1932
|
-
if (len === 1) return {
|
|
1933
|
-
t
|
|
1934
|
-
};
|
|
1935
|
-
let s = t[0];
|
|
1936
|
-
let result = null;
|
|
1937
|
-
let lastGroup = null;
|
|
1938
|
-
let lastGroupVal = null;
|
|
1939
|
-
let lastGroupIdx = 0;
|
|
1940
|
-
const live = sharedConfig.context && sharedConfig.context.liveHoles;
|
|
1941
|
-
const hp = live ? holeContentPositions(t) : null;
|
|
1942
|
-
let lastOpen = null;
|
|
1943
|
-
let cap = null;
|
|
1944
|
-
if (live && hp.openOff[0] >= 0) lastOpen = {
|
|
1945
|
-
r: null,
|
|
1946
|
-
seg: -1,
|
|
1947
|
-
off: hp.openOff[0]
|
|
1948
|
-
};
|
|
1949
|
-
const captureStart = () => {
|
|
1950
|
-
if (cap) return true;
|
|
1951
|
-
if (!lastOpen || live.suppressed || live.sweeping || !live.active()) return false;
|
|
1952
|
-
if (lastOpen.r !== result || result !== null && lastOpen.seg !== result.t.length - 1) {
|
|
1953
|
-
return false;
|
|
1954
|
-
}
|
|
1955
|
-
const id = live.mint();
|
|
1956
|
-
const inject = ` data-lha="${id}"`;
|
|
1957
|
-
let prefix;
|
|
1958
|
-
if (result === null) {
|
|
1959
|
-
s = s.slice(0, lastOpen.off) + inject + s.slice(lastOpen.off);
|
|
1960
|
-
prefix = s.slice(lastOpen.off + inject.length);
|
|
1961
|
-
} else {
|
|
1962
|
-
const seg = result.t[lastOpen.seg];
|
|
1963
|
-
result.t[lastOpen.seg] = seg.slice(0, lastOpen.off) + inject + seg.slice(lastOpen.off);
|
|
1964
|
-
prefix = result.t[lastOpen.seg].slice(lastOpen.off + inject.length);
|
|
1965
|
-
}
|
|
1966
|
-
cap = {
|
|
1967
|
-
id,
|
|
1968
|
-
parts: [prefix],
|
|
1969
|
-
base: prefix
|
|
1970
|
-
};
|
|
1971
|
-
return true;
|
|
1972
|
-
};
|
|
1973
|
-
for (let i = 1; i < len; i++) {
|
|
1974
|
-
const hole = arguments[i];
|
|
1975
|
-
const ht = typeof hole;
|
|
1976
|
-
if (ht === "string") {
|
|
1977
|
-
if (result === null) s += hole;else result.t[result.t.length - 1] += hole;
|
|
1978
|
-
if (cap) {
|
|
1979
|
-
cap.parts.push(hole);
|
|
1980
|
-
cap.base += hole;
|
|
1981
|
-
}
|
|
1982
|
-
} else if (ht === "number") {
|
|
1983
|
-
if (result === null) s += hole;else result.t[result.t.length - 1] += hole;
|
|
1984
|
-
if (cap) {
|
|
1985
|
-
cap.parts.push("" + hole);
|
|
1986
|
-
cap.base += hole;
|
|
1987
|
-
}
|
|
1988
|
-
} else if (hole == null || ht === "boolean") ; else if (ht === "function" && hole.$g) {
|
|
1989
|
-
let value;
|
|
1990
|
-
let hasValue = false;
|
|
1991
|
-
if (lastGroup !== hole) {
|
|
1992
|
-
const r = ssrFirstGroupHit(hole);
|
|
1993
|
-
if (r !== null) {
|
|
1994
|
-
lastGroup = hole;
|
|
1995
|
-
lastGroupVal = r;
|
|
1996
|
-
lastGroupIdx = 0;
|
|
1997
|
-
if (!Array.isArray(r) && result === null) {
|
|
1998
|
-
result = {
|
|
1999
|
-
t: [s],
|
|
2000
|
-
h: [],
|
|
2001
|
-
p: []
|
|
2002
|
-
};
|
|
2003
|
-
s = "";
|
|
2004
|
-
}
|
|
2005
|
-
}
|
|
2006
|
-
}
|
|
2007
|
-
if (lastGroup === hole) {
|
|
2008
|
-
if (Array.isArray(lastGroupVal)) {
|
|
2009
|
-
value = lastGroupVal[lastGroupIdx++];
|
|
2010
|
-
hasValue = true;
|
|
2011
|
-
if (live && !hp.pos[i - 1] && captureStart()) {
|
|
2012
|
-
cap.parts.push({
|
|
2013
|
-
g: hole,
|
|
2014
|
-
i: lastGroupIdx - 1
|
|
2015
|
-
});
|
|
2016
|
-
}
|
|
2017
|
-
} else {
|
|
2018
|
-
cap = null;
|
|
2019
|
-
result.h.push(ssrGroupSlot(lastGroupVal.fn, lastGroupIdx++));
|
|
2020
|
-
result.p.push(lastGroupVal.p);
|
|
2021
|
-
result.t.push("");
|
|
2022
|
-
}
|
|
2023
|
-
}
|
|
2024
|
-
if (hasValue) {
|
|
2025
|
-
const vt = typeof value;
|
|
2026
|
-
if (vt === "string" || vt === "number") {
|
|
2027
|
-
if (result === null) s += value;else result.t[result.t.length - 1] += value;
|
|
2028
|
-
if (cap && !hp.pos[i - 1]) cap.base += value;
|
|
2029
|
-
} else if (value == null || vt === "boolean") ; else if (result !== null) {
|
|
2030
|
-
resolveSSRNode(value, result);
|
|
2031
|
-
} else {
|
|
2032
|
-
const rs = tryResolveString(value);
|
|
2033
|
-
if (typeof rs === "string") {
|
|
2034
|
-
s += rs;
|
|
2035
|
-
} else {
|
|
2036
|
-
result = {
|
|
2037
|
-
t: [s],
|
|
2038
|
-
h: [],
|
|
2039
|
-
p: []
|
|
2040
|
-
};
|
|
2041
|
-
s = "";
|
|
2042
|
-
if (rs.merge !== undefined) mergeTemplateInto(result, rs.merge);else resolveSSRNode(rs.bail, result);
|
|
2043
|
-
}
|
|
2044
|
-
}
|
|
2045
|
-
}
|
|
2046
|
-
} else if (ht === "function") {
|
|
2047
|
-
let liveNode = null;
|
|
2048
|
-
if (live && hp.pos[i - 1] && (liveNode = live.content(hole)) !== null) {
|
|
2049
|
-
if (typeof liveNode === "string") {
|
|
2050
|
-
if (result === null) s += liveNode;else result.t[result.t.length - 1] += liveNode;
|
|
2051
|
-
} else {
|
|
2052
|
-
if (result === null) {
|
|
2053
|
-
result = {
|
|
2054
|
-
t: [s],
|
|
2055
|
-
h: [],
|
|
2056
|
-
p: []
|
|
2057
|
-
};
|
|
2058
|
-
s = "";
|
|
2059
|
-
}
|
|
2060
|
-
resolveSSRNode(liveNode, result);
|
|
2061
|
-
}
|
|
2062
|
-
} else if (result !== null) {
|
|
2063
|
-
const inTag = live && !hp.pos[i - 1];
|
|
2064
|
-
const capturing = inTag && captureStart();
|
|
2065
|
-
const li = capturing ? result.t.length - 1 : 0;
|
|
2066
|
-
const before = capturing ? result.t[li].length : 0;
|
|
2067
|
-
if (live) live.suppressed++;
|
|
2068
|
-
try {
|
|
2069
|
-
resolveSSRNode(hole, result);
|
|
2070
|
-
} finally {
|
|
2071
|
-
if (live) live.suppressed--;
|
|
2072
|
-
}
|
|
2073
|
-
if (capturing) {
|
|
2074
|
-
if (result.t.length - 1 === li) {
|
|
2075
|
-
cap.base += result.t[li].slice(before);
|
|
2076
|
-
cap.parts.push({
|
|
2077
|
-
f: hole
|
|
2078
|
-
});
|
|
2079
|
-
} else {
|
|
2080
|
-
cap = null;
|
|
2081
|
-
}
|
|
2082
|
-
}
|
|
2083
|
-
} else {
|
|
2084
|
-
const capturing = live && !hp.pos[i - 1] && captureStart();
|
|
2085
|
-
const r = tryResolveFunctionHole(hole);
|
|
2086
|
-
if (typeof r === "string") {
|
|
2087
|
-
s += r;
|
|
2088
|
-
if (capturing) {
|
|
2089
|
-
cap.base += r;
|
|
2090
|
-
cap.parts.push({
|
|
2091
|
-
f: hole
|
|
2092
|
-
});
|
|
2093
|
-
}
|
|
2094
|
-
} else {
|
|
2095
|
-
if (capturing) cap = null;
|
|
2096
|
-
result = {
|
|
2097
|
-
t: [s],
|
|
2098
|
-
h: [],
|
|
2099
|
-
p: []
|
|
2100
|
-
};
|
|
2101
|
-
s = "";
|
|
2102
|
-
appendResolvedNode(result, r);
|
|
2103
|
-
}
|
|
2104
|
-
}
|
|
2105
|
-
} else if (result !== null) {
|
|
2106
|
-
resolveSSRNode(hole, result);
|
|
2107
|
-
} else {
|
|
2108
|
-
const r = tryResolveString(hole);
|
|
2109
|
-
if (typeof r === "string") {
|
|
2110
|
-
s += r;
|
|
2111
|
-
} else {
|
|
2112
|
-
result = {
|
|
2113
|
-
t: [s],
|
|
2114
|
-
h: [],
|
|
2115
|
-
p: []
|
|
2116
|
-
};
|
|
2117
|
-
s = "";
|
|
2118
|
-
appendResolvedNode(result, r);
|
|
2119
|
-
}
|
|
2120
|
-
}
|
|
2121
|
-
const next = t[i];
|
|
2122
|
-
if (live) {
|
|
2123
|
-
if (cap) {
|
|
2124
|
-
const co = hp.closeOff[i];
|
|
2125
|
-
if (co >= 0) {
|
|
2126
|
-
const tail = next.slice(0, co);
|
|
2127
|
-
cap.parts.push(tail);
|
|
2128
|
-
cap.base += tail;
|
|
2129
|
-
live.attr(cap);
|
|
2130
|
-
cap = null;
|
|
2131
|
-
} else {
|
|
2132
|
-
cap.parts.push(next);
|
|
2133
|
-
cap.base += next;
|
|
2134
|
-
}
|
|
2135
|
-
}
|
|
2136
|
-
if (hp.openOff[i] >= 0) {
|
|
2137
|
-
lastOpen = result === null ? {
|
|
2138
|
-
r: null,
|
|
2139
|
-
seg: -1,
|
|
2140
|
-
off: s.length + hp.openOff[i]
|
|
2141
|
-
} : {
|
|
2142
|
-
r: result,
|
|
2143
|
-
seg: result.t.length - 1,
|
|
2144
|
-
off: result.t[result.t.length - 1].length + hp.openOff[i]
|
|
2145
|
-
};
|
|
2146
|
-
}
|
|
2147
|
-
}
|
|
2148
|
-
if (result === null) s += next;else result.t[result.t.length - 1] += next;
|
|
2149
|
-
}
|
|
2150
|
-
if (result === null) return {
|
|
2151
|
-
t: s
|
|
2152
|
-
};
|
|
2153
|
-
return result;
|
|
2154
|
-
}
|
|
2155
|
-
function escape(s, attr) {
|
|
2156
|
-
const t = typeof s;
|
|
2157
|
-
if (t !== "string") {
|
|
2158
|
-
if (!attr && Array.isArray(s)) {
|
|
2159
|
-
const joined = tryJoinPlainSSRArray(s);
|
|
2160
|
-
if (joined !== undefined) return joined;
|
|
2161
|
-
s = s.slice();
|
|
2162
|
-
for (let i = 0; i < s.length; i++) s[i] = escape(s[i]);
|
|
2163
|
-
return s;
|
|
2164
|
-
}
|
|
2165
|
-
if (attr) {
|
|
2166
|
-
if (s == null || t === "boolean" || t === "number") return s;
|
|
2167
|
-
return escape(String(s), attr);
|
|
2168
|
-
}
|
|
2169
|
-
return s;
|
|
2170
|
-
}
|
|
2171
|
-
const i = s.search(attr ? ESCAPE_ATTR : ESCAPE_CONTENT);
|
|
2172
|
-
if (i < 0) return s;
|
|
2173
|
-
return escapeSlow(s, attr, i);
|
|
2174
|
-
}
|
|
2175
|
-
const ESCAPE_CONTENT = /[&<]/;
|
|
2176
|
-
const ESCAPE_ATTR = /[&"]/;
|
|
2177
|
-
function escapeSlow(s, attr, start) {
|
|
2178
|
-
const delim = attr ? '"' : "<";
|
|
2179
|
-
const delimCode = attr ? 34 : 60;
|
|
2180
|
-
const escDelim = attr ? """ : "<";
|
|
2181
|
-
const c0 = s.charCodeAt(start);
|
|
2182
|
-
let iDelim = c0 === delimCode ? start : s.indexOf(delim, start);
|
|
2183
|
-
let iAmp = c0 === 38 ? start : s.indexOf("&", start);
|
|
2184
|
-
let left = 0,
|
|
2185
|
-
out = "";
|
|
2186
|
-
while (iDelim >= 0 && iAmp >= 0) {
|
|
2187
|
-
if (iDelim < iAmp) {
|
|
2188
|
-
if (left < iDelim) out += s.substring(left, iDelim);
|
|
2189
|
-
out += escDelim;
|
|
2190
|
-
left = iDelim + 1;
|
|
2191
|
-
iDelim = s.indexOf(delim, left);
|
|
2192
|
-
} else {
|
|
2193
|
-
if (left < iAmp) out += s.substring(left, iAmp);
|
|
2194
|
-
out += "&";
|
|
2195
|
-
left = iAmp + 1;
|
|
2196
|
-
iAmp = s.indexOf("&", left);
|
|
2197
|
-
}
|
|
2198
|
-
}
|
|
2199
|
-
if (iDelim >= 0) {
|
|
2200
|
-
do {
|
|
2201
|
-
if (left < iDelim) out += s.substring(left, iDelim);
|
|
2202
|
-
out += escDelim;
|
|
2203
|
-
left = iDelim + 1;
|
|
2204
|
-
iDelim = s.indexOf(delim, left);
|
|
2205
|
-
} while (iDelim >= 0);
|
|
2206
|
-
} else while (iAmp >= 0) {
|
|
2207
|
-
if (left < iAmp) out += s.substring(left, iAmp);
|
|
2208
|
-
out += "&";
|
|
2209
|
-
left = iAmp + 1;
|
|
2210
|
-
iAmp = s.indexOf("&", left);
|
|
2211
|
-
}
|
|
2212
|
-
return left < s.length ? out + s.substring(left) : out;
|
|
2213
|
-
}
|
|
2214
|
-
function tryJoinPlainSSRArray(nodes) {
|
|
2215
|
-
if (nodes.length === 0) return undefined;
|
|
2216
|
-
let out = "";
|
|
2217
|
-
for (let i = 0, len = nodes.length; i < len; i++) {
|
|
2218
|
-
const node = nodes[i];
|
|
2219
|
-
if (node == null || typeof node !== "object" || node.h || typeof node.t !== "string") {
|
|
2220
|
-
return undefined;
|
|
2221
|
-
}
|
|
2222
|
-
out += node.t;
|
|
2223
|
-
}
|
|
2224
|
-
return out;
|
|
2225
|
-
}
|
|
2226
|
-
function queue(fn) {
|
|
2227
|
-
return Promise.resolve().then(fn);
|
|
2228
|
-
}
|
|
2229
|
-
function allSettled(promises) {
|
|
2230
|
-
let size = promises.size;
|
|
2231
|
-
return Promise.allSettled(promises).then(() => {
|
|
2232
|
-
if (promises.size !== size) return allSettled(promises);
|
|
2233
|
-
return;
|
|
2234
|
-
});
|
|
2235
|
-
}
|
|
2236
|
-
function assembleDocument(html, emittedAssets, inlineStyles, scripts, nonce, headTags, onHead) {
|
|
2237
|
-
const scriptTag = scripts ? `<script${nonce ? ` nonce="${nonce}"` : ""}>${scripts}</script>` : "";
|
|
2238
|
-
const headTagsHtml = headTags ? headTags.html : "";
|
|
2239
|
-
const headPrelude = headTags ? headTags.prelude : "";
|
|
2240
|
-
if (!onHead && !headTagsHtml && !headPrelude && !(emittedAssets && emittedAssets.size) && !(inlineStyles && inlineStyles.size)) {
|
|
2241
|
-
if (!scriptTag) return html;
|
|
2242
|
-
const xs = html.indexOf("<!--xs-->");
|
|
2243
|
-
return xs === -1 ? html + scriptTag : html.slice(0, xs) + scriptTag + html.slice(xs);
|
|
2244
|
-
}
|
|
2245
|
-
if (headPrelude) {
|
|
2246
|
-
const open = html.match(/<head(?:\s[^>]*)?>/);
|
|
2247
|
-
if (open) {
|
|
2248
|
-
const at = open.index + open[0].length;
|
|
2249
|
-
html = html.slice(0, at) + headPrelude + html.slice(at);
|
|
2250
|
-
}
|
|
2251
|
-
}
|
|
2252
|
-
const headIdx = html.indexOf("</head>");
|
|
2253
|
-
if (headIdx === -1) {
|
|
2254
|
-
if (onHead) {
|
|
2255
|
-
onHead(headPrelude + headTagsHtml + renderHeadAssets(emittedAssets, inlineStyles, nonce));
|
|
57
|
+
};
|
|
58
|
+
out[key] = next;
|
|
59
|
+
}
|
|
2256
60
|
}
|
|
2257
|
-
|
|
2258
|
-
const xs = html.indexOf("<!--xs-->");
|
|
2259
|
-
return xs === -1 ? html + scriptTag : html.slice(0, xs) + scriptTag + html.slice(xs);
|
|
61
|
+
return out;
|
|
2260
62
|
}
|
|
2261
|
-
|
|
2262
|
-
if (!scriptTag) return html.slice(0, headIdx) + head + html.slice(headIdx);
|
|
2263
|
-
const xsIdx = html.indexOf("<!--xs-->");
|
|
2264
|
-
if (xsIdx === -1) return html.slice(0, headIdx) + head + html.slice(headIdx) + scriptTag;
|
|
2265
|
-
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);
|
|
63
|
+
return value;
|
|
2266
64
|
}
|
|
2267
|
-
function
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
if (inlineStyles && inlineStyles.size) {
|
|
2275
|
-
for (const entry of inlineStyles.values()) {
|
|
2276
|
-
if (entry.emitted) continue;
|
|
2277
|
-
entry.emitted = true;
|
|
2278
|
-
head += renderInlineStyle(entry, nonce);
|
|
2279
|
-
}
|
|
65
|
+
function isShareableIterable(value) {
|
|
66
|
+
try {
|
|
67
|
+
if (value.__SEROVAL_STREAM__ === true) return false;
|
|
68
|
+
if (typeof ReadableStream !== "undefined" && value instanceof ReadableStream) return false;
|
|
69
|
+
return typeof value[Symbol.asyncIterator] === "function";
|
|
70
|
+
} catch {
|
|
71
|
+
return false;
|
|
2280
72
|
}
|
|
2281
|
-
return head;
|
|
2282
|
-
}
|
|
2283
|
-
function serializeFragmentAssets(key, boundaryModules, context, name = key) {
|
|
2284
|
-
const map = boundaryModules.get(key);
|
|
2285
|
-
if (!map || !Object.keys(map).length) return;
|
|
2286
|
-
context.serialize(name + "_assets", map);
|
|
2287
73
|
}
|
|
2288
|
-
function
|
|
2289
|
-
|
|
2290
|
-
if (
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
tracking.boundaryStyles.set(parentKey, parentStyles);
|
|
2295
|
-
}
|
|
2296
|
-
for (const url of childStyles) {
|
|
2297
|
-
parentStyles.add(url);
|
|
74
|
+
function materialize(marker) {
|
|
75
|
+
let value = state.materialized.get(marker.$tr);
|
|
76
|
+
if (value === undefined) {
|
|
77
|
+
value = state.materializeTrace(marker);
|
|
78
|
+
state.materialized.set(marker.$tr, value);
|
|
79
|
+
if (value !== null && typeof value === "object") state.materializedValues.add(value);
|
|
2298
80
|
}
|
|
81
|
+
return value;
|
|
2299
82
|
}
|
|
2300
|
-
function
|
|
2301
|
-
const
|
|
2302
|
-
const
|
|
2303
|
-
const inline = [];
|
|
2304
|
-
if (!styles) return {
|
|
2305
|
-
links,
|
|
2306
|
-
inline
|
|
2307
|
-
};
|
|
2308
|
-
for (const entry of styles) {
|
|
2309
|
-
if (typeof entry === "string") {
|
|
2310
|
-
if (!headStyles || !headStyles.has(entry)) links.push(entry);
|
|
2311
|
-
} else if (entry.emitted) {
|
|
2312
|
-
continue;
|
|
2313
|
-
} else if (entry.attrHtml !== undefined) {
|
|
2314
|
-
entry.emitted = true;
|
|
2315
|
-
links.push(entry);
|
|
2316
|
-
} else {
|
|
2317
|
-
entry.emitted = true;
|
|
2318
|
-
inline.push(entry);
|
|
2319
|
-
}
|
|
2320
|
-
}
|
|
83
|
+
function parseTrace(value, ctx) {
|
|
84
|
+
const trace = value[TRACE];
|
|
85
|
+
const sub = trace.subscribe();
|
|
2321
86
|
return {
|
|
2322
|
-
|
|
2323
|
-
|
|
87
|
+
a: trace.array ? 1 : 0,
|
|
88
|
+
i: ctx.parse(state.streamOf ? state.streamOf(sub) : sub)
|
|
2324
89
|
};
|
|
2325
90
|
}
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
}
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
const t = typeof node;
|
|
2354
|
-
if (t === "string") return node;
|
|
2355
|
-
if (t === "number") return "" + node;
|
|
2356
|
-
if (node == null || t === "boolean") return "";
|
|
2357
|
-
if (t === "object") {
|
|
2358
|
-
if (Array.isArray(node)) {
|
|
2359
|
-
const joined = tryJoinPlainSSRArray(node);
|
|
2360
|
-
if (joined !== undefined) return joined;
|
|
2361
|
-
let s = "";
|
|
2362
|
-
let prevNonObj = false;
|
|
2363
|
-
for (let i = 0, len = node.length; i < len; i++) {
|
|
2364
|
-
const item = node[i];
|
|
2365
|
-
const itemNonObj = item !== null && typeof item !== "object";
|
|
2366
|
-
if (prevNonObj && itemNonObj) s += "<!--!$-->";
|
|
2367
|
-
prevNonObj = itemNonObj;
|
|
2368
|
-
const r = tryResolveString(item);
|
|
2369
|
-
if (typeof r !== "string") return {
|
|
2370
|
-
bail: node
|
|
2371
|
-
};
|
|
2372
|
-
s += r;
|
|
2373
|
-
}
|
|
2374
|
-
return s;
|
|
2375
|
-
}
|
|
2376
|
-
if (node.h && node.h.length > 0) return {
|
|
2377
|
-
merge: node
|
|
91
|
+
const ContainerTracePlugin = {
|
|
92
|
+
tag: "solid/container-trace",
|
|
93
|
+
test(value) {
|
|
94
|
+
return value != null && typeof value === "object" && TRACE in value;
|
|
95
|
+
},
|
|
96
|
+
parse: {
|
|
97
|
+
sync() {
|
|
98
|
+
throw new Error("A reactive container can only be serialized by a streaming serializer.");
|
|
99
|
+
},
|
|
100
|
+
async async(value, ctx) {
|
|
101
|
+
const trace = value[TRACE];
|
|
102
|
+
const sub = trace.subscribe();
|
|
103
|
+
return {
|
|
104
|
+
a: trace.array ? 1 : 0,
|
|
105
|
+
i: await ctx.parse(state.streamOf ? state.streamOf(sub) : sub)
|
|
106
|
+
};
|
|
107
|
+
},
|
|
108
|
+
stream: parseTrace
|
|
109
|
+
},
|
|
110
|
+
serialize(node, ctx) {
|
|
111
|
+
return "{$tr:" + ctx.serialize(node.i) + ",$ta:" + node.a + "}";
|
|
112
|
+
},
|
|
113
|
+
deserialize(node, ctx) {
|
|
114
|
+
const iterable = ctx.deserialize(node.i);
|
|
115
|
+
const marker = {
|
|
116
|
+
$tr: iterable,
|
|
117
|
+
$ta: node.a
|
|
2378
118
|
};
|
|
2379
|
-
|
|
2380
|
-
return "";
|
|
2381
|
-
}
|
|
2382
|
-
return Array.isArray(node.t) ? node.t[0] : node.t;
|
|
119
|
+
return state.materializeTrace ? materialize(marker) : marker;
|
|
2383
120
|
}
|
|
2384
|
-
|
|
2385
|
-
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
setContainerTraceStreamMint(iterable => {
|
|
124
|
+
const stream = createStream();
|
|
125
|
+
(async () => {
|
|
2386
126
|
try {
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
127
|
+
for await (const value of iterable) stream.next(value);
|
|
128
|
+
stream.return(undefined);
|
|
129
|
+
} catch (error) {
|
|
130
|
+
stream.throw(error);
|
|
2390
131
|
}
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
132
|
+
})();
|
|
133
|
+
return stream;
|
|
134
|
+
});
|
|
135
|
+
const DEFAULT_WEB_PLUGINS = Object.freeze([AbortSignalPlugin,
|
|
136
|
+
CustomEventPlugin, DOMExceptionPlugin, EventPlugin,
|
|
137
|
+
FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin,
|
|
138
|
+
ContainerTracePlugin]);
|
|
139
|
+
function resolveSerializerPlugins(customPlugins) {
|
|
140
|
+
return customPlugins ? [...customPlugins, ...DEFAULT_WEB_PLUGINS] : [...DEFAULT_WEB_PLUGINS];
|
|
2394
141
|
}
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
142
|
+
const JSON_CODEC_DISABLED_FEATURES = Feature.RegExp;
|
|
143
|
+
const JSON_CODEC_DEPTH_LIMIT = 64;
|
|
144
|
+
function resolveCodecOptions({
|
|
145
|
+
plugins,
|
|
146
|
+
disabledFeatures,
|
|
147
|
+
depthLimit,
|
|
148
|
+
serializeErrorStacks
|
|
149
|
+
} = {}) {
|
|
150
|
+
return {
|
|
151
|
+
plugins: resolveSerializerPlugins(plugins),
|
|
152
|
+
disabledFeatures: disabledFeatures === undefined ? JSON_CODEC_DISABLED_FEATURES : disabledFeatures,
|
|
153
|
+
depthLimit: depthLimit === undefined ? JSON_CODEC_DEPTH_LIMIT : depthLimit,
|
|
154
|
+
serializeErrorStacks
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
Feature.AggregateError | Feature.BigIntTypedArray;
|
|
159
|
+
const serializeOnlyDisabledFeatures = serializeErrorStacks => (serializeErrorStacks === undefined ? process.env.NODE_ENV === "development" : serializeErrorStacks) ? 0 : Feature.ErrorPrototypeStack;
|
|
160
|
+
function createJSONSerializer({
|
|
161
|
+
onData,
|
|
162
|
+
onDone,
|
|
163
|
+
onError,
|
|
164
|
+
plugins,
|
|
165
|
+
disabledFeatures,
|
|
166
|
+
depthLimit,
|
|
167
|
+
serializeErrorStacks
|
|
168
|
+
}) {
|
|
169
|
+
const resolved = resolveCodecOptions({
|
|
170
|
+
plugins,
|
|
171
|
+
disabledFeatures,
|
|
172
|
+
depthLimit,
|
|
173
|
+
serializeErrorStacks
|
|
174
|
+
});
|
|
175
|
+
const refs = new Map();
|
|
176
|
+
const cancels = new Set();
|
|
177
|
+
let pendingWrites = 0;
|
|
178
|
+
let flushed = false;
|
|
179
|
+
let done = false;
|
|
180
|
+
const maybeDone = () => {
|
|
181
|
+
if (flushed && pendingWrites === 0 && !done) {
|
|
182
|
+
done = true;
|
|
183
|
+
onDone && onDone();
|
|
2417
184
|
}
|
|
2418
|
-
}
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
if (
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
result.t.push("");
|
|
185
|
+
};
|
|
186
|
+
return {
|
|
187
|
+
write(key, value) {
|
|
188
|
+
if (flushed) return;
|
|
189
|
+
pendingWrites++;
|
|
190
|
+
let settled = false;
|
|
191
|
+
let cancel = null;
|
|
192
|
+
const stream = toCrossJSONStream(value, {
|
|
193
|
+
refs,
|
|
194
|
+
plugins: resolved.plugins,
|
|
195
|
+
disabledFeatures: resolved.disabledFeatures | serializeOnlyDisabledFeatures(resolved.serializeErrorStacks),
|
|
196
|
+
onParse(node, initial) {
|
|
197
|
+
onData({
|
|
198
|
+
key,
|
|
199
|
+
node,
|
|
200
|
+
initial
|
|
201
|
+
});
|
|
202
|
+
},
|
|
203
|
+
onError,
|
|
204
|
+
onDone() {
|
|
205
|
+
settled = true;
|
|
206
|
+
if (cancel) cancels.delete(cancel);
|
|
207
|
+
pendingWrites--;
|
|
208
|
+
maybeDone();
|
|
2443
209
|
}
|
|
210
|
+
});
|
|
211
|
+
if (!settled) {
|
|
212
|
+
cancel = stream;
|
|
213
|
+
cancels.add(cancel);
|
|
2444
214
|
}
|
|
215
|
+
},
|
|
216
|
+
flush() {
|
|
217
|
+
flushed = true;
|
|
218
|
+
maybeDone();
|
|
219
|
+
},
|
|
220
|
+
close() {
|
|
221
|
+
flushed = true;
|
|
222
|
+
for (const cancel of cancels) cancel();
|
|
223
|
+
cancels.clear();
|
|
2445
224
|
}
|
|
2446
|
-
}
|
|
2447
|
-
return result;
|
|
225
|
+
};
|
|
2448
226
|
}
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
227
|
+
|
|
228
|
+
function records() {
|
|
229
|
+
return undefined;
|
|
230
|
+
}
|
|
231
|
+
function frameCensus(event, type, own) {
|
|
232
|
+
event.chunks++;
|
|
233
|
+
switch (type) {
|
|
234
|
+
case "html":
|
|
235
|
+
if (!own) event.regions++;else if (event.shellMs === undefined) event.shellMs = performance.now() - event.at;
|
|
236
|
+
break;
|
|
237
|
+
case "fragment":
|
|
238
|
+
event.fragments++;
|
|
239
|
+
break;
|
|
240
|
+
case "slot":
|
|
241
|
+
event.slots++;
|
|
242
|
+
break;
|
|
243
|
+
case "error":
|
|
244
|
+
event.errors++;
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
2453
247
|
}
|
|
2454
|
-
/*#__PURE__*/new Set([ERROR_HEADER, BODY_FORMAT_HEADER, SINGLE_FLIGHT_HEADER, REVALIDATE_HEADER, "Location"].map(header => header.toLowerCase()));
|
|
2455
248
|
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
249
|
+
function observeFrame(frame) {
|
|
250
|
+
const channel = records();
|
|
251
|
+
if (channel === undefined || !channel.observed("frame")) return undefined;
|
|
252
|
+
const event = {
|
|
253
|
+
side: "server",
|
|
254
|
+
id: frame.id,
|
|
255
|
+
version: frame.version,
|
|
256
|
+
at: performance.now(),
|
|
257
|
+
durationMs: 0,
|
|
258
|
+
outcome: "complete",
|
|
259
|
+
chunks: 0,
|
|
260
|
+
fragments: 0,
|
|
261
|
+
slots: 0,
|
|
262
|
+
regions: 0,
|
|
263
|
+
errors: 0
|
|
264
|
+
};
|
|
265
|
+
let settled = false;
|
|
266
|
+
return {
|
|
267
|
+
chunk(chunk) {
|
|
268
|
+
if (chunk.type === "complete") return;
|
|
269
|
+
frameCensus(event, chunk.type, chunk.id === frame.id);
|
|
270
|
+
},
|
|
271
|
+
settle(outcome, error) {
|
|
272
|
+
if (settled) return;
|
|
273
|
+
settled = true;
|
|
274
|
+
event.durationMs = performance.now() - event.at;
|
|
275
|
+
event.outcome = outcome;
|
|
276
|
+
const live = {};
|
|
277
|
+
if (outcome === "error") live.error = error;
|
|
278
|
+
channel.emit("frame", event, live);
|
|
279
|
+
}
|
|
280
|
+
};
|
|
2459
281
|
}
|
|
2460
282
|
|
|
2461
283
|
const FRAME_STREAM_HEADER = "X-Frame-Stream";
|
|
284
|
+
const FRAME_HAVE_HEADER = "X-Frame-Have";
|
|
285
|
+
const FRAME_HAVE_BUDGET = 4096;
|
|
286
|
+
function decodeHaveList(text) {
|
|
287
|
+
if (!text) return undefined;
|
|
288
|
+
const have = {};
|
|
289
|
+
let any = false;
|
|
290
|
+
for (const entry of text.split(",")) {
|
|
291
|
+
const eq = entry.indexOf("=");
|
|
292
|
+
if (eq === -1) continue;
|
|
293
|
+
const digest = entry.slice(eq + 1).trim();
|
|
294
|
+
if (!/^[0-9a-f]{16}$/.test(digest)) continue;
|
|
295
|
+
have[entry.slice(0, eq).trim()] = digest;
|
|
296
|
+
any = true;
|
|
297
|
+
}
|
|
298
|
+
return any ? have : undefined;
|
|
299
|
+
}
|
|
2462
300
|
function isFrameStreamResponse(response) {
|
|
2463
301
|
return response.headers.has(FRAME_STREAM_HEADER);
|
|
2464
302
|
}
|
|
2465
|
-
const SERVER_COMPONENT = /*#__PURE__*/Symbol.for("
|
|
2466
|
-
const SERVER_COMPONENT_SOURCE = /*#__PURE__*/Symbol.for("
|
|
2467
|
-
const SERVER_COMPONENT_ADDRESS = /*#__PURE__*/Symbol.for("
|
|
303
|
+
const SERVER_COMPONENT = /*#__PURE__*/Symbol.for("solid.server-component");
|
|
304
|
+
const SERVER_COMPONENT_SOURCE = /*#__PURE__*/Symbol.for("solid.server-component-source");
|
|
305
|
+
const SERVER_COMPONENT_ADDRESS = /*#__PURE__*/Symbol.for("solid.server-component-address");
|
|
2468
306
|
let serverComponentRegistryExpr;
|
|
2469
307
|
function setServerComponentBootstrap(resolve) {
|
|
2470
308
|
serverComponentRegistryExpr = resolve;
|
|
@@ -2476,7 +314,7 @@ function parseServerComponent(value, ctx) {
|
|
|
2476
314
|
};
|
|
2477
315
|
}
|
|
2478
316
|
const ServerComponentPlugin = {
|
|
2479
|
-
tag: "
|
|
317
|
+
tag: "solid/server-component",
|
|
2480
318
|
test(value) {
|
|
2481
319
|
return typeof value === "function" && SERVER_COMPONENT in value;
|
|
2482
320
|
},
|
|
@@ -2509,6 +347,12 @@ function flightCodec(codec) {
|
|
|
2509
347
|
};
|
|
2510
348
|
}
|
|
2511
349
|
|
|
350
|
+
const runWithHydrationScope = (id, fn) => runWithOwner(createOwner({
|
|
351
|
+
id
|
|
352
|
+
}), fn);
|
|
353
|
+
const ssrAsyncValue = value => createMemo(() => value, {
|
|
354
|
+
serialize: false
|
|
355
|
+
});
|
|
2512
356
|
const scopeStamp = typeof creationStamp === "function" ? creationStamp : () => 0;
|
|
2513
357
|
function serverOwned(render) {
|
|
2514
358
|
return NoHydration ? NoHydration({
|
|
@@ -2517,10 +361,21 @@ function serverOwned(render) {
|
|
|
2517
361
|
}
|
|
2518
362
|
}) : render();
|
|
2519
363
|
}
|
|
2520
|
-
function serverComponentScope(render) {
|
|
2521
|
-
return runInServerComponentScope ? runInServerComponentScope(render
|
|
364
|
+
function serverComponentScope(render, live = false) {
|
|
365
|
+
return runInServerComponentScope ? runInServerComponentScope(render, live ? {
|
|
366
|
+
live: true
|
|
367
|
+
} : undefined) : render();
|
|
368
|
+
}
|
|
369
|
+
const LIVE_SOURCE = Symbol.for("solid.LiveSource");
|
|
370
|
+
function wirePreload(entry) {
|
|
371
|
+
return entry.href ? {
|
|
372
|
+
href: entry.href,
|
|
373
|
+
attrs: entry.attrs
|
|
374
|
+
} : {
|
|
375
|
+
attrs: entry.attrs
|
|
376
|
+
};
|
|
2522
377
|
}
|
|
2523
|
-
const SERVER_COMPONENT_BOOTSTRAP_EXPR = "(self._$SC||(self._$SC={c:{},a:{},r(i,a){
|
|
378
|
+
const SERVER_COMPONENT_BOOTSTRAP_EXPR = "(self._$SC||(self._$SC={c:{},a:{},b:{},r(i,a){var c=this.c[i]||(this.c[i]=(p,b)=>self._$SC.impl(i,p,b));" + "if(!a)return c;this.a[a]=i;this.reg&&this.reg(a,i);" + 'return this.b[a]||(this.b[a]=Object.assign(p=>c(p,()=>a),{[Symbol.for("solid.component-binding")]:{component:c,address:a}}))}}))';
|
|
2524
379
|
const bootstrappedScripts = new WeakSet();
|
|
2525
380
|
setServerComponentBootstrap(ctx => {
|
|
2526
381
|
if (bootstrappedScripts.has(ctx)) return "self._$SC";
|
|
@@ -2528,11 +383,71 @@ setServerComponentBootstrap(ctx => {
|
|
|
2528
383
|
return SERVER_COMPONENT_BOOTSTRAP_EXPR;
|
|
2529
384
|
});
|
|
2530
385
|
const SERVER_COMPONENT_BOOTSTRAP = SERVER_COMPONENT_BOOTSTRAP_EXPR + ";";
|
|
2531
|
-
|
|
386
|
+
const HOLE_RANGE = /<!--lh:(\d+)-->([\s\S]*?)<!--lh:\/\1-->/g;
|
|
387
|
+
const SLOT_RANGE = /<!--slot:([^>]*?):start-->[\s\S]*?<!--slot:\1:end-->/g;
|
|
388
|
+
const ATTR_ADDRESS = / data-lha="([^"]*)"/g;
|
|
389
|
+
const stripHoleMarkers = html => html.replace(/<!--lh:\/?\d+-->/g, "");
|
|
390
|
+
function frameSkeleton(html) {
|
|
391
|
+
return html.replace(HOLE_RANGE, "<!--lh:$1--><!--lh:/$1-->").replace(SLOT_RANGE, "<!--slot:$1:start--><!--slot:$1:end-->");
|
|
392
|
+
}
|
|
393
|
+
function holeDigests(html, attrText, into = {}) {
|
|
394
|
+
for (const m of html.matchAll(HOLE_RANGE)) {
|
|
395
|
+
into["lh:" + m[1]] = textDigest(stripHoleMarkers(m[2]));
|
|
396
|
+
holeDigests(m[2], null, into);
|
|
397
|
+
}
|
|
398
|
+
if (attrText) {
|
|
399
|
+
for (const m of html.matchAll(ATTR_ADDRESS)) {
|
|
400
|
+
const key = "lha:" + m[1];
|
|
401
|
+
const text = attrText.get(key);
|
|
402
|
+
if (text !== undefined) into[key] = textDigest(text);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
return into;
|
|
406
|
+
}
|
|
407
|
+
function withHoles(chunk, holes) {
|
|
408
|
+
for (const _ in holes) {
|
|
409
|
+
chunk.holes = holes;
|
|
410
|
+
break;
|
|
411
|
+
}
|
|
412
|
+
return chunk;
|
|
413
|
+
}
|
|
414
|
+
function createFrameSink(emit, frame, have) {
|
|
2532
415
|
const {
|
|
2533
416
|
id,
|
|
2534
417
|
version
|
|
2535
418
|
} = frame;
|
|
419
|
+
let conditional = false;
|
|
420
|
+
const skipped = new Set();
|
|
421
|
+
const attrText = new Map();
|
|
422
|
+
const emitDiffering = html => {
|
|
423
|
+
for (const m of html.matchAll(HOLE_RANGE)) {
|
|
424
|
+
const key = "lh:" + m[1];
|
|
425
|
+
const digest = textDigest(stripHoleMarkers(m[2]));
|
|
426
|
+
if (have[key] === digest) continue;
|
|
427
|
+
emit(withHoles({
|
|
428
|
+
type: "hole",
|
|
429
|
+
id,
|
|
430
|
+
version,
|
|
431
|
+
key,
|
|
432
|
+
html: m[2],
|
|
433
|
+
digest
|
|
434
|
+
}, holeDigests(m[2], null)));
|
|
435
|
+
}
|
|
436
|
+
for (const m of html.matchAll(ATTR_ADDRESS)) {
|
|
437
|
+
const text = attrText.get("lha:" + m[1]);
|
|
438
|
+
if (text === undefined) continue;
|
|
439
|
+
const digest = textDigest(text);
|
|
440
|
+
if (have["lha:" + m[1]] === digest) continue;
|
|
441
|
+
emit({
|
|
442
|
+
type: "attr",
|
|
443
|
+
id,
|
|
444
|
+
version,
|
|
445
|
+
key: m[1],
|
|
446
|
+
attrs: text,
|
|
447
|
+
digest
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
};
|
|
2536
451
|
const styledKeys = new Set();
|
|
2537
452
|
const bindings = new Map();
|
|
2538
453
|
const sweepMinted = new Set();
|
|
@@ -2564,28 +479,43 @@ function createFrameSink(emit, frame) {
|
|
|
2564
479
|
if (!regionKeys.has(key)) regionKeys.set(key, childId);
|
|
2565
480
|
},
|
|
2566
481
|
shell(html, meta = {}) {
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
482
|
+
const digest = textDigest(frameSkeleton(html));
|
|
483
|
+
if (have && have[""] === digest) {
|
|
484
|
+
conditional = true;
|
|
485
|
+
emitDiffering(html);
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
if (meta.preloads && meta.preloads.size || meta.preloadLinks) {
|
|
2573
489
|
const chunk = {
|
|
2574
490
|
type: "assets",
|
|
2575
491
|
id,
|
|
2576
492
|
version,
|
|
2577
493
|
key: ""
|
|
2578
494
|
};
|
|
2579
|
-
if (
|
|
2580
|
-
|
|
495
|
+
if (meta.preloads && meta.preloads.size) {
|
|
496
|
+
const styles = [];
|
|
497
|
+
const modules = [];
|
|
498
|
+
for (const url of meta.preloads) {
|
|
499
|
+
(url.endsWith(".css") ? styles : modules).push(url);
|
|
500
|
+
}
|
|
501
|
+
if (styles.length) chunk.styles = styles;
|
|
502
|
+
if (modules.length) chunk.modules = modules;
|
|
503
|
+
}
|
|
504
|
+
if (meta.preloadLinks) {
|
|
505
|
+
chunk.preloads = [];
|
|
506
|
+
for (const entry of meta.preloadLinks) {
|
|
507
|
+
chunk.preloads.push(wirePreload(entry));
|
|
508
|
+
}
|
|
509
|
+
}
|
|
2581
510
|
emit(chunk);
|
|
2582
511
|
}
|
|
2583
|
-
emit({
|
|
512
|
+
emit(withHoles({
|
|
2584
513
|
type: "html",
|
|
2585
514
|
id,
|
|
2586
515
|
version,
|
|
2587
|
-
html
|
|
2588
|
-
|
|
516
|
+
html,
|
|
517
|
+
digest
|
|
518
|
+
}, holeDigests(html, attrText)));
|
|
2589
519
|
},
|
|
2590
520
|
data(record) {
|
|
2591
521
|
if (record && typeof record.key === "string" && (record.key.endsWith("_fr") || /^\d+$/.test(record.key))) {
|
|
@@ -2613,6 +543,22 @@ function createFrameSink(emit, frame) {
|
|
|
2613
543
|
},
|
|
2614
544
|
fragment(key, value, meta = {}) {
|
|
2615
545
|
const fid = frameOf(key);
|
|
546
|
+
if (conditional && fid === id && have[key] !== undefined) {
|
|
547
|
+
skipped.add(key);
|
|
548
|
+
scheduleSweep();
|
|
549
|
+
if (meta.error) {
|
|
550
|
+
emit({
|
|
551
|
+
type: "error",
|
|
552
|
+
id: fid,
|
|
553
|
+
version,
|
|
554
|
+
key,
|
|
555
|
+
error: {
|
|
556
|
+
message: String(meta.error && meta.error.message || meta.error)
|
|
557
|
+
}
|
|
558
|
+
});
|
|
559
|
+
} else emitDiffering(value);
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
2616
562
|
const links = meta.styles && meta.styles.links || [];
|
|
2617
563
|
const inline = meta.styles && meta.styles.inline || [];
|
|
2618
564
|
if (links.length || inline.length) {
|
|
@@ -2638,13 +584,14 @@ function createFrameSink(emit, frame) {
|
|
|
2638
584
|
}
|
|
2639
585
|
emit(chunk);
|
|
2640
586
|
}
|
|
2641
|
-
emit({
|
|
587
|
+
emit(withHoles({
|
|
2642
588
|
type: "fragment",
|
|
2643
589
|
id: fid,
|
|
2644
590
|
version,
|
|
2645
591
|
key,
|
|
2646
|
-
html: value
|
|
2647
|
-
|
|
592
|
+
html: value,
|
|
593
|
+
digest: textDigest(value)
|
|
594
|
+
}, holeDigests(value, attrText)));
|
|
2648
595
|
scheduleSweep();
|
|
2649
596
|
if (meta.error) {
|
|
2650
597
|
emit({
|
|
@@ -2670,6 +617,7 @@ function createFrameSink(emit, frame) {
|
|
|
2670
617
|
reveal(keys, meta = {}) {
|
|
2671
618
|
const byFrame = new Map();
|
|
2672
619
|
for (const key of keys) {
|
|
620
|
+
if (conditional && (skipped.has(key) || meta.fallback && have[key] !== undefined)) continue;
|
|
2673
621
|
const fid = frameOf(key);
|
|
2674
622
|
let group = byFrame.get(fid);
|
|
2675
623
|
if (!group) byFrame.set(fid, group = []);
|
|
@@ -2689,15 +637,24 @@ function createFrameSink(emit, frame) {
|
|
|
2689
637
|
emit(chunk);
|
|
2690
638
|
}
|
|
2691
639
|
},
|
|
2692
|
-
asset(type,
|
|
2693
|
-
if (type
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
640
|
+
asset(type, value) {
|
|
641
|
+
if (type === "module") {
|
|
642
|
+
emit({
|
|
643
|
+
type: "assets",
|
|
644
|
+
id,
|
|
645
|
+
version,
|
|
646
|
+
key: "",
|
|
647
|
+
modules: [value]
|
|
648
|
+
});
|
|
649
|
+
} else if (type === "preload") {
|
|
650
|
+
emit({
|
|
651
|
+
type: "assets",
|
|
652
|
+
id,
|
|
653
|
+
version,
|
|
654
|
+
key: "",
|
|
655
|
+
preloads: [wirePreload(value)]
|
|
656
|
+
});
|
|
657
|
+
}
|
|
2701
658
|
},
|
|
2702
659
|
end() {
|
|
2703
660
|
if (bindings.size) sweep();
|
|
@@ -2740,7 +697,8 @@ function createFrameSink(emit, frame) {
|
|
|
2740
697
|
id,
|
|
2741
698
|
version,
|
|
2742
699
|
key,
|
|
2743
|
-
html
|
|
700
|
+
html,
|
|
701
|
+
digest: textDigest(html)
|
|
2744
702
|
});
|
|
2745
703
|
},
|
|
2746
704
|
attr(key, attrs, removed) {
|
|
@@ -2749,11 +707,15 @@ function createFrameSink(emit, frame) {
|
|
|
2749
707
|
id,
|
|
2750
708
|
version,
|
|
2751
709
|
key,
|
|
2752
|
-
attrs
|
|
710
|
+
attrs,
|
|
711
|
+
digest: textDigest(attrs)
|
|
2753
712
|
};
|
|
2754
713
|
if (removed && removed.length) chunk.removed = removed;
|
|
2755
714
|
emit(chunk);
|
|
2756
715
|
},
|
|
716
|
+
attrBaseline(key, text) {
|
|
717
|
+
attrText.set(key, text);
|
|
718
|
+
},
|
|
2757
719
|
openBinding(key, b) {
|
|
2758
720
|
bindings.set(key, b);
|
|
2759
721
|
},
|
|
@@ -2786,6 +748,7 @@ function renderServerComponent(component, options = {}) {
|
|
|
2786
748
|
ctx.commit = sink.commit;
|
|
2787
749
|
ctx.commitEpoch = () => sink.epoch;
|
|
2788
750
|
ctx.liveHoles = createLiveHoles(sink);
|
|
751
|
+
ctx.claims = CLAIMS_STREAM;
|
|
2789
752
|
}
|
|
2790
753
|
return serverComponentScope(() => component(props));
|
|
2791
754
|
};
|
|
@@ -2801,9 +764,13 @@ function frameStream(makeCode, options) {
|
|
|
2801
764
|
version
|
|
2802
765
|
};
|
|
2803
766
|
function stream(w) {
|
|
2804
|
-
const
|
|
2805
|
-
const
|
|
2806
|
-
|
|
767
|
+
const observation = observeFrame(frame);
|
|
768
|
+
const emit = observation ? chunk => {
|
|
769
|
+
observation.chunk(chunk);
|
|
770
|
+
w.write(chunk);
|
|
771
|
+
} : chunk => w.write(chunk);
|
|
772
|
+
const sink = createFrameSink(emit, frame, options.resume && options.resume.have);
|
|
773
|
+
w.write({
|
|
2807
774
|
type: "start",
|
|
2808
775
|
id,
|
|
2809
776
|
version
|
|
@@ -2818,12 +785,15 @@ function frameStream(makeCode, options) {
|
|
|
2818
785
|
write() {},
|
|
2819
786
|
end() {
|
|
2820
787
|
sink.end();
|
|
788
|
+
observation && observation.settle("complete");
|
|
2821
789
|
w.end && w.end();
|
|
2822
790
|
}
|
|
2823
791
|
});
|
|
2824
792
|
} catch (err) {
|
|
2825
|
-
|
|
793
|
+
const wire = ssrSanitizeError(err, null);
|
|
794
|
+
sink.error("", wire instanceof Error ? wire.message : String(wire));
|
|
2826
795
|
sink.end();
|
|
796
|
+
observation && observation.settle("error", err);
|
|
2827
797
|
w.end && w.end();
|
|
2828
798
|
}
|
|
2829
799
|
}
|
|
@@ -2870,29 +840,15 @@ function isAsyncValue(v) {
|
|
|
2870
840
|
return !!v && typeof v === "object" && (typeof v.then === "function" || typeof v[Symbol.asyncIterator] === "function");
|
|
2871
841
|
}
|
|
2872
842
|
function tapFirstYield(iterable) {
|
|
2873
|
-
const
|
|
2874
|
-
const
|
|
843
|
+
const rest = shareAsyncIterable(iterable);
|
|
844
|
+
const iter = shareAsyncIterable(iterable)[Symbol.asyncIterator]();
|
|
845
|
+
const first = Promise.resolve(iter.next()).then(r => {
|
|
846
|
+
if (!r.done) iter.return?.();
|
|
847
|
+
return r.done ? undefined : r.value;
|
|
848
|
+
});
|
|
2875
849
|
return {
|
|
2876
|
-
first
|
|
2877
|
-
rest
|
|
2878
|
-
[Symbol.asyncIterator]() {
|
|
2879
|
-
let replayed = false;
|
|
2880
|
-
return {
|
|
2881
|
-
next: () => {
|
|
2882
|
-
if (!replayed) {
|
|
2883
|
-
replayed = true;
|
|
2884
|
-
return firstStep;
|
|
2885
|
-
}
|
|
2886
|
-
return iter.next();
|
|
2887
|
-
},
|
|
2888
|
-
return: v => iter.return ? iter.return(v) : Promise.resolve({
|
|
2889
|
-
done: true,
|
|
2890
|
-
value: v
|
|
2891
|
-
}),
|
|
2892
|
-
throw: e => iter.throw ? iter.throw(e) : Promise.reject(e)
|
|
2893
|
-
};
|
|
2894
|
-
}
|
|
2895
|
-
}
|
|
850
|
+
first,
|
|
851
|
+
rest
|
|
2896
852
|
};
|
|
2897
853
|
}
|
|
2898
854
|
function suppressedFill(render) {
|
|
@@ -3053,7 +1009,7 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
3053
1009
|
continue;
|
|
3054
1010
|
}
|
|
3055
1011
|
if (!isContainerTraced(value) && isServerContent(value)) continue;
|
|
3056
|
-
args[key] =
|
|
1012
|
+
args[key] = toBorderForm(value);
|
|
3057
1013
|
}
|
|
3058
1014
|
sharedConfig.context.serialize(`sc:slot:${frameId}:${occurrence}`, {
|
|
3059
1015
|
...args
|
|
@@ -3068,7 +1024,7 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
3068
1024
|
if (minted[key]) continue;
|
|
3069
1025
|
const ledgerKey = `${frameId}:${occurrence}:${key}`;
|
|
3070
1026
|
openArgBinding(liveArgs, ledgerKey, occurrence, key, evals[key], states[key], value => {
|
|
3071
|
-
args[key] =
|
|
1027
|
+
args[key] = toBorderForm(value);
|
|
3072
1028
|
liveArgs.slot(frameId, occurrence, {
|
|
3073
1029
|
...args
|
|
3074
1030
|
});
|
|
@@ -3079,13 +1035,14 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
3079
1035
|
return out;
|
|
3080
1036
|
};
|
|
3081
1037
|
fn.$lhSkip = true;
|
|
1038
|
+
fn[CLAIM_PROP] = prop;
|
|
3082
1039
|
getters.set(prop, fn);
|
|
3083
1040
|
}
|
|
3084
1041
|
return fn;
|
|
3085
1042
|
}
|
|
3086
1043
|
});
|
|
3087
1044
|
}
|
|
3088
|
-
const FRAME_TAG = "
|
|
1045
|
+
const FRAME_TAG = "solid-frame";
|
|
3089
1046
|
const FRAME_ID_ATTR = "data-fid";
|
|
3090
1047
|
function frameElementOpen(id) {
|
|
3091
1048
|
const escaped = sharedConfig.context ? sharedConfig.context.escape(String(id), true) : String(id);
|
|
@@ -3149,14 +1106,16 @@ function armDocumentLiveHoles(ctx) {
|
|
|
3149
1106
|
push({
|
|
3150
1107
|
type: "hole",
|
|
3151
1108
|
key,
|
|
3152
|
-
html
|
|
1109
|
+
html,
|
|
1110
|
+
digest: textDigest(html)
|
|
3153
1111
|
});
|
|
3154
1112
|
},
|
|
3155
1113
|
attr(key, attrs, removed) {
|
|
3156
1114
|
const op = {
|
|
3157
1115
|
type: "attr",
|
|
3158
1116
|
key,
|
|
3159
|
-
attrs
|
|
1117
|
+
attrs,
|
|
1118
|
+
digest: textDigest(attrs)
|
|
3160
1119
|
};
|
|
3161
1120
|
if (removed && removed.length) op.removed = removed;
|
|
3162
1121
|
push(op);
|
|
@@ -3210,8 +1169,9 @@ function frameTransformDirectResult(value, {
|
|
|
3210
1169
|
},
|
|
3211
1170
|
serverOwned(() => {
|
|
3212
1171
|
armDocumentLiveHoles(sharedConfig.context);
|
|
1172
|
+
sharedConfig.context.claims = CLAIMS_DOCUMENT;
|
|
3213
1173
|
const slotProps = createDocumentSlotProps(props, id);
|
|
3214
|
-
return serverComponentScope(() => component(slotProps));
|
|
1174
|
+
return serverComponentScope(() => component(slotProps), !!wrapped[LIVE_SOURCE]);
|
|
3215
1175
|
}), {
|
|
3216
1176
|
t: FRAME_ELEMENT_CLOSE
|
|
3217
1177
|
}];
|
|
@@ -3408,7 +1368,7 @@ function createSlotProps(sink, frame) {
|
|
|
3408
1368
|
};
|
|
3409
1369
|
} else {
|
|
3410
1370
|
const ref = `arg:${occurrence}:${key}`;
|
|
3411
|
-
ctx.serialize(ref,
|
|
1371
|
+
ctx.serialize(ref, toBorderForm(value, true));
|
|
3412
1372
|
args[key] = {
|
|
3413
1373
|
$ref: ref
|
|
3414
1374
|
};
|
|
@@ -3440,7 +1400,7 @@ function createSlotProps(sink, frame) {
|
|
|
3440
1400
|
} else {
|
|
3441
1401
|
const ref = `arg:${occurrence}:${key}@${sink.nextArgRef(ledgerKey)}`;
|
|
3442
1402
|
sink.mintRef(ref);
|
|
3443
|
-
ctx.serialize(ref,
|
|
1403
|
+
ctx.serialize(ref, toBorderForm(value));
|
|
3444
1404
|
args[key] = {
|
|
3445
1405
|
$ref: ref
|
|
3446
1406
|
};
|
|
@@ -3453,6 +1413,7 @@ function createSlotProps(sink, frame) {
|
|
|
3453
1413
|
return slotRange(occurrence);
|
|
3454
1414
|
};
|
|
3455
1415
|
fn.$lhSkip = true;
|
|
1416
|
+
fn[CLAIM_PROP] = prop;
|
|
3456
1417
|
getters.set(prop, fn);
|
|
3457
1418
|
}
|
|
3458
1419
|
return fn;
|
|
@@ -3473,38 +1434,65 @@ function serverComponentResponse(component, options = {}, init = {}) {
|
|
|
3473
1434
|
id = "",
|
|
3474
1435
|
version = 1
|
|
3475
1436
|
} = options.frame || {};
|
|
1437
|
+
const live = !!options.live;
|
|
3476
1438
|
const headers = copyInitHeaders(init.headers);
|
|
3477
|
-
headers.set("Content-Type", "application/x-frame-stream");
|
|
3478
1439
|
headers.set(FRAME_STREAM_HEADER, id);
|
|
3479
1440
|
headers.set("X-Content-Raw", "1");
|
|
1441
|
+
if (live) {
|
|
1442
|
+
headers.set("Content-Type", "text/event-stream");
|
|
1443
|
+
headers.set("Cache-Control", "no-store");
|
|
1444
|
+
headers.set("X-Accel-Buffering", "no");
|
|
1445
|
+
} else headers.set("Content-Type", "application/x-frame-stream");
|
|
1446
|
+
const frame = live ? createEventChunk : createChunk;
|
|
1447
|
+
const teardown = new AbortController();
|
|
1448
|
+
const disarm = followSignal(options.signal, teardown);
|
|
3480
1449
|
const stream = renderServerComponent(component, {
|
|
3481
1450
|
...options,
|
|
1451
|
+
signal: teardown.signal,
|
|
3482
1452
|
frame: {
|
|
3483
1453
|
id,
|
|
3484
1454
|
version
|
|
3485
1455
|
}
|
|
3486
1456
|
});
|
|
3487
1457
|
let closed = false;
|
|
1458
|
+
let stopLive = null;
|
|
3488
1459
|
const body = new ReadableStream({
|
|
3489
1460
|
start(controller) {
|
|
1461
|
+
const end = () => {
|
|
1462
|
+
if (closed) return;
|
|
1463
|
+
closed = true;
|
|
1464
|
+
disarm();
|
|
1465
|
+
if (stopLive) stopLive();
|
|
1466
|
+
try {
|
|
1467
|
+
controller.close();
|
|
1468
|
+
} catch (_) {}
|
|
1469
|
+
};
|
|
1470
|
+
if (teardown.signal.aborted) return end();
|
|
1471
|
+
teardown.signal.addEventListener("abort", end, {
|
|
1472
|
+
once: true
|
|
1473
|
+
});
|
|
1474
|
+
if (live) stopLive = armLiveBody(controller, () => {
|
|
1475
|
+
closed = true;
|
|
1476
|
+
disarm();
|
|
1477
|
+
teardown.abort();
|
|
1478
|
+
});
|
|
3490
1479
|
stream.pipe({
|
|
3491
1480
|
write(chunk) {
|
|
3492
1481
|
if (closed) return;
|
|
3493
1482
|
try {
|
|
3494
|
-
controller.enqueue(
|
|
1483
|
+
controller.enqueue(frame(JSON.stringify(chunk)));
|
|
3495
1484
|
} catch (_) {
|
|
3496
1485
|
closed = true;
|
|
3497
1486
|
}
|
|
3498
1487
|
},
|
|
3499
|
-
end
|
|
3500
|
-
if (closed) return;
|
|
3501
|
-
closed = true;
|
|
3502
|
-
controller.close();
|
|
3503
|
-
}
|
|
1488
|
+
end
|
|
3504
1489
|
});
|
|
3505
1490
|
},
|
|
3506
1491
|
cancel() {
|
|
3507
1492
|
closed = true;
|
|
1493
|
+
disarm();
|
|
1494
|
+
if (stopLive) stopLive();
|
|
1495
|
+
teardown.abort();
|
|
3508
1496
|
}
|
|
3509
1497
|
});
|
|
3510
1498
|
return new Response(body, {
|
|
@@ -3512,6 +1500,18 @@ function serverComponentResponse(component, options = {}, init = {}) {
|
|
|
3512
1500
|
headers
|
|
3513
1501
|
});
|
|
3514
1502
|
}
|
|
1503
|
+
function followSignal(upstream, controller) {
|
|
1504
|
+
if (!upstream) return () => {};
|
|
1505
|
+
if (upstream.aborted) {
|
|
1506
|
+
controller.abort(upstream.reason);
|
|
1507
|
+
return () => {};
|
|
1508
|
+
}
|
|
1509
|
+
const forward = () => controller.abort(upstream.reason);
|
|
1510
|
+
upstream.addEventListener("abort", forward, {
|
|
1511
|
+
once: true
|
|
1512
|
+
});
|
|
1513
|
+
return () => upstream.removeEventListener("abort", forward);
|
|
1514
|
+
}
|
|
3515
1515
|
function frameTransformResult(event, result, context) {
|
|
3516
1516
|
let init;
|
|
3517
1517
|
if (isResponseEnvelope(result)) {
|
|
@@ -3532,12 +1532,28 @@ function frameTransformResult(event, result, context) {
|
|
|
3532
1532
|
value: result
|
|
3533
1533
|
} : result;
|
|
3534
1534
|
const invocation = getEventServerFunctionInvocation(event);
|
|
1535
|
+
const live = !!(invocation && invocation.live);
|
|
1536
|
+
const have = live ? decodeHaveList(requestHeader(event, FRAME_HAVE_HEADER)) : undefined;
|
|
3535
1537
|
return serverComponentResponse(result, {
|
|
3536
1538
|
frame: {
|
|
3537
1539
|
id: invocation && invocation.id || ""
|
|
1540
|
+
},
|
|
1541
|
+
signal: requestSignal(event),
|
|
1542
|
+
live,
|
|
1543
|
+
resume: have && {
|
|
1544
|
+
have
|
|
3538
1545
|
}
|
|
3539
1546
|
}, init);
|
|
3540
1547
|
}
|
|
1548
|
+
function requestSignal(event) {
|
|
1549
|
+
const request = event && event.request;
|
|
1550
|
+
return request && request.signal instanceof AbortSignal ? request.signal : undefined;
|
|
1551
|
+
}
|
|
1552
|
+
function requestHeader(event, name) {
|
|
1553
|
+
const request = event && event.request;
|
|
1554
|
+
const headers = request && request.headers;
|
|
1555
|
+
return headers && typeof headers.get === "function" ? headers.get(name) : null;
|
|
1556
|
+
}
|
|
3541
1557
|
async function frameTransformFlightResult(event, outcome, context) {
|
|
3542
1558
|
const {
|
|
3543
1559
|
value,
|
|
@@ -3547,16 +1563,35 @@ async function frameTransformFlightResult(event, outcome, context) {
|
|
|
3547
1563
|
let serialized = data;
|
|
3548
1564
|
if (data && typeof data === "object") {
|
|
3549
1565
|
serialized = {};
|
|
3550
|
-
const
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
|
|
3554
|
-
|
|
3555
|
-
|
|
1566
|
+
for (const source of Object.keys(data)) {
|
|
1567
|
+
const slice = data[source];
|
|
1568
|
+
if (!slice || typeof slice !== "object" || Array.isArray(slice)) {
|
|
1569
|
+
serialized[source] = slice;
|
|
1570
|
+
continue;
|
|
1571
|
+
}
|
|
1572
|
+
const keys = Object.keys(slice);
|
|
1573
|
+
const settled = await Promise.allSettled(keys.map(key => slice[key]));
|
|
1574
|
+
const out = serialized[source] = {};
|
|
1575
|
+
for (let i = 0; i < keys.length; i++) {
|
|
1576
|
+
const result = settled[i];
|
|
1577
|
+
const entry = result.status === "fulfilled" ? result.value : slice[keys[i]];
|
|
1578
|
+
if (typeof entry !== "function") {
|
|
1579
|
+
out[keys[i]] = entry;
|
|
1580
|
+
continue;
|
|
1581
|
+
}
|
|
1582
|
+
const address = entry[SERVER_COMPONENT_ADDRESS] || keys[i];
|
|
3556
1583
|
regions.push({
|
|
3557
|
-
id:
|
|
1584
|
+
id: address,
|
|
3558
1585
|
component: entry[SERVER_COMPONENT_SOURCE] || entry
|
|
3559
1586
|
});
|
|
1587
|
+
if (SERVER_COMPONENT in entry) {
|
|
1588
|
+
out[keys[i]] = entry;
|
|
1589
|
+
} else {
|
|
1590
|
+
const reference = () => undefined;
|
|
1591
|
+
reference[SERVER_COMPONENT] = keys[i];
|
|
1592
|
+
reference[SERVER_COMPONENT_ADDRESS] = address;
|
|
1593
|
+
out[keys[i]] = reference;
|
|
1594
|
+
}
|
|
3560
1595
|
}
|
|
3561
1596
|
}
|
|
3562
1597
|
}
|
|
@@ -3573,21 +1608,24 @@ async function frameTransformFlightResult(event, outcome, context) {
|
|
|
3573
1608
|
value: primary ? undefined : value,
|
|
3574
1609
|
data: serialized
|
|
3575
1610
|
},
|
|
3576
|
-
codec: context && context.codec
|
|
1611
|
+
codec: context && context.codec,
|
|
1612
|
+
signal: requestSignal(event)
|
|
3577
1613
|
});
|
|
3578
1614
|
}
|
|
3579
1615
|
function frameFlightResponse({
|
|
3580
1616
|
primary,
|
|
3581
1617
|
regions = [],
|
|
3582
1618
|
outcome,
|
|
3583
|
-
codec
|
|
1619
|
+
codec,
|
|
1620
|
+
signal
|
|
3584
1621
|
}, init = {}) {
|
|
3585
1622
|
const frames = primary ? [primary, ...regions] : regions;
|
|
3586
1623
|
const headers = copyInitHeaders(init.headers);
|
|
3587
1624
|
headers.set("Content-Type", "application/x-frame-stream");
|
|
3588
1625
|
headers.set(FRAME_STREAM_HEADER, primary ? primary.id : "");
|
|
3589
1626
|
headers.set("X-Content-Raw", "1");
|
|
3590
|
-
|
|
1627
|
+
const teardown = new AbortController();
|
|
1628
|
+
const disarm = followSignal(signal, teardown);
|
|
3591
1629
|
let closed = false;
|
|
3592
1630
|
const body = new ReadableStream({
|
|
3593
1631
|
async start(controller) {
|
|
@@ -3604,20 +1642,35 @@ function frameFlightResponse({
|
|
|
3604
1642
|
id,
|
|
3605
1643
|
component
|
|
3606
1644
|
} of frames) {
|
|
1645
|
+
if (teardown.signal.aborted) break;
|
|
3607
1646
|
await new Promise(resolve => {
|
|
1647
|
+
teardown.signal.addEventListener("abort", resolve, {
|
|
1648
|
+
once: true
|
|
1649
|
+
});
|
|
3608
1650
|
renderServerComponent(component, {
|
|
3609
1651
|
frame: {
|
|
3610
1652
|
id,
|
|
3611
1653
|
version: 1
|
|
3612
|
-
}
|
|
1654
|
+
},
|
|
1655
|
+
signal: teardown.signal
|
|
3613
1656
|
}).pipe({
|
|
3614
1657
|
write,
|
|
3615
|
-
end:
|
|
1658
|
+
end: () => {
|
|
1659
|
+
teardown.signal.removeEventListener("abort", resolve);
|
|
1660
|
+
resolve();
|
|
1661
|
+
}
|
|
3616
1662
|
});
|
|
3617
1663
|
});
|
|
3618
1664
|
}
|
|
1665
|
+
if (teardown.signal.aborted) {
|
|
1666
|
+
closed = true;
|
|
1667
|
+
try {
|
|
1668
|
+
controller.close();
|
|
1669
|
+
} catch (_) {}
|
|
1670
|
+
return;
|
|
1671
|
+
}
|
|
3619
1672
|
if (outcome) {
|
|
3620
|
-
const reader = new ChunkReader(serializeStream(outcome, flightCodec(codec)));
|
|
1673
|
+
const reader = new ChunkReader(serializeStream(guardFailures(outcome), flightCodec(codec)));
|
|
3621
1674
|
for (let node = await reader.next(); !node.done; node = await reader.next()) {
|
|
3622
1675
|
write({
|
|
3623
1676
|
type: "outcome",
|
|
@@ -3634,10 +1687,14 @@ function frameFlightResponse({
|
|
|
3634
1687
|
closed = true;
|
|
3635
1688
|
controller.error(err);
|
|
3636
1689
|
}
|
|
1690
|
+
} finally {
|
|
1691
|
+
disarm();
|
|
3637
1692
|
}
|
|
3638
1693
|
},
|
|
3639
1694
|
cancel() {
|
|
3640
1695
|
closed = true;
|
|
1696
|
+
disarm();
|
|
1697
|
+
teardown.abort();
|
|
3641
1698
|
}
|
|
3642
1699
|
});
|
|
3643
1700
|
return new Response(body, {
|
|
@@ -3647,8 +1704,9 @@ function frameFlightResponse({
|
|
|
3647
1704
|
}
|
|
3648
1705
|
|
|
3649
1706
|
setContainerTraceResolver(getProjectionTrace);
|
|
1707
|
+
setAsyncIterableSharer(shareAsyncIterable);
|
|
3650
1708
|
function asyncArg(value) {
|
|
3651
1709
|
return value;
|
|
3652
1710
|
}
|
|
3653
1711
|
|
|
3654
|
-
export { FRAME_STREAM_HEADER, SERVER_COMPONENT_BOOTSTRAP, ServerComponentPlugin, asyncArg, createFrameSink, frameTransformDirectResult, frameTransformFlightResult, frameTransformResult, isFrameStreamResponse, renderServerComponent, renderToFrameStream, serverComponentResponse };
|
|
1712
|
+
export { FRAME_HAVE_BUDGET, FRAME_HAVE_HEADER, FRAME_STREAM_HEADER, SERVER_COMPONENT_BOOTSTRAP, ServerComponentPlugin, asyncArg, createFrameSink, frameTransformDirectResult, frameTransformFlightResult, frameTransformResult, isFrameStreamResponse, renderServerComponent, renderToFrameStream, serverComponentResponse };
|