@solidjs/web 2.0.0-rc.2 → 2.0.0-rc.20
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 +5065 -0
- package/dist/server.js +1757 -355
- package/dist/{server.cjs → server.observe.js} +1951 -558
- package/dist/{dev.cjs → web.dev.js} +945 -550
- package/dist/web.js +635 -332
- package/dist/{dev.js → web.observe.js} +688 -403
- package/frames/dist/assets.js +92 -0
- package/frames/dist/client.dev.js +1296 -1198
- package/frames/dist/client.js +1128 -1191
- package/frames/dist/client.observe.js +2041 -0
- package/frames/dist/regions.js +171 -0
- package/frames/dist/server.dev.js +2549 -0
- package/frames/dist/server.js +1688 -3005
- package/frames/dist/server.observe.js +2548 -0
- package/frames/dist/trace.js +45 -0
- package/frames/dist/wire.js +594 -0
- package/frames/package.json +2 -25
- package/package.json +244 -256
- package/performance-tracks/dist/performance-tracks.dev.js +679 -0
- package/performance-tracks/dist/performance-tracks.js +6 -0
- package/performance-tracks/dist/performance-tracks.observe.js +667 -0
- package/performance-tracks/package.json +7 -0
- package/performance-tracks/types/index.d.ts +69 -0
- package/serialization/decode/package.json +2 -15
- package/serialization/dist/decode.js +121 -25
- package/serialization/dist/serialization.js +242 -88
- package/serialization/package.json +2 -15
- package/serialization/types/index.d.ts +85 -158
- package/serialization/types/serializer-decode.d.ts +173 -114
- package/serialization/types/serializer.d.ts +109 -0
- package/server-functions/dist/client.dev.js +1462 -0
- package/server-functions/dist/client.js +667 -165
- package/server-functions/dist/client.observe.js +1441 -0
- package/server-functions/dist/rich-args.js +84 -1
- package/server-functions/dist/server.dev.js +2714 -297
- package/server-functions/dist/server.js +2595 -271
- package/server-functions/dist/server.observe.js +3594 -0
- package/server-functions/package.json +2 -35
- package/server-functions/rich-args/package.json +2 -15
- package/skills/server-components/SKILL.md +117 -0
- package/storage/package.json +2 -15
- package/types/client.d.ts +342 -288
- package/types/constants.d.ts +22 -0
- package/types/cookies.d.ts +32 -84
- package/types/diagnostics.d.ts +80 -0
- package/types/frames/assets-tier.d.ts +78 -0
- package/types/frames/client.d.ts +40 -1
- package/types/frames/frame-client.d.ts +443 -280
- package/types/frames/frame-container-plugin.d.ts +64 -0
- package/types/frames/frame-morph.d.ts +29 -0
- package/types/frames/frame-sink.d.ts +141 -161
- package/types/frames/frame-transport.d.ts +263 -184
- package/types/frames/regions-tier.d.ts +60 -0
- package/types/frames/serializer-decode.d.ts +241 -0
- package/types/frames/serializer.d.ts +85 -158
- package/types/frames/server.d.ts +2 -2
- package/types/frames/trace-tier.d.ts +2 -0
- package/types/frames/tree-rewrite.d.ts +39 -0
- package/types/frames/wire-tier.d.ts +169 -0
- package/types/head.d.ts +20 -0
- package/types/index.d.ts +98 -81
- package/types/index.server.d.ts +159 -0
- package/types/jsx.d.ts +49 -44
- package/types/observe.d.ts +535 -0
- package/types/reconcile.d.ts +1 -0
- package/types/render.d.ts +11 -0
- package/types/request-error-hook.d.ts +5 -0
- package/types/response.d.ts +95 -147
- package/types/serializer-decode.d.ts +173 -114
- package/types/serializer.d.ts +85 -158
- package/types/server-functions/argument-codec.d.ts +30 -0
- package/types/server-functions/client.d.ts +238 -223
- package/types/server-functions/flash.d.ts +28 -30
- package/types/server-functions/registry.d.ts +105 -0
- package/types/server-functions/rich-args.d.ts +1 -10
- package/types/server-functions/server.d.ts +539 -531
- package/types/server-functions/shared.d.ts +398 -425
- package/types/server-functions/uploads.d.ts +50 -0
- package/types/server-mock.d.ts +120 -13
- package/types/server-observe.d.ts +86 -0
- package/types/server.d.ts +571 -422
- package/types/trace.d.ts +127 -0
- package/LICENSE +0 -21
- package/dist/web.cjs +0 -2033
- package/frames/dist/client.cjs +0 -2002
- package/frames/dist/client.dev.cjs +0 -2022
- package/frames/dist/server.cjs +0 -3877
- package/serialization/dist/decode.cjs +0 -139
- package/serialization/dist/serialization.cjs +0 -261
- 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 -834
- package/server-functions/dist/rich-args.cjs +0 -11
- package/server-functions/dist/server.cjs +0 -1242
- package/server-functions/dist/server.dev.cjs +0 -1242
- 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 -9
- package/types-cjs/client.d.cts +0 -337
- package/types-cjs/cookies.d.cts +0 -93
- package/types-cjs/core.d.cts +0 -9
- package/types-cjs/frames/client.d.cts +0 -36
- package/types-cjs/frames/frame-client.d.cts +0 -356
- 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 -244
- package/types-cjs/jsx-properties.d.cts +0 -93
- package/types-cjs/jsx.d.cts +0 -4159
- 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 -262
- 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 -681
- package/types-cjs/server-functions/shared.d.cts +0 -523
- package/types-cjs/server-mock.d.cts +0 -286
- package/types-cjs/server.d.cts +0 -544
|
@@ -0,0 +1,2548 @@
|
|
|
1
|
+
import { sharedConfig, ssrSanitizeError, creationStamp, ssrHandleError, runInServerComponentScope, trackFillReads, shareAsyncIterable, getProjectionTrace } from 'solid-js/internal';
|
|
2
|
+
import { getOwner, NoHydration, runWithOwner, createMemo, createOwner, Hydration } from 'solid-js';
|
|
3
|
+
import { isResponseEnvelope, RequestContext, renderToStream, createLiveHoles } 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 { frameAddress, getEventServerFunctionInvocation, ChunkReader, serializeStream, guardFailures, armLiveBody, createEventChunk, createChunk, textDigest } from '@solidjs/web/server-functions/server';
|
|
7
|
+
|
|
8
|
+
const DESCEND = Symbol("descend");
|
|
9
|
+
const CYCLE = {};
|
|
10
|
+
const TRACK = 16;
|
|
11
|
+
function rewriteTree(value, visit, withPath) {
|
|
12
|
+
if (value === null || typeof value !== "object") return value;
|
|
13
|
+
const path = withPath ? "" : undefined;
|
|
14
|
+
const state = {
|
|
15
|
+
memo: undefined,
|
|
16
|
+
ancestors: undefined
|
|
17
|
+
};
|
|
18
|
+
try {
|
|
19
|
+
return cow(value, visit, path, 0, state);
|
|
20
|
+
} catch (err) {
|
|
21
|
+
if (err !== CYCLE) throw err;
|
|
22
|
+
}
|
|
23
|
+
return clone(value, visit, path, state.memo || (state.memo = new Map()));
|
|
24
|
+
}
|
|
25
|
+
function shape(value) {
|
|
26
|
+
return Array.isArray(value) ? 1 : Object.getPrototypeOf(value) === Object.prototype ? 2 : 0;
|
|
27
|
+
}
|
|
28
|
+
function cow(value, visit, path, depth, state) {
|
|
29
|
+
const memo = state.memo;
|
|
30
|
+
if (memo !== undefined && memo.has(value)) return memo.get(value);
|
|
31
|
+
const r = visit(value, path);
|
|
32
|
+
if (r !== DESCEND) {
|
|
33
|
+
if (r !== value) (memo || (state.memo = new Map())).set(value, r);
|
|
34
|
+
return r;
|
|
35
|
+
}
|
|
36
|
+
const s = shape(value);
|
|
37
|
+
if (s === 0) return value;
|
|
38
|
+
let ancestors;
|
|
39
|
+
if (depth >= TRACK) {
|
|
40
|
+
ancestors = state.ancestors || (state.ancestors = new Set());
|
|
41
|
+
if (ancestors.has(value)) throw CYCLE;
|
|
42
|
+
ancestors.add(value);
|
|
43
|
+
}
|
|
44
|
+
let out = value;
|
|
45
|
+
if (s === 1) {
|
|
46
|
+
for (let i = 0; i < value.length; i++) {
|
|
47
|
+
const c = value[i];
|
|
48
|
+
if (c === null || typeof c !== "object") continue;
|
|
49
|
+
const next = cow(c, visit, path === undefined ? undefined : `${path}[${i}]`, depth + 1, state);
|
|
50
|
+
if (next !== c) {
|
|
51
|
+
if (out === value) out = value.slice();
|
|
52
|
+
out[i] = next;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
} else {
|
|
56
|
+
for (const k of Object.keys(value)) {
|
|
57
|
+
const c = value[k];
|
|
58
|
+
if (c === null || typeof c !== "object") continue;
|
|
59
|
+
const next = cow(c, visit, path === undefined ? undefined : `${path}.${k}`, depth + 1, state);
|
|
60
|
+
if (next !== c) {
|
|
61
|
+
if (out === value) out = {
|
|
62
|
+
...value
|
|
63
|
+
};
|
|
64
|
+
out[k] = next;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (ancestors !== undefined) ancestors.delete(value);
|
|
69
|
+
return out;
|
|
70
|
+
}
|
|
71
|
+
function clone(value, visit, path, memo) {
|
|
72
|
+
if (memo.has(value)) return memo.get(value);
|
|
73
|
+
const r = visit(value, path);
|
|
74
|
+
if (r !== DESCEND) {
|
|
75
|
+
memo.set(value, r);
|
|
76
|
+
return r;
|
|
77
|
+
}
|
|
78
|
+
const s = shape(value);
|
|
79
|
+
if (s === 0) return value;
|
|
80
|
+
const out = s === 1 ? value.slice() : {
|
|
81
|
+
...value
|
|
82
|
+
};
|
|
83
|
+
memo.set(value, out);
|
|
84
|
+
if (s === 1) {
|
|
85
|
+
for (let i = 0; i < value.length; i++) {
|
|
86
|
+
const c = value[i];
|
|
87
|
+
if (c !== null && typeof c === "object") out[i] = clone(c, visit, path === undefined ? undefined : `${path}[${i}]`, memo);
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
90
|
+
for (const k of Object.keys(value)) {
|
|
91
|
+
const c = value[k];
|
|
92
|
+
if (c !== null && typeof c === "object") out[k] = clone(c, visit, path === undefined ? undefined : `${path}.${k}`, memo);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return out;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const STATE = Symbol.for("solid.container-trace-state");
|
|
99
|
+
const state = globalThis[STATE] || (globalThis[STATE] = {
|
|
100
|
+
materialized: new WeakMap(),
|
|
101
|
+
materializedValues: new WeakSet()
|
|
102
|
+
});
|
|
103
|
+
function setContainerTraceResolver(fn) {
|
|
104
|
+
state.resolveTrace = fn;
|
|
105
|
+
}
|
|
106
|
+
function setAsyncIterableSharer(fn) {
|
|
107
|
+
state.shareIterable = fn;
|
|
108
|
+
}
|
|
109
|
+
function setContainerTraceStreamMint(fn) {
|
|
110
|
+
state.streamOf = fn;
|
|
111
|
+
}
|
|
112
|
+
function isContainerTraced(value) {
|
|
113
|
+
const resolve = state.resolveTrace;
|
|
114
|
+
return !!(resolve && value && typeof value === "object" && resolve(value));
|
|
115
|
+
}
|
|
116
|
+
const TRACE = Symbol.for("solid.container-trace");
|
|
117
|
+
function toBorderForm(value, envelopeContainers) {
|
|
118
|
+
if (value == null || typeof value !== "object") return value;
|
|
119
|
+
const resolve = state.resolveTrace ;
|
|
120
|
+
const share = state.shareIterable;
|
|
121
|
+
if (!resolve && !share) return value;
|
|
122
|
+
return rewriteTree(value, v => {
|
|
123
|
+
if (resolve) {
|
|
124
|
+
const trace = resolve(v);
|
|
125
|
+
if (trace) return {
|
|
126
|
+
[TRACE]: trace
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
if (share && isShareableIterable(v)) return share(v);
|
|
130
|
+
return DESCEND;
|
|
131
|
+
}, false);
|
|
132
|
+
}
|
|
133
|
+
function isShareableIterable(value) {
|
|
134
|
+
try {
|
|
135
|
+
return typeof value[Symbol.asyncIterator] === "function" && !(typeof ReadableStream !== "undefined" && value instanceof ReadableStream);
|
|
136
|
+
} catch {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function materialize(marker, claiming) {
|
|
141
|
+
let value = state.materialized.get(marker.$tr);
|
|
142
|
+
if (value === undefined) {
|
|
143
|
+
value = state.materializeTrace(marker, claiming);
|
|
144
|
+
state.materialized.set(marker.$tr, value);
|
|
145
|
+
if (value !== null && typeof value === "object") state.materializedValues.add(value);
|
|
146
|
+
}
|
|
147
|
+
return value;
|
|
148
|
+
}
|
|
149
|
+
function parseTrace(value, ctx) {
|
|
150
|
+
const trace = value[TRACE];
|
|
151
|
+
const sub = trace.subscribe();
|
|
152
|
+
return {
|
|
153
|
+
a: trace.array ? 1 : 0,
|
|
154
|
+
i: ctx.parse(state.streamOf ? state.streamOf(sub) : sub)
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
const ContainerTracePlugin = {
|
|
158
|
+
tag: "solid/container-trace",
|
|
159
|
+
test(value) {
|
|
160
|
+
return value != null && typeof value === "object" && TRACE in value;
|
|
161
|
+
},
|
|
162
|
+
parse: {
|
|
163
|
+
sync() {
|
|
164
|
+
throw new Error("A reactive container can only be serialized by a streaming serializer.");
|
|
165
|
+
},
|
|
166
|
+
async async(value, ctx) {
|
|
167
|
+
const trace = value[TRACE];
|
|
168
|
+
const sub = trace.subscribe();
|
|
169
|
+
return {
|
|
170
|
+
a: trace.array ? 1 : 0,
|
|
171
|
+
i: await ctx.parse(state.streamOf ? state.streamOf(sub) : sub)
|
|
172
|
+
};
|
|
173
|
+
},
|
|
174
|
+
stream: parseTrace
|
|
175
|
+
},
|
|
176
|
+
serialize(node, ctx) {
|
|
177
|
+
return "{$tr:" + ctx.serialize(node.i) + ",$ta:" + node.a + "}";
|
|
178
|
+
},
|
|
179
|
+
deserialize(node, ctx) {
|
|
180
|
+
const iterable = ctx.deserialize(node.i);
|
|
181
|
+
const marker = {
|
|
182
|
+
$tr: iterable,
|
|
183
|
+
$ta: node.a
|
|
184
|
+
};
|
|
185
|
+
return state.materializeTrace ? materialize(marker) : marker;
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
setContainerTraceStreamMint(iterable => {
|
|
190
|
+
const stream = createStream();
|
|
191
|
+
(async () => {
|
|
192
|
+
try {
|
|
193
|
+
for await (const value of iterable) stream.next(value);
|
|
194
|
+
stream.return(undefined);
|
|
195
|
+
} catch (error) {
|
|
196
|
+
stream.throw(error);
|
|
197
|
+
}
|
|
198
|
+
})();
|
|
199
|
+
return stream;
|
|
200
|
+
});
|
|
201
|
+
const DEFAULT_WEB_PLUGINS = /* @__PURE__ */Object.freeze([AbortSignalPlugin,
|
|
202
|
+
CustomEventPlugin, DOMExceptionPlugin, EventPlugin,
|
|
203
|
+
FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin,
|
|
204
|
+
ContainerTracePlugin]);
|
|
205
|
+
function resolveSerializerPlugins(customPlugins) {
|
|
206
|
+
return customPlugins ? [...customPlugins, ...DEFAULT_WEB_PLUGINS] : [...DEFAULT_WEB_PLUGINS];
|
|
207
|
+
}
|
|
208
|
+
const jsonCodecDisabledFeatures = () => Feature.RegExp;
|
|
209
|
+
const JSON_CODEC_DEPTH_LIMIT = 64;
|
|
210
|
+
const RESOLVED_PLUGINS = Symbol.for("solid.codec.resolvedPlugins");
|
|
211
|
+
function resolveCodecOptions(options = {}) {
|
|
212
|
+
const {
|
|
213
|
+
plugins,
|
|
214
|
+
disabledFeatures,
|
|
215
|
+
depthLimit,
|
|
216
|
+
serializeErrorStacks
|
|
217
|
+
} = options;
|
|
218
|
+
return {
|
|
219
|
+
plugins: options[RESOLVED_PLUGINS] || resolveSerializerPlugins(plugins),
|
|
220
|
+
disabledFeatures: disabledFeatures === undefined ? jsonCodecDisabledFeatures() : disabledFeatures,
|
|
221
|
+
depthLimit: depthLimit === undefined ? JSON_CODEC_DEPTH_LIMIT : depthLimit,
|
|
222
|
+
serializeErrorStacks
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const serializeOnlyDisabledFeatures = serializeErrorStacks => (serializeErrorStacks === undefined ? process.env.NODE_ENV === "development" : serializeErrorStacks) ? 0 : Feature.ErrorPrototypeStack;
|
|
227
|
+
function createKeyedSerializer(serialize, onError, onDone) {
|
|
228
|
+
const cancels = new Set();
|
|
229
|
+
let pendingWrites = 0;
|
|
230
|
+
let flushed = false;
|
|
231
|
+
let done = false;
|
|
232
|
+
let closed = false;
|
|
233
|
+
const maybeDone = () => {
|
|
234
|
+
if (flushed && pendingWrites === 0 && !done) {
|
|
235
|
+
done = true;
|
|
236
|
+
onDone && onDone();
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
return {
|
|
240
|
+
write(key, value) {
|
|
241
|
+
if (flushed) return;
|
|
242
|
+
pendingWrites++;
|
|
243
|
+
let settled = false;
|
|
244
|
+
let failed = false;
|
|
245
|
+
let started = false;
|
|
246
|
+
let cancel = null;
|
|
247
|
+
const settle = () => {
|
|
248
|
+
if (settled) return;
|
|
249
|
+
settled = true;
|
|
250
|
+
if (cancel) cancels.delete(cancel);
|
|
251
|
+
pendingWrites--;
|
|
252
|
+
maybeDone();
|
|
253
|
+
};
|
|
254
|
+
let stream;
|
|
255
|
+
try {
|
|
256
|
+
stream = serialize(key, value, {
|
|
257
|
+
onError: onError && (err => {
|
|
258
|
+
failed = true;
|
|
259
|
+
onError(err);
|
|
260
|
+
if (cancel) {
|
|
261
|
+
cancel();
|
|
262
|
+
settle();
|
|
263
|
+
}
|
|
264
|
+
}),
|
|
265
|
+
onDone: settle
|
|
266
|
+
}, initial => {
|
|
267
|
+
if (initial) started = true;
|
|
268
|
+
return !closed;
|
|
269
|
+
});
|
|
270
|
+
} catch (err) {
|
|
271
|
+
settle();
|
|
272
|
+
throw err;
|
|
273
|
+
}
|
|
274
|
+
if (settled) return;
|
|
275
|
+
if (closed || failed) {
|
|
276
|
+
stream();
|
|
277
|
+
settle();
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
cancel = stream;
|
|
281
|
+
cancels.add(cancel);
|
|
282
|
+
},
|
|
283
|
+
flush() {
|
|
284
|
+
flushed = true;
|
|
285
|
+
maybeDone();
|
|
286
|
+
},
|
|
287
|
+
close() {
|
|
288
|
+
closed = flushed = true;
|
|
289
|
+
for (const cancel of cancels) cancel();
|
|
290
|
+
cancels.clear();
|
|
291
|
+
if (!done) {
|
|
292
|
+
done = true;
|
|
293
|
+
onDone && onDone();
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
function createJSONSerializer({
|
|
299
|
+
onData,
|
|
300
|
+
onDone,
|
|
301
|
+
onError,
|
|
302
|
+
plugins,
|
|
303
|
+
disabledFeatures,
|
|
304
|
+
depthLimit,
|
|
305
|
+
serializeErrorStacks
|
|
306
|
+
}) {
|
|
307
|
+
const resolved = resolveCodecOptions({
|
|
308
|
+
plugins,
|
|
309
|
+
disabledFeatures,
|
|
310
|
+
depthLimit,
|
|
311
|
+
serializeErrorStacks
|
|
312
|
+
});
|
|
313
|
+
const refs = new Map();
|
|
314
|
+
return createKeyedSerializer((key, value, callbacks, live) => toCrossJSONStream(value, {
|
|
315
|
+
refs,
|
|
316
|
+
plugins: resolved.plugins,
|
|
317
|
+
disabledFeatures: resolved.disabledFeatures | serializeOnlyDisabledFeatures(resolved.serializeErrorStacks),
|
|
318
|
+
onParse(node, initial) {
|
|
319
|
+
if (live(initial)) onData({
|
|
320
|
+
key,
|
|
321
|
+
node,
|
|
322
|
+
initial
|
|
323
|
+
});
|
|
324
|
+
},
|
|
325
|
+
...callbacks
|
|
326
|
+
}), onError, onDone);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
const RECORDS = Symbol.for("@solidjs/signals/observe/records");
|
|
330
|
+
function records() {
|
|
331
|
+
return globalThis[RECORDS];
|
|
332
|
+
}
|
|
333
|
+
function frameRecordCensus(event, message, own) {
|
|
334
|
+
const r = message.r;
|
|
335
|
+
let counted = !r;
|
|
336
|
+
for (const key in r) {
|
|
337
|
+
if (key === ":complete" || key === ":bound") continue;
|
|
338
|
+
counted = true;
|
|
339
|
+
countEvent(event, key === "" ? "html" : key.endsWith(":error") ? "error" : key.startsWith("slot:") ? "slot" : key.startsWith("seg:") && r[key] && r[key].kind === "html" ? "fragment" : key, own);
|
|
340
|
+
}
|
|
341
|
+
if (counted) event.chunks++;
|
|
342
|
+
}
|
|
343
|
+
function countEvent(event, type, own) {
|
|
344
|
+
switch (type) {
|
|
345
|
+
case "html":
|
|
346
|
+
if (!own) event.regions++;else if (event.shellMs === undefined) event.shellMs = performance.now() - event.at;
|
|
347
|
+
break;
|
|
348
|
+
case "fragment":
|
|
349
|
+
event.fragments++;
|
|
350
|
+
break;
|
|
351
|
+
case "slot":
|
|
352
|
+
event.slots++;
|
|
353
|
+
break;
|
|
354
|
+
case "error":
|
|
355
|
+
event.errors++;
|
|
356
|
+
break;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function observeFrame(frame) {
|
|
361
|
+
const channel = records();
|
|
362
|
+
if (channel === undefined || !channel.observed("frame")) return undefined;
|
|
363
|
+
const event = {
|
|
364
|
+
side: "server",
|
|
365
|
+
id: frame.id,
|
|
366
|
+
version: frame.version,
|
|
367
|
+
at: performance.now(),
|
|
368
|
+
durationMs: 0,
|
|
369
|
+
outcome: "complete",
|
|
370
|
+
chunks: 0,
|
|
371
|
+
fragments: 0,
|
|
372
|
+
slots: 0,
|
|
373
|
+
regions: 0,
|
|
374
|
+
errors: 0
|
|
375
|
+
};
|
|
376
|
+
let settled = false;
|
|
377
|
+
return {
|
|
378
|
+
chunk(message) {
|
|
379
|
+
frameRecordCensus(event, message, message.id === frame.id);
|
|
380
|
+
},
|
|
381
|
+
settle(outcome, error) {
|
|
382
|
+
if (settled) return;
|
|
383
|
+
settled = true;
|
|
384
|
+
event.durationMs = performance.now() - event.at;
|
|
385
|
+
event.outcome = outcome;
|
|
386
|
+
const live = {};
|
|
387
|
+
if (outcome === "error") live.error = error;
|
|
388
|
+
channel.emit("frame", event, live);
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
const FRAME_STREAM_HEADER = "X-Frame-Stream";
|
|
394
|
+
const FRAME_TIERS_HEADER = "X-Frame-Tiers";
|
|
395
|
+
const FRAME_HAVE_HEADER = "X-Frame-Have";
|
|
396
|
+
const FRAME_HAVE_BUDGET = 4096;
|
|
397
|
+
function decodeHaveList(text) {
|
|
398
|
+
if (!text) return undefined;
|
|
399
|
+
const have = {};
|
|
400
|
+
let any = false;
|
|
401
|
+
for (const entry of text.split(",")) {
|
|
402
|
+
const eq = entry.indexOf("=");
|
|
403
|
+
if (eq === -1) continue;
|
|
404
|
+
const digest = entry.slice(eq + 1).trim();
|
|
405
|
+
if (!/^[0-9a-f]{16}$/.test(digest)) continue;
|
|
406
|
+
have[entry.slice(0, eq).trim()] = digest;
|
|
407
|
+
any = true;
|
|
408
|
+
}
|
|
409
|
+
return any ? have : undefined;
|
|
410
|
+
}
|
|
411
|
+
function isFrameStreamResponse(response) {
|
|
412
|
+
return response.headers.has(FRAME_STREAM_HEADER);
|
|
413
|
+
}
|
|
414
|
+
const SERVER_COMPONENT = /*#__PURE__*/Symbol.for("solid.server-component");
|
|
415
|
+
const SERVER_COMPONENT_SOURCE = /*#__PURE__*/Symbol.for("solid.server-component-source");
|
|
416
|
+
const SERVER_COMPONENT_ADDRESS = /*#__PURE__*/Symbol.for("solid.server-component-address");
|
|
417
|
+
let serverComponentRegistryExpr;
|
|
418
|
+
function setServerComponentBootstrap(resolve) {
|
|
419
|
+
serverComponentRegistryExpr = resolve;
|
|
420
|
+
}
|
|
421
|
+
function parseServerComponent(value, ctx) {
|
|
422
|
+
return {
|
|
423
|
+
id: ctx.parse(value[SERVER_COMPONENT]),
|
|
424
|
+
address: ctx.parse(value[SERVER_COMPONENT_ADDRESS])
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
const ServerComponentPlugin = {
|
|
428
|
+
tag: "solid/server-component",
|
|
429
|
+
test(value) {
|
|
430
|
+
return typeof value === "function" && SERVER_COMPONENT in value;
|
|
431
|
+
},
|
|
432
|
+
parse: {
|
|
433
|
+
sync: parseServerComponent,
|
|
434
|
+
async async(value, ctx) {
|
|
435
|
+
return {
|
|
436
|
+
id: await ctx.parse(value[SERVER_COMPONENT]),
|
|
437
|
+
address: await ctx.parse(value[SERVER_COMPONENT_ADDRESS])
|
|
438
|
+
};
|
|
439
|
+
},
|
|
440
|
+
stream: parseServerComponent
|
|
441
|
+
},
|
|
442
|
+
serialize(node, ctx) {
|
|
443
|
+
const registry = serverComponentRegistryExpr ? serverComponentRegistryExpr(ctx) : "self._$SC";
|
|
444
|
+
return registry + ".r(" + ctx.serialize(node.id) + "," + ctx.serialize(node.address) + ")";
|
|
445
|
+
},
|
|
446
|
+
deserialize(node, ctx) {
|
|
447
|
+
const id = ctx.deserialize(node.id);
|
|
448
|
+
ctx.deserialize(node.address);
|
|
449
|
+
return globalThis._$SC.r(id);
|
|
450
|
+
}
|
|
451
|
+
};
|
|
452
|
+
function flightCodec(codec) {
|
|
453
|
+
const plugins = codec && codec.plugins || [];
|
|
454
|
+
if (plugins.some(plugin => plugin && plugin.tag === ServerComponentPlugin.tag)) return codec;
|
|
455
|
+
return {
|
|
456
|
+
...codec,
|
|
457
|
+
plugins: [...plugins, ServerComponentPlugin]
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
const runWithHydrationScope = (id, fn) => runWithOwner(createOwner({
|
|
462
|
+
id
|
|
463
|
+
}), fn);
|
|
464
|
+
const ssrAsyncValue = value => createMemo(() => value, {
|
|
465
|
+
serialize: false
|
|
466
|
+
});
|
|
467
|
+
const scopeStamp = typeof creationStamp === "function" ? creationStamp : () => 0;
|
|
468
|
+
function serverOwned(render) {
|
|
469
|
+
return NoHydration ? NoHydration({
|
|
470
|
+
get children() {
|
|
471
|
+
return render();
|
|
472
|
+
}
|
|
473
|
+
}) : render();
|
|
474
|
+
}
|
|
475
|
+
function serverComponentScope(render, live = false) {
|
|
476
|
+
return runInServerComponentScope ? runInServerComponentScope(render, live ? {
|
|
477
|
+
live: true
|
|
478
|
+
} : undefined) : render();
|
|
479
|
+
}
|
|
480
|
+
const LIVE_SOURCE = Symbol.for("solid.LiveSource");
|
|
481
|
+
function wirePreload(entry) {
|
|
482
|
+
return entry.href ? {
|
|
483
|
+
href: entry.href,
|
|
484
|
+
attrs: entry.attrs
|
|
485
|
+
} : {
|
|
486
|
+
attrs: entry.attrs
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
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}}))}}))';
|
|
490
|
+
const bootstrappedScripts = new WeakSet();
|
|
491
|
+
setServerComponentBootstrap(ctx => {
|
|
492
|
+
if (bootstrappedScripts.has(ctx)) return "self._$SC";
|
|
493
|
+
bootstrappedScripts.add(ctx);
|
|
494
|
+
return SERVER_COMPONENT_BOOTSTRAP_EXPR;
|
|
495
|
+
});
|
|
496
|
+
const SERVER_COMPONENT_BOOTSTRAP = SERVER_COMPONENT_BOOTSTRAP_EXPR + ";";
|
|
497
|
+
const HOLE_RANGE = /<!--lh:(\d+)-->([\s\S]*?)<!--lh:\/\1-->/g;
|
|
498
|
+
const SLOT_RANGE = /<!--slot:([^>]*?):start-->[\s\S]*?<!--slot:\1:end-->/g;
|
|
499
|
+
const ATTR_ADDRESS = / data-lha="([^"]*)"/g;
|
|
500
|
+
const stripHoleMarkers = html => html.replace(/<!--lh:\/?\d+-->/g, "");
|
|
501
|
+
function frameSkeleton(html) {
|
|
502
|
+
return html.replace(HOLE_RANGE, "<!--lh:$1--><!--lh:/$1-->").replace(SLOT_RANGE, "<!--slot:$1:start--><!--slot:$1:end-->");
|
|
503
|
+
}
|
|
504
|
+
const ROW_HTML = Symbol.for("solid.rowHtml");
|
|
505
|
+
function holeDigests(html, attrText, into = {}) {
|
|
506
|
+
for (const m of html.matchAll(HOLE_RANGE)) {
|
|
507
|
+
into["lh:" + m[1]] = textDigest(stripHoleMarkers(m[2]));
|
|
508
|
+
holeDigests(m[2], null, into);
|
|
509
|
+
}
|
|
510
|
+
if (attrText) {
|
|
511
|
+
for (const m of html.matchAll(ATTR_ADDRESS)) {
|
|
512
|
+
const key = "lha:" + m[1];
|
|
513
|
+
const text = attrText.get(key);
|
|
514
|
+
if (text !== undefined) into[key] = textDigest(text);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
return into;
|
|
518
|
+
}
|
|
519
|
+
function withHoles(chunk, holes) {
|
|
520
|
+
for (const _ in holes) {
|
|
521
|
+
chunk.holes = holes;
|
|
522
|
+
break;
|
|
523
|
+
}
|
|
524
|
+
return chunk;
|
|
525
|
+
}
|
|
526
|
+
function createFrameSink(write, frame, have, hooks) {
|
|
527
|
+
const {
|
|
528
|
+
id,
|
|
529
|
+
version
|
|
530
|
+
} = frame;
|
|
531
|
+
const tiers = new Set();
|
|
532
|
+
let staged = [];
|
|
533
|
+
const send = message => {
|
|
534
|
+
if (staged.length) {
|
|
535
|
+
message.tiers = staged;
|
|
536
|
+
staged = [];
|
|
537
|
+
}
|
|
538
|
+
write(message);
|
|
539
|
+
};
|
|
540
|
+
let queue = [];
|
|
541
|
+
let open = null;
|
|
542
|
+
let scheduled = false;
|
|
543
|
+
const flush = () => {
|
|
544
|
+
scheduled = false;
|
|
545
|
+
open = null;
|
|
546
|
+
const out = queue;
|
|
547
|
+
queue = [];
|
|
548
|
+
for (const message of out) send(message);
|
|
549
|
+
};
|
|
550
|
+
const put = (fid, r) => {
|
|
551
|
+
if (swept) swept.emitted = true;
|
|
552
|
+
showing(r);
|
|
553
|
+
let merge = open && open.id === fid;
|
|
554
|
+
if (merge) for (const key in r) if (key in open.r) merge = false;
|
|
555
|
+
if (merge) Object.assign(open.r, r);else queue.push(open = {
|
|
556
|
+
id: fid,
|
|
557
|
+
version,
|
|
558
|
+
r
|
|
559
|
+
});
|
|
560
|
+
if (!scheduled) {
|
|
561
|
+
scheduled = true;
|
|
562
|
+
queueMicrotask(flush);
|
|
563
|
+
}
|
|
564
|
+
};
|
|
565
|
+
const putError = (fid, key, error) => put(fid, {
|
|
566
|
+
[key ? `${/^lha?:/.test(key) ? "hole" : "seg"}:${key}:error` : ":error"]: error
|
|
567
|
+
});
|
|
568
|
+
const needs = name => {
|
|
569
|
+
if (!tiers.has(name)) {
|
|
570
|
+
tiers.add(name);
|
|
571
|
+
staged.push(name);
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
let conditional = false;
|
|
575
|
+
const skipped = new Set();
|
|
576
|
+
const attrText = new Map();
|
|
577
|
+
const holeDigest = new Map();
|
|
578
|
+
if (have) for (const key in have) key.startsWith("lh:") && holeDigest.set(key, have[key]);
|
|
579
|
+
function showing(r) {
|
|
580
|
+
if ("" in r) holeDigest.clear();
|
|
581
|
+
for (const k in r) {
|
|
582
|
+
const record = r[k];
|
|
583
|
+
if (k.startsWith("hole:lh:") && !k.endsWith(":error")) holeDigest.set(k.slice(5), record.digest);
|
|
584
|
+
if (record) for (const key in record.holes) key.startsWith("lh:") && holeDigest.set(key, record.holes[key]);
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
const html = (value, digest, holes) => withHoles({
|
|
588
|
+
kind: "html",
|
|
589
|
+
value,
|
|
590
|
+
digest
|
|
591
|
+
}, holes);
|
|
592
|
+
const emitDiffering = source => {
|
|
593
|
+
for (const m of source.matchAll(HOLE_RANGE)) {
|
|
594
|
+
const key = "lh:" + m[1];
|
|
595
|
+
const digest = textDigest(stripHoleMarkers(m[2]));
|
|
596
|
+
if (have[key] === digest) continue;
|
|
597
|
+
put(id, {
|
|
598
|
+
["hole:" + key]: html(m[2], digest, holeDigests(m[2], null))
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
for (const m of source.matchAll(ATTR_ADDRESS)) {
|
|
602
|
+
const text = attrText.get("lha:" + m[1]);
|
|
603
|
+
if (text === undefined) continue;
|
|
604
|
+
const digest = textDigest(text);
|
|
605
|
+
if (have["lha:" + m[1]] === digest) continue;
|
|
606
|
+
put(id, {
|
|
607
|
+
["attr:" + m[1]]: {
|
|
608
|
+
kind: "attrs",
|
|
609
|
+
value: text,
|
|
610
|
+
digest
|
|
611
|
+
}
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
};
|
|
615
|
+
const bindings = new Map();
|
|
616
|
+
const sweepMinted = new Set();
|
|
617
|
+
const argRefVersions = new Map();
|
|
618
|
+
let sweepScheduled = false;
|
|
619
|
+
let closed = false;
|
|
620
|
+
let epoch = 0;
|
|
621
|
+
let swept = null;
|
|
622
|
+
const sweep = () => {
|
|
623
|
+
epoch++;
|
|
624
|
+
const pass = swept = {
|
|
625
|
+
r: {},
|
|
626
|
+
emitted: false
|
|
627
|
+
};
|
|
628
|
+
try {
|
|
629
|
+
for (const [key, b] of [...bindings]) {
|
|
630
|
+
if (bindings.get(key) !== b) continue;
|
|
631
|
+
try {
|
|
632
|
+
b.sweep();
|
|
633
|
+
} catch (_) {
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
for (const _ in pass.r) {
|
|
637
|
+
put(id, pass.r);
|
|
638
|
+
break;
|
|
639
|
+
}
|
|
640
|
+
flush();
|
|
641
|
+
if (pass.emitted && hooks && hooks.onYield) hooks.onYield();
|
|
642
|
+
} finally {
|
|
643
|
+
swept = null;
|
|
644
|
+
}
|
|
645
|
+
};
|
|
646
|
+
const scheduleSweep = () => {
|
|
647
|
+
if (closed || sweepScheduled || !bindings.size) return;
|
|
648
|
+
sweepScheduled = true;
|
|
649
|
+
queueMicrotask(() => {
|
|
650
|
+
sweepScheduled = false;
|
|
651
|
+
if (!closed) sweep();
|
|
652
|
+
});
|
|
653
|
+
};
|
|
654
|
+
const regionKeys = new Map();
|
|
655
|
+
const frameOf = key => regionKeys.get(key) || id;
|
|
656
|
+
return {
|
|
657
|
+
tagRegion(key, childId) {
|
|
658
|
+
if (!regionKeys.has(key)) regionKeys.set(key, childId);
|
|
659
|
+
},
|
|
660
|
+
shell(source, meta = {}) {
|
|
661
|
+
const digest = textDigest(frameSkeleton(source));
|
|
662
|
+
if (have && have[""] === digest) {
|
|
663
|
+
conditional = true;
|
|
664
|
+
emitDiffering(source);
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
if (meta.preloads && meta.preloads.size || meta.preloadLinks) {
|
|
668
|
+
const record = {};
|
|
669
|
+
if (meta.preloads && meta.preloads.size) {
|
|
670
|
+
const styles = [];
|
|
671
|
+
const modules = [];
|
|
672
|
+
for (const url of meta.preloads) {
|
|
673
|
+
(url.endsWith(".css") ? styles : modules).push(url);
|
|
674
|
+
}
|
|
675
|
+
if (styles.length) record.styles = styles;
|
|
676
|
+
if (modules.length) record.modules = modules;
|
|
677
|
+
}
|
|
678
|
+
if (meta.preloadLinks) {
|
|
679
|
+
record.preloads = [];
|
|
680
|
+
for (const entry of meta.preloadLinks) {
|
|
681
|
+
record.preloads.push(wirePreload(entry));
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
needs("assets");
|
|
685
|
+
put(id, {
|
|
686
|
+
"seg::assets": record
|
|
687
|
+
});
|
|
688
|
+
}
|
|
689
|
+
put(id, {
|
|
690
|
+
"": html(source, digest, holeDigests(source, attrText))
|
|
691
|
+
});
|
|
692
|
+
},
|
|
693
|
+
data(record) {
|
|
694
|
+
if (record && typeof record.key === "string" && (record.key.endsWith("_fr") || /^\d+$/.test(record.key))) {
|
|
695
|
+
return;
|
|
696
|
+
}
|
|
697
|
+
if (swept) swept.emitted = true;
|
|
698
|
+
flush();
|
|
699
|
+
if (typeof record === "string") {
|
|
700
|
+
send({
|
|
701
|
+
type: "data",
|
|
702
|
+
id,
|
|
703
|
+
version,
|
|
704
|
+
payload: record
|
|
705
|
+
});
|
|
706
|
+
scheduleSweep();
|
|
707
|
+
} else {
|
|
708
|
+
send({
|
|
709
|
+
type: "data",
|
|
710
|
+
id,
|
|
711
|
+
version,
|
|
712
|
+
key: record.key,
|
|
713
|
+
node: record.node,
|
|
714
|
+
initial: record.initial
|
|
715
|
+
});
|
|
716
|
+
if (!sweepMinted.has(record.key)) scheduleSweep();
|
|
717
|
+
}
|
|
718
|
+
},
|
|
719
|
+
fragment(key, value, meta = {}) {
|
|
720
|
+
const fid = frameOf(key);
|
|
721
|
+
if (conditional && fid === id && have[key] !== undefined) {
|
|
722
|
+
skipped.add(key);
|
|
723
|
+
scheduleSweep();
|
|
724
|
+
if (meta.error) {
|
|
725
|
+
putError(fid, key, {
|
|
726
|
+
message: String(meta.error && meta.error.message || meta.error)
|
|
727
|
+
});
|
|
728
|
+
} else emitDiffering(value);
|
|
729
|
+
return;
|
|
730
|
+
}
|
|
731
|
+
const links = meta.styles && meta.styles.links || [];
|
|
732
|
+
const inline = meta.styles && meta.styles.inline || [];
|
|
733
|
+
const r = {};
|
|
734
|
+
if (links.length || inline.length) {
|
|
735
|
+
const record = {};
|
|
736
|
+
if (links.length) {
|
|
737
|
+
record.styles = links.map(e => typeof e === "string" ? e : e.attrs ? {
|
|
738
|
+
href: e.href,
|
|
739
|
+
attrs: e.attrs
|
|
740
|
+
} : e.href);
|
|
741
|
+
}
|
|
742
|
+
if (inline.length) {
|
|
743
|
+
record.inlineStyles = inline.map(e => ({
|
|
744
|
+
id: e.id,
|
|
745
|
+
content: e.content,
|
|
746
|
+
attrs: e.attrs
|
|
747
|
+
}));
|
|
748
|
+
}
|
|
749
|
+
needs("assets");
|
|
750
|
+
r[`seg:${key}:assets`] = record;
|
|
751
|
+
}
|
|
752
|
+
r[`seg:${key}`] = html(value, textDigest(value), holeDigests(value, attrText));
|
|
753
|
+
scheduleSweep();
|
|
754
|
+
if (meta.error) r[`seg:${key}:error`] = {
|
|
755
|
+
message: String(meta.error && meta.error.message || meta.error)
|
|
756
|
+
};
|
|
757
|
+
if (!meta.revealGroup) r[`seg:${key}:reveal`] = true;
|
|
758
|
+
put(fid, r);
|
|
759
|
+
},
|
|
760
|
+
reveal(keys, meta = {}) {
|
|
761
|
+
const byFrame = new Map();
|
|
762
|
+
for (const key of keys) {
|
|
763
|
+
if (conditional && (skipped.has(key) || meta.fallback && have[key] !== undefined)) continue;
|
|
764
|
+
const fid = frameOf(key);
|
|
765
|
+
let group = byFrame.get(fid);
|
|
766
|
+
if (!group) byFrame.set(fid, group = []);
|
|
767
|
+
group.push(key);
|
|
768
|
+
}
|
|
769
|
+
const gate = meta.fallback ? "fallback" : "reveal";
|
|
770
|
+
for (const [fid, groupKeys] of byFrame) {
|
|
771
|
+
const r = {};
|
|
772
|
+
for (const key of groupKeys) r[`seg:${key}:${gate}`] = true;
|
|
773
|
+
put(fid, r);
|
|
774
|
+
}
|
|
775
|
+
},
|
|
776
|
+
asset(type, value) {
|
|
777
|
+
if (type === "module") {
|
|
778
|
+
needs("assets");
|
|
779
|
+
put(id, {
|
|
780
|
+
"seg::assets": {
|
|
781
|
+
modules: [value]
|
|
782
|
+
}
|
|
783
|
+
});
|
|
784
|
+
} else if (type === "preload") {
|
|
785
|
+
needs("assets");
|
|
786
|
+
put(id, {
|
|
787
|
+
"seg::assets": {
|
|
788
|
+
preloads: [wirePreload(value)]
|
|
789
|
+
}
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
},
|
|
793
|
+
end(bound) {
|
|
794
|
+
if (closed) return;
|
|
795
|
+
if (bindings.size && !swept) sweep();
|
|
796
|
+
closed = true;
|
|
797
|
+
put(id, bound ? {
|
|
798
|
+
":complete": true,
|
|
799
|
+
":bound": bound
|
|
800
|
+
} : {
|
|
801
|
+
":complete": true
|
|
802
|
+
});
|
|
803
|
+
flush();
|
|
804
|
+
},
|
|
805
|
+
error(errorId, error) {
|
|
806
|
+
putError(id, errorId, error);
|
|
807
|
+
},
|
|
808
|
+
flush,
|
|
809
|
+
slot(key, args) {
|
|
810
|
+
const r = {
|
|
811
|
+
[`slot:${key}`]: {
|
|
812
|
+
kind: "slot",
|
|
813
|
+
args
|
|
814
|
+
}
|
|
815
|
+
};
|
|
816
|
+
swept ? Object.assign(swept.r, r) : put(id, r);
|
|
817
|
+
},
|
|
818
|
+
region(childId, value) {
|
|
819
|
+
needs("regions");
|
|
820
|
+
put(childId, {
|
|
821
|
+
"": {
|
|
822
|
+
kind: "html",
|
|
823
|
+
value
|
|
824
|
+
}
|
|
825
|
+
});
|
|
826
|
+
},
|
|
827
|
+
hole(key, source, rows) {
|
|
828
|
+
const record = {
|
|
829
|
+
kind: "html",
|
|
830
|
+
digest: textDigest(source)
|
|
831
|
+
};
|
|
832
|
+
const base = holeDigest.get(key);
|
|
833
|
+
if (rows && base && hooks && hooks.live) {
|
|
834
|
+
record.rows = rows;
|
|
835
|
+
record.base = base;
|
|
836
|
+
} else record.value = source;
|
|
837
|
+
withHoles(record, holeDigests(record.rows ? (rows[ROW_HTML] || rows.r.map(r => r[1])).join("") : source, null));
|
|
838
|
+
if (record.rows && hooks && hooks.retain) record[HOLE_SOURCE] = withHoles({
|
|
839
|
+
kind: "html",
|
|
840
|
+
value: source,
|
|
841
|
+
digest: record.digest
|
|
842
|
+
}, holeDigests(source, null));
|
|
843
|
+
const r = {
|
|
844
|
+
["hole:" + key]: record
|
|
845
|
+
};
|
|
846
|
+
showing(r);
|
|
847
|
+
swept ? Object.assign(swept.r, r) : put(id, r);
|
|
848
|
+
},
|
|
849
|
+
attr(key, attrs, removed) {
|
|
850
|
+
const record = {
|
|
851
|
+
kind: "attrs",
|
|
852
|
+
value: attrs,
|
|
853
|
+
digest: textDigest(attrs)
|
|
854
|
+
};
|
|
855
|
+
if (removed && removed.length) record.removed = removed;
|
|
856
|
+
const r = {
|
|
857
|
+
["attr:" + key]: record
|
|
858
|
+
};
|
|
859
|
+
swept ? Object.assign(swept.r, r) : put(id, r);
|
|
860
|
+
},
|
|
861
|
+
attrBaseline(key, text) {
|
|
862
|
+
attrText.set(key, text);
|
|
863
|
+
if (hooks && hooks.retain) hooks.retain(key, text);
|
|
864
|
+
},
|
|
865
|
+
openBinding(key, b) {
|
|
866
|
+
if (/^lha?:/.test(key)) needs("wire");
|
|
867
|
+
bindings.set(key, b);
|
|
868
|
+
},
|
|
869
|
+
closeBinding(key) {
|
|
870
|
+
bindings.delete(key);
|
|
871
|
+
},
|
|
872
|
+
mintRef(ref) {
|
|
873
|
+
sweepMinted.add(ref);
|
|
874
|
+
},
|
|
875
|
+
nextArgRef(ledgerKey) {
|
|
876
|
+
const n = (argRefVersions.get(ledgerKey) || 0) + 1;
|
|
877
|
+
argRefVersions.set(ledgerKey, n);
|
|
878
|
+
return n;
|
|
879
|
+
},
|
|
880
|
+
commit: scheduleSweep,
|
|
881
|
+
get epoch() {
|
|
882
|
+
return epoch;
|
|
883
|
+
},
|
|
884
|
+
needs,
|
|
885
|
+
announce() {
|
|
886
|
+
staged = [];
|
|
887
|
+
return [...tiers];
|
|
888
|
+
}
|
|
889
|
+
};
|
|
890
|
+
}
|
|
891
|
+
function renderServerComponent(component, options = {}) {
|
|
892
|
+
return frameStream((sink, frame) => {
|
|
893
|
+
const props = createSlotProps(sink, frame);
|
|
894
|
+
return () => {
|
|
895
|
+
const ctx = sharedConfig.context;
|
|
896
|
+
if (ctx) {
|
|
897
|
+
ctx.commit = sink.commit;
|
|
898
|
+
ctx.commitEpoch = () => sink.epoch;
|
|
899
|
+
let unsettled = !!options.live;
|
|
900
|
+
if (!unsettled) ctx.unsettled = () => void (unsettled = true);
|
|
901
|
+
ctx.liveHoles = createLiveHoles(sink, false, () => !unsettled, ctx._errorScope);
|
|
902
|
+
}
|
|
903
|
+
return serverComponentScope(() => component(props));
|
|
904
|
+
};
|
|
905
|
+
}, options);
|
|
906
|
+
}
|
|
907
|
+
const DEFAULT_MAX_YIELDS = 64;
|
|
908
|
+
const DEFAULT_MAX_DURATION_MS = 30_000;
|
|
909
|
+
const DISCONNECTED = Symbol("solid.frames.disconnected");
|
|
910
|
+
const ANNOUNCE = Symbol("solid.frames.announce");
|
|
911
|
+
function frameStream(makeCode, options) {
|
|
912
|
+
const {
|
|
913
|
+
id = "",
|
|
914
|
+
version = 1
|
|
915
|
+
} = options.frame || {};
|
|
916
|
+
const frame = {
|
|
917
|
+
id,
|
|
918
|
+
version
|
|
919
|
+
};
|
|
920
|
+
const bounded = !options.live;
|
|
921
|
+
const maxYields = bounded ? options.maxYields ?? DEFAULT_MAX_YIELDS : 0;
|
|
922
|
+
const maxDurationMs = bounded ? options.maxDurationMs ?? DEFAULT_MAX_DURATION_MS : 0;
|
|
923
|
+
function stream(w) {
|
|
924
|
+
const observation = observeFrame(frame);
|
|
925
|
+
const render = new AbortController();
|
|
926
|
+
const upstream = options.signal;
|
|
927
|
+
let ended = false;
|
|
928
|
+
let flushed = false;
|
|
929
|
+
let yields = 0;
|
|
930
|
+
let timer;
|
|
931
|
+
function finish() {
|
|
932
|
+
if (ended) return;
|
|
933
|
+
ended = true;
|
|
934
|
+
sink.flush();
|
|
935
|
+
if (timer) clearTimeout(timer);
|
|
936
|
+
if (upstream) upstream.removeEventListener("abort", onSignal);
|
|
937
|
+
w.end && w.end();
|
|
938
|
+
}
|
|
939
|
+
function cut(bound) {
|
|
940
|
+
if (ended) return;
|
|
941
|
+
sink.end(bound);
|
|
942
|
+
observation && observation.settle("complete");
|
|
943
|
+
finish();
|
|
944
|
+
render.abort({
|
|
945
|
+
quiet: true,
|
|
946
|
+
bound
|
|
947
|
+
});
|
|
948
|
+
}
|
|
949
|
+
function onSignal() {
|
|
950
|
+
const gone = upstream.reason && upstream.reason[DISCONNECTED];
|
|
951
|
+
if (bounded && flushed && !gone) return cut("time");
|
|
952
|
+
finish();
|
|
953
|
+
render.abort(upstream.reason);
|
|
954
|
+
}
|
|
955
|
+
const emit = message => {
|
|
956
|
+
if (observation) observation.chunk(message);
|
|
957
|
+
w.write(message);
|
|
958
|
+
if (bounded && !flushed && message.id === id && message.r && "" in message.r) {
|
|
959
|
+
flushed = true;
|
|
960
|
+
if (maxDurationMs > 0 && maxDurationMs !== Infinity) timer = setTimeout(() => cut("time"), maxDurationMs);
|
|
961
|
+
}
|
|
962
|
+
};
|
|
963
|
+
const sink = createFrameSink(emit, frame, options.resume && options.resume.have, {
|
|
964
|
+
live: options.live,
|
|
965
|
+
retain: options.broadcast,
|
|
966
|
+
onYield: bounded ? () => {
|
|
967
|
+
if (flushed && maxYields > 0 && ++yields >= maxYields) cut("yields");
|
|
968
|
+
} : undefined
|
|
969
|
+
});
|
|
970
|
+
if (options.live) sink.needs("wire");
|
|
971
|
+
w.write({
|
|
972
|
+
type: "start",
|
|
973
|
+
id,
|
|
974
|
+
version
|
|
975
|
+
});
|
|
976
|
+
if (upstream && upstream.aborted) return finish();
|
|
977
|
+
if (upstream) upstream.addEventListener("abort", onSignal, {
|
|
978
|
+
once: true
|
|
979
|
+
});
|
|
980
|
+
const code = makeCode(sink, frame);
|
|
981
|
+
try {
|
|
982
|
+
renderToStream(() => serverOwned(code), {
|
|
983
|
+
serializer: createJSONSerializer,
|
|
984
|
+
...options,
|
|
985
|
+
signal: render.signal,
|
|
986
|
+
sink
|
|
987
|
+
}).pipe({
|
|
988
|
+
write() {},
|
|
989
|
+
end() {
|
|
990
|
+
if (ended) return;
|
|
991
|
+
sink.end();
|
|
992
|
+
observation && observation.settle("complete");
|
|
993
|
+
finish();
|
|
994
|
+
}
|
|
995
|
+
});
|
|
996
|
+
} catch (err) {
|
|
997
|
+
const wire = ssrSanitizeError(err, null);
|
|
998
|
+
sink.error("", wire instanceof Error ? wire.message : String(wire));
|
|
999
|
+
sink.end();
|
|
1000
|
+
observation && observation.settle("error", err);
|
|
1001
|
+
finish();
|
|
1002
|
+
}
|
|
1003
|
+
if (w[ANNOUNCE]) w[ANNOUNCE](sink.announce());
|
|
1004
|
+
sink.flush();
|
|
1005
|
+
}
|
|
1006
|
+
return {
|
|
1007
|
+
pipe: stream,
|
|
1008
|
+
then(onFulfilled, onRejected) {
|
|
1009
|
+
return new Promise((resolve, reject) => {
|
|
1010
|
+
const chunks = [];
|
|
1011
|
+
try {
|
|
1012
|
+
stream({
|
|
1013
|
+
write: chunk => chunks.push(chunk),
|
|
1014
|
+
end: () => resolve(chunks)
|
|
1015
|
+
});
|
|
1016
|
+
} catch (err) {
|
|
1017
|
+
reject(err);
|
|
1018
|
+
}
|
|
1019
|
+
}).then(onFulfilled, onRejected);
|
|
1020
|
+
}
|
|
1021
|
+
};
|
|
1022
|
+
}
|
|
1023
|
+
function slotRange(occurrence) {
|
|
1024
|
+
return {
|
|
1025
|
+
t: `<!--slot:${occurrence}:start--><!--slot:${occurrence}:end-->`,
|
|
1026
|
+
$slot: true
|
|
1027
|
+
};
|
|
1028
|
+
}
|
|
1029
|
+
function argBorderForm(value, needs) {
|
|
1030
|
+
return toBorderForm(noteTraces(value, needs));
|
|
1031
|
+
}
|
|
1032
|
+
function noteTraces(value, needs) {
|
|
1033
|
+
return rewriteTree(value, v => {
|
|
1034
|
+
if (isContainerTraced(v)) {
|
|
1035
|
+
needs("trace");
|
|
1036
|
+
return v;
|
|
1037
|
+
}
|
|
1038
|
+
return DESCEND;
|
|
1039
|
+
}, true);
|
|
1040
|
+
}
|
|
1041
|
+
const OCCURRENCE_UNSAFE = /[^A-Za-z0-9_.-]/g;
|
|
1042
|
+
function encodeOccurrenceKey(key) {
|
|
1043
|
+
return String(key).replace(OCCURRENCE_UNSAFE, c => {
|
|
1044
|
+
const code = c.codePointAt(0);
|
|
1045
|
+
return "%" + (code < 16 ? "0" : "") + code.toString(16);
|
|
1046
|
+
});
|
|
1047
|
+
}
|
|
1048
|
+
function occurrenceId(prop, raw, counts) {
|
|
1049
|
+
const keyed = keyedId(prop, raw);
|
|
1050
|
+
if (keyed !== undefined) return keyed;
|
|
1051
|
+
const n = counts[prop] || 0;
|
|
1052
|
+
counts[prop] = n + 1;
|
|
1053
|
+
return `${prop}#${n}`;
|
|
1054
|
+
}
|
|
1055
|
+
function keyedId(prop, raw) {
|
|
1056
|
+
const k = raw.$key;
|
|
1057
|
+
return typeof k === "string" || typeof k === "number" ? `${prop}#${encodeOccurrenceKey(k)}` : undefined;
|
|
1058
|
+
}
|
|
1059
|
+
function structuralArgsKey(raw) {
|
|
1060
|
+
let out = "";
|
|
1061
|
+
let ancestors;
|
|
1062
|
+
const walk = (v, top) => {
|
|
1063
|
+
if (v === null) out += "N";else if (typeof v === "string") out += "s" + v.length + ":" + v;else if (typeof v === "boolean") out += v ? "T" : "F";else if (typeof v === "undefined") out += "U";else if (typeof v === "number") out += "n" + v + ";";else if (typeof v === "bigint") out += "b" + v + ";";else if (typeof v !== "object") return false;else {
|
|
1064
|
+
const isArray = Array.isArray(v);
|
|
1065
|
+
if (!isArray) {
|
|
1066
|
+
const proto = Object.getPrototypeOf(v);
|
|
1067
|
+
if (proto !== Object.prototype && proto !== null) return false;
|
|
1068
|
+
}
|
|
1069
|
+
if (ancestors === undefined) ancestors = new Set();else if (ancestors.has(v)) return false;
|
|
1070
|
+
ancestors.add(v);
|
|
1071
|
+
try {
|
|
1072
|
+
if (isArray) {
|
|
1073
|
+
out += "[";
|
|
1074
|
+
for (const item of v) if (!walk(item)) return false;
|
|
1075
|
+
out += "]";
|
|
1076
|
+
} else {
|
|
1077
|
+
out += "{";
|
|
1078
|
+
for (const k of Object.keys(v).sort()) {
|
|
1079
|
+
if (top && k === "$key") continue;
|
|
1080
|
+
const desc = Object.getOwnPropertyDescriptor(v, k);
|
|
1081
|
+
if (desc.get || desc.set) return false;
|
|
1082
|
+
out += "k" + k.length + ":" + k;
|
|
1083
|
+
if (!walk(desc.value)) return false;
|
|
1084
|
+
}
|
|
1085
|
+
out += "}";
|
|
1086
|
+
}
|
|
1087
|
+
} finally {
|
|
1088
|
+
ancestors.delete(v);
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
return true;
|
|
1092
|
+
};
|
|
1093
|
+
return walk(raw, true) ? out : undefined;
|
|
1094
|
+
}
|
|
1095
|
+
function argDigest(value) {
|
|
1096
|
+
const t = typeof value;
|
|
1097
|
+
if (value == null || t !== "object" && t !== "function" && value === value) return value;
|
|
1098
|
+
if (isContainerTraced(value)) return value;
|
|
1099
|
+
try {
|
|
1100
|
+
const key = structuralArgsKey([value]);
|
|
1101
|
+
return key === undefined ? value : key;
|
|
1102
|
+
} catch (_) {
|
|
1103
|
+
return value;
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
const PENDING_ARG = {};
|
|
1107
|
+
const noDigest = () => NaN;
|
|
1108
|
+
function isAsyncValue(v) {
|
|
1109
|
+
return !!v && typeof v === "object" && (typeof v.then === "function" || typeof v[Symbol.asyncIterator] === "function");
|
|
1110
|
+
}
|
|
1111
|
+
function tapFirstYield(iterable) {
|
|
1112
|
+
const rest = shareAsyncIterable(iterable);
|
|
1113
|
+
const iter = shareAsyncIterable(iterable)[Symbol.asyncIterator]();
|
|
1114
|
+
const first = Promise.resolve(iter.next()).then(r => {
|
|
1115
|
+
if (!r.done) iter.return?.();
|
|
1116
|
+
return r.done ? undefined : r.value;
|
|
1117
|
+
});
|
|
1118
|
+
return {
|
|
1119
|
+
first,
|
|
1120
|
+
rest
|
|
1121
|
+
};
|
|
1122
|
+
}
|
|
1123
|
+
function packOccurrences(occs) {
|
|
1124
|
+
const out = [];
|
|
1125
|
+
let prop = "",
|
|
1126
|
+
a = -1,
|
|
1127
|
+
b = -1;
|
|
1128
|
+
const flush = () => a >= 0 && out.push(prop + "#" + (a === b ? a : a + "-" + b));
|
|
1129
|
+
for (const o of occs) {
|
|
1130
|
+
const m = /^(.*)#(\d+)$/.exec(o);
|
|
1131
|
+
if (m && m[1] === prop && +m[2] === b + 1 && a >= 0) {
|
|
1132
|
+
b++;
|
|
1133
|
+
continue;
|
|
1134
|
+
}
|
|
1135
|
+
flush();
|
|
1136
|
+
a = b = -1;
|
|
1137
|
+
if (m) {
|
|
1138
|
+
prop = m[1];
|
|
1139
|
+
a = b = +m[2];
|
|
1140
|
+
} else out.push(o);
|
|
1141
|
+
}
|
|
1142
|
+
flush();
|
|
1143
|
+
return out.join(" ");
|
|
1144
|
+
}
|
|
1145
|
+
function hasAsyncHoles(node, depth = 0) {
|
|
1146
|
+
if (!node || typeof node !== "object" || depth > 64) return false;
|
|
1147
|
+
if (Array.isArray(node)) {
|
|
1148
|
+
for (const n of node) if (hasAsyncHoles(n, depth + 1)) return true;
|
|
1149
|
+
return false;
|
|
1150
|
+
}
|
|
1151
|
+
if (node.h && node.h.length) return true;
|
|
1152
|
+
return false;
|
|
1153
|
+
}
|
|
1154
|
+
function suppressedFill(render) {
|
|
1155
|
+
const live = sharedConfig.context && sharedConfig.context.liveHoles;
|
|
1156
|
+
if (!live) return render();
|
|
1157
|
+
live.suppressed++;
|
|
1158
|
+
try {
|
|
1159
|
+
return render();
|
|
1160
|
+
} finally {
|
|
1161
|
+
live.suppressed--;
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
let parked = null;
|
|
1165
|
+
let parkedIds = 0;
|
|
1166
|
+
const PARKED = /<!--sc-n:(\d+)-->/;
|
|
1167
|
+
function park(render) {
|
|
1168
|
+
if (!parked) return render();
|
|
1169
|
+
const id = ++parkedIds;
|
|
1170
|
+
parked.set(id, {
|
|
1171
|
+
render,
|
|
1172
|
+
out: undefined
|
|
1173
|
+
});
|
|
1174
|
+
return {
|
|
1175
|
+
t: `<!--sc-n:${id}-->`
|
|
1176
|
+
};
|
|
1177
|
+
}
|
|
1178
|
+
const runParked = (entry, owner) => entry.out || (entry.out = entry.render(owner));
|
|
1179
|
+
function placeParked(node, nested, owner) {
|
|
1180
|
+
const out = expandParked(node, nested, owner);
|
|
1181
|
+
for (const entry of nested.values()) runParked(entry, owner);
|
|
1182
|
+
return out;
|
|
1183
|
+
}
|
|
1184
|
+
function expandParked(node, nested, owner) {
|
|
1185
|
+
if (Array.isArray(node)) {
|
|
1186
|
+
const out = node.map(n => expandParked(n, nested, owner));
|
|
1187
|
+
out.$slot = node.$slot;
|
|
1188
|
+
return out;
|
|
1189
|
+
}
|
|
1190
|
+
if (!node || node.t === undefined) return node;
|
|
1191
|
+
if (!node.h) return splitParked(node.t, nested, owner) || node;
|
|
1192
|
+
const out = [];
|
|
1193
|
+
node.t.forEach((t, i) => {
|
|
1194
|
+
out.push(splitParked(t, nested, owner) || {
|
|
1195
|
+
t
|
|
1196
|
+
});
|
|
1197
|
+
if (i < node.h.length) out.push({
|
|
1198
|
+
t: ["", ""],
|
|
1199
|
+
h: [node.h[i]],
|
|
1200
|
+
p: [node.p[i]]
|
|
1201
|
+
});
|
|
1202
|
+
});
|
|
1203
|
+
return out;
|
|
1204
|
+
}
|
|
1205
|
+
function splitParked(t, nested, owner) {
|
|
1206
|
+
const parts = typeof t === "string" ? t.split(PARKED) : [t];
|
|
1207
|
+
return parts.length > 1 ? parts.map((part, i) => i & 1 ? runParked(nested.get(+part), owner) : {
|
|
1208
|
+
t: part
|
|
1209
|
+
}) : undefined;
|
|
1210
|
+
}
|
|
1211
|
+
function createDocumentSlotProps(clientProps, frameId) {
|
|
1212
|
+
const counts = Object.create(null);
|
|
1213
|
+
let depsBatch = null;
|
|
1214
|
+
let depsN = 0;
|
|
1215
|
+
let wideSent = 0;
|
|
1216
|
+
const depsContext = sharedConfig.context;
|
|
1217
|
+
const noteDeps = (occurrence, reads, untracked) => {
|
|
1218
|
+
if (!depsContext || !depsContext.serialize || !depsContext.edges) return;
|
|
1219
|
+
const own = `sc-${frameId}-${occurrence}-`;
|
|
1220
|
+
const batch = () => {
|
|
1221
|
+
if (depsBatch) return depsBatch;
|
|
1222
|
+
queueMicrotask(() => {
|
|
1223
|
+
const b = {};
|
|
1224
|
+
for (const sid in depsBatch) b[sid] = packOccurrences(depsBatch[sid]);
|
|
1225
|
+
depsBatch = null;
|
|
1226
|
+
const wide = depsContext.edgeWide?.s || null;
|
|
1227
|
+
if (wide && wide.size > wideSent) {
|
|
1228
|
+
b["*"] = [...wide].slice(wideSent).join(" ");
|
|
1229
|
+
wideSent = wide.size;
|
|
1230
|
+
}
|
|
1231
|
+
if (depsN === 0 || Object.keys(b).length) depsContext.serialize(`sc:deps:${frameId}:${depsN++}`, b);
|
|
1232
|
+
});
|
|
1233
|
+
return depsBatch = Object.create(null);
|
|
1234
|
+
};
|
|
1235
|
+
const b = batch();
|
|
1236
|
+
if (reads) for (const sid of reads) if (!sid.startsWith(own)) (b[sid] ||= []).push(occurrence);
|
|
1237
|
+
if (untracked) (b["!"] ||= []).push(occurrence);
|
|
1238
|
+
};
|
|
1239
|
+
const getters = new Map();
|
|
1240
|
+
const repeats = new Map();
|
|
1241
|
+
const range = (occurrence, content, tail) => {
|
|
1242
|
+
const r = [{
|
|
1243
|
+
t: `<!--slot:${occurrence}:start-->`
|
|
1244
|
+
}, content, tail, {
|
|
1245
|
+
t: `<!--slot:${occurrence}:end-->`
|
|
1246
|
+
}];
|
|
1247
|
+
r.$slot = true;
|
|
1248
|
+
return r;
|
|
1249
|
+
};
|
|
1250
|
+
const zoneOwner = getOwner ? getOwner() : null;
|
|
1251
|
+
const scoped = (occurrence, render, owner) => {
|
|
1252
|
+
const id = `sc-${frameId}-${occurrence}-`;
|
|
1253
|
+
if (owner) return runWithOwner(owner, () => runWithHydrationScope(id, render));
|
|
1254
|
+
const run = () => Hydration ? Hydration({
|
|
1255
|
+
id,
|
|
1256
|
+
get children() {
|
|
1257
|
+
return render();
|
|
1258
|
+
}
|
|
1259
|
+
}) : runWithHydrationScope(id, render);
|
|
1260
|
+
return zoneOwner ? runWithOwner(zoneOwner, run) : run();
|
|
1261
|
+
};
|
|
1262
|
+
return new Proxy(Object.create(null), {
|
|
1263
|
+
has() {
|
|
1264
|
+
return true;
|
|
1265
|
+
},
|
|
1266
|
+
get(_, prop) {
|
|
1267
|
+
if (typeof prop !== "string") return undefined;
|
|
1268
|
+
if (prop === "then") return undefined;
|
|
1269
|
+
let fn = getters.get(prop);
|
|
1270
|
+
if (!fn) {
|
|
1271
|
+
fn = (...callArgs) => {
|
|
1272
|
+
if (callArgs.length === 0 || callArgs[0] === undefined) {
|
|
1273
|
+
return park(owner => suppressedFill(() => scoped(prop, () => {
|
|
1274
|
+
const value = clientProps[prop];
|
|
1275
|
+
return range(prop, typeof value === "function" ? value() : value);
|
|
1276
|
+
}, owner)));
|
|
1277
|
+
}
|
|
1278
|
+
const raw = callArgs[0];
|
|
1279
|
+
const rk = keyedId(prop, raw);
|
|
1280
|
+
const repeat = rk !== undefined && repeats.get(rk);
|
|
1281
|
+
if (repeat) return repeat;
|
|
1282
|
+
const occurrence = occurrenceId(prop, raw, counts);
|
|
1283
|
+
const slot = clientProps[prop];
|
|
1284
|
+
if (typeof slot !== "function") return range(occurrence, undefined);
|
|
1285
|
+
const context = sharedConfig.context;
|
|
1286
|
+
const recordKey = `sc:slot:${frameId}:${occurrence}`;
|
|
1287
|
+
const deferred = !!parked;
|
|
1288
|
+
let settleRecord;
|
|
1289
|
+
const declare = () => context && context.async && context.serialize(recordKey, new Promise(resolve => settleRecord = resolve));
|
|
1290
|
+
deferred || declare();
|
|
1291
|
+
try {
|
|
1292
|
+
const resolved = {};
|
|
1293
|
+
const liveArgs = sharedConfig.context && sharedConfig.context.live && sharedConfig.context.live.args;
|
|
1294
|
+
const vals = {};
|
|
1295
|
+
const evals = {};
|
|
1296
|
+
const states = {};
|
|
1297
|
+
const minted = {};
|
|
1298
|
+
const nestedOf = {};
|
|
1299
|
+
for (const key of Object.keys(raw)) {
|
|
1300
|
+
if (key === "$key") continue;
|
|
1301
|
+
const desc = Object.getOwnPropertyDescriptor(raw, key);
|
|
1302
|
+
let evaluate = null;
|
|
1303
|
+
let value;
|
|
1304
|
+
if (desc.get) {
|
|
1305
|
+
const get = desc.get;
|
|
1306
|
+
evaluate = () => unwrapThunks(get.call(raw));
|
|
1307
|
+
} else {
|
|
1308
|
+
value = desc.value;
|
|
1309
|
+
if (typeof value === "function") {
|
|
1310
|
+
const fn = value;
|
|
1311
|
+
evaluate = () => unwrapThunks(fn);
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
if (evaluate) {
|
|
1315
|
+
evals[key] = evaluate;
|
|
1316
|
+
const stampBefore = scopeStamp();
|
|
1317
|
+
const outer = parked;
|
|
1318
|
+
const nested = nestedOf[key] = parked = new Map();
|
|
1319
|
+
try {
|
|
1320
|
+
value = evaluate();
|
|
1321
|
+
states[key] = {
|
|
1322
|
+
settled: true,
|
|
1323
|
+
last: value
|
|
1324
|
+
};
|
|
1325
|
+
} catch (err) {
|
|
1326
|
+
parked = outer;
|
|
1327
|
+
for (const entry of nested.values()) runParked(entry);
|
|
1328
|
+
nested.clear();
|
|
1329
|
+
const blocked = ssrHandleError && ssrHandleError(err);
|
|
1330
|
+
if (!blocked) throw err;
|
|
1331
|
+
const state = states[key] = {
|
|
1332
|
+
settled: false,
|
|
1333
|
+
last: undefined
|
|
1334
|
+
};
|
|
1335
|
+
value = retryArgUntilSettled(evaluate, blocked, key, occurrence, v => {
|
|
1336
|
+
state.settled = true;
|
|
1337
|
+
state.last = v;
|
|
1338
|
+
if (liveArgs) liveArgs.commit();
|
|
1339
|
+
});
|
|
1340
|
+
}
|
|
1341
|
+
parked = outer;
|
|
1342
|
+
if (scopeStamp() !== stampBefore) minted[key] = true;
|
|
1343
|
+
}
|
|
1344
|
+
vals[key] = value;
|
|
1345
|
+
}
|
|
1346
|
+
const regions = [];
|
|
1347
|
+
for (const key of Object.keys(vals)) {
|
|
1348
|
+
const value = vals[key];
|
|
1349
|
+
if (isContainerTraced(value)) {
|
|
1350
|
+
documentNeeds("trace");
|
|
1351
|
+
resolved[key] = value;
|
|
1352
|
+
} else if (isServerContent(value)) {
|
|
1353
|
+
const childId = `${frameId}.${occurrence}.${key}`;
|
|
1354
|
+
const region = {
|
|
1355
|
+
key,
|
|
1356
|
+
childId,
|
|
1357
|
+
value,
|
|
1358
|
+
nested: nestedOf[key],
|
|
1359
|
+
used: false,
|
|
1360
|
+
locked: false
|
|
1361
|
+
};
|
|
1362
|
+
regions.push(region);
|
|
1363
|
+
documentNeeds("regions");
|
|
1364
|
+
resolved[key] = () => {
|
|
1365
|
+
if (region.locked) return [];
|
|
1366
|
+
region.used = true;
|
|
1367
|
+
return [{
|
|
1368
|
+
t: frameElementOpen(childId)
|
|
1369
|
+
}, region.nested && region.nested.size ? placeParked(value, region.nested, getOwner()) : value, {
|
|
1370
|
+
t: FRAME_ELEMENT_CLOSE
|
|
1371
|
+
}];
|
|
1372
|
+
};
|
|
1373
|
+
} else if (ssrAsyncValue && isAsyncValue(value)) {
|
|
1374
|
+
let readable = value;
|
|
1375
|
+
if (typeof value.then !== "function") {
|
|
1376
|
+
const {
|
|
1377
|
+
first,
|
|
1378
|
+
rest
|
|
1379
|
+
} = tapFirstYield(value);
|
|
1380
|
+
readable = first;
|
|
1381
|
+
vals[key] = rest;
|
|
1382
|
+
}
|
|
1383
|
+
const read = ssrAsyncValue(readable);
|
|
1384
|
+
Object.defineProperty(resolved, key, {
|
|
1385
|
+
get: read,
|
|
1386
|
+
enumerable: true,
|
|
1387
|
+
configurable: true
|
|
1388
|
+
});
|
|
1389
|
+
} else {
|
|
1390
|
+
resolved[key] = vals[key] = noteTraces(value, documentNeeds);
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
for (const key in nestedOf) if (!regions.some(r => r.key === key)) for (const entry of nestedOf[key].values()) runParked(entry);
|
|
1394
|
+
const flip = () => {
|
|
1395
|
+
if (flip.done || !context) return;
|
|
1396
|
+
flip.done = true;
|
|
1397
|
+
for (const region of regions) {
|
|
1398
|
+
if (region.used) continue;
|
|
1399
|
+
region.locked = true;
|
|
1400
|
+
context.serialize(`sc:region:${region.childId}`, resolveRegionHtml(context, region.nested && region.nested.size ? placeParked(region.value, region.nested) : region.value));
|
|
1401
|
+
}
|
|
1402
|
+
};
|
|
1403
|
+
flip.$lhSkip = true;
|
|
1404
|
+
const finish = owner => {
|
|
1405
|
+
if (deferred) declare();
|
|
1406
|
+
try {
|
|
1407
|
+
const tracked = trackFillReads(() => suppressedFill(() => scoped(occurrence, () => range(occurrence, slot(resolved), flip), owner)));
|
|
1408
|
+
const out = tracked.result;
|
|
1409
|
+
noteDeps(occurrence, tracked.reads, tracked.untracked || hasAsyncHoles(out));
|
|
1410
|
+
if (context) {
|
|
1411
|
+
const args = {};
|
|
1412
|
+
for (const key of Object.keys(vals)) {
|
|
1413
|
+
const value = vals[key];
|
|
1414
|
+
const region = regions.find(r => r.key === key);
|
|
1415
|
+
if (region) {
|
|
1416
|
+
args[key] = {
|
|
1417
|
+
$frame: region.childId
|
|
1418
|
+
};
|
|
1419
|
+
continue;
|
|
1420
|
+
}
|
|
1421
|
+
if (!isContainerTraced(value) && isServerContent(value)) continue;
|
|
1422
|
+
args[key] = argBorderForm(value, documentNeeds);
|
|
1423
|
+
}
|
|
1424
|
+
settleRecord ? settleRecord({
|
|
1425
|
+
...args
|
|
1426
|
+
}) : context.serialize(recordKey, {
|
|
1427
|
+
...args
|
|
1428
|
+
});
|
|
1429
|
+
if (liveArgs) {
|
|
1430
|
+
for (const key of Object.keys(evals)) {
|
|
1431
|
+
if (regions.some(r => r.key === key)) continue;
|
|
1432
|
+
if (minted[key]) continue;
|
|
1433
|
+
const ledgerKey = `${frameId}:${occurrence}:${key}`;
|
|
1434
|
+
openArgBinding(liveArgs, ledgerKey, occurrence, key, evals[key], states[key], value => {
|
|
1435
|
+
args[key] = argBorderForm(value, documentNeeds);
|
|
1436
|
+
liveArgs.slot(frameId, occurrence, {
|
|
1437
|
+
...args
|
|
1438
|
+
});
|
|
1439
|
+
});
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
return out;
|
|
1444
|
+
} catch (error) {
|
|
1445
|
+
settleRecord && settleRecord(undefined);
|
|
1446
|
+
throw error;
|
|
1447
|
+
}
|
|
1448
|
+
};
|
|
1449
|
+
const out = park(finish);
|
|
1450
|
+
if (rk !== undefined && rk === occurrence) repeats.has(rk) || repeats.set(rk, out);
|
|
1451
|
+
return out;
|
|
1452
|
+
} catch (error) {
|
|
1453
|
+
settleRecord && settleRecord(undefined);
|
|
1454
|
+
throw error;
|
|
1455
|
+
}
|
|
1456
|
+
};
|
|
1457
|
+
fn.$lhSkip = true;
|
|
1458
|
+
getters.set(prop, fn);
|
|
1459
|
+
}
|
|
1460
|
+
return fn;
|
|
1461
|
+
}
|
|
1462
|
+
});
|
|
1463
|
+
}
|
|
1464
|
+
const FRAME_TAG = "solid-frame";
|
|
1465
|
+
const FRAME_ID_ATTR = "data-fid";
|
|
1466
|
+
const FRAME_ARGS_ATTR = "data-fa";
|
|
1467
|
+
function frameElementOpen(id, args) {
|
|
1468
|
+
const escaped = sharedConfig.context ? sharedConfig.context.escape(String(id), true) : String(id);
|
|
1469
|
+
return `<${FRAME_TAG} ${FRAME_ID_ATTR}="${escaped}"${args ? ` ${FRAME_ARGS_ATTR}="${args}"` : ""} style="display:contents">`;
|
|
1470
|
+
}
|
|
1471
|
+
const DOCUMENT_SITES = Symbol();
|
|
1472
|
+
function contextSites(ctx) {
|
|
1473
|
+
if (ctx[DOCUMENT_SITES]) return ctx[DOCUMENT_SITES];
|
|
1474
|
+
const proto = Object.getPrototypeOf(ctx);
|
|
1475
|
+
if (proto && proto[DOCUMENT_SITES]) return ctx[DOCUMENT_SITES] = proto[DOCUMENT_SITES];
|
|
1476
|
+
if (proto && typeof proto.escape === "function") return ctx[DOCUMENT_SITES] = contextSites(proto);
|
|
1477
|
+
return ctx[DOCUMENT_SITES] = {
|
|
1478
|
+
byOwner: new Map(),
|
|
1479
|
+
counts: Object.create(null)
|
|
1480
|
+
};
|
|
1481
|
+
}
|
|
1482
|
+
function mintSiteId(sites, fnId) {
|
|
1483
|
+
const n = sites.counts[fnId] || 0;
|
|
1484
|
+
sites.counts[fnId] = n + 1;
|
|
1485
|
+
return n === 0 ? fnId : fnId + "~" + (n + 1);
|
|
1486
|
+
}
|
|
1487
|
+
function documentSiteId(fnId) {
|
|
1488
|
+
const ctx = sharedConfig.context;
|
|
1489
|
+
if (!ctx) return fnId;
|
|
1490
|
+
const sites = contextSites(ctx);
|
|
1491
|
+
const owner = getOwner ? getOwner() : null;
|
|
1492
|
+
if (!owner) return mintSiteId(sites, fnId);
|
|
1493
|
+
let byFn = sites.byOwner.get(owner);
|
|
1494
|
+
if (!byFn) sites.byOwner.set(owner, byFn = new Map());
|
|
1495
|
+
const prev = byFn.get(fnId);
|
|
1496
|
+
if (prev) return prev;
|
|
1497
|
+
const siteId = mintSiteId(sites, fnId);
|
|
1498
|
+
byFn.set(fnId, siteId);
|
|
1499
|
+
return siteId;
|
|
1500
|
+
}
|
|
1501
|
+
const FRAME_ELEMENT_CLOSE = `</${FRAME_TAG}>`;
|
|
1502
|
+
function documentNeeds(name) {
|
|
1503
|
+
const ctx = sharedConfig.context;
|
|
1504
|
+
const live = ctx && ctx.live;
|
|
1505
|
+
if (!live || !ctx.serialize) return;
|
|
1506
|
+
const tiers = live.tiers || (live.tiers = []);
|
|
1507
|
+
if (tiers.includes(name)) return;
|
|
1508
|
+
tiers.push(name);
|
|
1509
|
+
ctx.serialize("sc:tiers", tiers.slice());
|
|
1510
|
+
const url = live.tierUrls && live.tierUrls[name];
|
|
1511
|
+
if (url && ctx.registerAsset) ctx.registerAsset("module", url);
|
|
1512
|
+
}
|
|
1513
|
+
function armDocumentLiveHoles(ctx) {
|
|
1514
|
+
if (!ctx || ctx.liveHoles !== undefined) return;
|
|
1515
|
+
const live = ctx.live;
|
|
1516
|
+
if (live && live.holes !== undefined) {
|
|
1517
|
+
ctx.liveHoles = live.holes;
|
|
1518
|
+
if (live.holes) {
|
|
1519
|
+
ctx.commit = live.commit;
|
|
1520
|
+
ctx.commitEpoch = live.commitEpoch;
|
|
1521
|
+
ctx.unsettled = live.unsettled;
|
|
1522
|
+
}
|
|
1523
|
+
return;
|
|
1524
|
+
}
|
|
1525
|
+
if (!live || !ctx.async || !ctx.serialize || typeof ReadableStream !== "function") {
|
|
1526
|
+
ctx.liveHoles = null;
|
|
1527
|
+
if (live) live.holes = null;
|
|
1528
|
+
return;
|
|
1529
|
+
}
|
|
1530
|
+
let unsettled = false;
|
|
1531
|
+
const bindings = new Map();
|
|
1532
|
+
let epoch = 0;
|
|
1533
|
+
let sweepScheduled = false;
|
|
1534
|
+
let closed = false;
|
|
1535
|
+
let swept = null;
|
|
1536
|
+
const sweep = () => {
|
|
1537
|
+
epoch++;
|
|
1538
|
+
const r = swept = {};
|
|
1539
|
+
try {
|
|
1540
|
+
for (const b of [...bindings.values()]) {
|
|
1541
|
+
try {
|
|
1542
|
+
b.sweep();
|
|
1543
|
+
} catch (_) {
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
} finally {
|
|
1547
|
+
swept = null;
|
|
1548
|
+
}
|
|
1549
|
+
for (const _ in r) return push({
|
|
1550
|
+
r
|
|
1551
|
+
});
|
|
1552
|
+
};
|
|
1553
|
+
const scheduleSweep = () => {
|
|
1554
|
+
if (closed || sweepScheduled || !bindings.size) return;
|
|
1555
|
+
sweepScheduled = true;
|
|
1556
|
+
queueMicrotask(() => {
|
|
1557
|
+
sweepScheduled = false;
|
|
1558
|
+
if (!closed) sweep();
|
|
1559
|
+
});
|
|
1560
|
+
};
|
|
1561
|
+
let channel;
|
|
1562
|
+
ctx.serialize("sc:live", new ReadableStream({
|
|
1563
|
+
start(c) {
|
|
1564
|
+
channel = c;
|
|
1565
|
+
},
|
|
1566
|
+
cancel() {
|
|
1567
|
+
closed = true;
|
|
1568
|
+
}
|
|
1569
|
+
}));
|
|
1570
|
+
const push = batch => {
|
|
1571
|
+
if (!closed) channel.enqueue(batch);
|
|
1572
|
+
};
|
|
1573
|
+
const write = r => swept ? Object.assign(swept, r) : push({
|
|
1574
|
+
r
|
|
1575
|
+
});
|
|
1576
|
+
ctx.liveHoles = live.holes = createLiveHoles({
|
|
1577
|
+
openBinding(key, b) {
|
|
1578
|
+
documentNeeds("wire");
|
|
1579
|
+
bindings.set(key, b);
|
|
1580
|
+
},
|
|
1581
|
+
closeBinding(key) {
|
|
1582
|
+
bindings.delete(key);
|
|
1583
|
+
},
|
|
1584
|
+
hole(key, value) {
|
|
1585
|
+
write({
|
|
1586
|
+
["hole:" + key]: {
|
|
1587
|
+
kind: "html",
|
|
1588
|
+
value,
|
|
1589
|
+
digest: textDigest(value)
|
|
1590
|
+
}
|
|
1591
|
+
});
|
|
1592
|
+
},
|
|
1593
|
+
attr(key, value, removed) {
|
|
1594
|
+
const record = {
|
|
1595
|
+
kind: "attrs",
|
|
1596
|
+
value,
|
|
1597
|
+
digest: textDigest(value)
|
|
1598
|
+
};
|
|
1599
|
+
if (removed && removed.length) record.removed = removed;
|
|
1600
|
+
write({
|
|
1601
|
+
["attr:" + key]: record
|
|
1602
|
+
});
|
|
1603
|
+
},
|
|
1604
|
+
error(key, error) {
|
|
1605
|
+
push({
|
|
1606
|
+
r: {
|
|
1607
|
+
[`hole:${key}:error`]: error
|
|
1608
|
+
}
|
|
1609
|
+
});
|
|
1610
|
+
},
|
|
1611
|
+
commit: scheduleSweep,
|
|
1612
|
+
get epoch() {
|
|
1613
|
+
return epoch;
|
|
1614
|
+
}
|
|
1615
|
+
}, true, () => !unsettled, ctx._errorScope);
|
|
1616
|
+
ctx.commit = live.commit = scheduleSweep;
|
|
1617
|
+
ctx.commitEpoch = live.commitEpoch = () => epoch;
|
|
1618
|
+
ctx.unsettled = live.unsettled = () => {
|
|
1619
|
+
unsettled = true;
|
|
1620
|
+
};
|
|
1621
|
+
live.args = {
|
|
1622
|
+
openBinding(key, b) {
|
|
1623
|
+
bindings.set(key, b);
|
|
1624
|
+
},
|
|
1625
|
+
closeBinding(key) {
|
|
1626
|
+
bindings.delete(key);
|
|
1627
|
+
},
|
|
1628
|
+
slot(fid, occurrence, args) {
|
|
1629
|
+
push({
|
|
1630
|
+
r: {
|
|
1631
|
+
[`slot:${occurrence}`]: {
|
|
1632
|
+
kind: "slot",
|
|
1633
|
+
args
|
|
1634
|
+
}
|
|
1635
|
+
},
|
|
1636
|
+
fid
|
|
1637
|
+
});
|
|
1638
|
+
},
|
|
1639
|
+
commit: scheduleSweep
|
|
1640
|
+
};
|
|
1641
|
+
live.error = (fid, error) => {
|
|
1642
|
+
push({
|
|
1643
|
+
r: {
|
|
1644
|
+
":error": error
|
|
1645
|
+
},
|
|
1646
|
+
fid
|
|
1647
|
+
});
|
|
1648
|
+
};
|
|
1649
|
+
live.end = () => {
|
|
1650
|
+
if (closed) return;
|
|
1651
|
+
if (bindings.size) sweep();
|
|
1652
|
+
closed = true;
|
|
1653
|
+
channel.close();
|
|
1654
|
+
};
|
|
1655
|
+
}
|
|
1656
|
+
function frameTransformDirectResult(value, {
|
|
1657
|
+
id,
|
|
1658
|
+
args,
|
|
1659
|
+
tierUrls
|
|
1660
|
+
}) {
|
|
1661
|
+
if (typeof value !== "function") return value;
|
|
1662
|
+
const component = value;
|
|
1663
|
+
const address = frameAddress(id, args);
|
|
1664
|
+
const wrapped = props => {
|
|
1665
|
+
const siteId = documentSiteId(id);
|
|
1666
|
+
return [{
|
|
1667
|
+
t: frameElementOpen(siteId, address.slice(id.length + 1))
|
|
1668
|
+
},
|
|
1669
|
+
serverOwned(() => {
|
|
1670
|
+
const page = sharedConfig.context;
|
|
1671
|
+
armDocumentLiveHoles(page);
|
|
1672
|
+
if (tierUrls && page && page.live && !page.live.tierUrls) page.live.tierUrls = tierUrls;
|
|
1673
|
+
const ctx = Object.create(page);
|
|
1674
|
+
ctx.frameId = siteId;
|
|
1675
|
+
sharedConfig.context = ctx;
|
|
1676
|
+
try {
|
|
1677
|
+
const slotProps = createDocumentSlotProps(props, siteId);
|
|
1678
|
+
const live = !!wrapped[LIVE_SOURCE];
|
|
1679
|
+
if (live) documentNeeds("wire");
|
|
1680
|
+
return serverComponentScope(() => component(slotProps), live);
|
|
1681
|
+
} finally {
|
|
1682
|
+
sharedConfig.context = page;
|
|
1683
|
+
}
|
|
1684
|
+
}), {
|
|
1685
|
+
t: FRAME_ELEMENT_CLOSE
|
|
1686
|
+
}];
|
|
1687
|
+
};
|
|
1688
|
+
wrapped[SERVER_COMPONENT] = id;
|
|
1689
|
+
wrapped[SERVER_COMPONENT_SOURCE] = component;
|
|
1690
|
+
wrapped[SERVER_COMPONENT_ADDRESS] = address;
|
|
1691
|
+
return wrapped;
|
|
1692
|
+
}
|
|
1693
|
+
function resolveRegionHtml(ctx, node) {
|
|
1694
|
+
const res = ctx.resolve(node);
|
|
1695
|
+
if (!res || !res.t) return String(res ?? "");
|
|
1696
|
+
if (!res.h || !res.h.length) return res.t[0];
|
|
1697
|
+
return Promise.all(res.p).then(() => {
|
|
1698
|
+
let out = Promise.resolve(res.t[0]);
|
|
1699
|
+
for (let i = 0; i < res.h.length; i++) {
|
|
1700
|
+
const hole = res.h[i];
|
|
1701
|
+
const tail = res.t[i + 1];
|
|
1702
|
+
out = out.then(acc => Promise.resolve(resolveRegionHtml(ctx, hole)).then(part => acc + part + tail));
|
|
1703
|
+
}
|
|
1704
|
+
return out;
|
|
1705
|
+
});
|
|
1706
|
+
}
|
|
1707
|
+
function isServerContent(value) {
|
|
1708
|
+
if (value && typeof value === "object") {
|
|
1709
|
+
if ("t" in value) return true;
|
|
1710
|
+
if (Array.isArray(value) && value.length > 0) {
|
|
1711
|
+
for (const item of value) {
|
|
1712
|
+
if (!(item && typeof item === "object" && "t" in item)) return false;
|
|
1713
|
+
}
|
|
1714
|
+
return true;
|
|
1715
|
+
}
|
|
1716
|
+
}
|
|
1717
|
+
return false;
|
|
1718
|
+
}
|
|
1719
|
+
function unwrapThunks(value) {
|
|
1720
|
+
for (let d = 0; typeof value === "function" && d < 16; d++) value = value();
|
|
1721
|
+
return value;
|
|
1722
|
+
}
|
|
1723
|
+
function contentArgError(key, occurrence) {
|
|
1724
|
+
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.");
|
|
1725
|
+
}
|
|
1726
|
+
function retryArgUntilSettled(evaluate, blocked, key, occurrence, onSettle) {
|
|
1727
|
+
const owner = getOwner();
|
|
1728
|
+
return new Promise((resolve, reject) => {
|
|
1729
|
+
const retry = () => {
|
|
1730
|
+
try {
|
|
1731
|
+
const value = owner ? runWithOwner(owner, evaluate) : evaluate();
|
|
1732
|
+
if (isServerContent(value)) {
|
|
1733
|
+
reject(contentArgError(key, occurrence));
|
|
1734
|
+
return;
|
|
1735
|
+
}
|
|
1736
|
+
if (onSettle) onSettle(value);
|
|
1737
|
+
resolve(value);
|
|
1738
|
+
} catch (err) {
|
|
1739
|
+
const next = ssrHandleError && ssrHandleError(err);
|
|
1740
|
+
if (next) next.then(retry, retry);else reject(err);
|
|
1741
|
+
}
|
|
1742
|
+
};
|
|
1743
|
+
blocked.then(retry, retry);
|
|
1744
|
+
});
|
|
1745
|
+
}
|
|
1746
|
+
function openArgBinding(sink, ledgerKey, occurrence, key, evaluate, state, emit) {
|
|
1747
|
+
const owner = getOwner();
|
|
1748
|
+
sink.openBinding(ledgerKey, {
|
|
1749
|
+
sweep() {
|
|
1750
|
+
if (!state.settled) return;
|
|
1751
|
+
let value;
|
|
1752
|
+
const stampBefore = scopeStamp();
|
|
1753
|
+
try {
|
|
1754
|
+
value = owner ? runWithOwner(owner, evaluate) : evaluate();
|
|
1755
|
+
} catch (err) {
|
|
1756
|
+
const blocked = ssrHandleError && ssrHandleError(err);
|
|
1757
|
+
if (!blocked) {
|
|
1758
|
+
sink.closeBinding(ledgerKey);
|
|
1759
|
+
emit(Promise.reject(err instanceof Error ? err : new Error(String(err))));
|
|
1760
|
+
return;
|
|
1761
|
+
}
|
|
1762
|
+
if (scopeStamp() !== stampBefore) {
|
|
1763
|
+
sink.closeBinding(ledgerKey);
|
|
1764
|
+
return;
|
|
1765
|
+
}
|
|
1766
|
+
state.settled = false;
|
|
1767
|
+
emit(retryArgUntilSettled(evaluate, blocked, key, occurrence, v => {
|
|
1768
|
+
state.settled = true;
|
|
1769
|
+
state.last = v;
|
|
1770
|
+
sink.commit();
|
|
1771
|
+
}));
|
|
1772
|
+
return;
|
|
1773
|
+
}
|
|
1774
|
+
if (scopeStamp() !== stampBefore) {
|
|
1775
|
+
sink.closeBinding(ledgerKey);
|
|
1776
|
+
return;
|
|
1777
|
+
}
|
|
1778
|
+
if (value === state.last) return;
|
|
1779
|
+
state.last = value;
|
|
1780
|
+
if (isServerContent(value)) {
|
|
1781
|
+
sink.closeBinding(ledgerKey);
|
|
1782
|
+
emit(Promise.reject(contentArgError(key, occurrence)));
|
|
1783
|
+
return;
|
|
1784
|
+
}
|
|
1785
|
+
emit(value);
|
|
1786
|
+
}
|
|
1787
|
+
});
|
|
1788
|
+
}
|
|
1789
|
+
function createSlotProps(sink, frame) {
|
|
1790
|
+
const counts = Object.create(null);
|
|
1791
|
+
const getters = new Map();
|
|
1792
|
+
const repeats = new Map();
|
|
1793
|
+
let pass = null;
|
|
1794
|
+
let passRepeats = null;
|
|
1795
|
+
const recs = new Map();
|
|
1796
|
+
const forget = occurrence => {
|
|
1797
|
+
const rec = recs.get(occurrence);
|
|
1798
|
+
if (!rec) return;
|
|
1799
|
+
recs.delete(occurrence);
|
|
1800
|
+
for (const key in rec.vals) sink.closeBinding(`${occurrence}:${key}`);
|
|
1801
|
+
};
|
|
1802
|
+
const needs = sink.needs || (() => {});
|
|
1803
|
+
return new Proxy(Object.create(null), {
|
|
1804
|
+
has() {
|
|
1805
|
+
return true;
|
|
1806
|
+
},
|
|
1807
|
+
get(_, prop) {
|
|
1808
|
+
if (typeof prop !== "string") return undefined;
|
|
1809
|
+
if (prop === "then") return undefined;
|
|
1810
|
+
let fn = getters.get(prop);
|
|
1811
|
+
if (!fn) {
|
|
1812
|
+
fn = (...callArgs) => {
|
|
1813
|
+
if (callArgs.length === 0 || callArgs[0] === undefined) {
|
|
1814
|
+
return slotRange(prop);
|
|
1815
|
+
}
|
|
1816
|
+
const live = sharedConfig.context && sharedConfig.context.liveHoles;
|
|
1817
|
+
const sweeping = !!live && live.sweeping;
|
|
1818
|
+
let rmap = repeats;
|
|
1819
|
+
if (sweeping) {
|
|
1820
|
+
if (pass !== live.visit) passRepeats = new Map();
|
|
1821
|
+
pass = live.visit;
|
|
1822
|
+
rmap = passRepeats;
|
|
1823
|
+
}
|
|
1824
|
+
const rk = keyedId(prop, callArgs[0]);
|
|
1825
|
+
const repeat = rk !== undefined && rmap.get(rk);
|
|
1826
|
+
if (repeat) return repeat;
|
|
1827
|
+
if (sweeping && !live.scope) {
|
|
1828
|
+
live.gateHit = true;
|
|
1829
|
+
return {
|
|
1830
|
+
t: "",
|
|
1831
|
+
$slot: true
|
|
1832
|
+
};
|
|
1833
|
+
}
|
|
1834
|
+
const raw = callArgs[0];
|
|
1835
|
+
let occurrence = keyedId(prop, raw);
|
|
1836
|
+
if (occurrence === undefined) {
|
|
1837
|
+
const positional = sweeping ? undefined : occurrenceId(prop, raw, counts);
|
|
1838
|
+
occurrence = live ? live.slotId(prop, positional) : positional;
|
|
1839
|
+
}
|
|
1840
|
+
if (sweeping && live.dry) return slotRange(occurrence);
|
|
1841
|
+
const prev = recs.get(occurrence);
|
|
1842
|
+
let changed = !prev;
|
|
1843
|
+
const digest = live && live.scope ? argDigest : noDigest;
|
|
1844
|
+
const args = {};
|
|
1845
|
+
const vals = {};
|
|
1846
|
+
const opened = [];
|
|
1847
|
+
for (const key of Object.keys(raw)) {
|
|
1848
|
+
if (key === "$key") continue;
|
|
1849
|
+
const childId = `${frame.id}.${occurrence}.${key}`;
|
|
1850
|
+
const ctx = sharedConfig.context;
|
|
1851
|
+
const origRegister = ctx.registerFragment;
|
|
1852
|
+
ctx.registerFragment = (fragKey, fragOptions) => {
|
|
1853
|
+
sink.tagRegion(fragKey, childId);
|
|
1854
|
+
return origRegister.call(ctx, fragKey, fragOptions);
|
|
1855
|
+
};
|
|
1856
|
+
try {
|
|
1857
|
+
const desc = Object.getOwnPropertyDescriptor(raw, key);
|
|
1858
|
+
let evaluate = null;
|
|
1859
|
+
let value;
|
|
1860
|
+
let state = null;
|
|
1861
|
+
let pending = false;
|
|
1862
|
+
const stampBefore = scopeStamp();
|
|
1863
|
+
try {
|
|
1864
|
+
if (desc.get) {
|
|
1865
|
+
const get = desc.get;
|
|
1866
|
+
evaluate = () => unwrapThunks(get.call(raw));
|
|
1867
|
+
value = evaluate();
|
|
1868
|
+
} else {
|
|
1869
|
+
value = desc.value;
|
|
1870
|
+
if (typeof value === "function") {
|
|
1871
|
+
const fn = value;
|
|
1872
|
+
evaluate = () => unwrapThunks(fn);
|
|
1873
|
+
value = evaluate();
|
|
1874
|
+
}
|
|
1875
|
+
}
|
|
1876
|
+
} catch (err) {
|
|
1877
|
+
const blocked = ssrHandleError && ssrHandleError(err);
|
|
1878
|
+
if (!blocked) throw err;
|
|
1879
|
+
state = {
|
|
1880
|
+
settled: false,
|
|
1881
|
+
last: undefined
|
|
1882
|
+
};
|
|
1883
|
+
pending = true;
|
|
1884
|
+
const pendingState = state;
|
|
1885
|
+
value = retryArgUntilSettled(evaluate, blocked, key, occurrence, v => {
|
|
1886
|
+
pendingState.settled = true;
|
|
1887
|
+
pendingState.last = v;
|
|
1888
|
+
sink.commit();
|
|
1889
|
+
});
|
|
1890
|
+
}
|
|
1891
|
+
const mintedEval = scopeStamp() !== stampBefore;
|
|
1892
|
+
const t = typeof value;
|
|
1893
|
+
if (value == null || t === "string" || t === "number" || t === "boolean") {
|
|
1894
|
+
args[key] = value;
|
|
1895
|
+
vals[key] = digest(value);
|
|
1896
|
+
if (evaluate) state = {
|
|
1897
|
+
settled: true,
|
|
1898
|
+
last: value
|
|
1899
|
+
};
|
|
1900
|
+
} else if (!isContainerTraced(value) && isServerContent(value)) {
|
|
1901
|
+
const resolved = ctx.resolve(value);
|
|
1902
|
+
if (resolved.h.length) {
|
|
1903
|
+
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.");
|
|
1904
|
+
}
|
|
1905
|
+
vals[key] = "<" + resolved.t[0];
|
|
1906
|
+
if (!prev || prev.vals[key] !== vals[key]) sink.region(childId, resolved.t[0]);
|
|
1907
|
+
args[key] = {
|
|
1908
|
+
$frame: childId
|
|
1909
|
+
};
|
|
1910
|
+
} else {
|
|
1911
|
+
vals[key] = pending ? PENDING_ARG : digest(value);
|
|
1912
|
+
if (prev && prev.vals[key] === vals[key]) args[key] = prev.args[key];else {
|
|
1913
|
+
const ref = prev ? `arg:${occurrence}:${key}@${sink.nextArgRef(`${occurrence}:${key}`)}` : `arg:${occurrence}:${key}`;
|
|
1914
|
+
if (prev) sink.mintRef(ref);
|
|
1915
|
+
ctx.serialize(ref, argBorderForm(value, needs));
|
|
1916
|
+
args[key] = {
|
|
1917
|
+
$ref: ref
|
|
1918
|
+
};
|
|
1919
|
+
}
|
|
1920
|
+
if (evaluate && !state) state = {
|
|
1921
|
+
settled: true,
|
|
1922
|
+
last: value
|
|
1923
|
+
};
|
|
1924
|
+
}
|
|
1925
|
+
if (prev && prev.vals[key] !== vals[key]) changed = true;
|
|
1926
|
+
if (evaluate && state && !mintedEval) opened.push({
|
|
1927
|
+
key,
|
|
1928
|
+
evaluate,
|
|
1929
|
+
state
|
|
1930
|
+
});
|
|
1931
|
+
} finally {
|
|
1932
|
+
ctx.registerFragment = origRegister;
|
|
1933
|
+
}
|
|
1934
|
+
}
|
|
1935
|
+
if (prev) for (const key in prev.vals) if (!(key in vals)) changed = true;
|
|
1936
|
+
const rec = changed ? {
|
|
1937
|
+
args,
|
|
1938
|
+
vals
|
|
1939
|
+
} : prev;
|
|
1940
|
+
if (changed) {
|
|
1941
|
+
recs.set(occurrence, rec);
|
|
1942
|
+
sink.slot(occurrence, {
|
|
1943
|
+
...args
|
|
1944
|
+
});
|
|
1945
|
+
}
|
|
1946
|
+
if (live && live.visit) live.seen(occurrence, () => recs.get(occurrence) === rec && forget(occurrence));
|
|
1947
|
+
const ctx = sharedConfig.context;
|
|
1948
|
+
for (const b of opened) {
|
|
1949
|
+
const key = b.key;
|
|
1950
|
+
const ledgerKey = `${occurrence}:${key}`;
|
|
1951
|
+
openArgBinding(sink, ledgerKey, occurrence, key, b.evaluate, b.state, value => {
|
|
1952
|
+
const t = typeof value;
|
|
1953
|
+
if (value == null || t === "string" || t === "number" || t === "boolean") {
|
|
1954
|
+
rec.args[key] = value;
|
|
1955
|
+
} else {
|
|
1956
|
+
const ref = `arg:${occurrence}:${key}@${sink.nextArgRef(ledgerKey)}`;
|
|
1957
|
+
sink.mintRef(ref);
|
|
1958
|
+
ctx.serialize(ref, argBorderForm(value, needs));
|
|
1959
|
+
rec.args[key] = {
|
|
1960
|
+
$ref: ref
|
|
1961
|
+
};
|
|
1962
|
+
}
|
|
1963
|
+
rec.vals[key] = digest(value);
|
|
1964
|
+
sink.slot(occurrence, {
|
|
1965
|
+
...rec.args
|
|
1966
|
+
});
|
|
1967
|
+
});
|
|
1968
|
+
}
|
|
1969
|
+
const out = slotRange(occurrence);
|
|
1970
|
+
if (rk !== undefined && rk === occurrence) rmap.set(rk, out);
|
|
1971
|
+
return out;
|
|
1972
|
+
};
|
|
1973
|
+
fn.$lhSkip = true;
|
|
1974
|
+
getters.set(prop, fn);
|
|
1975
|
+
}
|
|
1976
|
+
return fn;
|
|
1977
|
+
}
|
|
1978
|
+
});
|
|
1979
|
+
}
|
|
1980
|
+
function copyInitHeaders(init) {
|
|
1981
|
+
if (!init || !init.getSetCookie) return new Headers(init);
|
|
1982
|
+
const headers = new Headers();
|
|
1983
|
+
init.forEach((value, key) => {
|
|
1984
|
+
if (key !== "set-cookie") headers.append(key, value);
|
|
1985
|
+
});
|
|
1986
|
+
for (const cookie of init.getSetCookie()) headers.append("Set-Cookie", cookie);
|
|
1987
|
+
return headers;
|
|
1988
|
+
}
|
|
1989
|
+
function serverComponentResponse(component, options = {}, init = {}) {
|
|
1990
|
+
const {
|
|
1991
|
+
id = "",
|
|
1992
|
+
version = 1
|
|
1993
|
+
} = options.frame || {};
|
|
1994
|
+
const live = !!options.live;
|
|
1995
|
+
const headers = copyInitHeaders(init.headers);
|
|
1996
|
+
headers.set(FRAME_STREAM_HEADER, id);
|
|
1997
|
+
headers.set("X-Content-Raw", "1");
|
|
1998
|
+
if (live) {
|
|
1999
|
+
headers.set("Content-Type", "text/event-stream");
|
|
2000
|
+
headers.set("Cache-Control", "no-store");
|
|
2001
|
+
headers.set("X-Accel-Buffering", "no");
|
|
2002
|
+
} else headers.set("Content-Type", "application/x-frame-stream");
|
|
2003
|
+
const frame = live ? createEventChunk : createChunk;
|
|
2004
|
+
const teardown = new AbortController();
|
|
2005
|
+
const disarm = followSignal(options.signal, teardown);
|
|
2006
|
+
const stream = renderServerComponent(component, {
|
|
2007
|
+
...options,
|
|
2008
|
+
signal: teardown.signal,
|
|
2009
|
+
frame: {
|
|
2010
|
+
id,
|
|
2011
|
+
version
|
|
2012
|
+
}
|
|
2013
|
+
});
|
|
2014
|
+
let closed = false;
|
|
2015
|
+
let stopLive = null;
|
|
2016
|
+
let failed = false;
|
|
2017
|
+
const body = new ReadableStream({
|
|
2018
|
+
start(controller) {
|
|
2019
|
+
const end = () => {
|
|
2020
|
+
if (closed) return;
|
|
2021
|
+
closed = true;
|
|
2022
|
+
disarm();
|
|
2023
|
+
if (stopLive) stopLive();
|
|
2024
|
+
try {
|
|
2025
|
+
controller.close();
|
|
2026
|
+
} catch (_) {}
|
|
2027
|
+
};
|
|
2028
|
+
if (teardown.signal.aborted) return end();
|
|
2029
|
+
if (live) stopLive = armLiveBody(controller, () => {
|
|
2030
|
+
closed = true;
|
|
2031
|
+
disarm();
|
|
2032
|
+
teardown.abort();
|
|
2033
|
+
});
|
|
2034
|
+
stream.pipe({
|
|
2035
|
+
write(message) {
|
|
2036
|
+
if (message.r && ":error" in message.r) failed = true;
|
|
2037
|
+
if (closed) return;
|
|
2038
|
+
try {
|
|
2039
|
+
controller.enqueue(frame(JSON.stringify(message)));
|
|
2040
|
+
} catch (_) {
|
|
2041
|
+
closed = true;
|
|
2042
|
+
}
|
|
2043
|
+
},
|
|
2044
|
+
end,
|
|
2045
|
+
[ANNOUNCE](tiers) {
|
|
2046
|
+
if (tiers.length) headers.set(FRAME_TIERS_HEADER, tiers.join(","));
|
|
2047
|
+
}
|
|
2048
|
+
});
|
|
2049
|
+
},
|
|
2050
|
+
cancel() {
|
|
2051
|
+
closed = true;
|
|
2052
|
+
disarm();
|
|
2053
|
+
if (stopLive) stopLive();
|
|
2054
|
+
teardown.abort({
|
|
2055
|
+
[DISCONNECTED]: true
|
|
2056
|
+
});
|
|
2057
|
+
}
|
|
2058
|
+
});
|
|
2059
|
+
if (failed) {
|
|
2060
|
+
headers.set("Cache-Control", "no-store");
|
|
2061
|
+
for (const name of [...headers.keys()]) if (name === "surrogate-control" || name.endsWith("cdn-cache-control")) headers.delete(name);
|
|
2062
|
+
}
|
|
2063
|
+
return new Response(body, {
|
|
2064
|
+
status: init.status || 200,
|
|
2065
|
+
headers
|
|
2066
|
+
});
|
|
2067
|
+
}
|
|
2068
|
+
function followSignal(upstream, controller) {
|
|
2069
|
+
if (!upstream) return () => {};
|
|
2070
|
+
if (upstream.aborted) {
|
|
2071
|
+
controller.abort(upstream.reason);
|
|
2072
|
+
return () => {};
|
|
2073
|
+
}
|
|
2074
|
+
const forward = () => controller.abort(upstream.reason);
|
|
2075
|
+
upstream.addEventListener("abort", forward, {
|
|
2076
|
+
once: true
|
|
2077
|
+
});
|
|
2078
|
+
return () => upstream.removeEventListener("abort", forward);
|
|
2079
|
+
}
|
|
2080
|
+
function frameTransformResult(event, result, context) {
|
|
2081
|
+
let init;
|
|
2082
|
+
if (isResponseEnvelope(result)) {
|
|
2083
|
+
const {
|
|
2084
|
+
response,
|
|
2085
|
+
value
|
|
2086
|
+
} = result;
|
|
2087
|
+
if (typeof value !== "function") return result;
|
|
2088
|
+
init = response ? {
|
|
2089
|
+
headers: response.headers,
|
|
2090
|
+
status: response.status
|
|
2091
|
+
} : undefined;
|
|
2092
|
+
result = value;
|
|
2093
|
+
}
|
|
2094
|
+
if (typeof result !== "function") return result;
|
|
2095
|
+
if (context && context.collectsFlight) return init ? {
|
|
2096
|
+
response: init,
|
|
2097
|
+
value: result
|
|
2098
|
+
} : result;
|
|
2099
|
+
const invocation = getEventServerFunctionInvocation(event);
|
|
2100
|
+
const live = !!(invocation && invocation.live);
|
|
2101
|
+
const have = live ? decodeHaveList(requestHeader(event, FRAME_HAVE_HEADER)) : undefined;
|
|
2102
|
+
if (live && invocation.broadcast && invocation.shareKey !== undefined) return broadcastResponse(invocation.id + "\0" + invocation.shareKey, result, {
|
|
2103
|
+
frame: {
|
|
2104
|
+
id: invocation.id || ""
|
|
2105
|
+
},
|
|
2106
|
+
live: true
|
|
2107
|
+
}, requestSignal(event), have, init);
|
|
2108
|
+
return serverComponentResponse(result, {
|
|
2109
|
+
frame: {
|
|
2110
|
+
id: invocation && invocation.id || ""
|
|
2111
|
+
},
|
|
2112
|
+
signal: requestSignal(event),
|
|
2113
|
+
live,
|
|
2114
|
+
resume: have && {
|
|
2115
|
+
have
|
|
2116
|
+
}
|
|
2117
|
+
}, init);
|
|
2118
|
+
}
|
|
2119
|
+
const HOLE_SOURCE = Symbol("solid.frames.holeSource");
|
|
2120
|
+
const BROADCASTS = new Map();
|
|
2121
|
+
function broadcastResponse(key, component, options, signal, have, init) {
|
|
2122
|
+
let shared = BROADCASTS.get(key);
|
|
2123
|
+
if (!shared || shared.ended) shared = startBroadcast(key, component, options);
|
|
2124
|
+
return tapResponse(shared, signal, have, init);
|
|
2125
|
+
}
|
|
2126
|
+
function startBroadcast(key, component, options) {
|
|
2127
|
+
const shared = {
|
|
2128
|
+
key,
|
|
2129
|
+
id: options.frame.id,
|
|
2130
|
+
start: null,
|
|
2131
|
+
taps: new Set(),
|
|
2132
|
+
records: new Map(),
|
|
2133
|
+
data: [],
|
|
2134
|
+
kept: 0,
|
|
2135
|
+
attrs: new Map(),
|
|
2136
|
+
tiers: new Set(["wire"]),
|
|
2137
|
+
failed: false,
|
|
2138
|
+
ended: false,
|
|
2139
|
+
teardown: new AbortController()
|
|
2140
|
+
};
|
|
2141
|
+
BROADCASTS.set(key, shared);
|
|
2142
|
+
const stream = renderServerComponent(component, {
|
|
2143
|
+
...options,
|
|
2144
|
+
broadcast: (key, text) => shared.attrs.set(key, text),
|
|
2145
|
+
signal: shared.teardown.signal
|
|
2146
|
+
});
|
|
2147
|
+
const run = () => stream.pipe({
|
|
2148
|
+
write(message) {
|
|
2149
|
+
const bytes = createEventChunk(JSON.stringify(message));
|
|
2150
|
+
if (message.type === "start") return void (shared.start = bytes);
|
|
2151
|
+
retain(shared, message);
|
|
2152
|
+
for (const tap of shared.taps) tap.write(bytes);
|
|
2153
|
+
},
|
|
2154
|
+
end() {
|
|
2155
|
+
shared.ended = true;
|
|
2156
|
+
if (BROADCASTS.get(key) === shared) BROADCASTS.delete(key);
|
|
2157
|
+
for (const tap of [...shared.taps]) tap.end();
|
|
2158
|
+
},
|
|
2159
|
+
[ANNOUNCE](tiers) {
|
|
2160
|
+
for (const tier of tiers) shared.tiers.add(tier);
|
|
2161
|
+
}
|
|
2162
|
+
});
|
|
2163
|
+
const store = globalThis[RequestContext];
|
|
2164
|
+
store ? store.run(broadcastEvent(), run) : run();
|
|
2165
|
+
return shared;
|
|
2166
|
+
}
|
|
2167
|
+
function broadcastEvent() {
|
|
2168
|
+
const event = {
|
|
2169
|
+
broadcast: true
|
|
2170
|
+
};
|
|
2171
|
+
for (const name of ["request", "locals", "clientAddress", "nativeEvent"]) Object.defineProperty(event, name, {
|
|
2172
|
+
get() {
|
|
2173
|
+
return undefined;
|
|
2174
|
+
}
|
|
2175
|
+
});
|
|
2176
|
+
return event;
|
|
2177
|
+
}
|
|
2178
|
+
function retain(shared, message) {
|
|
2179
|
+
if (message.tiers) for (const tier of message.tiers) shared.tiers.add(tier);
|
|
2180
|
+
if (!message.r) {
|
|
2181
|
+
shared.data.push(message);
|
|
2182
|
+
if (shared.data.length > 64 && shared.data.length > 2 * shared.kept) shared.kept = (shared.data = referencedData(shared)).length;
|
|
2183
|
+
return;
|
|
2184
|
+
}
|
|
2185
|
+
const {
|
|
2186
|
+
id,
|
|
2187
|
+
version
|
|
2188
|
+
} = message;
|
|
2189
|
+
for (const k in message.r) {
|
|
2190
|
+
let record = message.r[k];
|
|
2191
|
+
if (k === ":error") shared.failed = true;
|
|
2192
|
+
if (k === "") for (const [rk, e] of shared.records) if (e.id === id) shared.records.delete(rk);
|
|
2193
|
+
if (record && record[HOLE_SOURCE]) record = record[HOLE_SOURCE];
|
|
2194
|
+
const rk = id + "\0" + k;
|
|
2195
|
+
const prev = shared.records.get(rk);
|
|
2196
|
+
if (prev && record && record.kind === "attrs" && prev.record.removed) {
|
|
2197
|
+
const removed = new Set(prev.record.removed);
|
|
2198
|
+
if (record.removed) for (const name of record.removed) removed.add(name);
|
|
2199
|
+
record = {
|
|
2200
|
+
...record,
|
|
2201
|
+
removed: [...removed]
|
|
2202
|
+
};
|
|
2203
|
+
}
|
|
2204
|
+
shared.records.delete(rk);
|
|
2205
|
+
shared.records.set(rk, {
|
|
2206
|
+
id,
|
|
2207
|
+
version,
|
|
2208
|
+
k,
|
|
2209
|
+
record
|
|
2210
|
+
});
|
|
2211
|
+
}
|
|
2212
|
+
}
|
|
2213
|
+
function referencedData(shared) {
|
|
2214
|
+
const refs = new Set();
|
|
2215
|
+
for (const {
|
|
2216
|
+
record
|
|
2217
|
+
} of shared.records.values()) if (record && typeof record === "object") for (const m of JSON.stringify(record).matchAll(/"\$ref":"((?:[^"\\]|\\.)*)"/g)) refs.add(JSON.parse(`"${m[1]}"`));
|
|
2218
|
+
return shared.data.filter(m => typeof m.key !== "string" || refs.has(m.key));
|
|
2219
|
+
}
|
|
2220
|
+
function snapshot(shared, have) {
|
|
2221
|
+
const out = referencedData(shared);
|
|
2222
|
+
const root = shared.records.get(shared.id + "\0");
|
|
2223
|
+
const conditional = !!(have && root && root.record && have[""] === root.record.digest);
|
|
2224
|
+
let open = null;
|
|
2225
|
+
const put = (id, version, k, record) => {
|
|
2226
|
+
if (!open || open.id !== id) out.push(open = {
|
|
2227
|
+
id,
|
|
2228
|
+
version,
|
|
2229
|
+
r: {}
|
|
2230
|
+
});
|
|
2231
|
+
open.r[k] = record;
|
|
2232
|
+
};
|
|
2233
|
+
if (!conditional) {
|
|
2234
|
+
for (const {
|
|
2235
|
+
id,
|
|
2236
|
+
version,
|
|
2237
|
+
k,
|
|
2238
|
+
record
|
|
2239
|
+
} of shared.records.values()) put(id, version, k, record);
|
|
2240
|
+
return out;
|
|
2241
|
+
}
|
|
2242
|
+
const containers = [];
|
|
2243
|
+
for (const e of shared.records.values()) if (e.id === shared.id && (e.k === "" || /^seg:[^:]+$/.test(e.k)) && e.record) containers.push({
|
|
2244
|
+
e,
|
|
2245
|
+
value: e.record.value
|
|
2246
|
+
});
|
|
2247
|
+
for (const {
|
|
2248
|
+
k,
|
|
2249
|
+
record
|
|
2250
|
+
} of shared.records.values()) {
|
|
2251
|
+
if (!k.startsWith("hole:lh:") || k.endsWith(":error") || !record || record.value == null) continue;
|
|
2252
|
+
const n = k.slice(8);
|
|
2253
|
+
const startMark = `<!--lh:${n}-->`;
|
|
2254
|
+
const endMark = `<!--lh:/${n}-->`;
|
|
2255
|
+
for (const c of containers) {
|
|
2256
|
+
const start = c.value.indexOf(startMark);
|
|
2257
|
+
if (start < 0) continue;
|
|
2258
|
+
const end = c.value.indexOf(endMark, start);
|
|
2259
|
+
if (end < 0) continue;
|
|
2260
|
+
c.value = c.value.slice(0, start + startMark.length) + record.value + c.value.slice(end);
|
|
2261
|
+
break;
|
|
2262
|
+
}
|
|
2263
|
+
}
|
|
2264
|
+
for (const e of shared.records.values()) {
|
|
2265
|
+
const {
|
|
2266
|
+
id,
|
|
2267
|
+
version,
|
|
2268
|
+
k,
|
|
2269
|
+
record
|
|
2270
|
+
} = e;
|
|
2271
|
+
if (id !== shared.id) {
|
|
2272
|
+
put(id, version, k, record);
|
|
2273
|
+
continue;
|
|
2274
|
+
}
|
|
2275
|
+
if (k === "" || k === "seg::assets" || k.startsWith("hole:lh:") && !k.endsWith(":error")) continue;
|
|
2276
|
+
const seg = /^seg:([^:]+)(?::(.*))?$/.exec(k);
|
|
2277
|
+
if (seg && have[seg[1]] !== undefined && seg[2] !== "error") continue;
|
|
2278
|
+
if (seg && seg[2] === undefined) {
|
|
2279
|
+
const c = containers.find(c => c.e === e);
|
|
2280
|
+
if (c && c.value !== record.value) {
|
|
2281
|
+
put(id, version, k, withHoles({
|
|
2282
|
+
...record,
|
|
2283
|
+
value: c.value,
|
|
2284
|
+
digest: textDigest(c.value)
|
|
2285
|
+
}, holeDigests(c.value, null)));
|
|
2286
|
+
continue;
|
|
2287
|
+
}
|
|
2288
|
+
}
|
|
2289
|
+
if (k.startsWith("attr:")) continue;
|
|
2290
|
+
put(id, version, k, record);
|
|
2291
|
+
}
|
|
2292
|
+
for (const c of containers) {
|
|
2293
|
+
const seg = c.e.k && /^seg:([^:]+)$/.exec(c.e.k);
|
|
2294
|
+
if (seg && have[seg[1]] === undefined) continue;
|
|
2295
|
+
for (const m of c.value.matchAll(HOLE_RANGE)) {
|
|
2296
|
+
const key = "lh:" + m[1];
|
|
2297
|
+
const digest = textDigest(stripHoleMarkers(m[2]));
|
|
2298
|
+
if (have[key] === digest) continue;
|
|
2299
|
+
put(shared.id, c.e.version, "hole:" + key, withHoles({
|
|
2300
|
+
kind: "html",
|
|
2301
|
+
value: m[2],
|
|
2302
|
+
digest
|
|
2303
|
+
}, holeDigests(m[2], null)));
|
|
2304
|
+
}
|
|
2305
|
+
for (const m of c.value.matchAll(ATTR_ADDRESS)) {
|
|
2306
|
+
const latest = shared.records.get(shared.id + "\0attr:" + m[1]);
|
|
2307
|
+
const text = latest ? latest.record.value : shared.attrs.get("lha:" + m[1]);
|
|
2308
|
+
if (text === undefined) continue;
|
|
2309
|
+
const digest = latest ? latest.record.digest : textDigest(text);
|
|
2310
|
+
if (have["lha:" + m[1]] === digest) continue;
|
|
2311
|
+
put(shared.id, c.e.version, "attr:" + m[1], latest ? latest.record : {
|
|
2312
|
+
kind: "attrs",
|
|
2313
|
+
value: text,
|
|
2314
|
+
digest
|
|
2315
|
+
});
|
|
2316
|
+
}
|
|
2317
|
+
}
|
|
2318
|
+
return out;
|
|
2319
|
+
}
|
|
2320
|
+
function tapResponse(shared, signal, have, init = {}) {
|
|
2321
|
+
const headers = copyInitHeaders(init.headers);
|
|
2322
|
+
headers.set(FRAME_STREAM_HEADER, shared.id);
|
|
2323
|
+
headers.set("X-Content-Raw", "1");
|
|
2324
|
+
headers.set("Content-Type", "text/event-stream");
|
|
2325
|
+
headers.set("Cache-Control", "no-store");
|
|
2326
|
+
headers.set("X-Accel-Buffering", "no");
|
|
2327
|
+
headers.set(FRAME_TIERS_HEADER, [...shared.tiers].join(","));
|
|
2328
|
+
let closed = false;
|
|
2329
|
+
let stopLive = null;
|
|
2330
|
+
let tap = null;
|
|
2331
|
+
const leave = () => {
|
|
2332
|
+
if (closed) return;
|
|
2333
|
+
closed = true;
|
|
2334
|
+
if (stopLive) stopLive();
|
|
2335
|
+
if (signal) signal.removeEventListener("abort", leave);
|
|
2336
|
+
shared.taps.delete(tap);
|
|
2337
|
+
if (!shared.taps.size && !shared.ended) {
|
|
2338
|
+
shared.ended = true;
|
|
2339
|
+
if (BROADCASTS.get(shared.key) === shared) BROADCASTS.delete(shared.key);
|
|
2340
|
+
shared.teardown.abort({
|
|
2341
|
+
[DISCONNECTED]: true
|
|
2342
|
+
});
|
|
2343
|
+
}
|
|
2344
|
+
};
|
|
2345
|
+
const body = new ReadableStream({
|
|
2346
|
+
start(controller) {
|
|
2347
|
+
tap = {
|
|
2348
|
+
write(bytes) {
|
|
2349
|
+
if (closed) return;
|
|
2350
|
+
try {
|
|
2351
|
+
controller.enqueue(bytes);
|
|
2352
|
+
} catch (_) {
|
|
2353
|
+
leave();
|
|
2354
|
+
}
|
|
2355
|
+
},
|
|
2356
|
+
end() {
|
|
2357
|
+
leave();
|
|
2358
|
+
try {
|
|
2359
|
+
controller.close();
|
|
2360
|
+
} catch (_) {}
|
|
2361
|
+
}
|
|
2362
|
+
};
|
|
2363
|
+
if (shared.start) controller.enqueue(shared.start);
|
|
2364
|
+
for (const message of snapshot(shared, have)) controller.enqueue(createEventChunk(JSON.stringify(message)));
|
|
2365
|
+
if (shared.ended || signal && signal.aborted) return tap.end();
|
|
2366
|
+
shared.taps.add(tap);
|
|
2367
|
+
stopLive = armLiveBody(controller, leave);
|
|
2368
|
+
if (signal) signal.addEventListener("abort", leave, {
|
|
2369
|
+
once: true
|
|
2370
|
+
});
|
|
2371
|
+
},
|
|
2372
|
+
cancel() {
|
|
2373
|
+
leave();
|
|
2374
|
+
}
|
|
2375
|
+
});
|
|
2376
|
+
if (shared.failed) headers.set("Cache-Control", "no-store");
|
|
2377
|
+
return new Response(body, {
|
|
2378
|
+
status: init.status || 200,
|
|
2379
|
+
headers
|
|
2380
|
+
});
|
|
2381
|
+
}
|
|
2382
|
+
function requestSignal(event) {
|
|
2383
|
+
const request = event && event.request;
|
|
2384
|
+
return request && request.signal instanceof AbortSignal ? request.signal : undefined;
|
|
2385
|
+
}
|
|
2386
|
+
function requestHeader(event, name) {
|
|
2387
|
+
const request = event && event.request;
|
|
2388
|
+
const headers = request && request.headers;
|
|
2389
|
+
return headers && typeof headers.get === "function" ? headers.get(name) : null;
|
|
2390
|
+
}
|
|
2391
|
+
async function frameTransformFlightResult(event, outcome, context) {
|
|
2392
|
+
const {
|
|
2393
|
+
value,
|
|
2394
|
+
data
|
|
2395
|
+
} = outcome;
|
|
2396
|
+
const regions = [];
|
|
2397
|
+
let serialized = data;
|
|
2398
|
+
if (data && typeof data === "object") {
|
|
2399
|
+
serialized = {};
|
|
2400
|
+
for (const source of Object.keys(data)) {
|
|
2401
|
+
const slice = data[source];
|
|
2402
|
+
if (!slice || typeof slice !== "object" || Array.isArray(slice)) {
|
|
2403
|
+
serialized[source] = slice;
|
|
2404
|
+
continue;
|
|
2405
|
+
}
|
|
2406
|
+
const keys = Object.keys(slice);
|
|
2407
|
+
const settled = await Promise.allSettled(keys.map(key => slice[key]));
|
|
2408
|
+
const out = serialized[source] = {};
|
|
2409
|
+
for (let i = 0; i < keys.length; i++) {
|
|
2410
|
+
const result = settled[i];
|
|
2411
|
+
const entry = result.status === "fulfilled" ? result.value : slice[keys[i]];
|
|
2412
|
+
if (typeof entry !== "function") {
|
|
2413
|
+
out[keys[i]] = entry;
|
|
2414
|
+
continue;
|
|
2415
|
+
}
|
|
2416
|
+
const address = entry[SERVER_COMPONENT_ADDRESS] || keys[i];
|
|
2417
|
+
regions.push({
|
|
2418
|
+
id: address,
|
|
2419
|
+
component: entry[SERVER_COMPONENT_SOURCE] || entry
|
|
2420
|
+
});
|
|
2421
|
+
if (SERVER_COMPONENT in entry) {
|
|
2422
|
+
out[keys[i]] = entry;
|
|
2423
|
+
} else {
|
|
2424
|
+
const reference = () => undefined;
|
|
2425
|
+
reference[SERVER_COMPONENT] = keys[i];
|
|
2426
|
+
reference[SERVER_COMPONENT_ADDRESS] = address;
|
|
2427
|
+
out[keys[i]] = reference;
|
|
2428
|
+
}
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2431
|
+
}
|
|
2432
|
+
const invocation = getEventServerFunctionInvocation(event);
|
|
2433
|
+
const primary = typeof value === "function" ? {
|
|
2434
|
+
id: invocation && invocation.id || "",
|
|
2435
|
+
component: value
|
|
2436
|
+
} : undefined;
|
|
2437
|
+
if (!primary && !regions.length) return undefined;
|
|
2438
|
+
return frameFlightResponse({
|
|
2439
|
+
primary,
|
|
2440
|
+
regions,
|
|
2441
|
+
outcome: {
|
|
2442
|
+
value: primary ? undefined : value,
|
|
2443
|
+
data: serialized
|
|
2444
|
+
},
|
|
2445
|
+
codec: context && context.codec,
|
|
2446
|
+
signal: requestSignal(event)
|
|
2447
|
+
});
|
|
2448
|
+
}
|
|
2449
|
+
function frameFlightResponse({
|
|
2450
|
+
primary,
|
|
2451
|
+
regions = [],
|
|
2452
|
+
outcome,
|
|
2453
|
+
codec,
|
|
2454
|
+
signal
|
|
2455
|
+
}, init = {}) {
|
|
2456
|
+
const frames = primary ? [primary, ...regions] : regions;
|
|
2457
|
+
const headers = copyInitHeaders(init.headers);
|
|
2458
|
+
headers.set("Content-Type", "application/x-frame-stream");
|
|
2459
|
+
headers.set(FRAME_STREAM_HEADER, primary ? primary.id : "");
|
|
2460
|
+
headers.set("X-Content-Raw", "1");
|
|
2461
|
+
const teardown = new AbortController();
|
|
2462
|
+
const disarm = followSignal(signal, teardown);
|
|
2463
|
+
let closed = false;
|
|
2464
|
+
const body = new ReadableStream({
|
|
2465
|
+
async start(controller) {
|
|
2466
|
+
const write = message => {
|
|
2467
|
+
if (closed) return;
|
|
2468
|
+
try {
|
|
2469
|
+
controller.enqueue(createChunk(JSON.stringify(message)));
|
|
2470
|
+
} catch (_) {
|
|
2471
|
+
closed = true;
|
|
2472
|
+
}
|
|
2473
|
+
};
|
|
2474
|
+
try {
|
|
2475
|
+
for (const {
|
|
2476
|
+
id,
|
|
2477
|
+
component
|
|
2478
|
+
} of frames) {
|
|
2479
|
+
if (teardown.signal.aborted) break;
|
|
2480
|
+
await new Promise(resolve => {
|
|
2481
|
+
teardown.signal.addEventListener("abort", resolve, {
|
|
2482
|
+
once: true
|
|
2483
|
+
});
|
|
2484
|
+
renderServerComponent(component, {
|
|
2485
|
+
frame: {
|
|
2486
|
+
id,
|
|
2487
|
+
version: 1
|
|
2488
|
+
},
|
|
2489
|
+
signal: teardown.signal
|
|
2490
|
+
}).pipe({
|
|
2491
|
+
write,
|
|
2492
|
+
end: () => {
|
|
2493
|
+
teardown.signal.removeEventListener("abort", resolve);
|
|
2494
|
+
resolve();
|
|
2495
|
+
}
|
|
2496
|
+
});
|
|
2497
|
+
});
|
|
2498
|
+
}
|
|
2499
|
+
if (teardown.signal.aborted) {
|
|
2500
|
+
closed = true;
|
|
2501
|
+
try {
|
|
2502
|
+
controller.close();
|
|
2503
|
+
} catch (_) {}
|
|
2504
|
+
return;
|
|
2505
|
+
}
|
|
2506
|
+
if (outcome) {
|
|
2507
|
+
const reader = new ChunkReader(serializeStream(guardFailures(outcome), flightCodec(codec)));
|
|
2508
|
+
for (let node = await reader.next(); !node.done; node = await reader.next()) {
|
|
2509
|
+
write({
|
|
2510
|
+
type: "outcome",
|
|
2511
|
+
payload: node.value
|
|
2512
|
+
});
|
|
2513
|
+
}
|
|
2514
|
+
}
|
|
2515
|
+
if (!closed) {
|
|
2516
|
+
closed = true;
|
|
2517
|
+
controller.close();
|
|
2518
|
+
}
|
|
2519
|
+
} catch (err) {
|
|
2520
|
+
if (!closed) {
|
|
2521
|
+
closed = true;
|
|
2522
|
+
controller.error(err);
|
|
2523
|
+
}
|
|
2524
|
+
} finally {
|
|
2525
|
+
disarm();
|
|
2526
|
+
}
|
|
2527
|
+
},
|
|
2528
|
+
cancel() {
|
|
2529
|
+
closed = true;
|
|
2530
|
+
disarm();
|
|
2531
|
+
teardown.abort({
|
|
2532
|
+
[DISCONNECTED]: true
|
|
2533
|
+
});
|
|
2534
|
+
}
|
|
2535
|
+
});
|
|
2536
|
+
return new Response(body, {
|
|
2537
|
+
status: init.status || 200,
|
|
2538
|
+
headers
|
|
2539
|
+
});
|
|
2540
|
+
}
|
|
2541
|
+
|
|
2542
|
+
setContainerTraceResolver(getProjectionTrace);
|
|
2543
|
+
setAsyncIterableSharer(shareAsyncIterable);
|
|
2544
|
+
function asyncArg(value) {
|
|
2545
|
+
return value;
|
|
2546
|
+
}
|
|
2547
|
+
|
|
2548
|
+
export { FRAME_HAVE_BUDGET, FRAME_HAVE_HEADER, FRAME_STREAM_HEADER, FRAME_TIERS_HEADER, SERVER_COMPONENT_BOOTSTRAP, ServerComponentPlugin, asyncArg, frameTransformDirectResult, frameTransformFlightResult, frameTransformResult, isFrameStreamResponse };
|