@solidjs/web 2.0.0-rc.16 → 2.0.0-rc.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/server.dev.js +16 -17
- package/dist/server.js +16 -17
- package/dist/server.observe.js +16 -17
- package/dist/web.dev.js +53 -1
- package/dist/web.js +4 -1
- package/dist/web.observe.js +4 -1
- package/frames/dist/server.dev.js +281 -3
- package/frames/dist/server.js +280 -3
- package/frames/dist/server.observe.js +280 -3
- package/package.json +2 -2
- package/server-functions/dist/client.dev.js +10 -21
- package/server-functions/dist/client.js +10 -21
- package/server-functions/dist/client.observe.js +10 -21
- package/server-functions/dist/rich-args.js +54 -3
- package/server-functions/dist/server.dev.js +68 -3
- package/server-functions/dist/server.js +68 -3
- package/server-functions/dist/server.observe.js +68 -3
- package/types/client.d.ts +12 -0
- package/types/diagnostics.d.ts +16 -0
- package/types/server-functions/argument-codec.d.ts +11 -2
- package/types/server-functions/client.d.ts +13 -4
- package/types/server-functions/server.d.ts +17 -0
- package/types/server-functions/uploads.d.ts +50 -0
- package/types/server.d.ts +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { sharedConfig, ssrSanitizeError, creationStamp, ssrHandleError, runInServerComponentScope, trackFillReads, shareAsyncIterable, getProjectionTrace } from 'solid-js/internal';
|
|
2
2
|
import { getOwner, NoHydration, runWithOwner, createMemo, createOwner, Hydration } from 'solid-js';
|
|
3
|
-
import { isResponseEnvelope, renderToStream, createLiveHoles } from '@solidjs/web';
|
|
3
|
+
import { isResponseEnvelope, RequestContext, renderToStream, createLiveHoles } from '@solidjs/web';
|
|
4
4
|
import { Feature, createStream, toCrossJSONStream } from 'seroval';
|
|
5
5
|
import { AbortSignalPlugin, CustomEventPlugin, DOMExceptionPlugin, EventPlugin, FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin } from 'seroval-plugins/web';
|
|
6
6
|
import { frameAddress, getEventServerFunctionInvocation, ChunkReader, serializeStream, guardFailures, armLiveBody, createEventChunk, createChunk, textDigest } from '@solidjs/web/server-functions/server';
|
|
@@ -772,12 +772,13 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
772
772
|
},
|
|
773
773
|
flush,
|
|
774
774
|
slot(key, args) {
|
|
775
|
-
|
|
775
|
+
const r = {
|
|
776
776
|
[`slot:${key}`]: {
|
|
777
777
|
kind: "slot",
|
|
778
778
|
args
|
|
779
779
|
}
|
|
780
|
-
}
|
|
780
|
+
};
|
|
781
|
+
swept ? Object.assign(swept.r, r) : put(id, r);
|
|
781
782
|
},
|
|
782
783
|
region(childId, value) {
|
|
783
784
|
needs("regions");
|
|
@@ -799,6 +800,11 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
799
800
|
record.base = base;
|
|
800
801
|
} else record.value = source;
|
|
801
802
|
withHoles(record, holeDigests(record.rows ? rows.r.map(r => r[1]).join("") : source, null));
|
|
803
|
+
if (record.rows && hooks && hooks.retain) record[HOLE_SOURCE] = withHoles({
|
|
804
|
+
kind: "html",
|
|
805
|
+
value: source,
|
|
806
|
+
digest: record.digest
|
|
807
|
+
}, holeDigests(source, null));
|
|
802
808
|
const r = {
|
|
803
809
|
["hole:" + key]: record
|
|
804
810
|
};
|
|
@@ -819,6 +825,7 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
819
825
|
},
|
|
820
826
|
attrBaseline(key, text) {
|
|
821
827
|
attrText.set(key, text);
|
|
828
|
+
if (hooks && hooks.retain) hooks.retain(key, text);
|
|
822
829
|
},
|
|
823
830
|
openBinding(key, b) {
|
|
824
831
|
if (/^lha?:/.test(key)) needs("wire");
|
|
@@ -920,6 +927,7 @@ function frameStream(makeCode, options) {
|
|
|
920
927
|
};
|
|
921
928
|
const sink = createFrameSink(emit, frame, options.resume && options.resume.have, {
|
|
922
929
|
live: options.live,
|
|
930
|
+
retain: options.broadcast,
|
|
923
931
|
onYield: bounded ? () => {
|
|
924
932
|
if (flushed && maxYields > 0 && ++yields >= maxYields) cut("yields");
|
|
925
933
|
} : undefined
|
|
@@ -2056,6 +2064,12 @@ function frameTransformResult(event, result, context) {
|
|
|
2056
2064
|
const invocation = getEventServerFunctionInvocation(event);
|
|
2057
2065
|
const live = !!(invocation && invocation.live);
|
|
2058
2066
|
const have = live ? decodeHaveList(requestHeader(event, FRAME_HAVE_HEADER)) : undefined;
|
|
2067
|
+
if (live && invocation.broadcast && invocation.shareKey !== undefined) return broadcastResponse(invocation.id + "\0" + invocation.shareKey, result, {
|
|
2068
|
+
frame: {
|
|
2069
|
+
id: invocation.id || ""
|
|
2070
|
+
},
|
|
2071
|
+
live: true
|
|
2072
|
+
}, requestSignal(event), have, init);
|
|
2059
2073
|
return serverComponentResponse(result, {
|
|
2060
2074
|
frame: {
|
|
2061
2075
|
id: invocation && invocation.id || ""
|
|
@@ -2067,6 +2081,270 @@ function frameTransformResult(event, result, context) {
|
|
|
2067
2081
|
}
|
|
2068
2082
|
}, init);
|
|
2069
2083
|
}
|
|
2084
|
+
const HOLE_SOURCE = Symbol("solid.frames.holeSource");
|
|
2085
|
+
const BROADCASTS = new Map();
|
|
2086
|
+
function broadcastResponse(key, component, options, signal, have, init) {
|
|
2087
|
+
let shared = BROADCASTS.get(key);
|
|
2088
|
+
if (!shared || shared.ended) shared = startBroadcast(key, component, options);
|
|
2089
|
+
return tapResponse(shared, signal, have, init);
|
|
2090
|
+
}
|
|
2091
|
+
function startBroadcast(key, component, options) {
|
|
2092
|
+
const shared = {
|
|
2093
|
+
key,
|
|
2094
|
+
id: options.frame.id,
|
|
2095
|
+
start: null,
|
|
2096
|
+
taps: new Set(),
|
|
2097
|
+
records: new Map(),
|
|
2098
|
+
data: [],
|
|
2099
|
+
kept: 0,
|
|
2100
|
+
attrs: new Map(),
|
|
2101
|
+
tiers: new Set(["wire"]),
|
|
2102
|
+
failed: false,
|
|
2103
|
+
ended: false,
|
|
2104
|
+
teardown: new AbortController()
|
|
2105
|
+
};
|
|
2106
|
+
BROADCASTS.set(key, shared);
|
|
2107
|
+
const stream = renderServerComponent(component, {
|
|
2108
|
+
...options,
|
|
2109
|
+
broadcast: (key, text) => shared.attrs.set(key, text),
|
|
2110
|
+
signal: shared.teardown.signal
|
|
2111
|
+
});
|
|
2112
|
+
const run = () => stream.pipe({
|
|
2113
|
+
write(message) {
|
|
2114
|
+
const bytes = createEventChunk(JSON.stringify(message));
|
|
2115
|
+
if (message.type === "start") return void (shared.start = bytes);
|
|
2116
|
+
retain(shared, message);
|
|
2117
|
+
for (const tap of shared.taps) tap.write(bytes);
|
|
2118
|
+
},
|
|
2119
|
+
end() {
|
|
2120
|
+
shared.ended = true;
|
|
2121
|
+
if (BROADCASTS.get(key) === shared) BROADCASTS.delete(key);
|
|
2122
|
+
for (const tap of [...shared.taps]) tap.end();
|
|
2123
|
+
},
|
|
2124
|
+
[ANNOUNCE](tiers) {
|
|
2125
|
+
for (const tier of tiers) shared.tiers.add(tier);
|
|
2126
|
+
}
|
|
2127
|
+
});
|
|
2128
|
+
const store = globalThis[RequestContext];
|
|
2129
|
+
store ? store.run(broadcastEvent(), run) : run();
|
|
2130
|
+
return shared;
|
|
2131
|
+
}
|
|
2132
|
+
function broadcastEvent() {
|
|
2133
|
+
const event = {
|
|
2134
|
+
broadcast: true
|
|
2135
|
+
};
|
|
2136
|
+
for (const name of ["request", "locals", "clientAddress", "nativeEvent"]) Object.defineProperty(event, name, {
|
|
2137
|
+
get() {
|
|
2138
|
+
console.warn(`A broadcast server component read the request (\`event.${name}\`). Its answer is ` + "shared by every viewer; read per-viewer state in the server function body instead.");
|
|
2139
|
+
return undefined;
|
|
2140
|
+
}
|
|
2141
|
+
});
|
|
2142
|
+
return event;
|
|
2143
|
+
}
|
|
2144
|
+
function retain(shared, message) {
|
|
2145
|
+
if (message.tiers) for (const tier of message.tiers) shared.tiers.add(tier);
|
|
2146
|
+
if (!message.r) {
|
|
2147
|
+
shared.data.push(message);
|
|
2148
|
+
if (shared.data.length > 64 && shared.data.length > 2 * shared.kept) shared.kept = (shared.data = referencedData(shared)).length;
|
|
2149
|
+
return;
|
|
2150
|
+
}
|
|
2151
|
+
const {
|
|
2152
|
+
id,
|
|
2153
|
+
version
|
|
2154
|
+
} = message;
|
|
2155
|
+
for (const k in message.r) {
|
|
2156
|
+
let record = message.r[k];
|
|
2157
|
+
if (k === ":error") shared.failed = true;
|
|
2158
|
+
if (k === "") for (const [rk, e] of shared.records) if (e.id === id) shared.records.delete(rk);
|
|
2159
|
+
if (record && record[HOLE_SOURCE]) record = record[HOLE_SOURCE];
|
|
2160
|
+
const rk = id + "\0" + k;
|
|
2161
|
+
const prev = shared.records.get(rk);
|
|
2162
|
+
if (prev && record && record.kind === "attrs" && prev.record.removed) {
|
|
2163
|
+
const removed = new Set(prev.record.removed);
|
|
2164
|
+
if (record.removed) for (const name of record.removed) removed.add(name);
|
|
2165
|
+
record = {
|
|
2166
|
+
...record,
|
|
2167
|
+
removed: [...removed]
|
|
2168
|
+
};
|
|
2169
|
+
}
|
|
2170
|
+
shared.records.delete(rk);
|
|
2171
|
+
shared.records.set(rk, {
|
|
2172
|
+
id,
|
|
2173
|
+
version,
|
|
2174
|
+
k,
|
|
2175
|
+
record
|
|
2176
|
+
});
|
|
2177
|
+
}
|
|
2178
|
+
}
|
|
2179
|
+
function referencedData(shared) {
|
|
2180
|
+
const refs = new Set();
|
|
2181
|
+
for (const {
|
|
2182
|
+
record
|
|
2183
|
+
} 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]}"`));
|
|
2184
|
+
return shared.data.filter(m => typeof m.key !== "string" || refs.has(m.key));
|
|
2185
|
+
}
|
|
2186
|
+
function snapshot(shared, have) {
|
|
2187
|
+
const out = referencedData(shared);
|
|
2188
|
+
const root = shared.records.get(shared.id + "\0");
|
|
2189
|
+
const conditional = !!(have && root && root.record && have[""] === root.record.digest);
|
|
2190
|
+
let open = null;
|
|
2191
|
+
const put = (id, version, k, record) => {
|
|
2192
|
+
if (!open || open.id !== id) out.push(open = {
|
|
2193
|
+
id,
|
|
2194
|
+
version,
|
|
2195
|
+
r: {}
|
|
2196
|
+
});
|
|
2197
|
+
open.r[k] = record;
|
|
2198
|
+
};
|
|
2199
|
+
if (!conditional) {
|
|
2200
|
+
for (const {
|
|
2201
|
+
id,
|
|
2202
|
+
version,
|
|
2203
|
+
k,
|
|
2204
|
+
record
|
|
2205
|
+
} of shared.records.values()) put(id, version, k, record);
|
|
2206
|
+
return out;
|
|
2207
|
+
}
|
|
2208
|
+
const containers = [];
|
|
2209
|
+
for (const e of shared.records.values()) if (e.id === shared.id && (e.k === "" || /^seg:[^:]+$/.test(e.k)) && e.record) containers.push({
|
|
2210
|
+
e,
|
|
2211
|
+
value: e.record.value
|
|
2212
|
+
});
|
|
2213
|
+
for (const {
|
|
2214
|
+
k,
|
|
2215
|
+
record
|
|
2216
|
+
} of shared.records.values()) {
|
|
2217
|
+
if (!k.startsWith("hole:lh:") || k.endsWith(":error") || !record || record.value == null) continue;
|
|
2218
|
+
const n = k.slice(8);
|
|
2219
|
+
const startMark = `<!--lh:${n}-->`;
|
|
2220
|
+
const endMark = `<!--lh:/${n}-->`;
|
|
2221
|
+
for (const c of containers) {
|
|
2222
|
+
const start = c.value.indexOf(startMark);
|
|
2223
|
+
if (start < 0) continue;
|
|
2224
|
+
const end = c.value.indexOf(endMark, start);
|
|
2225
|
+
if (end < 0) continue;
|
|
2226
|
+
c.value = c.value.slice(0, start + startMark.length) + record.value + c.value.slice(end);
|
|
2227
|
+
break;
|
|
2228
|
+
}
|
|
2229
|
+
}
|
|
2230
|
+
for (const e of shared.records.values()) {
|
|
2231
|
+
const {
|
|
2232
|
+
id,
|
|
2233
|
+
version,
|
|
2234
|
+
k,
|
|
2235
|
+
record
|
|
2236
|
+
} = e;
|
|
2237
|
+
if (id !== shared.id) {
|
|
2238
|
+
put(id, version, k, record);
|
|
2239
|
+
continue;
|
|
2240
|
+
}
|
|
2241
|
+
if (k === "" || k === "seg::assets" || k.startsWith("hole:lh:") && !k.endsWith(":error")) continue;
|
|
2242
|
+
const seg = /^seg:([^:]+)(?::(.*))?$/.exec(k);
|
|
2243
|
+
if (seg && have[seg[1]] !== undefined && seg[2] !== "error") continue;
|
|
2244
|
+
if (seg && seg[2] === undefined) {
|
|
2245
|
+
const c = containers.find(c => c.e === e);
|
|
2246
|
+
if (c && c.value !== record.value) {
|
|
2247
|
+
put(id, version, k, withHoles({
|
|
2248
|
+
...record,
|
|
2249
|
+
value: c.value,
|
|
2250
|
+
digest: textDigest(c.value)
|
|
2251
|
+
}, holeDigests(c.value, null)));
|
|
2252
|
+
continue;
|
|
2253
|
+
}
|
|
2254
|
+
}
|
|
2255
|
+
if (k.startsWith("attr:")) continue;
|
|
2256
|
+
put(id, version, k, record);
|
|
2257
|
+
}
|
|
2258
|
+
for (const c of containers) {
|
|
2259
|
+
const seg = c.e.k && /^seg:([^:]+)$/.exec(c.e.k);
|
|
2260
|
+
if (seg && have[seg[1]] === undefined) continue;
|
|
2261
|
+
for (const m of c.value.matchAll(HOLE_RANGE)) {
|
|
2262
|
+
const key = "lh:" + m[1];
|
|
2263
|
+
const digest = textDigest(stripHoleMarkers(m[2]));
|
|
2264
|
+
if (have[key] === digest) continue;
|
|
2265
|
+
put(shared.id, c.e.version, "hole:" + key, withHoles({
|
|
2266
|
+
kind: "html",
|
|
2267
|
+
value: m[2],
|
|
2268
|
+
digest
|
|
2269
|
+
}, holeDigests(m[2], null)));
|
|
2270
|
+
}
|
|
2271
|
+
for (const m of c.value.matchAll(ATTR_ADDRESS)) {
|
|
2272
|
+
const latest = shared.records.get(shared.id + "\0attr:" + m[1]);
|
|
2273
|
+
const text = latest ? latest.record.value : shared.attrs.get("lha:" + m[1]);
|
|
2274
|
+
if (text === undefined) continue;
|
|
2275
|
+
const digest = latest ? latest.record.digest : textDigest(text);
|
|
2276
|
+
if (have["lha:" + m[1]] === digest) continue;
|
|
2277
|
+
put(shared.id, c.e.version, "attr:" + m[1], latest ? latest.record : {
|
|
2278
|
+
kind: "attrs",
|
|
2279
|
+
value: text,
|
|
2280
|
+
digest
|
|
2281
|
+
});
|
|
2282
|
+
}
|
|
2283
|
+
}
|
|
2284
|
+
return out;
|
|
2285
|
+
}
|
|
2286
|
+
function tapResponse(shared, signal, have, init = {}) {
|
|
2287
|
+
const headers = copyInitHeaders(init.headers);
|
|
2288
|
+
headers.set(FRAME_STREAM_HEADER, shared.id);
|
|
2289
|
+
headers.set("X-Content-Raw", "1");
|
|
2290
|
+
headers.set("Content-Type", "text/event-stream");
|
|
2291
|
+
headers.set("Cache-Control", "no-store");
|
|
2292
|
+
headers.set("X-Accel-Buffering", "no");
|
|
2293
|
+
headers.set(FRAME_TIERS_HEADER, [...shared.tiers].join(","));
|
|
2294
|
+
let closed = false;
|
|
2295
|
+
let stopLive = null;
|
|
2296
|
+
let tap = null;
|
|
2297
|
+
const leave = () => {
|
|
2298
|
+
if (closed) return;
|
|
2299
|
+
closed = true;
|
|
2300
|
+
if (stopLive) stopLive();
|
|
2301
|
+
if (signal) signal.removeEventListener("abort", leave);
|
|
2302
|
+
shared.taps.delete(tap);
|
|
2303
|
+
if (!shared.taps.size && !shared.ended) {
|
|
2304
|
+
shared.ended = true;
|
|
2305
|
+
if (BROADCASTS.get(shared.key) === shared) BROADCASTS.delete(shared.key);
|
|
2306
|
+
shared.teardown.abort({
|
|
2307
|
+
[DISCONNECTED]: true
|
|
2308
|
+
});
|
|
2309
|
+
}
|
|
2310
|
+
};
|
|
2311
|
+
const body = new ReadableStream({
|
|
2312
|
+
start(controller) {
|
|
2313
|
+
tap = {
|
|
2314
|
+
write(bytes) {
|
|
2315
|
+
if (closed) return;
|
|
2316
|
+
try {
|
|
2317
|
+
controller.enqueue(bytes);
|
|
2318
|
+
} catch (_) {
|
|
2319
|
+
leave();
|
|
2320
|
+
}
|
|
2321
|
+
},
|
|
2322
|
+
end() {
|
|
2323
|
+
leave();
|
|
2324
|
+
try {
|
|
2325
|
+
controller.close();
|
|
2326
|
+
} catch (_) {}
|
|
2327
|
+
}
|
|
2328
|
+
};
|
|
2329
|
+
if (shared.start) controller.enqueue(shared.start);
|
|
2330
|
+
for (const message of snapshot(shared, have)) controller.enqueue(createEventChunk(JSON.stringify(message)));
|
|
2331
|
+
if (shared.ended || signal && signal.aborted) return tap.end();
|
|
2332
|
+
shared.taps.add(tap);
|
|
2333
|
+
stopLive = armLiveBody(controller, leave);
|
|
2334
|
+
if (signal) signal.addEventListener("abort", leave, {
|
|
2335
|
+
once: true
|
|
2336
|
+
});
|
|
2337
|
+
},
|
|
2338
|
+
cancel() {
|
|
2339
|
+
leave();
|
|
2340
|
+
}
|
|
2341
|
+
});
|
|
2342
|
+
if (shared.failed) headers.set("Cache-Control", "no-store");
|
|
2343
|
+
return new Response(body, {
|
|
2344
|
+
status: init.status || 200,
|
|
2345
|
+
headers
|
|
2346
|
+
});
|
|
2347
|
+
}
|
|
2070
2348
|
function requestSignal(event) {
|
|
2071
2349
|
const request = event && event.request;
|
|
2072
2350
|
return request && request.signal instanceof AbortSignal ? request.signal : undefined;
|
package/frames/dist/server.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { sharedConfig, ssrSanitizeError, creationStamp, ssrHandleError, runInServerComponentScope, trackFillReads, shareAsyncIterable, getProjectionTrace } from 'solid-js/internal';
|
|
2
2
|
import { getOwner, NoHydration, runWithOwner, createMemo, createOwner, Hydration } from 'solid-js';
|
|
3
|
-
import { isResponseEnvelope, renderToStream, createLiveHoles } from '@solidjs/web';
|
|
3
|
+
import { isResponseEnvelope, RequestContext, renderToStream, createLiveHoles } from '@solidjs/web';
|
|
4
4
|
import { Feature, createStream, toCrossJSONStream } from 'seroval';
|
|
5
5
|
import { AbortSignalPlugin, CustomEventPlugin, DOMExceptionPlugin, EventPlugin, FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin } from 'seroval-plugins/web';
|
|
6
6
|
import { frameAddress, getEventServerFunctionInvocation, ChunkReader, serializeStream, guardFailures, armLiveBody, createEventChunk, createChunk, textDigest } from '@solidjs/web/server-functions/server';
|
|
@@ -771,12 +771,13 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
771
771
|
},
|
|
772
772
|
flush,
|
|
773
773
|
slot(key, args) {
|
|
774
|
-
|
|
774
|
+
const r = {
|
|
775
775
|
[`slot:${key}`]: {
|
|
776
776
|
kind: "slot",
|
|
777
777
|
args
|
|
778
778
|
}
|
|
779
|
-
}
|
|
779
|
+
};
|
|
780
|
+
swept ? Object.assign(swept.r, r) : put(id, r);
|
|
780
781
|
},
|
|
781
782
|
region(childId, value) {
|
|
782
783
|
needs("regions");
|
|
@@ -798,6 +799,11 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
798
799
|
record.base = base;
|
|
799
800
|
} else record.value = source;
|
|
800
801
|
withHoles(record, holeDigests(record.rows ? rows.r.map(r => r[1]).join("") : source, null));
|
|
802
|
+
if (record.rows && hooks && hooks.retain) record[HOLE_SOURCE] = withHoles({
|
|
803
|
+
kind: "html",
|
|
804
|
+
value: source,
|
|
805
|
+
digest: record.digest
|
|
806
|
+
}, holeDigests(source, null));
|
|
801
807
|
const r = {
|
|
802
808
|
["hole:" + key]: record
|
|
803
809
|
};
|
|
@@ -818,6 +824,7 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
818
824
|
},
|
|
819
825
|
attrBaseline(key, text) {
|
|
820
826
|
attrText.set(key, text);
|
|
827
|
+
if (hooks && hooks.retain) hooks.retain(key, text);
|
|
821
828
|
},
|
|
822
829
|
openBinding(key, b) {
|
|
823
830
|
if (/^lha?:/.test(key)) needs("wire");
|
|
@@ -919,6 +926,7 @@ function frameStream(makeCode, options) {
|
|
|
919
926
|
};
|
|
920
927
|
const sink = createFrameSink(emit, frame, options.resume && options.resume.have, {
|
|
921
928
|
live: options.live,
|
|
929
|
+
retain: options.broadcast,
|
|
922
930
|
onYield: bounded ? () => {
|
|
923
931
|
if (flushed && maxYields > 0 && ++yields >= maxYields) cut("yields");
|
|
924
932
|
} : undefined
|
|
@@ -2055,6 +2063,12 @@ function frameTransformResult(event, result, context) {
|
|
|
2055
2063
|
const invocation = getEventServerFunctionInvocation(event);
|
|
2056
2064
|
const live = !!(invocation && invocation.live);
|
|
2057
2065
|
const have = live ? decodeHaveList(requestHeader(event, FRAME_HAVE_HEADER)) : undefined;
|
|
2066
|
+
if (live && invocation.broadcast && invocation.shareKey !== undefined) return broadcastResponse(invocation.id + "\0" + invocation.shareKey, result, {
|
|
2067
|
+
frame: {
|
|
2068
|
+
id: invocation.id || ""
|
|
2069
|
+
},
|
|
2070
|
+
live: true
|
|
2071
|
+
}, requestSignal(event), have, init);
|
|
2058
2072
|
return serverComponentResponse(result, {
|
|
2059
2073
|
frame: {
|
|
2060
2074
|
id: invocation && invocation.id || ""
|
|
@@ -2066,6 +2080,269 @@ function frameTransformResult(event, result, context) {
|
|
|
2066
2080
|
}
|
|
2067
2081
|
}, init);
|
|
2068
2082
|
}
|
|
2083
|
+
const HOLE_SOURCE = Symbol("solid.frames.holeSource");
|
|
2084
|
+
const BROADCASTS = new Map();
|
|
2085
|
+
function broadcastResponse(key, component, options, signal, have, init) {
|
|
2086
|
+
let shared = BROADCASTS.get(key);
|
|
2087
|
+
if (!shared || shared.ended) shared = startBroadcast(key, component, options);
|
|
2088
|
+
return tapResponse(shared, signal, have, init);
|
|
2089
|
+
}
|
|
2090
|
+
function startBroadcast(key, component, options) {
|
|
2091
|
+
const shared = {
|
|
2092
|
+
key,
|
|
2093
|
+
id: options.frame.id,
|
|
2094
|
+
start: null,
|
|
2095
|
+
taps: new Set(),
|
|
2096
|
+
records: new Map(),
|
|
2097
|
+
data: [],
|
|
2098
|
+
kept: 0,
|
|
2099
|
+
attrs: new Map(),
|
|
2100
|
+
tiers: new Set(["wire"]),
|
|
2101
|
+
failed: false,
|
|
2102
|
+
ended: false,
|
|
2103
|
+
teardown: new AbortController()
|
|
2104
|
+
};
|
|
2105
|
+
BROADCASTS.set(key, shared);
|
|
2106
|
+
const stream = renderServerComponent(component, {
|
|
2107
|
+
...options,
|
|
2108
|
+
broadcast: (key, text) => shared.attrs.set(key, text),
|
|
2109
|
+
signal: shared.teardown.signal
|
|
2110
|
+
});
|
|
2111
|
+
const run = () => stream.pipe({
|
|
2112
|
+
write(message) {
|
|
2113
|
+
const bytes = createEventChunk(JSON.stringify(message));
|
|
2114
|
+
if (message.type === "start") return void (shared.start = bytes);
|
|
2115
|
+
retain(shared, message);
|
|
2116
|
+
for (const tap of shared.taps) tap.write(bytes);
|
|
2117
|
+
},
|
|
2118
|
+
end() {
|
|
2119
|
+
shared.ended = true;
|
|
2120
|
+
if (BROADCASTS.get(key) === shared) BROADCASTS.delete(key);
|
|
2121
|
+
for (const tap of [...shared.taps]) tap.end();
|
|
2122
|
+
},
|
|
2123
|
+
[ANNOUNCE](tiers) {
|
|
2124
|
+
for (const tier of tiers) shared.tiers.add(tier);
|
|
2125
|
+
}
|
|
2126
|
+
});
|
|
2127
|
+
const store = globalThis[RequestContext];
|
|
2128
|
+
store ? store.run(broadcastEvent(), run) : run();
|
|
2129
|
+
return shared;
|
|
2130
|
+
}
|
|
2131
|
+
function broadcastEvent() {
|
|
2132
|
+
const event = {
|
|
2133
|
+
broadcast: true
|
|
2134
|
+
};
|
|
2135
|
+
for (const name of ["request", "locals", "clientAddress", "nativeEvent"]) Object.defineProperty(event, name, {
|
|
2136
|
+
get() {
|
|
2137
|
+
return undefined;
|
|
2138
|
+
}
|
|
2139
|
+
});
|
|
2140
|
+
return event;
|
|
2141
|
+
}
|
|
2142
|
+
function retain(shared, message) {
|
|
2143
|
+
if (message.tiers) for (const tier of message.tiers) shared.tiers.add(tier);
|
|
2144
|
+
if (!message.r) {
|
|
2145
|
+
shared.data.push(message);
|
|
2146
|
+
if (shared.data.length > 64 && shared.data.length > 2 * shared.kept) shared.kept = (shared.data = referencedData(shared)).length;
|
|
2147
|
+
return;
|
|
2148
|
+
}
|
|
2149
|
+
const {
|
|
2150
|
+
id,
|
|
2151
|
+
version
|
|
2152
|
+
} = message;
|
|
2153
|
+
for (const k in message.r) {
|
|
2154
|
+
let record = message.r[k];
|
|
2155
|
+
if (k === ":error") shared.failed = true;
|
|
2156
|
+
if (k === "") for (const [rk, e] of shared.records) if (e.id === id) shared.records.delete(rk);
|
|
2157
|
+
if (record && record[HOLE_SOURCE]) record = record[HOLE_SOURCE];
|
|
2158
|
+
const rk = id + "\0" + k;
|
|
2159
|
+
const prev = shared.records.get(rk);
|
|
2160
|
+
if (prev && record && record.kind === "attrs" && prev.record.removed) {
|
|
2161
|
+
const removed = new Set(prev.record.removed);
|
|
2162
|
+
if (record.removed) for (const name of record.removed) removed.add(name);
|
|
2163
|
+
record = {
|
|
2164
|
+
...record,
|
|
2165
|
+
removed: [...removed]
|
|
2166
|
+
};
|
|
2167
|
+
}
|
|
2168
|
+
shared.records.delete(rk);
|
|
2169
|
+
shared.records.set(rk, {
|
|
2170
|
+
id,
|
|
2171
|
+
version,
|
|
2172
|
+
k,
|
|
2173
|
+
record
|
|
2174
|
+
});
|
|
2175
|
+
}
|
|
2176
|
+
}
|
|
2177
|
+
function referencedData(shared) {
|
|
2178
|
+
const refs = new Set();
|
|
2179
|
+
for (const {
|
|
2180
|
+
record
|
|
2181
|
+
} 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]}"`));
|
|
2182
|
+
return shared.data.filter(m => typeof m.key !== "string" || refs.has(m.key));
|
|
2183
|
+
}
|
|
2184
|
+
function snapshot(shared, have) {
|
|
2185
|
+
const out = referencedData(shared);
|
|
2186
|
+
const root = shared.records.get(shared.id + "\0");
|
|
2187
|
+
const conditional = !!(have && root && root.record && have[""] === root.record.digest);
|
|
2188
|
+
let open = null;
|
|
2189
|
+
const put = (id, version, k, record) => {
|
|
2190
|
+
if (!open || open.id !== id) out.push(open = {
|
|
2191
|
+
id,
|
|
2192
|
+
version,
|
|
2193
|
+
r: {}
|
|
2194
|
+
});
|
|
2195
|
+
open.r[k] = record;
|
|
2196
|
+
};
|
|
2197
|
+
if (!conditional) {
|
|
2198
|
+
for (const {
|
|
2199
|
+
id,
|
|
2200
|
+
version,
|
|
2201
|
+
k,
|
|
2202
|
+
record
|
|
2203
|
+
} of shared.records.values()) put(id, version, k, record);
|
|
2204
|
+
return out;
|
|
2205
|
+
}
|
|
2206
|
+
const containers = [];
|
|
2207
|
+
for (const e of shared.records.values()) if (e.id === shared.id && (e.k === "" || /^seg:[^:]+$/.test(e.k)) && e.record) containers.push({
|
|
2208
|
+
e,
|
|
2209
|
+
value: e.record.value
|
|
2210
|
+
});
|
|
2211
|
+
for (const {
|
|
2212
|
+
k,
|
|
2213
|
+
record
|
|
2214
|
+
} of shared.records.values()) {
|
|
2215
|
+
if (!k.startsWith("hole:lh:") || k.endsWith(":error") || !record || record.value == null) continue;
|
|
2216
|
+
const n = k.slice(8);
|
|
2217
|
+
const startMark = `<!--lh:${n}-->`;
|
|
2218
|
+
const endMark = `<!--lh:/${n}-->`;
|
|
2219
|
+
for (const c of containers) {
|
|
2220
|
+
const start = c.value.indexOf(startMark);
|
|
2221
|
+
if (start < 0) continue;
|
|
2222
|
+
const end = c.value.indexOf(endMark, start);
|
|
2223
|
+
if (end < 0) continue;
|
|
2224
|
+
c.value = c.value.slice(0, start + startMark.length) + record.value + c.value.slice(end);
|
|
2225
|
+
break;
|
|
2226
|
+
}
|
|
2227
|
+
}
|
|
2228
|
+
for (const e of shared.records.values()) {
|
|
2229
|
+
const {
|
|
2230
|
+
id,
|
|
2231
|
+
version,
|
|
2232
|
+
k,
|
|
2233
|
+
record
|
|
2234
|
+
} = e;
|
|
2235
|
+
if (id !== shared.id) {
|
|
2236
|
+
put(id, version, k, record);
|
|
2237
|
+
continue;
|
|
2238
|
+
}
|
|
2239
|
+
if (k === "" || k === "seg::assets" || k.startsWith("hole:lh:") && !k.endsWith(":error")) continue;
|
|
2240
|
+
const seg = /^seg:([^:]+)(?::(.*))?$/.exec(k);
|
|
2241
|
+
if (seg && have[seg[1]] !== undefined && seg[2] !== "error") continue;
|
|
2242
|
+
if (seg && seg[2] === undefined) {
|
|
2243
|
+
const c = containers.find(c => c.e === e);
|
|
2244
|
+
if (c && c.value !== record.value) {
|
|
2245
|
+
put(id, version, k, withHoles({
|
|
2246
|
+
...record,
|
|
2247
|
+
value: c.value,
|
|
2248
|
+
digest: textDigest(c.value)
|
|
2249
|
+
}, holeDigests(c.value, null)));
|
|
2250
|
+
continue;
|
|
2251
|
+
}
|
|
2252
|
+
}
|
|
2253
|
+
if (k.startsWith("attr:")) continue;
|
|
2254
|
+
put(id, version, k, record);
|
|
2255
|
+
}
|
|
2256
|
+
for (const c of containers) {
|
|
2257
|
+
const seg = c.e.k && /^seg:([^:]+)$/.exec(c.e.k);
|
|
2258
|
+
if (seg && have[seg[1]] === undefined) continue;
|
|
2259
|
+
for (const m of c.value.matchAll(HOLE_RANGE)) {
|
|
2260
|
+
const key = "lh:" + m[1];
|
|
2261
|
+
const digest = textDigest(stripHoleMarkers(m[2]));
|
|
2262
|
+
if (have[key] === digest) continue;
|
|
2263
|
+
put(shared.id, c.e.version, "hole:" + key, withHoles({
|
|
2264
|
+
kind: "html",
|
|
2265
|
+
value: m[2],
|
|
2266
|
+
digest
|
|
2267
|
+
}, holeDigests(m[2], null)));
|
|
2268
|
+
}
|
|
2269
|
+
for (const m of c.value.matchAll(ATTR_ADDRESS)) {
|
|
2270
|
+
const latest = shared.records.get(shared.id + "\0attr:" + m[1]);
|
|
2271
|
+
const text = latest ? latest.record.value : shared.attrs.get("lha:" + m[1]);
|
|
2272
|
+
if (text === undefined) continue;
|
|
2273
|
+
const digest = latest ? latest.record.digest : textDigest(text);
|
|
2274
|
+
if (have["lha:" + m[1]] === digest) continue;
|
|
2275
|
+
put(shared.id, c.e.version, "attr:" + m[1], latest ? latest.record : {
|
|
2276
|
+
kind: "attrs",
|
|
2277
|
+
value: text,
|
|
2278
|
+
digest
|
|
2279
|
+
});
|
|
2280
|
+
}
|
|
2281
|
+
}
|
|
2282
|
+
return out;
|
|
2283
|
+
}
|
|
2284
|
+
function tapResponse(shared, signal, have, init = {}) {
|
|
2285
|
+
const headers = copyInitHeaders(init.headers);
|
|
2286
|
+
headers.set(FRAME_STREAM_HEADER, shared.id);
|
|
2287
|
+
headers.set("X-Content-Raw", "1");
|
|
2288
|
+
headers.set("Content-Type", "text/event-stream");
|
|
2289
|
+
headers.set("Cache-Control", "no-store");
|
|
2290
|
+
headers.set("X-Accel-Buffering", "no");
|
|
2291
|
+
headers.set(FRAME_TIERS_HEADER, [...shared.tiers].join(","));
|
|
2292
|
+
let closed = false;
|
|
2293
|
+
let stopLive = null;
|
|
2294
|
+
let tap = null;
|
|
2295
|
+
const leave = () => {
|
|
2296
|
+
if (closed) return;
|
|
2297
|
+
closed = true;
|
|
2298
|
+
if (stopLive) stopLive();
|
|
2299
|
+
if (signal) signal.removeEventListener("abort", leave);
|
|
2300
|
+
shared.taps.delete(tap);
|
|
2301
|
+
if (!shared.taps.size && !shared.ended) {
|
|
2302
|
+
shared.ended = true;
|
|
2303
|
+
if (BROADCASTS.get(shared.key) === shared) BROADCASTS.delete(shared.key);
|
|
2304
|
+
shared.teardown.abort({
|
|
2305
|
+
[DISCONNECTED]: true
|
|
2306
|
+
});
|
|
2307
|
+
}
|
|
2308
|
+
};
|
|
2309
|
+
const body = new ReadableStream({
|
|
2310
|
+
start(controller) {
|
|
2311
|
+
tap = {
|
|
2312
|
+
write(bytes) {
|
|
2313
|
+
if (closed) return;
|
|
2314
|
+
try {
|
|
2315
|
+
controller.enqueue(bytes);
|
|
2316
|
+
} catch (_) {
|
|
2317
|
+
leave();
|
|
2318
|
+
}
|
|
2319
|
+
},
|
|
2320
|
+
end() {
|
|
2321
|
+
leave();
|
|
2322
|
+
try {
|
|
2323
|
+
controller.close();
|
|
2324
|
+
} catch (_) {}
|
|
2325
|
+
}
|
|
2326
|
+
};
|
|
2327
|
+
if (shared.start) controller.enqueue(shared.start);
|
|
2328
|
+
for (const message of snapshot(shared, have)) controller.enqueue(createEventChunk(JSON.stringify(message)));
|
|
2329
|
+
if (shared.ended || signal && signal.aborted) return tap.end();
|
|
2330
|
+
shared.taps.add(tap);
|
|
2331
|
+
stopLive = armLiveBody(controller, leave);
|
|
2332
|
+
if (signal) signal.addEventListener("abort", leave, {
|
|
2333
|
+
once: true
|
|
2334
|
+
});
|
|
2335
|
+
},
|
|
2336
|
+
cancel() {
|
|
2337
|
+
leave();
|
|
2338
|
+
}
|
|
2339
|
+
});
|
|
2340
|
+
if (shared.failed) headers.set("Cache-Control", "no-store");
|
|
2341
|
+
return new Response(body, {
|
|
2342
|
+
status: init.status || 200,
|
|
2343
|
+
headers
|
|
2344
|
+
});
|
|
2345
|
+
}
|
|
2069
2346
|
function requestSignal(event) {
|
|
2070
2347
|
const request = event && event.request;
|
|
2071
2348
|
return request && request.signal instanceof AbortSignal ? request.signal : undefined;
|