@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
|
@@ -0,0 +1,1713 @@
|
|
|
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';
|
|
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';
|
|
7
|
+
|
|
8
|
+
const STATE = Symbol.for("solid.container-trace-state");
|
|
9
|
+
const state = globalThis[STATE] || (globalThis[STATE] = {
|
|
10
|
+
materialized: new WeakMap(),
|
|
11
|
+
materializedValues: new WeakSet()
|
|
12
|
+
});
|
|
13
|
+
function setContainerTraceResolver(fn) {
|
|
14
|
+
state.resolveTrace = fn;
|
|
15
|
+
}
|
|
16
|
+
function setAsyncIterableSharer(fn) {
|
|
17
|
+
state.shareIterable = fn;
|
|
18
|
+
}
|
|
19
|
+
function setContainerTraceStreamMint(fn) {
|
|
20
|
+
state.streamOf = fn;
|
|
21
|
+
}
|
|
22
|
+
function isContainerTraced(value) {
|
|
23
|
+
const resolve = state.resolveTrace;
|
|
24
|
+
return !!(resolve && value && typeof value === "object" && resolve(value));
|
|
25
|
+
}
|
|
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);
|
|
39
|
+
if (Array.isArray(value)) {
|
|
40
|
+
let out = value;
|
|
41
|
+
for (let i = 0; i < value.length; i++) {
|
|
42
|
+
const next = toBorderForm(value[i]);
|
|
43
|
+
if (next !== value[i]) {
|
|
44
|
+
if (out === value) out = value.slice();
|
|
45
|
+
out[i] = next;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
if (Object.getPrototypeOf(value) === Object.prototype) {
|
|
51
|
+
let out = value;
|
|
52
|
+
for (const key of Object.keys(value)) {
|
|
53
|
+
const next = toBorderForm(value[key]);
|
|
54
|
+
if (next !== value[key]) {
|
|
55
|
+
if (out === value) out = {
|
|
56
|
+
...value
|
|
57
|
+
};
|
|
58
|
+
out[key] = next;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
return value;
|
|
64
|
+
}
|
|
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;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
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);
|
|
80
|
+
}
|
|
81
|
+
return value;
|
|
82
|
+
}
|
|
83
|
+
function parseTrace(value, ctx) {
|
|
84
|
+
const trace = value[TRACE];
|
|
85
|
+
const sub = trace.subscribe();
|
|
86
|
+
return {
|
|
87
|
+
a: trace.array ? 1 : 0,
|
|
88
|
+
i: ctx.parse(state.streamOf ? state.streamOf(sub) : sub)
|
|
89
|
+
};
|
|
90
|
+
}
|
|
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
|
|
118
|
+
};
|
|
119
|
+
return state.materializeTrace ? materialize(marker) : marker;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
setContainerTraceStreamMint(iterable => {
|
|
124
|
+
const stream = createStream();
|
|
125
|
+
(async () => {
|
|
126
|
+
try {
|
|
127
|
+
for await (const value of iterable) stream.next(value);
|
|
128
|
+
stream.return(undefined);
|
|
129
|
+
} catch (error) {
|
|
130
|
+
stream.throw(error);
|
|
131
|
+
}
|
|
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];
|
|
141
|
+
}
|
|
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();
|
|
184
|
+
}
|
|
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();
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
if (!settled) {
|
|
212
|
+
cancel = stream;
|
|
213
|
+
cancels.add(cancel);
|
|
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();
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const RECORDS = Symbol.for("@solidjs/signals/observe/records");
|
|
229
|
+
function records() {
|
|
230
|
+
return globalThis[RECORDS];
|
|
231
|
+
}
|
|
232
|
+
function frameCensus(event, type, own) {
|
|
233
|
+
event.chunks++;
|
|
234
|
+
switch (type) {
|
|
235
|
+
case "html":
|
|
236
|
+
if (!own) event.regions++;else if (event.shellMs === undefined) event.shellMs = performance.now() - event.at;
|
|
237
|
+
break;
|
|
238
|
+
case "fragment":
|
|
239
|
+
event.fragments++;
|
|
240
|
+
break;
|
|
241
|
+
case "slot":
|
|
242
|
+
event.slots++;
|
|
243
|
+
break;
|
|
244
|
+
case "error":
|
|
245
|
+
event.errors++;
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function observeFrame(frame) {
|
|
251
|
+
const channel = records();
|
|
252
|
+
if (channel === undefined || !channel.observed("frame")) return undefined;
|
|
253
|
+
const event = {
|
|
254
|
+
side: "server",
|
|
255
|
+
id: frame.id,
|
|
256
|
+
version: frame.version,
|
|
257
|
+
at: performance.now(),
|
|
258
|
+
durationMs: 0,
|
|
259
|
+
outcome: "complete",
|
|
260
|
+
chunks: 0,
|
|
261
|
+
fragments: 0,
|
|
262
|
+
slots: 0,
|
|
263
|
+
regions: 0,
|
|
264
|
+
errors: 0
|
|
265
|
+
};
|
|
266
|
+
let settled = false;
|
|
267
|
+
return {
|
|
268
|
+
chunk(chunk) {
|
|
269
|
+
if (chunk.type === "complete") return;
|
|
270
|
+
frameCensus(event, chunk.type, chunk.id === frame.id);
|
|
271
|
+
},
|
|
272
|
+
settle(outcome, error) {
|
|
273
|
+
if (settled) return;
|
|
274
|
+
settled = true;
|
|
275
|
+
event.durationMs = performance.now() - event.at;
|
|
276
|
+
event.outcome = outcome;
|
|
277
|
+
const live = {};
|
|
278
|
+
if (outcome === "error") live.error = error;
|
|
279
|
+
channel.emit("frame", event, live);
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const FRAME_STREAM_HEADER = "X-Frame-Stream";
|
|
285
|
+
const FRAME_HAVE_HEADER = "X-Frame-Have";
|
|
286
|
+
const FRAME_HAVE_BUDGET = 4096;
|
|
287
|
+
function decodeHaveList(text) {
|
|
288
|
+
if (!text) return undefined;
|
|
289
|
+
const have = {};
|
|
290
|
+
let any = false;
|
|
291
|
+
for (const entry of text.split(",")) {
|
|
292
|
+
const eq = entry.indexOf("=");
|
|
293
|
+
if (eq === -1) continue;
|
|
294
|
+
const digest = entry.slice(eq + 1).trim();
|
|
295
|
+
if (!/^[0-9a-f]{16}$/.test(digest)) continue;
|
|
296
|
+
have[entry.slice(0, eq).trim()] = digest;
|
|
297
|
+
any = true;
|
|
298
|
+
}
|
|
299
|
+
return any ? have : undefined;
|
|
300
|
+
}
|
|
301
|
+
function isFrameStreamResponse(response) {
|
|
302
|
+
return response.headers.has(FRAME_STREAM_HEADER);
|
|
303
|
+
}
|
|
304
|
+
const SERVER_COMPONENT = /*#__PURE__*/Symbol.for("solid.server-component");
|
|
305
|
+
const SERVER_COMPONENT_SOURCE = /*#__PURE__*/Symbol.for("solid.server-component-source");
|
|
306
|
+
const SERVER_COMPONENT_ADDRESS = /*#__PURE__*/Symbol.for("solid.server-component-address");
|
|
307
|
+
let serverComponentRegistryExpr;
|
|
308
|
+
function setServerComponentBootstrap(resolve) {
|
|
309
|
+
serverComponentRegistryExpr = resolve;
|
|
310
|
+
}
|
|
311
|
+
function parseServerComponent(value, ctx) {
|
|
312
|
+
return {
|
|
313
|
+
id: ctx.parse(value[SERVER_COMPONENT]),
|
|
314
|
+
address: ctx.parse(value[SERVER_COMPONENT_ADDRESS])
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
const ServerComponentPlugin = {
|
|
318
|
+
tag: "solid/server-component",
|
|
319
|
+
test(value) {
|
|
320
|
+
return typeof value === "function" && SERVER_COMPONENT in value;
|
|
321
|
+
},
|
|
322
|
+
parse: {
|
|
323
|
+
sync: parseServerComponent,
|
|
324
|
+
async async(value, ctx) {
|
|
325
|
+
return {
|
|
326
|
+
id: await ctx.parse(value[SERVER_COMPONENT]),
|
|
327
|
+
address: await ctx.parse(value[SERVER_COMPONENT_ADDRESS])
|
|
328
|
+
};
|
|
329
|
+
},
|
|
330
|
+
stream: parseServerComponent
|
|
331
|
+
},
|
|
332
|
+
serialize(node, ctx) {
|
|
333
|
+
const registry = serverComponentRegistryExpr ? serverComponentRegistryExpr(ctx) : "self._$SC";
|
|
334
|
+
return registry + ".r(" + ctx.serialize(node.id) + "," + ctx.serialize(node.address) + ")";
|
|
335
|
+
},
|
|
336
|
+
deserialize(node, ctx) {
|
|
337
|
+
const id = ctx.deserialize(node.id);
|
|
338
|
+
ctx.deserialize(node.address);
|
|
339
|
+
return globalThis._$SC.r(id);
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
function flightCodec(codec) {
|
|
343
|
+
const plugins = codec && codec.plugins || [];
|
|
344
|
+
if (plugins.some(plugin => plugin && plugin.tag === ServerComponentPlugin.tag)) return codec;
|
|
345
|
+
return {
|
|
346
|
+
...codec,
|
|
347
|
+
plugins: [...plugins, ServerComponentPlugin]
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
const runWithHydrationScope = (id, fn) => runWithOwner(createOwner({
|
|
352
|
+
id
|
|
353
|
+
}), fn);
|
|
354
|
+
const ssrAsyncValue = value => createMemo(() => value, {
|
|
355
|
+
serialize: false
|
|
356
|
+
});
|
|
357
|
+
const scopeStamp = typeof creationStamp === "function" ? creationStamp : () => 0;
|
|
358
|
+
function serverOwned(render) {
|
|
359
|
+
return NoHydration ? NoHydration({
|
|
360
|
+
get children() {
|
|
361
|
+
return render();
|
|
362
|
+
}
|
|
363
|
+
}) : render();
|
|
364
|
+
}
|
|
365
|
+
function serverComponentScope(render, live = false) {
|
|
366
|
+
return runInServerComponentScope ? runInServerComponentScope(render, live ? {
|
|
367
|
+
live: true
|
|
368
|
+
} : undefined) : render();
|
|
369
|
+
}
|
|
370
|
+
const LIVE_SOURCE = Symbol.for("solid.LiveSource");
|
|
371
|
+
function wirePreload(entry) {
|
|
372
|
+
return entry.href ? {
|
|
373
|
+
href: entry.href,
|
|
374
|
+
attrs: entry.attrs
|
|
375
|
+
} : {
|
|
376
|
+
attrs: entry.attrs
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
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}}))}}))';
|
|
380
|
+
const bootstrappedScripts = new WeakSet();
|
|
381
|
+
setServerComponentBootstrap(ctx => {
|
|
382
|
+
if (bootstrappedScripts.has(ctx)) return "self._$SC";
|
|
383
|
+
bootstrappedScripts.add(ctx);
|
|
384
|
+
return SERVER_COMPONENT_BOOTSTRAP_EXPR;
|
|
385
|
+
});
|
|
386
|
+
const SERVER_COMPONENT_BOOTSTRAP = SERVER_COMPONENT_BOOTSTRAP_EXPR + ";";
|
|
387
|
+
const HOLE_RANGE = /<!--lh:(\d+)-->([\s\S]*?)<!--lh:\/\1-->/g;
|
|
388
|
+
const SLOT_RANGE = /<!--slot:([^>]*?):start-->[\s\S]*?<!--slot:\1:end-->/g;
|
|
389
|
+
const ATTR_ADDRESS = / data-lha="([^"]*)"/g;
|
|
390
|
+
const stripHoleMarkers = html => html.replace(/<!--lh:\/?\d+-->/g, "");
|
|
391
|
+
function frameSkeleton(html) {
|
|
392
|
+
return html.replace(HOLE_RANGE, "<!--lh:$1--><!--lh:/$1-->").replace(SLOT_RANGE, "<!--slot:$1:start--><!--slot:$1:end-->");
|
|
393
|
+
}
|
|
394
|
+
function holeDigests(html, attrText, into = {}) {
|
|
395
|
+
for (const m of html.matchAll(HOLE_RANGE)) {
|
|
396
|
+
into["lh:" + m[1]] = textDigest(stripHoleMarkers(m[2]));
|
|
397
|
+
holeDigests(m[2], null, into);
|
|
398
|
+
}
|
|
399
|
+
if (attrText) {
|
|
400
|
+
for (const m of html.matchAll(ATTR_ADDRESS)) {
|
|
401
|
+
const key = "lha:" + m[1];
|
|
402
|
+
const text = attrText.get(key);
|
|
403
|
+
if (text !== undefined) into[key] = textDigest(text);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
return into;
|
|
407
|
+
}
|
|
408
|
+
function withHoles(chunk, holes) {
|
|
409
|
+
for (const _ in holes) {
|
|
410
|
+
chunk.holes = holes;
|
|
411
|
+
break;
|
|
412
|
+
}
|
|
413
|
+
return chunk;
|
|
414
|
+
}
|
|
415
|
+
function createFrameSink(emit, frame, have) {
|
|
416
|
+
const {
|
|
417
|
+
id,
|
|
418
|
+
version
|
|
419
|
+
} = frame;
|
|
420
|
+
let conditional = false;
|
|
421
|
+
const skipped = new Set();
|
|
422
|
+
const attrText = new Map();
|
|
423
|
+
const emitDiffering = html => {
|
|
424
|
+
for (const m of html.matchAll(HOLE_RANGE)) {
|
|
425
|
+
const key = "lh:" + m[1];
|
|
426
|
+
const digest = textDigest(stripHoleMarkers(m[2]));
|
|
427
|
+
if (have[key] === digest) continue;
|
|
428
|
+
emit(withHoles({
|
|
429
|
+
type: "hole",
|
|
430
|
+
id,
|
|
431
|
+
version,
|
|
432
|
+
key,
|
|
433
|
+
html: m[2],
|
|
434
|
+
digest
|
|
435
|
+
}, holeDigests(m[2], null)));
|
|
436
|
+
}
|
|
437
|
+
for (const m of html.matchAll(ATTR_ADDRESS)) {
|
|
438
|
+
const text = attrText.get("lha:" + m[1]);
|
|
439
|
+
if (text === undefined) continue;
|
|
440
|
+
const digest = textDigest(text);
|
|
441
|
+
if (have["lha:" + m[1]] === digest) continue;
|
|
442
|
+
emit({
|
|
443
|
+
type: "attr",
|
|
444
|
+
id,
|
|
445
|
+
version,
|
|
446
|
+
key: m[1],
|
|
447
|
+
attrs: text,
|
|
448
|
+
digest
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
};
|
|
452
|
+
const styledKeys = new Set();
|
|
453
|
+
const bindings = new Map();
|
|
454
|
+
const sweepMinted = new Set();
|
|
455
|
+
const argRefVersions = new Map();
|
|
456
|
+
let sweepScheduled = false;
|
|
457
|
+
let closed = false;
|
|
458
|
+
let epoch = 0;
|
|
459
|
+
const sweep = () => {
|
|
460
|
+
epoch++;
|
|
461
|
+
for (const b of [...bindings.values()]) {
|
|
462
|
+
try {
|
|
463
|
+
b.sweep();
|
|
464
|
+
} catch (_) {
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
const scheduleSweep = () => {
|
|
469
|
+
if (closed || sweepScheduled || !bindings.size) return;
|
|
470
|
+
sweepScheduled = true;
|
|
471
|
+
queueMicrotask(() => {
|
|
472
|
+
sweepScheduled = false;
|
|
473
|
+
if (!closed) sweep();
|
|
474
|
+
});
|
|
475
|
+
};
|
|
476
|
+
const regionKeys = new Map();
|
|
477
|
+
const frameOf = key => regionKeys.get(key) || id;
|
|
478
|
+
return {
|
|
479
|
+
tagRegion(key, childId) {
|
|
480
|
+
if (!regionKeys.has(key)) regionKeys.set(key, childId);
|
|
481
|
+
},
|
|
482
|
+
shell(html, meta = {}) {
|
|
483
|
+
const digest = textDigest(frameSkeleton(html));
|
|
484
|
+
if (have && have[""] === digest) {
|
|
485
|
+
conditional = true;
|
|
486
|
+
emitDiffering(html);
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
if (meta.preloads && meta.preloads.size || meta.preloadLinks) {
|
|
490
|
+
const chunk = {
|
|
491
|
+
type: "assets",
|
|
492
|
+
id,
|
|
493
|
+
version,
|
|
494
|
+
key: ""
|
|
495
|
+
};
|
|
496
|
+
if (meta.preloads && meta.preloads.size) {
|
|
497
|
+
const styles = [];
|
|
498
|
+
const modules = [];
|
|
499
|
+
for (const url of meta.preloads) {
|
|
500
|
+
(url.endsWith(".css") ? styles : modules).push(url);
|
|
501
|
+
}
|
|
502
|
+
if (styles.length) chunk.styles = styles;
|
|
503
|
+
if (modules.length) chunk.modules = modules;
|
|
504
|
+
}
|
|
505
|
+
if (meta.preloadLinks) {
|
|
506
|
+
chunk.preloads = [];
|
|
507
|
+
for (const entry of meta.preloadLinks) {
|
|
508
|
+
chunk.preloads.push(wirePreload(entry));
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
emit(chunk);
|
|
512
|
+
}
|
|
513
|
+
emit(withHoles({
|
|
514
|
+
type: "html",
|
|
515
|
+
id,
|
|
516
|
+
version,
|
|
517
|
+
html,
|
|
518
|
+
digest
|
|
519
|
+
}, holeDigests(html, attrText)));
|
|
520
|
+
},
|
|
521
|
+
data(record) {
|
|
522
|
+
if (record && typeof record.key === "string" && (record.key.endsWith("_fr") || /^\d+$/.test(record.key))) {
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
if (typeof record === "string") {
|
|
526
|
+
emit({
|
|
527
|
+
type: "data",
|
|
528
|
+
id,
|
|
529
|
+
version,
|
|
530
|
+
payload: record
|
|
531
|
+
});
|
|
532
|
+
scheduleSweep();
|
|
533
|
+
} else {
|
|
534
|
+
emit({
|
|
535
|
+
type: "data",
|
|
536
|
+
id,
|
|
537
|
+
version,
|
|
538
|
+
key: record.key,
|
|
539
|
+
node: record.node,
|
|
540
|
+
initial: record.initial
|
|
541
|
+
});
|
|
542
|
+
if (!sweepMinted.has(record.key)) scheduleSweep();
|
|
543
|
+
}
|
|
544
|
+
},
|
|
545
|
+
fragment(key, value, meta = {}) {
|
|
546
|
+
const fid = frameOf(key);
|
|
547
|
+
if (conditional && fid === id && have[key] !== undefined) {
|
|
548
|
+
skipped.add(key);
|
|
549
|
+
scheduleSweep();
|
|
550
|
+
if (meta.error) {
|
|
551
|
+
emit({
|
|
552
|
+
type: "error",
|
|
553
|
+
id: fid,
|
|
554
|
+
version,
|
|
555
|
+
key,
|
|
556
|
+
error: {
|
|
557
|
+
message: String(meta.error && meta.error.message || meta.error)
|
|
558
|
+
}
|
|
559
|
+
});
|
|
560
|
+
} else emitDiffering(value);
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
const links = meta.styles && meta.styles.links || [];
|
|
564
|
+
const inline = meta.styles && meta.styles.inline || [];
|
|
565
|
+
if (links.length || inline.length) {
|
|
566
|
+
if (links.length) styledKeys.add(key);
|
|
567
|
+
const chunk = {
|
|
568
|
+
type: "assets",
|
|
569
|
+
id: fid,
|
|
570
|
+
version,
|
|
571
|
+
key
|
|
572
|
+
};
|
|
573
|
+
if (links.length) {
|
|
574
|
+
chunk.styles = links.map(e => typeof e === "string" ? e : e.attrs ? {
|
|
575
|
+
href: e.href,
|
|
576
|
+
attrs: e.attrs
|
|
577
|
+
} : e.href);
|
|
578
|
+
}
|
|
579
|
+
if (inline.length) {
|
|
580
|
+
chunk.inlineStyles = inline.map(e => ({
|
|
581
|
+
id: e.id,
|
|
582
|
+
content: e.content,
|
|
583
|
+
attrs: e.attrs
|
|
584
|
+
}));
|
|
585
|
+
}
|
|
586
|
+
emit(chunk);
|
|
587
|
+
}
|
|
588
|
+
emit(withHoles({
|
|
589
|
+
type: "fragment",
|
|
590
|
+
id: fid,
|
|
591
|
+
version,
|
|
592
|
+
key,
|
|
593
|
+
html: value,
|
|
594
|
+
digest: textDigest(value)
|
|
595
|
+
}, holeDigests(value, attrText)));
|
|
596
|
+
scheduleSweep();
|
|
597
|
+
if (meta.error) {
|
|
598
|
+
emit({
|
|
599
|
+
type: "error",
|
|
600
|
+
id: fid,
|
|
601
|
+
version,
|
|
602
|
+
key,
|
|
603
|
+
error: {
|
|
604
|
+
message: String(meta.error && meta.error.message || meta.error)
|
|
605
|
+
}
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
if (!meta.revealGroup) {
|
|
609
|
+
emit({
|
|
610
|
+
type: "reveal",
|
|
611
|
+
id: fid,
|
|
612
|
+
version,
|
|
613
|
+
keys: [key],
|
|
614
|
+
waitForStyles: !!links.length
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
},
|
|
618
|
+
reveal(keys, meta = {}) {
|
|
619
|
+
const byFrame = new Map();
|
|
620
|
+
for (const key of keys) {
|
|
621
|
+
if (conditional && (skipped.has(key) || meta.fallback && have[key] !== undefined)) continue;
|
|
622
|
+
const fid = frameOf(key);
|
|
623
|
+
let group = byFrame.get(fid);
|
|
624
|
+
if (!group) byFrame.set(fid, group = []);
|
|
625
|
+
group.push(key);
|
|
626
|
+
}
|
|
627
|
+
for (const [fid, groupKeys] of byFrame) {
|
|
628
|
+
let waitForStyles = false;
|
|
629
|
+
for (const key of groupKeys) if (styledKeys.has(key)) waitForStyles = true;
|
|
630
|
+
const chunk = {
|
|
631
|
+
type: "reveal",
|
|
632
|
+
id: fid,
|
|
633
|
+
version,
|
|
634
|
+
keys: groupKeys,
|
|
635
|
+
waitForStyles
|
|
636
|
+
};
|
|
637
|
+
if (meta.fallback) chunk.fallback = true;
|
|
638
|
+
emit(chunk);
|
|
639
|
+
}
|
|
640
|
+
},
|
|
641
|
+
asset(type, value) {
|
|
642
|
+
if (type === "module") {
|
|
643
|
+
emit({
|
|
644
|
+
type: "assets",
|
|
645
|
+
id,
|
|
646
|
+
version,
|
|
647
|
+
key: "",
|
|
648
|
+
modules: [value]
|
|
649
|
+
});
|
|
650
|
+
} else if (type === "preload") {
|
|
651
|
+
emit({
|
|
652
|
+
type: "assets",
|
|
653
|
+
id,
|
|
654
|
+
version,
|
|
655
|
+
key: "",
|
|
656
|
+
preloads: [wirePreload(value)]
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
},
|
|
660
|
+
end() {
|
|
661
|
+
if (bindings.size) sweep();
|
|
662
|
+
closed = true;
|
|
663
|
+
emit({
|
|
664
|
+
type: "complete",
|
|
665
|
+
id,
|
|
666
|
+
version
|
|
667
|
+
});
|
|
668
|
+
},
|
|
669
|
+
error(errorId, error) {
|
|
670
|
+
emit({
|
|
671
|
+
type: "error",
|
|
672
|
+
id,
|
|
673
|
+
version,
|
|
674
|
+
key: errorId,
|
|
675
|
+
error
|
|
676
|
+
});
|
|
677
|
+
},
|
|
678
|
+
slot(key, args) {
|
|
679
|
+
emit({
|
|
680
|
+
type: "slot",
|
|
681
|
+
id,
|
|
682
|
+
version,
|
|
683
|
+
key,
|
|
684
|
+
args
|
|
685
|
+
});
|
|
686
|
+
},
|
|
687
|
+
region(childId, html) {
|
|
688
|
+
emit({
|
|
689
|
+
type: "html",
|
|
690
|
+
id: childId,
|
|
691
|
+
version,
|
|
692
|
+
html
|
|
693
|
+
});
|
|
694
|
+
},
|
|
695
|
+
hole(key, html) {
|
|
696
|
+
emit({
|
|
697
|
+
type: "hole",
|
|
698
|
+
id,
|
|
699
|
+
version,
|
|
700
|
+
key,
|
|
701
|
+
html,
|
|
702
|
+
digest: textDigest(html)
|
|
703
|
+
});
|
|
704
|
+
},
|
|
705
|
+
attr(key, attrs, removed) {
|
|
706
|
+
const chunk = {
|
|
707
|
+
type: "attr",
|
|
708
|
+
id,
|
|
709
|
+
version,
|
|
710
|
+
key,
|
|
711
|
+
attrs,
|
|
712
|
+
digest: textDigest(attrs)
|
|
713
|
+
};
|
|
714
|
+
if (removed && removed.length) chunk.removed = removed;
|
|
715
|
+
emit(chunk);
|
|
716
|
+
},
|
|
717
|
+
attrBaseline(key, text) {
|
|
718
|
+
attrText.set(key, text);
|
|
719
|
+
},
|
|
720
|
+
openBinding(key, b) {
|
|
721
|
+
bindings.set(key, b);
|
|
722
|
+
},
|
|
723
|
+
closeBinding(key) {
|
|
724
|
+
bindings.delete(key);
|
|
725
|
+
},
|
|
726
|
+
mintRef(ref) {
|
|
727
|
+
sweepMinted.add(ref);
|
|
728
|
+
},
|
|
729
|
+
nextArgRef(ledgerKey) {
|
|
730
|
+
const n = (argRefVersions.get(ledgerKey) || 0) + 1;
|
|
731
|
+
argRefVersions.set(ledgerKey, n);
|
|
732
|
+
return n;
|
|
733
|
+
},
|
|
734
|
+
commit: scheduleSweep,
|
|
735
|
+
get epoch() {
|
|
736
|
+
return epoch;
|
|
737
|
+
}
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
function renderToFrameStream(code, options = {}) {
|
|
741
|
+
return frameStream(() => code, options);
|
|
742
|
+
}
|
|
743
|
+
function renderServerComponent(component, options = {}) {
|
|
744
|
+
return frameStream((sink, frame) => {
|
|
745
|
+
const props = createSlotProps(sink, frame);
|
|
746
|
+
return () => {
|
|
747
|
+
const ctx = sharedConfig.context;
|
|
748
|
+
if (ctx) {
|
|
749
|
+
ctx.commit = sink.commit;
|
|
750
|
+
ctx.commitEpoch = () => sink.epoch;
|
|
751
|
+
ctx.liveHoles = createLiveHoles(sink);
|
|
752
|
+
ctx.claims = CLAIMS_STREAM;
|
|
753
|
+
}
|
|
754
|
+
return serverComponentScope(() => component(props));
|
|
755
|
+
};
|
|
756
|
+
}, options);
|
|
757
|
+
}
|
|
758
|
+
function frameStream(makeCode, options) {
|
|
759
|
+
const {
|
|
760
|
+
id = "",
|
|
761
|
+
version = 1
|
|
762
|
+
} = options.frame || {};
|
|
763
|
+
const frame = {
|
|
764
|
+
id,
|
|
765
|
+
version
|
|
766
|
+
};
|
|
767
|
+
function stream(w) {
|
|
768
|
+
const observation = observeFrame(frame);
|
|
769
|
+
const emit = observation ? chunk => {
|
|
770
|
+
observation.chunk(chunk);
|
|
771
|
+
w.write(chunk);
|
|
772
|
+
} : chunk => w.write(chunk);
|
|
773
|
+
const sink = createFrameSink(emit, frame, options.resume && options.resume.have);
|
|
774
|
+
w.write({
|
|
775
|
+
type: "start",
|
|
776
|
+
id,
|
|
777
|
+
version
|
|
778
|
+
});
|
|
779
|
+
const code = makeCode(sink, frame);
|
|
780
|
+
try {
|
|
781
|
+
renderToStream(() => serverOwned(code), {
|
|
782
|
+
serializer: createJSONSerializer,
|
|
783
|
+
...options,
|
|
784
|
+
sink
|
|
785
|
+
}).pipe({
|
|
786
|
+
write() {},
|
|
787
|
+
end() {
|
|
788
|
+
sink.end();
|
|
789
|
+
observation && observation.settle("complete");
|
|
790
|
+
w.end && w.end();
|
|
791
|
+
}
|
|
792
|
+
});
|
|
793
|
+
} catch (err) {
|
|
794
|
+
const wire = ssrSanitizeError(err, null);
|
|
795
|
+
sink.error("", wire instanceof Error ? wire.message : String(wire));
|
|
796
|
+
sink.end();
|
|
797
|
+
observation && observation.settle("error", err);
|
|
798
|
+
w.end && w.end();
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
return {
|
|
802
|
+
pipe: stream,
|
|
803
|
+
then(onFulfilled, onRejected) {
|
|
804
|
+
return new Promise((resolve, reject) => {
|
|
805
|
+
const chunks = [];
|
|
806
|
+
try {
|
|
807
|
+
stream({
|
|
808
|
+
write: chunk => chunks.push(chunk),
|
|
809
|
+
end: () => resolve(chunks)
|
|
810
|
+
});
|
|
811
|
+
} catch (err) {
|
|
812
|
+
reject(err);
|
|
813
|
+
}
|
|
814
|
+
}).then(onFulfilled, onRejected);
|
|
815
|
+
}
|
|
816
|
+
};
|
|
817
|
+
}
|
|
818
|
+
function slotRange(occurrence) {
|
|
819
|
+
return {
|
|
820
|
+
t: `<!--slot:${occurrence}:start--><!--slot:${occurrence}:end-->`,
|
|
821
|
+
$slot: true
|
|
822
|
+
};
|
|
823
|
+
}
|
|
824
|
+
const OCCURRENCE_UNSAFE = /[^A-Za-z0-9_.-]/g;
|
|
825
|
+
function encodeOccurrenceKey(key) {
|
|
826
|
+
return String(key).replace(OCCURRENCE_UNSAFE, c => {
|
|
827
|
+
const code = c.codePointAt(0);
|
|
828
|
+
return "%" + (code < 16 ? "0" : "") + code.toString(16);
|
|
829
|
+
});
|
|
830
|
+
}
|
|
831
|
+
function occurrenceId(prop, raw, counts) {
|
|
832
|
+
const k = raw.$key;
|
|
833
|
+
if (typeof k === "string" || typeof k === "number") {
|
|
834
|
+
return `${prop}#${encodeOccurrenceKey(k)}`;
|
|
835
|
+
}
|
|
836
|
+
const n = counts[prop] || 0;
|
|
837
|
+
counts[prop] = n + 1;
|
|
838
|
+
return `${prop}#${n}`;
|
|
839
|
+
}
|
|
840
|
+
function isAsyncValue(v) {
|
|
841
|
+
return !!v && typeof v === "object" && (typeof v.then === "function" || typeof v[Symbol.asyncIterator] === "function");
|
|
842
|
+
}
|
|
843
|
+
function tapFirstYield(iterable) {
|
|
844
|
+
const rest = shareAsyncIterable(iterable);
|
|
845
|
+
const iter = shareAsyncIterable(iterable)[Symbol.asyncIterator]();
|
|
846
|
+
const first = Promise.resolve(iter.next()).then(r => {
|
|
847
|
+
if (!r.done) iter.return?.();
|
|
848
|
+
return r.done ? undefined : r.value;
|
|
849
|
+
});
|
|
850
|
+
return {
|
|
851
|
+
first,
|
|
852
|
+
rest
|
|
853
|
+
};
|
|
854
|
+
}
|
|
855
|
+
function suppressedFill(render) {
|
|
856
|
+
const live = sharedConfig.context && sharedConfig.context.liveHoles;
|
|
857
|
+
if (!live) return render();
|
|
858
|
+
live.suppressed++;
|
|
859
|
+
try {
|
|
860
|
+
return render();
|
|
861
|
+
} finally {
|
|
862
|
+
live.suppressed--;
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
function createDocumentSlotProps(clientProps, frameId) {
|
|
866
|
+
const counts = Object.create(null);
|
|
867
|
+
const getters = new Map();
|
|
868
|
+
const range = (occurrence, content) => {
|
|
869
|
+
const r = [{
|
|
870
|
+
t: `<!--slot:${occurrence}:start-->`
|
|
871
|
+
}, content, {
|
|
872
|
+
t: `<!--slot:${occurrence}:end-->`
|
|
873
|
+
}];
|
|
874
|
+
r.$slot = true;
|
|
875
|
+
return r;
|
|
876
|
+
};
|
|
877
|
+
const zoneOwner = getOwner ? getOwner() : null;
|
|
878
|
+
const scoped = (occurrence, render) => {
|
|
879
|
+
const id = `sc-${frameId}-${occurrence}-`;
|
|
880
|
+
const run = () => Hydration ? Hydration({
|
|
881
|
+
id,
|
|
882
|
+
get children() {
|
|
883
|
+
return render();
|
|
884
|
+
}
|
|
885
|
+
}) : runWithHydrationScope(id, render);
|
|
886
|
+
return zoneOwner ? runWithOwner(zoneOwner, run) : run();
|
|
887
|
+
};
|
|
888
|
+
return new Proxy(Object.create(null), {
|
|
889
|
+
has() {
|
|
890
|
+
return true;
|
|
891
|
+
},
|
|
892
|
+
get(_, prop) {
|
|
893
|
+
if (typeof prop !== "string") return undefined;
|
|
894
|
+
if (prop === "then") return undefined;
|
|
895
|
+
let fn = getters.get(prop);
|
|
896
|
+
if (!fn) {
|
|
897
|
+
fn = (...callArgs) => {
|
|
898
|
+
if (callArgs.length === 0 || callArgs[0] === undefined) {
|
|
899
|
+
return suppressedFill(() => scoped(prop, () => {
|
|
900
|
+
const value = clientProps[prop];
|
|
901
|
+
return range(prop, typeof value === "function" ? value() : value);
|
|
902
|
+
}));
|
|
903
|
+
}
|
|
904
|
+
const raw = callArgs[0];
|
|
905
|
+
const occurrence = occurrenceId(prop, raw, counts);
|
|
906
|
+
const slot = clientProps[prop];
|
|
907
|
+
if (typeof slot !== "function") return range(occurrence, undefined);
|
|
908
|
+
const resolved = {};
|
|
909
|
+
const liveArgs = sharedConfig.context && sharedConfig.context.live && sharedConfig.context.live.args;
|
|
910
|
+
const vals = {};
|
|
911
|
+
const evals = {};
|
|
912
|
+
const states = {};
|
|
913
|
+
const minted = {};
|
|
914
|
+
for (const key of Object.keys(raw)) {
|
|
915
|
+
if (key === "$key") continue;
|
|
916
|
+
const desc = Object.getOwnPropertyDescriptor(raw, key);
|
|
917
|
+
let evaluate = null;
|
|
918
|
+
let value;
|
|
919
|
+
if (desc.get) {
|
|
920
|
+
const get = desc.get;
|
|
921
|
+
evaluate = () => unwrapThunks(get.call(raw));
|
|
922
|
+
} else {
|
|
923
|
+
value = desc.value;
|
|
924
|
+
if (typeof value === "function") {
|
|
925
|
+
const fn = value;
|
|
926
|
+
evaluate = () => unwrapThunks(fn);
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
if (evaluate) {
|
|
930
|
+
evals[key] = evaluate;
|
|
931
|
+
const stampBefore = scopeStamp();
|
|
932
|
+
try {
|
|
933
|
+
value = evaluate();
|
|
934
|
+
states[key] = {
|
|
935
|
+
settled: true,
|
|
936
|
+
last: value
|
|
937
|
+
};
|
|
938
|
+
} catch (err) {
|
|
939
|
+
const blocked = ssrHandleError && ssrHandleError(err);
|
|
940
|
+
if (!blocked) throw err;
|
|
941
|
+
const state = states[key] = {
|
|
942
|
+
settled: false,
|
|
943
|
+
last: undefined
|
|
944
|
+
};
|
|
945
|
+
value = retryArgUntilSettled(evaluate, blocked, key, occurrence, v => {
|
|
946
|
+
state.settled = true;
|
|
947
|
+
state.last = v;
|
|
948
|
+
if (liveArgs) liveArgs.commit();
|
|
949
|
+
});
|
|
950
|
+
}
|
|
951
|
+
if (scopeStamp() !== stampBefore) minted[key] = true;
|
|
952
|
+
}
|
|
953
|
+
vals[key] = value;
|
|
954
|
+
}
|
|
955
|
+
const regions = [];
|
|
956
|
+
for (const key of Object.keys(vals)) {
|
|
957
|
+
const value = vals[key];
|
|
958
|
+
if (isContainerTraced(value)) {
|
|
959
|
+
resolved[key] = value;
|
|
960
|
+
} else if (isServerContent(value)) {
|
|
961
|
+
const childId = `${frameId}.${occurrence}.${key}`;
|
|
962
|
+
const region = {
|
|
963
|
+
key,
|
|
964
|
+
childId,
|
|
965
|
+
value,
|
|
966
|
+
used: false,
|
|
967
|
+
locked: false
|
|
968
|
+
};
|
|
969
|
+
regions.push(region);
|
|
970
|
+
resolved[key] = () => {
|
|
971
|
+
if (region.locked) return [];
|
|
972
|
+
region.used = true;
|
|
973
|
+
return [{
|
|
974
|
+
t: frameElementOpen(childId)
|
|
975
|
+
}, value, {
|
|
976
|
+
t: FRAME_ELEMENT_CLOSE
|
|
977
|
+
}];
|
|
978
|
+
};
|
|
979
|
+
} else if (ssrAsyncValue && isAsyncValue(value)) {
|
|
980
|
+
let readable = value;
|
|
981
|
+
if (typeof value.then !== "function") {
|
|
982
|
+
const {
|
|
983
|
+
first,
|
|
984
|
+
rest
|
|
985
|
+
} = tapFirstYield(value);
|
|
986
|
+
readable = first;
|
|
987
|
+
vals[key] = rest;
|
|
988
|
+
}
|
|
989
|
+
const read = ssrAsyncValue(readable);
|
|
990
|
+
Object.defineProperty(resolved, key, {
|
|
991
|
+
get: read,
|
|
992
|
+
enumerable: true,
|
|
993
|
+
configurable: true
|
|
994
|
+
});
|
|
995
|
+
} else {
|
|
996
|
+
resolved[key] = value;
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
const out = suppressedFill(() => scoped(occurrence, () => range(occurrence, slot(resolved))));
|
|
1000
|
+
const unused = regions.filter(r => !r.used);
|
|
1001
|
+
if (sharedConfig.context) {
|
|
1002
|
+
const args = {};
|
|
1003
|
+
for (const key of Object.keys(vals)) {
|
|
1004
|
+
const value = vals[key];
|
|
1005
|
+
const region = regions.find(r => r.key === key);
|
|
1006
|
+
if (region) {
|
|
1007
|
+
args[key] = {
|
|
1008
|
+
$frame: region.childId
|
|
1009
|
+
};
|
|
1010
|
+
continue;
|
|
1011
|
+
}
|
|
1012
|
+
if (!isContainerTraced(value) && isServerContent(value)) continue;
|
|
1013
|
+
args[key] = toBorderForm(value);
|
|
1014
|
+
}
|
|
1015
|
+
sharedConfig.context.serialize(`sc:slot:${frameId}:${occurrence}`, {
|
|
1016
|
+
...args
|
|
1017
|
+
});
|
|
1018
|
+
for (const region of unused) {
|
|
1019
|
+
region.locked = true;
|
|
1020
|
+
sharedConfig.context.serialize(`sc:region:${region.childId}`, resolveRegionHtml(sharedConfig.context, region.value));
|
|
1021
|
+
}
|
|
1022
|
+
if (liveArgs) {
|
|
1023
|
+
for (const key of Object.keys(evals)) {
|
|
1024
|
+
if (regions.some(r => r.key === key)) continue;
|
|
1025
|
+
if (minted[key]) continue;
|
|
1026
|
+
const ledgerKey = `${frameId}:${occurrence}:${key}`;
|
|
1027
|
+
openArgBinding(liveArgs, ledgerKey, occurrence, key, evals[key], states[key], value => {
|
|
1028
|
+
args[key] = toBorderForm(value);
|
|
1029
|
+
liveArgs.slot(frameId, occurrence, {
|
|
1030
|
+
...args
|
|
1031
|
+
});
|
|
1032
|
+
});
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
return out;
|
|
1037
|
+
};
|
|
1038
|
+
fn.$lhSkip = true;
|
|
1039
|
+
fn[CLAIM_PROP] = prop;
|
|
1040
|
+
getters.set(prop, fn);
|
|
1041
|
+
}
|
|
1042
|
+
return fn;
|
|
1043
|
+
}
|
|
1044
|
+
});
|
|
1045
|
+
}
|
|
1046
|
+
const FRAME_TAG = "solid-frame";
|
|
1047
|
+
const FRAME_ID_ATTR = "data-fid";
|
|
1048
|
+
function frameElementOpen(id) {
|
|
1049
|
+
const escaped = sharedConfig.context ? sharedConfig.context.escape(String(id), true) : String(id);
|
|
1050
|
+
return `<${FRAME_TAG} ${FRAME_ID_ATTR}="${escaped}" style="display:contents">`;
|
|
1051
|
+
}
|
|
1052
|
+
const FRAME_ELEMENT_CLOSE = `</${FRAME_TAG}>`;
|
|
1053
|
+
function armDocumentLiveHoles(ctx) {
|
|
1054
|
+
if (!ctx || ctx.liveHoles !== undefined) return;
|
|
1055
|
+
const live = ctx.live;
|
|
1056
|
+
if (live && live.holes !== undefined) {
|
|
1057
|
+
ctx.liveHoles = live.holes;
|
|
1058
|
+
if (live.holes) {
|
|
1059
|
+
ctx.commit = live.commit;
|
|
1060
|
+
ctx.commitEpoch = live.commitEpoch;
|
|
1061
|
+
}
|
|
1062
|
+
return;
|
|
1063
|
+
}
|
|
1064
|
+
if (!live || !ctx.async || ctx.noHydrate || !ctx.serialize || typeof ReadableStream !== "function") {
|
|
1065
|
+
ctx.liveHoles = null;
|
|
1066
|
+
if (live) live.holes = null;
|
|
1067
|
+
return;
|
|
1068
|
+
}
|
|
1069
|
+
const bindings = new Map();
|
|
1070
|
+
let epoch = 0;
|
|
1071
|
+
let sweepScheduled = false;
|
|
1072
|
+
let closed = false;
|
|
1073
|
+
const sweep = () => {
|
|
1074
|
+
epoch++;
|
|
1075
|
+
for (const b of [...bindings.values()]) {
|
|
1076
|
+
try {
|
|
1077
|
+
b.sweep();
|
|
1078
|
+
} catch (_) {
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
};
|
|
1082
|
+
const scheduleSweep = () => {
|
|
1083
|
+
if (closed || sweepScheduled || !bindings.size) return;
|
|
1084
|
+
sweepScheduled = true;
|
|
1085
|
+
queueMicrotask(() => {
|
|
1086
|
+
sweepScheduled = false;
|
|
1087
|
+
if (!closed) sweep();
|
|
1088
|
+
});
|
|
1089
|
+
};
|
|
1090
|
+
let channel;
|
|
1091
|
+
ctx.serialize("sc:live", new ReadableStream({
|
|
1092
|
+
start(c) {
|
|
1093
|
+
channel = c;
|
|
1094
|
+
}
|
|
1095
|
+
}));
|
|
1096
|
+
const push = op => {
|
|
1097
|
+
if (!closed) channel.enqueue(op);
|
|
1098
|
+
};
|
|
1099
|
+
ctx.liveHoles = live.holes = createLiveHoles({
|
|
1100
|
+
openBinding(key, b) {
|
|
1101
|
+
bindings.set(key, b);
|
|
1102
|
+
},
|
|
1103
|
+
closeBinding(key) {
|
|
1104
|
+
bindings.delete(key);
|
|
1105
|
+
},
|
|
1106
|
+
hole(key, html) {
|
|
1107
|
+
push({
|
|
1108
|
+
type: "hole",
|
|
1109
|
+
key,
|
|
1110
|
+
html,
|
|
1111
|
+
digest: textDigest(html)
|
|
1112
|
+
});
|
|
1113
|
+
},
|
|
1114
|
+
attr(key, attrs, removed) {
|
|
1115
|
+
const op = {
|
|
1116
|
+
type: "attr",
|
|
1117
|
+
key,
|
|
1118
|
+
attrs,
|
|
1119
|
+
digest: textDigest(attrs)
|
|
1120
|
+
};
|
|
1121
|
+
if (removed && removed.length) op.removed = removed;
|
|
1122
|
+
push(op);
|
|
1123
|
+
},
|
|
1124
|
+
error(key, error) {
|
|
1125
|
+
push({
|
|
1126
|
+
type: "error",
|
|
1127
|
+
key,
|
|
1128
|
+
error
|
|
1129
|
+
});
|
|
1130
|
+
},
|
|
1131
|
+
commit: scheduleSweep,
|
|
1132
|
+
get epoch() {
|
|
1133
|
+
return epoch;
|
|
1134
|
+
}
|
|
1135
|
+
}, true);
|
|
1136
|
+
ctx.commit = live.commit = scheduleSweep;
|
|
1137
|
+
ctx.commitEpoch = live.commitEpoch = () => epoch;
|
|
1138
|
+
live.args = {
|
|
1139
|
+
openBinding(key, b) {
|
|
1140
|
+
bindings.set(key, b);
|
|
1141
|
+
},
|
|
1142
|
+
closeBinding(key) {
|
|
1143
|
+
bindings.delete(key);
|
|
1144
|
+
},
|
|
1145
|
+
slot(fid, occurrence, args) {
|
|
1146
|
+
push({
|
|
1147
|
+
type: "slot",
|
|
1148
|
+
fid,
|
|
1149
|
+
key: occurrence,
|
|
1150
|
+
args
|
|
1151
|
+
});
|
|
1152
|
+
},
|
|
1153
|
+
commit: scheduleSweep
|
|
1154
|
+
};
|
|
1155
|
+
live.end = () => {
|
|
1156
|
+
if (closed) return;
|
|
1157
|
+
if (bindings.size) sweep();
|
|
1158
|
+
closed = true;
|
|
1159
|
+
channel.close();
|
|
1160
|
+
};
|
|
1161
|
+
}
|
|
1162
|
+
function frameTransformDirectResult(value, {
|
|
1163
|
+
id,
|
|
1164
|
+
args
|
|
1165
|
+
}) {
|
|
1166
|
+
if (typeof value !== "function") return value;
|
|
1167
|
+
const component = value;
|
|
1168
|
+
const wrapped = props => [{
|
|
1169
|
+
t: frameElementOpen(id)
|
|
1170
|
+
},
|
|
1171
|
+
serverOwned(() => {
|
|
1172
|
+
armDocumentLiveHoles(sharedConfig.context);
|
|
1173
|
+
sharedConfig.context.claims = CLAIMS_DOCUMENT;
|
|
1174
|
+
const slotProps = createDocumentSlotProps(props, id);
|
|
1175
|
+
return serverComponentScope(() => component(slotProps), !!wrapped[LIVE_SOURCE]);
|
|
1176
|
+
}), {
|
|
1177
|
+
t: FRAME_ELEMENT_CLOSE
|
|
1178
|
+
}];
|
|
1179
|
+
wrapped[SERVER_COMPONENT] = id;
|
|
1180
|
+
wrapped[SERVER_COMPONENT_SOURCE] = component;
|
|
1181
|
+
wrapped[SERVER_COMPONENT_ADDRESS] = frameAddress(id, args);
|
|
1182
|
+
return wrapped;
|
|
1183
|
+
}
|
|
1184
|
+
function resolveRegionHtml(ctx, node) {
|
|
1185
|
+
const res = ctx.resolve(node);
|
|
1186
|
+
if (!res || !res.t) return String(res ?? "");
|
|
1187
|
+
if (!res.h || !res.h.length) return res.t[0];
|
|
1188
|
+
return Promise.all(res.p).then(() => {
|
|
1189
|
+
let out = Promise.resolve(res.t[0]);
|
|
1190
|
+
for (let i = 0; i < res.h.length; i++) {
|
|
1191
|
+
const hole = res.h[i];
|
|
1192
|
+
const tail = res.t[i + 1];
|
|
1193
|
+
out = out.then(acc => Promise.resolve(resolveRegionHtml(ctx, hole)).then(part => acc + part + tail));
|
|
1194
|
+
}
|
|
1195
|
+
return out;
|
|
1196
|
+
});
|
|
1197
|
+
}
|
|
1198
|
+
function isServerContent(value) {
|
|
1199
|
+
if (value && typeof value === "object") {
|
|
1200
|
+
if ("t" in value) return true;
|
|
1201
|
+
if (Array.isArray(value) && value.length > 0) {
|
|
1202
|
+
for (const item of value) {
|
|
1203
|
+
if (!(item && typeof item === "object" && "t" in item)) return false;
|
|
1204
|
+
}
|
|
1205
|
+
return true;
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
return false;
|
|
1209
|
+
}
|
|
1210
|
+
function unwrapThunks(value) {
|
|
1211
|
+
for (let d = 0; typeof value === "function" && d < 16; d++) value = value();
|
|
1212
|
+
return value;
|
|
1213
|
+
}
|
|
1214
|
+
function contentArgError(key, occurrence) {
|
|
1215
|
+
return new Error("Async slot arg resolved to JSX (arg '" + key + "' of " + occurrence + "). Async args must resolve to serializable values; render async content through a boundary instead.");
|
|
1216
|
+
}
|
|
1217
|
+
function retryArgUntilSettled(evaluate, blocked, key, occurrence, onSettle) {
|
|
1218
|
+
const owner = getOwner();
|
|
1219
|
+
return new Promise((resolve, reject) => {
|
|
1220
|
+
const retry = () => {
|
|
1221
|
+
try {
|
|
1222
|
+
const value = owner ? runWithOwner(owner, evaluate) : evaluate();
|
|
1223
|
+
if (isServerContent(value)) {
|
|
1224
|
+
reject(contentArgError(key, occurrence));
|
|
1225
|
+
return;
|
|
1226
|
+
}
|
|
1227
|
+
if (onSettle) onSettle(value);
|
|
1228
|
+
resolve(value);
|
|
1229
|
+
} catch (err) {
|
|
1230
|
+
const next = ssrHandleError && ssrHandleError(err);
|
|
1231
|
+
if (next) next.then(retry, retry);else reject(err);
|
|
1232
|
+
}
|
|
1233
|
+
};
|
|
1234
|
+
blocked.then(retry, retry);
|
|
1235
|
+
});
|
|
1236
|
+
}
|
|
1237
|
+
function openArgBinding(sink, ledgerKey, occurrence, key, evaluate, state, emit) {
|
|
1238
|
+
const owner = getOwner();
|
|
1239
|
+
sink.openBinding(ledgerKey, {
|
|
1240
|
+
sweep() {
|
|
1241
|
+
if (!state.settled) return;
|
|
1242
|
+
let value;
|
|
1243
|
+
const stampBefore = scopeStamp();
|
|
1244
|
+
try {
|
|
1245
|
+
value = owner ? runWithOwner(owner, evaluate) : evaluate();
|
|
1246
|
+
} catch (err) {
|
|
1247
|
+
const blocked = ssrHandleError && ssrHandleError(err);
|
|
1248
|
+
if (!blocked) {
|
|
1249
|
+
sink.closeBinding(ledgerKey);
|
|
1250
|
+
emit(Promise.reject(err instanceof Error ? err : new Error(String(err))));
|
|
1251
|
+
return;
|
|
1252
|
+
}
|
|
1253
|
+
if (scopeStamp() !== stampBefore) {
|
|
1254
|
+
sink.closeBinding(ledgerKey);
|
|
1255
|
+
return;
|
|
1256
|
+
}
|
|
1257
|
+
state.settled = false;
|
|
1258
|
+
emit(retryArgUntilSettled(evaluate, blocked, key, occurrence, v => {
|
|
1259
|
+
state.settled = true;
|
|
1260
|
+
state.last = v;
|
|
1261
|
+
sink.commit();
|
|
1262
|
+
}));
|
|
1263
|
+
return;
|
|
1264
|
+
}
|
|
1265
|
+
if (scopeStamp() !== stampBefore) {
|
|
1266
|
+
sink.closeBinding(ledgerKey);
|
|
1267
|
+
return;
|
|
1268
|
+
}
|
|
1269
|
+
if (value === state.last) return;
|
|
1270
|
+
state.last = value;
|
|
1271
|
+
if (isServerContent(value)) {
|
|
1272
|
+
sink.closeBinding(ledgerKey);
|
|
1273
|
+
emit(Promise.reject(contentArgError(key, occurrence)));
|
|
1274
|
+
return;
|
|
1275
|
+
}
|
|
1276
|
+
emit(value);
|
|
1277
|
+
}
|
|
1278
|
+
});
|
|
1279
|
+
}
|
|
1280
|
+
function createSlotProps(sink, frame) {
|
|
1281
|
+
const counts = Object.create(null);
|
|
1282
|
+
const getters = new Map();
|
|
1283
|
+
return new Proxy(Object.create(null), {
|
|
1284
|
+
has() {
|
|
1285
|
+
return true;
|
|
1286
|
+
},
|
|
1287
|
+
get(_, prop) {
|
|
1288
|
+
if (typeof prop !== "string") return undefined;
|
|
1289
|
+
if (prop === "then") return undefined;
|
|
1290
|
+
let fn = getters.get(prop);
|
|
1291
|
+
if (!fn) {
|
|
1292
|
+
fn = (...callArgs) => {
|
|
1293
|
+
if (callArgs.length === 0 || callArgs[0] === undefined) {
|
|
1294
|
+
return slotRange(prop);
|
|
1295
|
+
}
|
|
1296
|
+
const live = sharedConfig.context && sharedConfig.context.liveHoles;
|
|
1297
|
+
if (live) {
|
|
1298
|
+
if (live.sweeping) {
|
|
1299
|
+
live.gateHit = true;
|
|
1300
|
+
return {
|
|
1301
|
+
t: "",
|
|
1302
|
+
$slot: true
|
|
1303
|
+
};
|
|
1304
|
+
}
|
|
1305
|
+
live.recordStamp++;
|
|
1306
|
+
}
|
|
1307
|
+
const raw = callArgs[0];
|
|
1308
|
+
const occurrence = occurrenceId(prop, raw, counts);
|
|
1309
|
+
const args = {};
|
|
1310
|
+
const opened = [];
|
|
1311
|
+
for (const key of Object.keys(raw)) {
|
|
1312
|
+
if (key === "$key") continue;
|
|
1313
|
+
const childId = `${frame.id}.${occurrence}.${key}`;
|
|
1314
|
+
const ctx = sharedConfig.context;
|
|
1315
|
+
const origRegister = ctx.registerFragment;
|
|
1316
|
+
ctx.registerFragment = (fragKey, fragOptions) => {
|
|
1317
|
+
sink.tagRegion(fragKey, childId);
|
|
1318
|
+
return origRegister.call(ctx, fragKey, fragOptions);
|
|
1319
|
+
};
|
|
1320
|
+
try {
|
|
1321
|
+
const desc = Object.getOwnPropertyDescriptor(raw, key);
|
|
1322
|
+
let evaluate = null;
|
|
1323
|
+
let value;
|
|
1324
|
+
let state = null;
|
|
1325
|
+
const stampBefore = scopeStamp();
|
|
1326
|
+
try {
|
|
1327
|
+
if (desc.get) {
|
|
1328
|
+
const get = desc.get;
|
|
1329
|
+
evaluate = () => unwrapThunks(get.call(raw));
|
|
1330
|
+
value = evaluate();
|
|
1331
|
+
} else {
|
|
1332
|
+
value = desc.value;
|
|
1333
|
+
if (typeof value === "function") {
|
|
1334
|
+
const fn = value;
|
|
1335
|
+
evaluate = () => unwrapThunks(fn);
|
|
1336
|
+
value = evaluate();
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
} catch (err) {
|
|
1340
|
+
const blocked = ssrHandleError && ssrHandleError(err);
|
|
1341
|
+
if (!blocked) throw err;
|
|
1342
|
+
state = {
|
|
1343
|
+
settled: false,
|
|
1344
|
+
last: undefined
|
|
1345
|
+
};
|
|
1346
|
+
const pendingState = state;
|
|
1347
|
+
value = retryArgUntilSettled(evaluate, blocked, key, occurrence, v => {
|
|
1348
|
+
pendingState.settled = true;
|
|
1349
|
+
pendingState.last = v;
|
|
1350
|
+
sink.commit();
|
|
1351
|
+
});
|
|
1352
|
+
}
|
|
1353
|
+
const mintedEval = scopeStamp() !== stampBefore;
|
|
1354
|
+
const t = typeof value;
|
|
1355
|
+
if (value == null || t === "string" || t === "number" || t === "boolean") {
|
|
1356
|
+
args[key] = value;
|
|
1357
|
+
if (evaluate) state = {
|
|
1358
|
+
settled: true,
|
|
1359
|
+
last: value
|
|
1360
|
+
};
|
|
1361
|
+
} else if (!isContainerTraced(value) && isServerContent(value)) {
|
|
1362
|
+
const resolved = ctx.resolve(value);
|
|
1363
|
+
if (resolved.h.length) {
|
|
1364
|
+
throw new Error("Async server content in a slot arg needs a boundary (arg '" + key + "' of " + occurrence + "). Wrap the async read in a <Suspense>, or move it above the slot.");
|
|
1365
|
+
}
|
|
1366
|
+
sink.region(childId, resolved.t[0]);
|
|
1367
|
+
args[key] = {
|
|
1368
|
+
$frame: childId
|
|
1369
|
+
};
|
|
1370
|
+
} else {
|
|
1371
|
+
const ref = `arg:${occurrence}:${key}`;
|
|
1372
|
+
ctx.serialize(ref, toBorderForm(value, true));
|
|
1373
|
+
args[key] = {
|
|
1374
|
+
$ref: ref
|
|
1375
|
+
};
|
|
1376
|
+
if (evaluate && !state) state = {
|
|
1377
|
+
settled: true,
|
|
1378
|
+
last: value
|
|
1379
|
+
};
|
|
1380
|
+
}
|
|
1381
|
+
if (evaluate && state && !mintedEval) opened.push({
|
|
1382
|
+
key,
|
|
1383
|
+
evaluate,
|
|
1384
|
+
state
|
|
1385
|
+
});
|
|
1386
|
+
} finally {
|
|
1387
|
+
ctx.registerFragment = origRegister;
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
sink.slot(occurrence, {
|
|
1391
|
+
...args
|
|
1392
|
+
});
|
|
1393
|
+
const ctx = sharedConfig.context;
|
|
1394
|
+
for (const b of opened) {
|
|
1395
|
+
const key = b.key;
|
|
1396
|
+
const ledgerKey = `${occurrence}:${key}`;
|
|
1397
|
+
openArgBinding(sink, ledgerKey, occurrence, key, b.evaluate, b.state, value => {
|
|
1398
|
+
const t = typeof value;
|
|
1399
|
+
if (value == null || t === "string" || t === "number" || t === "boolean") {
|
|
1400
|
+
args[key] = value;
|
|
1401
|
+
} else {
|
|
1402
|
+
const ref = `arg:${occurrence}:${key}@${sink.nextArgRef(ledgerKey)}`;
|
|
1403
|
+
sink.mintRef(ref);
|
|
1404
|
+
ctx.serialize(ref, toBorderForm(value));
|
|
1405
|
+
args[key] = {
|
|
1406
|
+
$ref: ref
|
|
1407
|
+
};
|
|
1408
|
+
}
|
|
1409
|
+
sink.slot(occurrence, {
|
|
1410
|
+
...args
|
|
1411
|
+
});
|
|
1412
|
+
});
|
|
1413
|
+
}
|
|
1414
|
+
return slotRange(occurrence);
|
|
1415
|
+
};
|
|
1416
|
+
fn.$lhSkip = true;
|
|
1417
|
+
fn[CLAIM_PROP] = prop;
|
|
1418
|
+
getters.set(prop, fn);
|
|
1419
|
+
}
|
|
1420
|
+
return fn;
|
|
1421
|
+
}
|
|
1422
|
+
});
|
|
1423
|
+
}
|
|
1424
|
+
function copyInitHeaders(init) {
|
|
1425
|
+
if (!init || !init.getSetCookie) return new Headers(init);
|
|
1426
|
+
const headers = new Headers();
|
|
1427
|
+
init.forEach((value, key) => {
|
|
1428
|
+
if (key !== "set-cookie") headers.append(key, value);
|
|
1429
|
+
});
|
|
1430
|
+
for (const cookie of init.getSetCookie()) headers.append("Set-Cookie", cookie);
|
|
1431
|
+
return headers;
|
|
1432
|
+
}
|
|
1433
|
+
function serverComponentResponse(component, options = {}, init = {}) {
|
|
1434
|
+
const {
|
|
1435
|
+
id = "",
|
|
1436
|
+
version = 1
|
|
1437
|
+
} = options.frame || {};
|
|
1438
|
+
const live = !!options.live;
|
|
1439
|
+
const headers = copyInitHeaders(init.headers);
|
|
1440
|
+
headers.set(FRAME_STREAM_HEADER, id);
|
|
1441
|
+
headers.set("X-Content-Raw", "1");
|
|
1442
|
+
if (live) {
|
|
1443
|
+
headers.set("Content-Type", "text/event-stream");
|
|
1444
|
+
headers.set("Cache-Control", "no-store");
|
|
1445
|
+
headers.set("X-Accel-Buffering", "no");
|
|
1446
|
+
} else headers.set("Content-Type", "application/x-frame-stream");
|
|
1447
|
+
const frame = live ? createEventChunk : createChunk;
|
|
1448
|
+
const teardown = new AbortController();
|
|
1449
|
+
const disarm = followSignal(options.signal, teardown);
|
|
1450
|
+
const stream = renderServerComponent(component, {
|
|
1451
|
+
...options,
|
|
1452
|
+
signal: teardown.signal,
|
|
1453
|
+
frame: {
|
|
1454
|
+
id,
|
|
1455
|
+
version
|
|
1456
|
+
}
|
|
1457
|
+
});
|
|
1458
|
+
let closed = false;
|
|
1459
|
+
let stopLive = null;
|
|
1460
|
+
const body = new ReadableStream({
|
|
1461
|
+
start(controller) {
|
|
1462
|
+
const end = () => {
|
|
1463
|
+
if (closed) return;
|
|
1464
|
+
closed = true;
|
|
1465
|
+
disarm();
|
|
1466
|
+
if (stopLive) stopLive();
|
|
1467
|
+
try {
|
|
1468
|
+
controller.close();
|
|
1469
|
+
} catch (_) {}
|
|
1470
|
+
};
|
|
1471
|
+
if (teardown.signal.aborted) return end();
|
|
1472
|
+
teardown.signal.addEventListener("abort", end, {
|
|
1473
|
+
once: true
|
|
1474
|
+
});
|
|
1475
|
+
if (live) stopLive = armLiveBody(controller, () => {
|
|
1476
|
+
closed = true;
|
|
1477
|
+
disarm();
|
|
1478
|
+
teardown.abort();
|
|
1479
|
+
});
|
|
1480
|
+
stream.pipe({
|
|
1481
|
+
write(chunk) {
|
|
1482
|
+
if (closed) return;
|
|
1483
|
+
try {
|
|
1484
|
+
controller.enqueue(frame(JSON.stringify(chunk)));
|
|
1485
|
+
} catch (_) {
|
|
1486
|
+
closed = true;
|
|
1487
|
+
}
|
|
1488
|
+
},
|
|
1489
|
+
end
|
|
1490
|
+
});
|
|
1491
|
+
},
|
|
1492
|
+
cancel() {
|
|
1493
|
+
closed = true;
|
|
1494
|
+
disarm();
|
|
1495
|
+
if (stopLive) stopLive();
|
|
1496
|
+
teardown.abort();
|
|
1497
|
+
}
|
|
1498
|
+
});
|
|
1499
|
+
return new Response(body, {
|
|
1500
|
+
status: init.status || 200,
|
|
1501
|
+
headers
|
|
1502
|
+
});
|
|
1503
|
+
}
|
|
1504
|
+
function followSignal(upstream, controller) {
|
|
1505
|
+
if (!upstream) return () => {};
|
|
1506
|
+
if (upstream.aborted) {
|
|
1507
|
+
controller.abort(upstream.reason);
|
|
1508
|
+
return () => {};
|
|
1509
|
+
}
|
|
1510
|
+
const forward = () => controller.abort(upstream.reason);
|
|
1511
|
+
upstream.addEventListener("abort", forward, {
|
|
1512
|
+
once: true
|
|
1513
|
+
});
|
|
1514
|
+
return () => upstream.removeEventListener("abort", forward);
|
|
1515
|
+
}
|
|
1516
|
+
function frameTransformResult(event, result, context) {
|
|
1517
|
+
let init;
|
|
1518
|
+
if (isResponseEnvelope(result)) {
|
|
1519
|
+
const {
|
|
1520
|
+
response,
|
|
1521
|
+
value
|
|
1522
|
+
} = result;
|
|
1523
|
+
if (typeof value !== "function") return result;
|
|
1524
|
+
init = response ? {
|
|
1525
|
+
headers: response.headers,
|
|
1526
|
+
status: response.status
|
|
1527
|
+
} : undefined;
|
|
1528
|
+
result = value;
|
|
1529
|
+
}
|
|
1530
|
+
if (typeof result !== "function") return result;
|
|
1531
|
+
if (context && context.collectsFlight) return init ? {
|
|
1532
|
+
response: init,
|
|
1533
|
+
value: result
|
|
1534
|
+
} : result;
|
|
1535
|
+
const invocation = getEventServerFunctionInvocation(event);
|
|
1536
|
+
const live = !!(invocation && invocation.live);
|
|
1537
|
+
const have = live ? decodeHaveList(requestHeader(event, FRAME_HAVE_HEADER)) : undefined;
|
|
1538
|
+
return serverComponentResponse(result, {
|
|
1539
|
+
frame: {
|
|
1540
|
+
id: invocation && invocation.id || ""
|
|
1541
|
+
},
|
|
1542
|
+
signal: requestSignal(event),
|
|
1543
|
+
live,
|
|
1544
|
+
resume: have && {
|
|
1545
|
+
have
|
|
1546
|
+
}
|
|
1547
|
+
}, init);
|
|
1548
|
+
}
|
|
1549
|
+
function requestSignal(event) {
|
|
1550
|
+
const request = event && event.request;
|
|
1551
|
+
return request && request.signal instanceof AbortSignal ? request.signal : undefined;
|
|
1552
|
+
}
|
|
1553
|
+
function requestHeader(event, name) {
|
|
1554
|
+
const request = event && event.request;
|
|
1555
|
+
const headers = request && request.headers;
|
|
1556
|
+
return headers && typeof headers.get === "function" ? headers.get(name) : null;
|
|
1557
|
+
}
|
|
1558
|
+
async function frameTransformFlightResult(event, outcome, context) {
|
|
1559
|
+
const {
|
|
1560
|
+
value,
|
|
1561
|
+
data
|
|
1562
|
+
} = outcome;
|
|
1563
|
+
const regions = [];
|
|
1564
|
+
let serialized = data;
|
|
1565
|
+
if (data && typeof data === "object") {
|
|
1566
|
+
serialized = {};
|
|
1567
|
+
for (const source of Object.keys(data)) {
|
|
1568
|
+
const slice = data[source];
|
|
1569
|
+
if (!slice || typeof slice !== "object" || Array.isArray(slice)) {
|
|
1570
|
+
serialized[source] = slice;
|
|
1571
|
+
continue;
|
|
1572
|
+
}
|
|
1573
|
+
const keys = Object.keys(slice);
|
|
1574
|
+
const settled = await Promise.allSettled(keys.map(key => slice[key]));
|
|
1575
|
+
const out = serialized[source] = {};
|
|
1576
|
+
for (let i = 0; i < keys.length; i++) {
|
|
1577
|
+
const result = settled[i];
|
|
1578
|
+
const entry = result.status === "fulfilled" ? result.value : slice[keys[i]];
|
|
1579
|
+
if (typeof entry !== "function") {
|
|
1580
|
+
out[keys[i]] = entry;
|
|
1581
|
+
continue;
|
|
1582
|
+
}
|
|
1583
|
+
const address = entry[SERVER_COMPONENT_ADDRESS] || keys[i];
|
|
1584
|
+
regions.push({
|
|
1585
|
+
id: address,
|
|
1586
|
+
component: entry[SERVER_COMPONENT_SOURCE] || entry
|
|
1587
|
+
});
|
|
1588
|
+
if (SERVER_COMPONENT in entry) {
|
|
1589
|
+
out[keys[i]] = entry;
|
|
1590
|
+
} else {
|
|
1591
|
+
const reference = () => undefined;
|
|
1592
|
+
reference[SERVER_COMPONENT] = keys[i];
|
|
1593
|
+
reference[SERVER_COMPONENT_ADDRESS] = address;
|
|
1594
|
+
out[keys[i]] = reference;
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
const invocation = getEventServerFunctionInvocation(event);
|
|
1600
|
+
const primary = typeof value === "function" ? {
|
|
1601
|
+
id: invocation && invocation.id || "",
|
|
1602
|
+
component: value
|
|
1603
|
+
} : undefined;
|
|
1604
|
+
if (!primary && !regions.length) return undefined;
|
|
1605
|
+
return frameFlightResponse({
|
|
1606
|
+
primary,
|
|
1607
|
+
regions,
|
|
1608
|
+
outcome: {
|
|
1609
|
+
value: primary ? undefined : value,
|
|
1610
|
+
data: serialized
|
|
1611
|
+
},
|
|
1612
|
+
codec: context && context.codec,
|
|
1613
|
+
signal: requestSignal(event)
|
|
1614
|
+
});
|
|
1615
|
+
}
|
|
1616
|
+
function frameFlightResponse({
|
|
1617
|
+
primary,
|
|
1618
|
+
regions = [],
|
|
1619
|
+
outcome,
|
|
1620
|
+
codec,
|
|
1621
|
+
signal
|
|
1622
|
+
}, init = {}) {
|
|
1623
|
+
const frames = primary ? [primary, ...regions] : regions;
|
|
1624
|
+
const headers = copyInitHeaders(init.headers);
|
|
1625
|
+
headers.set("Content-Type", "application/x-frame-stream");
|
|
1626
|
+
headers.set(FRAME_STREAM_HEADER, primary ? primary.id : "");
|
|
1627
|
+
headers.set("X-Content-Raw", "1");
|
|
1628
|
+
const teardown = new AbortController();
|
|
1629
|
+
const disarm = followSignal(signal, teardown);
|
|
1630
|
+
let closed = false;
|
|
1631
|
+
const body = new ReadableStream({
|
|
1632
|
+
async start(controller) {
|
|
1633
|
+
const write = chunk => {
|
|
1634
|
+
if (closed) return;
|
|
1635
|
+
try {
|
|
1636
|
+
controller.enqueue(createChunk(JSON.stringify(chunk)));
|
|
1637
|
+
} catch (_) {
|
|
1638
|
+
closed = true;
|
|
1639
|
+
}
|
|
1640
|
+
};
|
|
1641
|
+
try {
|
|
1642
|
+
for (const {
|
|
1643
|
+
id,
|
|
1644
|
+
component
|
|
1645
|
+
} of frames) {
|
|
1646
|
+
if (teardown.signal.aborted) break;
|
|
1647
|
+
await new Promise(resolve => {
|
|
1648
|
+
teardown.signal.addEventListener("abort", resolve, {
|
|
1649
|
+
once: true
|
|
1650
|
+
});
|
|
1651
|
+
renderServerComponent(component, {
|
|
1652
|
+
frame: {
|
|
1653
|
+
id,
|
|
1654
|
+
version: 1
|
|
1655
|
+
},
|
|
1656
|
+
signal: teardown.signal
|
|
1657
|
+
}).pipe({
|
|
1658
|
+
write,
|
|
1659
|
+
end: () => {
|
|
1660
|
+
teardown.signal.removeEventListener("abort", resolve);
|
|
1661
|
+
resolve();
|
|
1662
|
+
}
|
|
1663
|
+
});
|
|
1664
|
+
});
|
|
1665
|
+
}
|
|
1666
|
+
if (teardown.signal.aborted) {
|
|
1667
|
+
closed = true;
|
|
1668
|
+
try {
|
|
1669
|
+
controller.close();
|
|
1670
|
+
} catch (_) {}
|
|
1671
|
+
return;
|
|
1672
|
+
}
|
|
1673
|
+
if (outcome) {
|
|
1674
|
+
const reader = new ChunkReader(serializeStream(guardFailures(outcome), flightCodec(codec)));
|
|
1675
|
+
for (let node = await reader.next(); !node.done; node = await reader.next()) {
|
|
1676
|
+
write({
|
|
1677
|
+
type: "outcome",
|
|
1678
|
+
payload: node.value
|
|
1679
|
+
});
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
if (!closed) {
|
|
1683
|
+
closed = true;
|
|
1684
|
+
controller.close();
|
|
1685
|
+
}
|
|
1686
|
+
} catch (err) {
|
|
1687
|
+
if (!closed) {
|
|
1688
|
+
closed = true;
|
|
1689
|
+
controller.error(err);
|
|
1690
|
+
}
|
|
1691
|
+
} finally {
|
|
1692
|
+
disarm();
|
|
1693
|
+
}
|
|
1694
|
+
},
|
|
1695
|
+
cancel() {
|
|
1696
|
+
closed = true;
|
|
1697
|
+
disarm();
|
|
1698
|
+
teardown.abort();
|
|
1699
|
+
}
|
|
1700
|
+
});
|
|
1701
|
+
return new Response(body, {
|
|
1702
|
+
status: init.status || 200,
|
|
1703
|
+
headers
|
|
1704
|
+
});
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
setContainerTraceResolver(getProjectionTrace);
|
|
1708
|
+
setAsyncIterableSharer(shareAsyncIterable);
|
|
1709
|
+
function asyncArg(value) {
|
|
1710
|
+
return value;
|
|
1711
|
+
}
|
|
1712
|
+
|
|
1713
|
+
export { FRAME_HAVE_BUDGET, FRAME_HAVE_HEADER, FRAME_STREAM_HEADER, SERVER_COMPONENT_BOOTSTRAP, ServerComponentPlugin, asyncArg, createFrameSink, frameTransformDirectResult, frameTransformFlightResult, frameTransformResult, isFrameStreamResponse, renderServerComponent, renderToFrameStream, serverComponentResponse };
|