@solidjs/web 2.0.0-rc.16 → 2.0.0-rc.18
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 +195 -35
- package/dist/server.js +190 -35
- package/dist/server.observe.js +190 -35
- 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 +356 -43
- package/frames/dist/server.js +355 -43
- package/frames/dist/server.observe.js +355 -43
- package/frames/dist/wire.js +110 -14
- package/package.json +4 -4
- package/serialization/dist/decode.js +10 -5
- package/serialization/dist/serialization.js +121 -61
- package/serialization/types/index.d.ts +12 -4
- package/serialization/types/serializer.d.ts +12 -4
- 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 +313 -11
- package/server-functions/dist/server.js +313 -11
- package/server-functions/dist/server.observe.js +313 -11
- package/types/client.d.ts +12 -0
- package/types/diagnostics.d.ts +16 -0
- package/types/frames/frame-morph.d.ts +1 -0
- package/types/frames/serializer.d.ts +12 -4
- package/types/serializer.d.ts +12 -4
- 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 +33 -0
- package/types/server-functions/shared.d.ts +9 -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';
|
|
@@ -224,26 +224,12 @@ function resolveCodecOptions(options = {}) {
|
|
|
224
224
|
}
|
|
225
225
|
|
|
226
226
|
const serializeOnlyDisabledFeatures = serializeErrorStacks => (serializeErrorStacks === undefined ? process.env.NODE_ENV === "development" : serializeErrorStacks) ? 0 : Feature.ErrorPrototypeStack;
|
|
227
|
-
function
|
|
228
|
-
onData,
|
|
229
|
-
onDone,
|
|
230
|
-
onError,
|
|
231
|
-
plugins,
|
|
232
|
-
disabledFeatures,
|
|
233
|
-
depthLimit,
|
|
234
|
-
serializeErrorStacks
|
|
235
|
-
}) {
|
|
236
|
-
const resolved = resolveCodecOptions({
|
|
237
|
-
plugins,
|
|
238
|
-
disabledFeatures,
|
|
239
|
-
depthLimit,
|
|
240
|
-
serializeErrorStacks
|
|
241
|
-
});
|
|
242
|
-
const refs = new Map();
|
|
227
|
+
function createKeyedSerializer(serialize, onError, onDone) {
|
|
243
228
|
const cancels = new Set();
|
|
244
229
|
let pendingWrites = 0;
|
|
245
230
|
let flushed = false;
|
|
246
231
|
let done = false;
|
|
232
|
+
let closed = false;
|
|
247
233
|
const maybeDone = () => {
|
|
248
234
|
if (flushed && pendingWrites === 0 && !done) {
|
|
249
235
|
done = true;
|
|
@@ -255,42 +241,90 @@ function createJSONSerializer({
|
|
|
255
241
|
if (flushed) return;
|
|
256
242
|
pendingWrites++;
|
|
257
243
|
let settled = false;
|
|
244
|
+
let failed = false;
|
|
245
|
+
let started = false;
|
|
258
246
|
let cancel = null;
|
|
259
|
-
const
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
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;
|
|
281
273
|
}
|
|
274
|
+
if (settled) return;
|
|
275
|
+
if (closed || failed) {
|
|
276
|
+
stream();
|
|
277
|
+
settle();
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
cancel = stream;
|
|
281
|
+
cancels.add(cancel);
|
|
282
282
|
},
|
|
283
283
|
flush() {
|
|
284
284
|
flushed = true;
|
|
285
285
|
maybeDone();
|
|
286
286
|
},
|
|
287
287
|
close() {
|
|
288
|
-
flushed = true;
|
|
288
|
+
closed = flushed = true;
|
|
289
289
|
for (const cancel of cancels) cancel();
|
|
290
290
|
cancels.clear();
|
|
291
|
+
if (!done) {
|
|
292
|
+
done = true;
|
|
293
|
+
onDone && onDone();
|
|
294
|
+
}
|
|
291
295
|
}
|
|
292
296
|
};
|
|
293
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
|
+
}
|
|
294
328
|
|
|
295
329
|
const RECORDS = Symbol.for("@solidjs/signals/observe/records");
|
|
296
330
|
function records() {
|
|
@@ -467,6 +501,7 @@ const stripHoleMarkers = html => html.replace(/<!--lh:\/?\d+-->/g, "");
|
|
|
467
501
|
function frameSkeleton(html) {
|
|
468
502
|
return html.replace(HOLE_RANGE, "<!--lh:$1--><!--lh:/$1-->").replace(SLOT_RANGE, "<!--slot:$1:start--><!--slot:$1:end-->");
|
|
469
503
|
}
|
|
504
|
+
const ROW_HTML = Symbol.for("solid.rowHtml");
|
|
470
505
|
function holeDigests(html, attrText, into = {}) {
|
|
471
506
|
for (const m of html.matchAll(HOLE_RANGE)) {
|
|
472
507
|
into["lh:" + m[1]] = textDigest(stripHoleMarkers(m[2]));
|
|
@@ -772,12 +807,13 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
772
807
|
},
|
|
773
808
|
flush,
|
|
774
809
|
slot(key, args) {
|
|
775
|
-
|
|
810
|
+
const r = {
|
|
776
811
|
[`slot:${key}`]: {
|
|
777
812
|
kind: "slot",
|
|
778
813
|
args
|
|
779
814
|
}
|
|
780
|
-
}
|
|
815
|
+
};
|
|
816
|
+
swept ? Object.assign(swept.r, r) : put(id, r);
|
|
781
817
|
},
|
|
782
818
|
region(childId, value) {
|
|
783
819
|
needs("regions");
|
|
@@ -798,7 +834,12 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
798
834
|
record.rows = rows;
|
|
799
835
|
record.base = base;
|
|
800
836
|
} else record.value = source;
|
|
801
|
-
withHoles(record, holeDigests(record.rows ? rows.r.map(r => r[1]).join("") : source, null));
|
|
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));
|
|
802
843
|
const r = {
|
|
803
844
|
["hole:" + key]: record
|
|
804
845
|
};
|
|
@@ -819,6 +860,7 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
819
860
|
},
|
|
820
861
|
attrBaseline(key, text) {
|
|
821
862
|
attrText.set(key, text);
|
|
863
|
+
if (hooks && hooks.retain) hooks.retain(key, text);
|
|
822
864
|
},
|
|
823
865
|
openBinding(key, b) {
|
|
824
866
|
if (/^lha?:/.test(key)) needs("wire");
|
|
@@ -920,6 +962,7 @@ function frameStream(makeCode, options) {
|
|
|
920
962
|
};
|
|
921
963
|
const sink = createFrameSink(emit, frame, options.resume && options.resume.have, {
|
|
922
964
|
live: options.live,
|
|
965
|
+
retain: options.broadcast,
|
|
923
966
|
onYield: bounded ? () => {
|
|
924
967
|
if (flushed && maxYields > 0 && ++yields >= maxYields) cut("yields");
|
|
925
968
|
} : undefined
|
|
@@ -2056,6 +2099,12 @@ function frameTransformResult(event, result, context) {
|
|
|
2056
2099
|
const invocation = getEventServerFunctionInvocation(event);
|
|
2057
2100
|
const live = !!(invocation && invocation.live);
|
|
2058
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);
|
|
2059
2108
|
return serverComponentResponse(result, {
|
|
2060
2109
|
frame: {
|
|
2061
2110
|
id: invocation && invocation.id || ""
|
|
@@ -2067,6 +2116,269 @@ function frameTransformResult(event, result, context) {
|
|
|
2067
2116
|
}
|
|
2068
2117
|
}, init);
|
|
2069
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
|
+
}
|
|
2070
2382
|
function requestSignal(event) {
|
|
2071
2383
|
const request = event && event.request;
|
|
2072
2384
|
return request && request.signal instanceof AbortSignal ? request.signal : undefined;
|
package/frames/dist/wire.js
CHANGED
|
@@ -391,7 +391,7 @@ function connect(response, wire, address, binding, host, bump, begin) {
|
|
|
391
391
|
});
|
|
392
392
|
return binding;
|
|
393
393
|
}
|
|
394
|
-
function rows(open, close, ops, parse, morph) {
|
|
394
|
+
function rows(open, close, ops, parse, morph, claim) {
|
|
395
395
|
const isRow = n => n.nodeType === 8 && n.data === "lr";
|
|
396
396
|
const starts = [];
|
|
397
397
|
for (let n = open.nextSibling; n && n !== close; n = n.nextSibling) {
|
|
@@ -405,29 +405,125 @@ function rows(open, close, ops, parse, morph) {
|
|
|
405
405
|
let appended = 0;
|
|
406
406
|
for (const [i] of ops.r) if (i >= had) appended++;
|
|
407
407
|
if (!had || appended !== Math.max(0, n - had)) return false;
|
|
408
|
-
const
|
|
408
|
+
const rowEnd = i => i + 1 < Math.min(n, had) ? starts[i + 1] : close;
|
|
409
|
+
const patched = [];
|
|
410
|
+
let html = "";
|
|
411
|
+
let whole = 0;
|
|
412
|
+
for (const op of ops.r) {
|
|
413
|
+
if (typeof op[1] === "string") {
|
|
414
|
+
html += "<!--lr-->" + op[1];
|
|
415
|
+
whole++;
|
|
416
|
+
patched.push(null);
|
|
417
|
+
continue;
|
|
418
|
+
}
|
|
419
|
+
if (op[0] >= had) return false;
|
|
420
|
+
const els = rowElements(starts[op[0]], rowEnd(op[0]), op[2]);
|
|
421
|
+
if (!els) return false;
|
|
422
|
+
for (const edit of op[1]) if (edit[0] >= els.length) return false;
|
|
423
|
+
patched.push(els);
|
|
424
|
+
}
|
|
409
425
|
const parsed = [];
|
|
410
|
-
|
|
411
|
-
const
|
|
412
|
-
|
|
413
|
-
|
|
426
|
+
if (whole) {
|
|
427
|
+
const fragment = parse(html);
|
|
428
|
+
for (let c = fragment.firstChild; c;) {
|
|
429
|
+
const next = c.nextSibling;
|
|
430
|
+
if (isRow(c)) parsed.push(document.createDocumentFragment());else parsed[parsed.length - 1].appendChild(c);
|
|
431
|
+
c = next;
|
|
432
|
+
}
|
|
433
|
+
if (parsed.length !== whole) return false;
|
|
414
434
|
}
|
|
415
|
-
if (parsed.length !== ops.r.length) return false;
|
|
416
435
|
const parent = open.parentNode;
|
|
417
436
|
if (n < had) while (starts[n].nextSibling !== close) parent.removeChild(close.previousSibling);
|
|
418
437
|
if (n < had) parent.removeChild(starts[n]);
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
438
|
+
let k = 0;
|
|
439
|
+
ops.r.forEach((op, j) => {
|
|
440
|
+
const i = op[0];
|
|
441
|
+
const els = patched[j];
|
|
442
|
+
if (els) return patchRow(starts[i], rowEnd(i), els, op[1], claim);
|
|
443
|
+
const fragment = parsed[k++];
|
|
444
|
+
if (i < had) morph(starts[i], rowEnd(i), fragment);else {
|
|
424
445
|
const marker = document.createComment("lr");
|
|
425
446
|
parent.insertBefore(marker, close);
|
|
426
|
-
parent.insertBefore(
|
|
447
|
+
parent.insertBefore(fragment, close);
|
|
427
448
|
}
|
|
428
449
|
});
|
|
429
450
|
return true;
|
|
430
451
|
}
|
|
452
|
+
function rowElements(start, end, shape) {
|
|
453
|
+
const els = [];
|
|
454
|
+
let h = 0x811c9dc5;
|
|
455
|
+
const walk = (n, stop, parent) => {
|
|
456
|
+
for (; n && n !== stop; n = n.nextSibling) {
|
|
457
|
+
if (n.nodeType === 8 && /^lh:/.test(n.data)) return false;
|
|
458
|
+
if (n.nodeType !== 1) continue;
|
|
459
|
+
const el = els.length;
|
|
460
|
+
if (shape !== undefined) {
|
|
461
|
+
const tag = n.localName;
|
|
462
|
+
for (let i = 0; i < tag.length; i++) h = Math.imul(h ^ (tag.charCodeAt(i) | 32), 16777619);
|
|
463
|
+
h = Math.imul(h ^ parent + 2, 16777619);
|
|
464
|
+
}
|
|
465
|
+
els.push(n);
|
|
466
|
+
if (!walk(n.firstChild, null, el)) return false;
|
|
467
|
+
}
|
|
468
|
+
return true;
|
|
469
|
+
};
|
|
470
|
+
if (!walk(start.nextSibling, end, -1)) return null;
|
|
471
|
+
if (shape !== undefined && h >>> 0 !== shape) {
|
|
472
|
+
console.error("A live row's markup doesn't parse to the elements the server rendered (invalid HTML nesting?); the row was re-sent whole.", start.nextSibling);
|
|
473
|
+
return null;
|
|
474
|
+
}
|
|
475
|
+
return els;
|
|
476
|
+
}
|
|
477
|
+
const ATTR = /\s([^\s=/>"']+)(?:="([^"]*)")?/g;
|
|
478
|
+
const ATTR_ENTITY = /&(?:amp|lt|gt|quot|#39);/g;
|
|
479
|
+
const ATTR_ENTITIES = {
|
|
480
|
+
"&": "&",
|
|
481
|
+
"<": "<",
|
|
482
|
+
">": ">",
|
|
483
|
+
""": '"',
|
|
484
|
+
"'": "'"
|
|
485
|
+
};
|
|
486
|
+
function attrArea(text) {
|
|
487
|
+
if (/=[^"]/.test(text) || text.replace(ATTR_ENTITY, "").includes("&")) return parseFragment(`<i${text}></i>`).firstChild;
|
|
488
|
+
const attributes = [];
|
|
489
|
+
const names = new Set();
|
|
490
|
+
for (const m of text.matchAll(ATTR)) {
|
|
491
|
+
const value = m[2] === undefined ? "" : m[2].replace(ATTR_ENTITY, e => ATTR_ENTITIES[e]);
|
|
492
|
+
const name = m[1].toLowerCase();
|
|
493
|
+
attributes.push({
|
|
494
|
+
name,
|
|
495
|
+
value
|
|
496
|
+
});
|
|
497
|
+
names.add(name);
|
|
498
|
+
}
|
|
499
|
+
return {
|
|
500
|
+
attributes,
|
|
501
|
+
hasAttribute: name => names.has(name)
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
function patchRow(start, end, els, patch, claim) {
|
|
505
|
+
for (const op of patch) {
|
|
506
|
+
const el = op[0] < 0 ? null : els[op[0]];
|
|
507
|
+
if (el && el.closest("[data-preserve]")) continue;
|
|
508
|
+
if (op.length === 2) {
|
|
509
|
+
morphAttributes(el, attrArea(op[1]), claim);
|
|
510
|
+
continue;
|
|
511
|
+
}
|
|
512
|
+
let seen = 0;
|
|
513
|
+
let at = el ? el.firstChild : start.nextSibling;
|
|
514
|
+
const stop = el ? null : end;
|
|
515
|
+
let text = null;
|
|
516
|
+
for (; at && at !== stop; at = at.nextSibling) {
|
|
517
|
+
if (at.nodeType === 3) {
|
|
518
|
+
if (seen === op[1]) {
|
|
519
|
+
text = at;
|
|
520
|
+
break;
|
|
521
|
+
}
|
|
522
|
+
} else if (seen++ === op[1]) break;
|
|
523
|
+
}
|
|
524
|
+
if (text) text.data = op[2];else if (op[2]) (el || start.parentNode).insertBefore(document.createTextNode(op[2]), at);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
431
527
|
function hole(f, marker, record, index) {
|
|
432
528
|
const open = target(f, "hole:" + marker, n => n.nodeType === 8 && n.data === marker);
|
|
433
529
|
if (!open) return false;
|
|
@@ -437,7 +533,7 @@ function hole(f, marker, record, index) {
|
|
|
437
533
|
return false;
|
|
438
534
|
}
|
|
439
535
|
if (record.rows) {
|
|
440
|
-
if (f.s()[marker] !== record.base || !rows(open, close, record.rows, parseFragment, (start, end, fragment) => reconcileChildren(start.parentNode, fragment, start, end, f.c))) {
|
|
536
|
+
if (f.s()[marker] !== record.base || !rows(open, close, record.rows, parseFragment, (start, end, fragment) => reconcileChildren(start.parentNode, fragment, start, end, f.c), f.c)) {
|
|
441
537
|
f.x("hole:" + marker, record);
|
|
442
538
|
return false;
|
|
443
539
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solidjs/web",
|
|
3
3
|
"description": "Solid's web runtime: client rendering, hydration, SSR, and DOM-specific control flow (Portal, Dynamic).",
|
|
4
|
-
"version": "2.0.0-rc.
|
|
4
|
+
"version": "2.0.0-rc.18",
|
|
5
5
|
"author": "Ryan Carniato",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://solidjs.com",
|
|
@@ -373,11 +373,11 @@
|
|
|
373
373
|
"test-types": "tsc --project tsconfig.test.json && tsc --project tsconfig.test.augment.json"
|
|
374
374
|
},
|
|
375
375
|
"dependencies": {
|
|
376
|
-
"seroval": "1.
|
|
377
|
-
"seroval-plugins": "1.
|
|
376
|
+
"seroval": "1.7.0",
|
|
377
|
+
"seroval-plugins": "1.7.0"
|
|
378
378
|
},
|
|
379
379
|
"peerDependencies": {
|
|
380
|
-
"solid-js": "^2.0.0-rc.
|
|
380
|
+
"solid-js": "^2.0.0-rc.18"
|
|
381
381
|
},
|
|
382
382
|
"devDependencies": {
|
|
383
383
|
"@codspeed/vitest-plugin": "^5.4.0",
|
|
@@ -132,11 +132,16 @@ function createJSONDeserializer(options) {
|
|
|
132
132
|
const close = () => {
|
|
133
133
|
alive = false;
|
|
134
134
|
};
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
135
|
+
let off;
|
|
136
|
+
try {
|
|
137
|
+
off = stream.on({
|
|
138
|
+
next() {},
|
|
139
|
+
throw: close,
|
|
140
|
+
return: close
|
|
141
|
+
});
|
|
142
|
+
} catch {
|
|
143
|
+
return stream.alive !== false;
|
|
144
|
+
}
|
|
140
145
|
if (typeof off === "function") off();
|
|
141
146
|
return alive;
|
|
142
147
|
}
|