@solidjs/web 2.0.0-rc.15 → 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/README.md +1 -1
- package/dist/server.dev.js +361 -483
- package/dist/server.js +346 -391
- package/dist/server.observe.js +346 -391
- package/dist/web.dev.js +110 -55
- package/dist/web.js +51 -50
- package/dist/web.observe.js +61 -55
- package/frames/dist/client.dev.js +610 -621
- package/frames/dist/client.js +540 -566
- package/frames/dist/client.observe.js +571 -573
- package/frames/dist/regions.js +43 -2
- package/frames/dist/server.dev.js +793 -424
- package/frames/dist/server.js +792 -371
- package/frames/dist/server.observe.js +792 -371
- package/frames/dist/wire.js +371 -6
- package/package.json +11 -11
- package/serialization/dist/decode.js +9 -7
- package/serialization/dist/serialization.js +9 -7
- package/serialization/types/serializer-decode.d.ts +2 -2
- package/server-functions/dist/client.dev.js +13 -22
- package/server-functions/dist/client.js +11 -22
- package/server-functions/dist/client.observe.js +13 -22
- package/server-functions/dist/rich-args.js +84 -1
- package/server-functions/dist/server.dev.js +194 -20
- package/server-functions/dist/server.js +194 -20
- package/server-functions/dist/server.observe.js +194 -20
- package/skills/server-components/SKILL.md +74 -185
- package/types/client.d.ts +27 -5
- package/types/diagnostics.d.ts +16 -0
- package/types/frames/assets-tier.d.ts +2 -2
- package/types/frames/client.d.ts +8 -3
- package/types/frames/frame-client.d.ts +121 -157
- package/types/frames/frame-morph.d.ts +28 -0
- package/types/frames/frame-sink.d.ts +13 -9
- package/types/frames/frame-transport.d.ts +30 -1
- package/types/frames/regions-tier.d.ts +15 -0
- package/types/frames/serializer-decode.d.ts +2 -2
- package/types/frames/server.d.ts +0 -52
- package/types/frames/wire-tier.d.ts +54 -1
- package/types/index.d.ts +2 -2
- package/types/jsx.d.ts +11 -5
- package/types/observe.d.ts +14 -7
- package/types/render.d.ts +3 -1
- package/types/response.d.ts +5 -4
- package/types/serializer-decode.d.ts +2 -2
- package/types/server-functions/argument-codec.d.ts +30 -0
- package/types/server-functions/client.d.ts +27 -9
- package/types/server-functions/server.d.ts +23 -2
- package/types/server-functions/shared.d.ts +19 -0
- package/types/server-functions/uploads.d.ts +50 -0
- package/types/server-observe.d.ts +3 -2
- package/types/server.d.ts +58 -77
- package/frames/dist/bind.dev.js +0 -326
- package/frames/dist/bind.js +0 -295
- package/types/frames/bind-tier.d.ts +0 -60
package/frames/dist/server.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { sharedConfig, ssrSanitizeError, creationStamp, ssrHandleError, runInServerComponentScope, shareAsyncIterable, getProjectionTrace } from 'solid-js/internal';
|
|
2
|
-
import { getOwner, NoHydration, runWithOwner, createMemo,
|
|
3
|
-
import { isResponseEnvelope, renderToStream, createLiveHoles
|
|
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
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';
|
|
@@ -207,14 +207,16 @@ function resolveSerializerPlugins(customPlugins) {
|
|
|
207
207
|
}
|
|
208
208
|
const jsonCodecDisabledFeatures = () => Feature.RegExp;
|
|
209
209
|
const JSON_CODEC_DEPTH_LIMIT = 64;
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
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;
|
|
216
218
|
return {
|
|
217
|
-
plugins: resolveSerializerPlugins(plugins),
|
|
219
|
+
plugins: options[RESOLVED_PLUGINS] || resolveSerializerPlugins(plugins),
|
|
218
220
|
disabledFeatures: disabledFeatures === undefined ? jsonCodecDisabledFeatures() : disabledFeatures,
|
|
219
221
|
depthLimit: depthLimit === undefined ? JSON_CODEC_DEPTH_LIMIT : depthLimit,
|
|
220
222
|
serializeErrorStacks
|
|
@@ -293,8 +295,17 @@ function createJSONSerializer({
|
|
|
293
295
|
function records() {
|
|
294
296
|
return undefined;
|
|
295
297
|
}
|
|
296
|
-
function
|
|
297
|
-
|
|
298
|
+
function frameRecordCensus(event, message, own) {
|
|
299
|
+
const r = message.r;
|
|
300
|
+
let counted = !r;
|
|
301
|
+
for (const key in r) {
|
|
302
|
+
if (key === ":complete" || key === ":bound") continue;
|
|
303
|
+
counted = true;
|
|
304
|
+
countEvent(event, key === "" ? "html" : key.endsWith(":error") ? "error" : key.startsWith("slot:") ? "slot" : key.startsWith("seg:") && r[key] && r[key].kind === "html" ? "fragment" : key, own);
|
|
305
|
+
}
|
|
306
|
+
if (counted) event.chunks++;
|
|
307
|
+
}
|
|
308
|
+
function countEvent(event, type, own) {
|
|
298
309
|
switch (type) {
|
|
299
310
|
case "html":
|
|
300
311
|
if (!own) event.regions++;else if (event.shellMs === undefined) event.shellMs = performance.now() - event.at;
|
|
@@ -329,9 +340,8 @@ function observeFrame(frame) {
|
|
|
329
340
|
};
|
|
330
341
|
let settled = false;
|
|
331
342
|
return {
|
|
332
|
-
chunk(
|
|
333
|
-
|
|
334
|
-
frameCensus(event, chunk.type, chunk.id === frame.id);
|
|
343
|
+
chunk(message) {
|
|
344
|
+
frameRecordCensus(event, message, message.id === frame.id);
|
|
335
345
|
},
|
|
336
346
|
settle(outcome, error) {
|
|
337
347
|
if (settled) return;
|
|
@@ -484,14 +494,41 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
484
494
|
} = frame;
|
|
485
495
|
const tiers = new Set();
|
|
486
496
|
let staged = [];
|
|
487
|
-
const
|
|
488
|
-
if (swept) swept.emitted = true;
|
|
497
|
+
const send = message => {
|
|
489
498
|
if (staged.length) {
|
|
490
|
-
|
|
499
|
+
message.tiers = staged;
|
|
491
500
|
staged = [];
|
|
492
501
|
}
|
|
493
|
-
write(
|
|
502
|
+
write(message);
|
|
503
|
+
};
|
|
504
|
+
let queue = [];
|
|
505
|
+
let open = null;
|
|
506
|
+
let scheduled = false;
|
|
507
|
+
const flush = () => {
|
|
508
|
+
scheduled = false;
|
|
509
|
+
open = null;
|
|
510
|
+
const out = queue;
|
|
511
|
+
queue = [];
|
|
512
|
+
for (const message of out) send(message);
|
|
494
513
|
};
|
|
514
|
+
const put = (fid, r) => {
|
|
515
|
+
if (swept) swept.emitted = true;
|
|
516
|
+
showing(r);
|
|
517
|
+
let merge = open && open.id === fid;
|
|
518
|
+
if (merge) for (const key in r) if (key in open.r) merge = false;
|
|
519
|
+
if (merge) Object.assign(open.r, r);else queue.push(open = {
|
|
520
|
+
id: fid,
|
|
521
|
+
version,
|
|
522
|
+
r
|
|
523
|
+
});
|
|
524
|
+
if (!scheduled) {
|
|
525
|
+
scheduled = true;
|
|
526
|
+
queueMicrotask(flush);
|
|
527
|
+
}
|
|
528
|
+
};
|
|
529
|
+
const putError = (fid, key, error) => put(fid, {
|
|
530
|
+
[key ? `${/^lha?:/.test(key) ? "hole" : "seg"}:${key}:error` : ":error"]: error
|
|
531
|
+
});
|
|
495
532
|
const needs = name => {
|
|
496
533
|
if (!tiers.has(name)) {
|
|
497
534
|
tiers.add(name);
|
|
@@ -501,36 +538,44 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
501
538
|
let conditional = false;
|
|
502
539
|
const skipped = new Set();
|
|
503
540
|
const attrText = new Map();
|
|
504
|
-
const
|
|
505
|
-
|
|
541
|
+
const holeDigest = new Map();
|
|
542
|
+
if (have) for (const key in have) key.startsWith("lh:") && holeDigest.set(key, have[key]);
|
|
543
|
+
function showing(r) {
|
|
544
|
+
if ("" in r) holeDigest.clear();
|
|
545
|
+
for (const k in r) {
|
|
546
|
+
const record = r[k];
|
|
547
|
+
if (k.startsWith("hole:lh:") && !k.endsWith(":error")) holeDigest.set(k.slice(5), record.digest);
|
|
548
|
+
if (record) for (const key in record.holes) key.startsWith("lh:") && holeDigest.set(key, record.holes[key]);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
const html = (value, digest, holes) => withHoles({
|
|
552
|
+
kind: "html",
|
|
553
|
+
value,
|
|
554
|
+
digest
|
|
555
|
+
}, holes);
|
|
556
|
+
const emitDiffering = source => {
|
|
557
|
+
for (const m of source.matchAll(HOLE_RANGE)) {
|
|
506
558
|
const key = "lh:" + m[1];
|
|
507
559
|
const digest = textDigest(stripHoleMarkers(m[2]));
|
|
508
560
|
if (have[key] === digest) continue;
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
version,
|
|
513
|
-
key,
|
|
514
|
-
html: m[2],
|
|
515
|
-
digest
|
|
516
|
-
}, holeDigests(m[2], null)));
|
|
561
|
+
put(id, {
|
|
562
|
+
["hole:" + key]: html(m[2], digest, holeDigests(m[2], null))
|
|
563
|
+
});
|
|
517
564
|
}
|
|
518
|
-
for (const m of
|
|
565
|
+
for (const m of source.matchAll(ATTR_ADDRESS)) {
|
|
519
566
|
const text = attrText.get("lha:" + m[1]);
|
|
520
567
|
if (text === undefined) continue;
|
|
521
568
|
const digest = textDigest(text);
|
|
522
569
|
if (have["lha:" + m[1]] === digest) continue;
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
digest
|
|
570
|
+
put(id, {
|
|
571
|
+
["attr:" + m[1]]: {
|
|
572
|
+
kind: "attrs",
|
|
573
|
+
value: text,
|
|
574
|
+
digest
|
|
575
|
+
}
|
|
530
576
|
});
|
|
531
577
|
}
|
|
532
578
|
};
|
|
533
|
-
const styledKeys = new Set();
|
|
534
579
|
const bindings = new Map();
|
|
535
580
|
const sweepMinted = new Set();
|
|
536
581
|
const argRefVersions = new Map();
|
|
@@ -541,34 +586,27 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
541
586
|
const sweep = () => {
|
|
542
587
|
epoch++;
|
|
543
588
|
const pass = swept = {
|
|
544
|
-
|
|
589
|
+
r: {},
|
|
545
590
|
emitted: false
|
|
546
591
|
};
|
|
547
592
|
try {
|
|
548
|
-
for (const b of [...bindings
|
|
593
|
+
for (const [key, b] of [...bindings]) {
|
|
594
|
+
if (bindings.get(key) !== b) continue;
|
|
549
595
|
try {
|
|
550
596
|
b.sweep();
|
|
551
597
|
} catch (_) {
|
|
552
598
|
}
|
|
553
599
|
}
|
|
554
|
-
|
|
600
|
+
for (const _ in pass.r) {
|
|
601
|
+
put(id, pass.r);
|
|
602
|
+
break;
|
|
603
|
+
}
|
|
604
|
+
flush();
|
|
555
605
|
if (pass.emitted && hooks && hooks.onYield) hooks.onYield();
|
|
556
606
|
} finally {
|
|
557
607
|
swept = null;
|
|
558
608
|
}
|
|
559
609
|
};
|
|
560
|
-
const emitOps = ops => {
|
|
561
|
-
if (ops.length === 1) emit(Object.assign({
|
|
562
|
-
type: ops[0].type,
|
|
563
|
-
id,
|
|
564
|
-
version
|
|
565
|
-
}, ops[0]));else if (ops.length) emit({
|
|
566
|
-
type: "ops",
|
|
567
|
-
id,
|
|
568
|
-
version,
|
|
569
|
-
ops
|
|
570
|
-
});
|
|
571
|
-
};
|
|
572
610
|
const scheduleSweep = () => {
|
|
573
611
|
if (closed || sweepScheduled || !bindings.size) return;
|
|
574
612
|
sweepScheduled = true;
|
|
@@ -583,52 +621,47 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
583
621
|
tagRegion(key, childId) {
|
|
584
622
|
if (!regionKeys.has(key)) regionKeys.set(key, childId);
|
|
585
623
|
},
|
|
586
|
-
shell(
|
|
587
|
-
const digest = textDigest(frameSkeleton(
|
|
624
|
+
shell(source, meta = {}) {
|
|
625
|
+
const digest = textDigest(frameSkeleton(source));
|
|
588
626
|
if (have && have[""] === digest) {
|
|
589
627
|
conditional = true;
|
|
590
|
-
emitDiffering(
|
|
628
|
+
emitDiffering(source);
|
|
591
629
|
return;
|
|
592
630
|
}
|
|
593
631
|
if (meta.preloads && meta.preloads.size || meta.preloadLinks) {
|
|
594
|
-
const
|
|
595
|
-
type: "assets",
|
|
596
|
-
id,
|
|
597
|
-
version,
|
|
598
|
-
key: ""
|
|
599
|
-
};
|
|
632
|
+
const record = {};
|
|
600
633
|
if (meta.preloads && meta.preloads.size) {
|
|
601
634
|
const styles = [];
|
|
602
635
|
const modules = [];
|
|
603
636
|
for (const url of meta.preloads) {
|
|
604
637
|
(url.endsWith(".css") ? styles : modules).push(url);
|
|
605
638
|
}
|
|
606
|
-
if (styles.length)
|
|
607
|
-
if (modules.length)
|
|
639
|
+
if (styles.length) record.styles = styles;
|
|
640
|
+
if (modules.length) record.modules = modules;
|
|
608
641
|
}
|
|
609
642
|
if (meta.preloadLinks) {
|
|
610
|
-
|
|
643
|
+
record.preloads = [];
|
|
611
644
|
for (const entry of meta.preloadLinks) {
|
|
612
|
-
|
|
645
|
+
record.preloads.push(wirePreload(entry));
|
|
613
646
|
}
|
|
614
647
|
}
|
|
615
648
|
needs("assets");
|
|
616
|
-
|
|
649
|
+
put(id, {
|
|
650
|
+
"seg::assets": record
|
|
651
|
+
});
|
|
617
652
|
}
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
version,
|
|
622
|
-
html,
|
|
623
|
-
digest
|
|
624
|
-
}, holeDigests(html, attrText)));
|
|
653
|
+
put(id, {
|
|
654
|
+
"": html(source, digest, holeDigests(source, attrText))
|
|
655
|
+
});
|
|
625
656
|
},
|
|
626
657
|
data(record) {
|
|
627
658
|
if (record && typeof record.key === "string" && (record.key.endsWith("_fr") || /^\d+$/.test(record.key))) {
|
|
628
659
|
return;
|
|
629
660
|
}
|
|
661
|
+
if (swept) swept.emitted = true;
|
|
662
|
+
flush();
|
|
630
663
|
if (typeof record === "string") {
|
|
631
|
-
|
|
664
|
+
send({
|
|
632
665
|
type: "data",
|
|
633
666
|
id,
|
|
634
667
|
version,
|
|
@@ -636,7 +669,7 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
636
669
|
});
|
|
637
670
|
scheduleSweep();
|
|
638
671
|
} else {
|
|
639
|
-
|
|
672
|
+
send({
|
|
640
673
|
type: "data",
|
|
641
674
|
id,
|
|
642
675
|
version,
|
|
@@ -653,73 +686,40 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
653
686
|
skipped.add(key);
|
|
654
687
|
scheduleSweep();
|
|
655
688
|
if (meta.error) {
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
id: fid,
|
|
659
|
-
version,
|
|
660
|
-
key,
|
|
661
|
-
error: {
|
|
662
|
-
message: String(meta.error && meta.error.message || meta.error)
|
|
663
|
-
}
|
|
689
|
+
putError(fid, key, {
|
|
690
|
+
message: String(meta.error && meta.error.message || meta.error)
|
|
664
691
|
});
|
|
665
692
|
} else emitDiffering(value);
|
|
666
693
|
return;
|
|
667
694
|
}
|
|
668
695
|
const links = meta.styles && meta.styles.links || [];
|
|
669
696
|
const inline = meta.styles && meta.styles.inline || [];
|
|
697
|
+
const r = {};
|
|
670
698
|
if (links.length || inline.length) {
|
|
671
|
-
|
|
672
|
-
const chunk = {
|
|
673
|
-
type: "assets",
|
|
674
|
-
id: fid,
|
|
675
|
-
version,
|
|
676
|
-
key
|
|
677
|
-
};
|
|
699
|
+
const record = {};
|
|
678
700
|
if (links.length) {
|
|
679
|
-
|
|
701
|
+
record.styles = links.map(e => typeof e === "string" ? e : e.attrs ? {
|
|
680
702
|
href: e.href,
|
|
681
703
|
attrs: e.attrs
|
|
682
704
|
} : e.href);
|
|
683
705
|
}
|
|
684
706
|
if (inline.length) {
|
|
685
|
-
|
|
707
|
+
record.inlineStyles = inline.map(e => ({
|
|
686
708
|
id: e.id,
|
|
687
709
|
content: e.content,
|
|
688
710
|
attrs: e.attrs
|
|
689
711
|
}));
|
|
690
712
|
}
|
|
691
713
|
needs("assets");
|
|
692
|
-
|
|
714
|
+
r[`seg:${key}:assets`] = record;
|
|
693
715
|
}
|
|
694
|
-
|
|
695
|
-
type: "fragment",
|
|
696
|
-
id: fid,
|
|
697
|
-
version,
|
|
698
|
-
key,
|
|
699
|
-
html: value,
|
|
700
|
-
digest: textDigest(value)
|
|
701
|
-
}, holeDigests(value, attrText)));
|
|
716
|
+
r[`seg:${key}`] = html(value, textDigest(value), holeDigests(value, attrText));
|
|
702
717
|
scheduleSweep();
|
|
703
|
-
if (meta.error) {
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
key,
|
|
709
|
-
error: {
|
|
710
|
-
message: String(meta.error && meta.error.message || meta.error)
|
|
711
|
-
}
|
|
712
|
-
});
|
|
713
|
-
}
|
|
714
|
-
if (!meta.revealGroup) {
|
|
715
|
-
emit({
|
|
716
|
-
type: "reveal",
|
|
717
|
-
id: fid,
|
|
718
|
-
version,
|
|
719
|
-
keys: [key],
|
|
720
|
-
waitForStyles: !!links.length
|
|
721
|
-
});
|
|
722
|
-
}
|
|
718
|
+
if (meta.error) r[`seg:${key}:error`] = {
|
|
719
|
+
message: String(meta.error && meta.error.message || meta.error)
|
|
720
|
+
};
|
|
721
|
+
if (!meta.revealGroup) r[`seg:${key}:reveal`] = true;
|
|
722
|
+
put(fid, r);
|
|
723
723
|
},
|
|
724
724
|
reveal(keys, meta = {}) {
|
|
725
725
|
const byFrame = new Map();
|
|
@@ -730,38 +730,27 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
730
730
|
if (!group) byFrame.set(fid, group = []);
|
|
731
731
|
group.push(key);
|
|
732
732
|
}
|
|
733
|
+
const gate = meta.fallback ? "fallback" : "reveal";
|
|
733
734
|
for (const [fid, groupKeys] of byFrame) {
|
|
734
|
-
|
|
735
|
-
for (const key of groupKeys)
|
|
736
|
-
|
|
737
|
-
type: "reveal",
|
|
738
|
-
id: fid,
|
|
739
|
-
version,
|
|
740
|
-
keys: groupKeys,
|
|
741
|
-
waitForStyles
|
|
742
|
-
};
|
|
743
|
-
if (meta.fallback) chunk.fallback = true;
|
|
744
|
-
emit(chunk);
|
|
735
|
+
const r = {};
|
|
736
|
+
for (const key of groupKeys) r[`seg:${key}:${gate}`] = true;
|
|
737
|
+
put(fid, r);
|
|
745
738
|
}
|
|
746
739
|
},
|
|
747
740
|
asset(type, value) {
|
|
748
741
|
if (type === "module") {
|
|
749
742
|
needs("assets");
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
key: "",
|
|
755
|
-
modules: [value]
|
|
743
|
+
put(id, {
|
|
744
|
+
"seg::assets": {
|
|
745
|
+
modules: [value]
|
|
746
|
+
}
|
|
756
747
|
});
|
|
757
748
|
} else if (type === "preload") {
|
|
758
749
|
needs("assets");
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
key: "",
|
|
764
|
-
preloads: [wirePreload(value)]
|
|
750
|
+
put(id, {
|
|
751
|
+
"seg::assets": {
|
|
752
|
+
preloads: [wirePreload(value)]
|
|
753
|
+
}
|
|
765
754
|
});
|
|
766
755
|
}
|
|
767
756
|
},
|
|
@@ -769,64 +758,76 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
769
758
|
if (closed) return;
|
|
770
759
|
if (bindings.size && !swept) sweep();
|
|
771
760
|
closed = true;
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
761
|
+
put(id, bound ? {
|
|
762
|
+
":complete": true,
|
|
763
|
+
":bound": bound
|
|
764
|
+
} : {
|
|
765
|
+
":complete": true
|
|
766
|
+
});
|
|
767
|
+
flush();
|
|
779
768
|
},
|
|
780
769
|
error(errorId, error) {
|
|
781
|
-
|
|
782
|
-
type: "error",
|
|
783
|
-
id,
|
|
784
|
-
version,
|
|
785
|
-
key: errorId,
|
|
786
|
-
error
|
|
787
|
-
});
|
|
770
|
+
putError(id, errorId, error);
|
|
788
771
|
},
|
|
772
|
+
flush,
|
|
789
773
|
slot(key, args) {
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
774
|
+
const r = {
|
|
775
|
+
[`slot:${key}`]: {
|
|
776
|
+
kind: "slot",
|
|
777
|
+
args
|
|
778
|
+
}
|
|
779
|
+
};
|
|
780
|
+
swept ? Object.assign(swept.r, r) : put(id, r);
|
|
797
781
|
},
|
|
798
|
-
region(childId,
|
|
782
|
+
region(childId, value) {
|
|
799
783
|
needs("regions");
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
784
|
+
put(childId, {
|
|
785
|
+
"": {
|
|
786
|
+
kind: "html",
|
|
787
|
+
value
|
|
788
|
+
}
|
|
805
789
|
});
|
|
806
790
|
},
|
|
807
|
-
hole(key,
|
|
808
|
-
const
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
html,
|
|
812
|
-
digest: textDigest(html)
|
|
791
|
+
hole(key, source, rows) {
|
|
792
|
+
const record = {
|
|
793
|
+
kind: "html",
|
|
794
|
+
digest: textDigest(source)
|
|
813
795
|
};
|
|
814
|
-
|
|
796
|
+
const base = holeDigest.get(key);
|
|
797
|
+
if (rows && base && hooks && hooks.live) {
|
|
798
|
+
record.rows = rows;
|
|
799
|
+
record.base = base;
|
|
800
|
+
} else record.value = source;
|
|
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));
|
|
807
|
+
const r = {
|
|
808
|
+
["hole:" + key]: record
|
|
809
|
+
};
|
|
810
|
+
showing(r);
|
|
811
|
+
swept ? Object.assign(swept.r, r) : put(id, r);
|
|
815
812
|
},
|
|
816
813
|
attr(key, attrs, removed) {
|
|
817
|
-
const
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
attrs,
|
|
814
|
+
const record = {
|
|
815
|
+
kind: "attrs",
|
|
816
|
+
value: attrs,
|
|
821
817
|
digest: textDigest(attrs)
|
|
822
818
|
};
|
|
823
|
-
if (removed && removed.length)
|
|
824
|
-
|
|
819
|
+
if (removed && removed.length) record.removed = removed;
|
|
820
|
+
const r = {
|
|
821
|
+
["attr:" + key]: record
|
|
822
|
+
};
|
|
823
|
+
swept ? Object.assign(swept.r, r) : put(id, r);
|
|
825
824
|
},
|
|
826
825
|
attrBaseline(key, text) {
|
|
827
826
|
attrText.set(key, text);
|
|
827
|
+
if (hooks && hooks.retain) hooks.retain(key, text);
|
|
828
828
|
},
|
|
829
829
|
openBinding(key, b) {
|
|
830
|
+
if (/^lha?:/.test(key)) needs("wire");
|
|
830
831
|
bindings.set(key, b);
|
|
831
832
|
},
|
|
832
833
|
closeBinding(key) {
|
|
@@ -859,8 +860,9 @@ function renderServerComponent(component, options = {}) {
|
|
|
859
860
|
if (ctx) {
|
|
860
861
|
ctx.commit = sink.commit;
|
|
861
862
|
ctx.commitEpoch = () => sink.epoch;
|
|
862
|
-
|
|
863
|
-
ctx.
|
|
863
|
+
let unsettled = !!options.live;
|
|
864
|
+
if (!unsettled) ctx.unsettled = () => void (unsettled = true);
|
|
865
|
+
ctx.liveHoles = createLiveHoles(sink, false, () => !unsettled, ctx._errorScope);
|
|
864
866
|
}
|
|
865
867
|
return serverComponentScope(() => component(props));
|
|
866
868
|
};
|
|
@@ -893,6 +895,7 @@ function frameStream(makeCode, options) {
|
|
|
893
895
|
function finish() {
|
|
894
896
|
if (ended) return;
|
|
895
897
|
ended = true;
|
|
898
|
+
sink.flush();
|
|
896
899
|
if (timer) clearTimeout(timer);
|
|
897
900
|
if (upstream) upstream.removeEventListener("abort", onSignal);
|
|
898
901
|
w.end && w.end();
|
|
@@ -913,19 +916,21 @@ function frameStream(makeCode, options) {
|
|
|
913
916
|
finish();
|
|
914
917
|
render.abort(upstream.reason);
|
|
915
918
|
}
|
|
916
|
-
const emit =
|
|
917
|
-
if (observation) observation.chunk(
|
|
918
|
-
w.write(
|
|
919
|
-
if (bounded && !flushed &&
|
|
919
|
+
const emit = message => {
|
|
920
|
+
if (observation) observation.chunk(message);
|
|
921
|
+
w.write(message);
|
|
922
|
+
if (bounded && !flushed && message.id === id && message.r && "" in message.r) {
|
|
920
923
|
flushed = true;
|
|
921
924
|
if (maxDurationMs > 0 && maxDurationMs !== Infinity) timer = setTimeout(() => cut("time"), maxDurationMs);
|
|
922
925
|
}
|
|
923
926
|
};
|
|
924
|
-
const sink = createFrameSink(emit, frame, options.resume && options.resume.have,
|
|
925
|
-
|
|
927
|
+
const sink = createFrameSink(emit, frame, options.resume && options.resume.have, {
|
|
928
|
+
live: options.live,
|
|
929
|
+
retain: options.broadcast,
|
|
930
|
+
onYield: bounded ? () => {
|
|
926
931
|
if (flushed && maxYields > 0 && ++yields >= maxYields) cut("yields");
|
|
927
|
-
}
|
|
928
|
-
}
|
|
932
|
+
} : undefined
|
|
933
|
+
});
|
|
929
934
|
if (options.live) sink.needs("wire");
|
|
930
935
|
w.write({
|
|
931
936
|
type: "start",
|
|
@@ -960,6 +965,7 @@ function frameStream(makeCode, options) {
|
|
|
960
965
|
finish();
|
|
961
966
|
}
|
|
962
967
|
if (w[ANNOUNCE]) w[ANNOUNCE](sink.announce());
|
|
968
|
+
sink.flush();
|
|
963
969
|
}
|
|
964
970
|
return {
|
|
965
971
|
pipe: stream,
|
|
@@ -981,56 +987,21 @@ function frameStream(makeCode, options) {
|
|
|
981
987
|
function slotRange(occurrence) {
|
|
982
988
|
return {
|
|
983
989
|
t: `<!--slot:${occurrence}:start--><!--slot:${occurrence}:end-->`,
|
|
984
|
-
$slot: true
|
|
985
|
-
$occurrence: occurrence
|
|
990
|
+
$slot: true
|
|
986
991
|
};
|
|
987
992
|
}
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
function isRangeKey(key) {
|
|
991
|
-
const c = key.charCodeAt(0);
|
|
992
|
-
return c === 36 || c >= 48 && c <= 57 || RANGE_KEYS.has(key);
|
|
993
|
-
}
|
|
994
|
-
function slotProxy(range, occurrence, face, content, onData, needs) {
|
|
995
|
-
return new Proxy(range, {
|
|
996
|
-
get(target, key, receiver) {
|
|
997
|
-
if (typeof key !== "string" || isRangeKey(key)) return Reflect.get(target, key, receiver);
|
|
998
|
-
if (onData) onData = void onData();
|
|
999
|
-
if (face !== SLOT_FACE_MARKUP) needs("bind");
|
|
1000
|
-
return slotValue(occurrence, key, content ? content[key] : undefined, face);
|
|
1001
|
-
}
|
|
1002
|
-
});
|
|
1003
|
-
}
|
|
1004
|
-
function argBorderForm(value, key, occurrence, needs) {
|
|
1005
|
-
return toBorderForm(withoutStandIns(value, key, occurrence, needs));
|
|
993
|
+
function argBorderForm(value, needs) {
|
|
994
|
+
return toBorderForm(noteTraces(value, needs));
|
|
1006
995
|
}
|
|
1007
|
-
function
|
|
1008
|
-
return rewriteTree(value,
|
|
996
|
+
function noteTraces(value, needs) {
|
|
997
|
+
return rewriteTree(value, v => {
|
|
1009
998
|
if (isContainerTraced(v)) {
|
|
1010
999
|
needs("trace");
|
|
1011
1000
|
return v;
|
|
1012
1001
|
}
|
|
1013
|
-
if (Object.getPrototypeOf(v) === Object.prototype && isSlotValue(v)) {
|
|
1014
|
-
return undefined;
|
|
1015
|
-
}
|
|
1016
1002
|
return DESCEND;
|
|
1017
1003
|
}, true);
|
|
1018
1004
|
}
|
|
1019
|
-
function slotFace(range, content) {
|
|
1020
|
-
if (content == null) return SLOT_FACE_DATA;
|
|
1021
|
-
if (typeof content !== "object" || Array.isArray(content)) return SLOT_FACE_MARKUP;
|
|
1022
|
-
if (isServerContent(content)) {
|
|
1023
|
-
let data = false;
|
|
1024
|
-
for (const key in content) {
|
|
1025
|
-
if (!NODE_KEYS.has(key)) {
|
|
1026
|
-
data = true;
|
|
1027
|
-
break;
|
|
1028
|
-
}
|
|
1029
|
-
}
|
|
1030
|
-
if (!data) return SLOT_FACE_MARKUP;
|
|
1031
|
-
}
|
|
1032
|
-
return SLOT_FACE_DATA;
|
|
1033
|
-
}
|
|
1034
1005
|
const OCCURRENCE_UNSAFE = /[^A-Za-z0-9_.-]/g;
|
|
1035
1006
|
function encodeOccurrenceKey(key) {
|
|
1036
1007
|
return String(key).replace(OCCURRENCE_UNSAFE, c => {
|
|
@@ -1085,12 +1056,19 @@ function structuralArgsKey(raw) {
|
|
|
1085
1056
|
};
|
|
1086
1057
|
return walk(raw, true) ? out : undefined;
|
|
1087
1058
|
}
|
|
1088
|
-
function
|
|
1089
|
-
const
|
|
1090
|
-
if (
|
|
1091
|
-
|
|
1092
|
-
|
|
1059
|
+
function argDigest(value) {
|
|
1060
|
+
const t = typeof value;
|
|
1061
|
+
if (value == null || t !== "object" && t !== "function" && value === value) return value;
|
|
1062
|
+
if (isContainerTraced(value)) return value;
|
|
1063
|
+
try {
|
|
1064
|
+
const key = structuralArgsKey([value]);
|
|
1065
|
+
return key === undefined ? value : key;
|
|
1066
|
+
} catch (_) {
|
|
1067
|
+
return value;
|
|
1068
|
+
}
|
|
1093
1069
|
}
|
|
1070
|
+
const PENDING_ARG = {};
|
|
1071
|
+
const noDigest = () => NaN;
|
|
1094
1072
|
function isAsyncValue(v) {
|
|
1095
1073
|
return !!v && typeof v === "object" && (typeof v.then === "function" || typeof v[Symbol.asyncIterator] === "function");
|
|
1096
1074
|
}
|
|
@@ -1106,6 +1084,37 @@ function tapFirstYield(iterable) {
|
|
|
1106
1084
|
rest
|
|
1107
1085
|
};
|
|
1108
1086
|
}
|
|
1087
|
+
function packOccurrences(occs) {
|
|
1088
|
+
const out = [];
|
|
1089
|
+
let prop = "",
|
|
1090
|
+
a = -1,
|
|
1091
|
+
b = -1;
|
|
1092
|
+
const flush = () => a >= 0 && out.push(prop + "#" + (a === b ? a : a + "-" + b));
|
|
1093
|
+
for (const o of occs) {
|
|
1094
|
+
const m = /^(.*)#(\d+)$/.exec(o);
|
|
1095
|
+
if (m && m[1] === prop && +m[2] === b + 1 && a >= 0) {
|
|
1096
|
+
b++;
|
|
1097
|
+
continue;
|
|
1098
|
+
}
|
|
1099
|
+
flush();
|
|
1100
|
+
a = b = -1;
|
|
1101
|
+
if (m) {
|
|
1102
|
+
prop = m[1];
|
|
1103
|
+
a = b = +m[2];
|
|
1104
|
+
} else out.push(o);
|
|
1105
|
+
}
|
|
1106
|
+
flush();
|
|
1107
|
+
return out.join(" ");
|
|
1108
|
+
}
|
|
1109
|
+
function hasAsyncHoles(node, depth = 0) {
|
|
1110
|
+
if (!node || typeof node !== "object" || depth > 64) return false;
|
|
1111
|
+
if (Array.isArray(node)) {
|
|
1112
|
+
for (const n of node) if (hasAsyncHoles(n, depth + 1)) return true;
|
|
1113
|
+
return false;
|
|
1114
|
+
}
|
|
1115
|
+
if (node.h && node.h.length) return true;
|
|
1116
|
+
return false;
|
|
1117
|
+
}
|
|
1109
1118
|
function suppressedFill(render) {
|
|
1110
1119
|
const live = sharedConfig.context && sharedConfig.context.liveHoles;
|
|
1111
1120
|
if (!live) return render();
|
|
@@ -1116,25 +1125,96 @@ function suppressedFill(render) {
|
|
|
1116
1125
|
live.suppressed--;
|
|
1117
1126
|
}
|
|
1118
1127
|
}
|
|
1128
|
+
let parked = null;
|
|
1129
|
+
let parkedIds = 0;
|
|
1130
|
+
const PARKED = /<!--sc-n:(\d+)-->/;
|
|
1131
|
+
function park(render) {
|
|
1132
|
+
if (!parked) return render();
|
|
1133
|
+
const id = ++parkedIds;
|
|
1134
|
+
parked.set(id, {
|
|
1135
|
+
render,
|
|
1136
|
+
out: undefined
|
|
1137
|
+
});
|
|
1138
|
+
return {
|
|
1139
|
+
t: `<!--sc-n:${id}-->`
|
|
1140
|
+
};
|
|
1141
|
+
}
|
|
1142
|
+
const runParked = (entry, owner) => entry.out || (entry.out = entry.render(owner));
|
|
1143
|
+
function placeParked(node, nested, owner) {
|
|
1144
|
+
const out = expandParked(node, nested, owner);
|
|
1145
|
+
for (const entry of nested.values()) runParked(entry, owner);
|
|
1146
|
+
return out;
|
|
1147
|
+
}
|
|
1148
|
+
function expandParked(node, nested, owner) {
|
|
1149
|
+
if (Array.isArray(node)) {
|
|
1150
|
+
const out = node.map(n => expandParked(n, nested, owner));
|
|
1151
|
+
out.$slot = node.$slot;
|
|
1152
|
+
return out;
|
|
1153
|
+
}
|
|
1154
|
+
if (!node || node.t === undefined) return node;
|
|
1155
|
+
if (!node.h) return splitParked(node.t, nested, owner) || node;
|
|
1156
|
+
const out = [];
|
|
1157
|
+
node.t.forEach((t, i) => {
|
|
1158
|
+
out.push(splitParked(t, nested, owner) || {
|
|
1159
|
+
t
|
|
1160
|
+
});
|
|
1161
|
+
if (i < node.h.length) out.push({
|
|
1162
|
+
t: ["", ""],
|
|
1163
|
+
h: [node.h[i]],
|
|
1164
|
+
p: [node.p[i]]
|
|
1165
|
+
});
|
|
1166
|
+
});
|
|
1167
|
+
return out;
|
|
1168
|
+
}
|
|
1169
|
+
function splitParked(t, nested, owner) {
|
|
1170
|
+
const parts = typeof t === "string" ? t.split(PARKED) : [t];
|
|
1171
|
+
return parts.length > 1 ? parts.map((part, i) => i & 1 ? runParked(nested.get(+part), owner) : {
|
|
1172
|
+
t: part
|
|
1173
|
+
}) : undefined;
|
|
1174
|
+
}
|
|
1119
1175
|
function createDocumentSlotProps(clientProps, frameId) {
|
|
1120
1176
|
const counts = Object.create(null);
|
|
1177
|
+
let depsBatch = null;
|
|
1178
|
+
let depsN = 0;
|
|
1179
|
+
let wideSent = 0;
|
|
1180
|
+
const depsContext = sharedConfig.context;
|
|
1181
|
+
const noteDeps = (occurrence, reads, untracked) => {
|
|
1182
|
+
if (!depsContext || !depsContext.serialize || !depsContext.edges) return;
|
|
1183
|
+
const own = `sc-${frameId}-${occurrence}-`;
|
|
1184
|
+
const batch = () => {
|
|
1185
|
+
if (depsBatch) return depsBatch;
|
|
1186
|
+
queueMicrotask(() => {
|
|
1187
|
+
const b = {};
|
|
1188
|
+
for (const sid in depsBatch) b[sid] = packOccurrences(depsBatch[sid]);
|
|
1189
|
+
depsBatch = null;
|
|
1190
|
+
const wide = depsContext.edgeWide?.s || null;
|
|
1191
|
+
if (wide && wide.size > wideSent) {
|
|
1192
|
+
b["*"] = [...wide].slice(wideSent).join(" ");
|
|
1193
|
+
wideSent = wide.size;
|
|
1194
|
+
}
|
|
1195
|
+
if (depsN === 0 || Object.keys(b).length) depsContext.serialize(`sc:deps:${frameId}:${depsN++}`, b);
|
|
1196
|
+
});
|
|
1197
|
+
return depsBatch = Object.create(null);
|
|
1198
|
+
};
|
|
1199
|
+
const b = batch();
|
|
1200
|
+
if (reads) for (const sid of reads) if (!sid.startsWith(own)) (b[sid] ||= []).push(occurrence);
|
|
1201
|
+
if (untracked) (b["!"] ||= []).push(occurrence);
|
|
1202
|
+
};
|
|
1121
1203
|
const getters = new Map();
|
|
1122
1204
|
const repeats = new Map();
|
|
1123
|
-
const range = (occurrence, content) => {
|
|
1205
|
+
const range = (occurrence, content, tail) => {
|
|
1124
1206
|
const r = [{
|
|
1125
1207
|
t: `<!--slot:${occurrence}:start-->`
|
|
1126
|
-
}, content, {
|
|
1208
|
+
}, content, tail, {
|
|
1127
1209
|
t: `<!--slot:${occurrence}:end-->`
|
|
1128
1210
|
}];
|
|
1129
1211
|
r.$slot = true;
|
|
1130
|
-
r
|
|
1131
|
-
const face = slotFace(r, content);
|
|
1132
|
-
r.$face = face;
|
|
1133
|
-
return slotProxy(r, occurrence, face, face === SLOT_FACE_DATA ? content : undefined, undefined, documentNeeds);
|
|
1212
|
+
return r;
|
|
1134
1213
|
};
|
|
1135
1214
|
const zoneOwner = getOwner ? getOwner() : null;
|
|
1136
|
-
const scoped = (occurrence, render) => {
|
|
1215
|
+
const scoped = (occurrence, render, owner) => {
|
|
1137
1216
|
const id = `sc-${frameId}-${occurrence}-`;
|
|
1217
|
+
if (owner) return runWithOwner(owner, () => runWithHydrationScope(id, render));
|
|
1138
1218
|
const run = () => Hydration ? Hydration({
|
|
1139
1219
|
id,
|
|
1140
1220
|
get children() {
|
|
@@ -1154,18 +1234,13 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1154
1234
|
if (!fn) {
|
|
1155
1235
|
fn = (...callArgs) => {
|
|
1156
1236
|
if (callArgs.length === 0 || callArgs[0] === undefined) {
|
|
1157
|
-
|
|
1158
|
-
const repeat = repeats.get(rk);
|
|
1159
|
-
if (repeat) return repeat;
|
|
1160
|
-
const out = suppressedFill(() => scoped(prop, () => {
|
|
1237
|
+
return park(owner => suppressedFill(() => scoped(prop, () => {
|
|
1161
1238
|
const value = clientProps[prop];
|
|
1162
1239
|
return range(prop, typeof value === "function" ? value() : value);
|
|
1163
|
-
}));
|
|
1164
|
-
if (out.$face === SLOT_FACE_DATA) repeats.set(rk, out);
|
|
1165
|
-
return out;
|
|
1240
|
+
}, owner)));
|
|
1166
1241
|
}
|
|
1167
1242
|
const raw = callArgs[0];
|
|
1168
|
-
const rk =
|
|
1243
|
+
const rk = keyedId(prop, raw);
|
|
1169
1244
|
const repeat = rk !== undefined && repeats.get(rk);
|
|
1170
1245
|
if (repeat) return repeat;
|
|
1171
1246
|
const occurrence = occurrenceId(prop, raw, counts);
|
|
@@ -1173,10 +1248,10 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1173
1248
|
if (typeof slot !== "function") return range(occurrence, undefined);
|
|
1174
1249
|
const context = sharedConfig.context;
|
|
1175
1250
|
const recordKey = `sc:slot:${frameId}:${occurrence}`;
|
|
1251
|
+
const deferred = !!parked;
|
|
1176
1252
|
let settleRecord;
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
}
|
|
1253
|
+
const declare = () => context && context.async && context.serialize(recordKey, new Promise(resolve => settleRecord = resolve));
|
|
1254
|
+
deferred || declare();
|
|
1180
1255
|
try {
|
|
1181
1256
|
const resolved = {};
|
|
1182
1257
|
const liveArgs = sharedConfig.context && sharedConfig.context.live && sharedConfig.context.live.args;
|
|
@@ -1184,6 +1259,7 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1184
1259
|
const evals = {};
|
|
1185
1260
|
const states = {};
|
|
1186
1261
|
const minted = {};
|
|
1262
|
+
const nestedOf = {};
|
|
1187
1263
|
for (const key of Object.keys(raw)) {
|
|
1188
1264
|
if (key === "$key") continue;
|
|
1189
1265
|
const desc = Object.getOwnPropertyDescriptor(raw, key);
|
|
@@ -1202,6 +1278,8 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1202
1278
|
if (evaluate) {
|
|
1203
1279
|
evals[key] = evaluate;
|
|
1204
1280
|
const stampBefore = scopeStamp();
|
|
1281
|
+
const outer = parked;
|
|
1282
|
+
const nested = nestedOf[key] = parked = new Map();
|
|
1205
1283
|
try {
|
|
1206
1284
|
value = evaluate();
|
|
1207
1285
|
states[key] = {
|
|
@@ -1209,6 +1287,9 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1209
1287
|
last: value
|
|
1210
1288
|
};
|
|
1211
1289
|
} catch (err) {
|
|
1290
|
+
parked = outer;
|
|
1291
|
+
for (const entry of nested.values()) runParked(entry);
|
|
1292
|
+
nested.clear();
|
|
1212
1293
|
const blocked = ssrHandleError && ssrHandleError(err);
|
|
1213
1294
|
if (!blocked) throw err;
|
|
1214
1295
|
const state = states[key] = {
|
|
@@ -1221,6 +1302,7 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1221
1302
|
if (liveArgs) liveArgs.commit();
|
|
1222
1303
|
});
|
|
1223
1304
|
}
|
|
1305
|
+
parked = outer;
|
|
1224
1306
|
if (scopeStamp() !== stampBefore) minted[key] = true;
|
|
1225
1307
|
}
|
|
1226
1308
|
vals[key] = value;
|
|
@@ -1237,6 +1319,7 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1237
1319
|
key,
|
|
1238
1320
|
childId,
|
|
1239
1321
|
value,
|
|
1322
|
+
nested: nestedOf[key],
|
|
1240
1323
|
used: false,
|
|
1241
1324
|
locked: false
|
|
1242
1325
|
};
|
|
@@ -1247,7 +1330,7 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1247
1330
|
region.used = true;
|
|
1248
1331
|
return [{
|
|
1249
1332
|
t: frameElementOpen(childId)
|
|
1250
|
-
}, value, {
|
|
1333
|
+
}, region.nested && region.nested.size ? placeParked(value, region.nested, getOwner()) : value, {
|
|
1251
1334
|
t: FRAME_ELEMENT_CLOSE
|
|
1252
1335
|
}];
|
|
1253
1336
|
};
|
|
@@ -1268,49 +1351,67 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1268
1351
|
configurable: true
|
|
1269
1352
|
});
|
|
1270
1353
|
} else {
|
|
1271
|
-
resolved[key] = vals[key] =
|
|
1354
|
+
resolved[key] = vals[key] = noteTraces(value, documentNeeds);
|
|
1272
1355
|
}
|
|
1273
1356
|
}
|
|
1274
|
-
const
|
|
1275
|
-
const
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
for (const
|
|
1279
|
-
|
|
1280
|
-
const region = regions.find(r => r.key === key);
|
|
1281
|
-
if (region) {
|
|
1282
|
-
args[key] = {
|
|
1283
|
-
$frame: region.childId
|
|
1284
|
-
};
|
|
1285
|
-
continue;
|
|
1286
|
-
}
|
|
1287
|
-
if (!isContainerTraced(value) && isServerContent(value)) continue;
|
|
1288
|
-
args[key] = argBorderForm(value, key, occurrence, documentNeeds);
|
|
1289
|
-
}
|
|
1290
|
-
settleRecord ? settleRecord({
|
|
1291
|
-
...args
|
|
1292
|
-
}) : context.serialize(recordKey, {
|
|
1293
|
-
...args
|
|
1294
|
-
});
|
|
1295
|
-
for (const region of unused) {
|
|
1357
|
+
for (const key in nestedOf) if (!regions.some(r => r.key === key)) for (const entry of nestedOf[key].values()) runParked(entry);
|
|
1358
|
+
const flip = () => {
|
|
1359
|
+
if (flip.done || !context) return;
|
|
1360
|
+
flip.done = true;
|
|
1361
|
+
for (const region of regions) {
|
|
1362
|
+
if (region.used) continue;
|
|
1296
1363
|
region.locked = true;
|
|
1297
|
-
context.serialize(`sc:region:${region.childId}`, resolveRegionHtml(context, region.value));
|
|
1364
|
+
context.serialize(`sc:region:${region.childId}`, resolveRegionHtml(context, region.nested && region.nested.size ? placeParked(region.value, region.nested) : region.value));
|
|
1298
1365
|
}
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1366
|
+
};
|
|
1367
|
+
flip.$lhSkip = true;
|
|
1368
|
+
const finish = owner => {
|
|
1369
|
+
if (deferred) declare();
|
|
1370
|
+
try {
|
|
1371
|
+
const tracked = trackFillReads(() => suppressedFill(() => scoped(occurrence, () => range(occurrence, slot(resolved), flip), owner)));
|
|
1372
|
+
const out = tracked.result;
|
|
1373
|
+
noteDeps(occurrence, tracked.reads, tracked.untracked || hasAsyncHoles(out));
|
|
1374
|
+
if (context) {
|
|
1375
|
+
const args = {};
|
|
1376
|
+
for (const key of Object.keys(vals)) {
|
|
1377
|
+
const value = vals[key];
|
|
1378
|
+
const region = regions.find(r => r.key === key);
|
|
1379
|
+
if (region) {
|
|
1380
|
+
args[key] = {
|
|
1381
|
+
$frame: region.childId
|
|
1382
|
+
};
|
|
1383
|
+
continue;
|
|
1384
|
+
}
|
|
1385
|
+
if (!isContainerTraced(value) && isServerContent(value)) continue;
|
|
1386
|
+
args[key] = argBorderForm(value, documentNeeds);
|
|
1387
|
+
}
|
|
1388
|
+
settleRecord ? settleRecord({
|
|
1389
|
+
...args
|
|
1390
|
+
}) : context.serialize(recordKey, {
|
|
1391
|
+
...args
|
|
1309
1392
|
});
|
|
1393
|
+
if (liveArgs) {
|
|
1394
|
+
for (const key of Object.keys(evals)) {
|
|
1395
|
+
if (regions.some(r => r.key === key)) continue;
|
|
1396
|
+
if (minted[key]) continue;
|
|
1397
|
+
const ledgerKey = `${frameId}:${occurrence}:${key}`;
|
|
1398
|
+
openArgBinding(liveArgs, ledgerKey, occurrence, key, evals[key], states[key], value => {
|
|
1399
|
+
args[key] = argBorderForm(value, documentNeeds);
|
|
1400
|
+
liveArgs.slot(frameId, occurrence, {
|
|
1401
|
+
...args
|
|
1402
|
+
});
|
|
1403
|
+
});
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1310
1406
|
}
|
|
1407
|
+
return out;
|
|
1408
|
+
} catch (error) {
|
|
1409
|
+
settleRecord && settleRecord(undefined);
|
|
1410
|
+
throw error;
|
|
1311
1411
|
}
|
|
1312
|
-
}
|
|
1313
|
-
|
|
1412
|
+
};
|
|
1413
|
+
const out = park(finish);
|
|
1414
|
+
if (rk !== undefined && rk === occurrence) repeats.has(rk) || repeats.set(rk, out);
|
|
1314
1415
|
return out;
|
|
1315
1416
|
} catch (error) {
|
|
1316
1417
|
settleRecord && settleRecord(undefined);
|
|
@@ -1326,9 +1427,10 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1326
1427
|
}
|
|
1327
1428
|
const FRAME_TAG = "solid-frame";
|
|
1328
1429
|
const FRAME_ID_ATTR = "data-fid";
|
|
1329
|
-
|
|
1430
|
+
const FRAME_ARGS_ATTR = "data-fa";
|
|
1431
|
+
function frameElementOpen(id, args) {
|
|
1330
1432
|
const escaped = sharedConfig.context ? sharedConfig.context.escape(String(id), true) : String(id);
|
|
1331
|
-
return `<${FRAME_TAG} ${FRAME_ID_ATTR}="${escaped}" style="display:contents">`;
|
|
1433
|
+
return `<${FRAME_TAG} ${FRAME_ID_ATTR}="${escaped}"${args ? ` ${FRAME_ARGS_ATTR}="${args}"` : ""} style="display:contents">`;
|
|
1332
1434
|
}
|
|
1333
1435
|
const DOCUMENT_SITES = Symbol();
|
|
1334
1436
|
function contextSites(ctx) {
|
|
@@ -1380,6 +1482,7 @@ function armDocumentLiveHoles(ctx) {
|
|
|
1380
1482
|
if (live.holes) {
|
|
1381
1483
|
ctx.commit = live.commit;
|
|
1382
1484
|
ctx.commitEpoch = live.commitEpoch;
|
|
1485
|
+
ctx.unsettled = live.unsettled;
|
|
1383
1486
|
}
|
|
1384
1487
|
return;
|
|
1385
1488
|
}
|
|
@@ -1388,6 +1491,7 @@ function armDocumentLiveHoles(ctx) {
|
|
|
1388
1491
|
if (live) live.holes = null;
|
|
1389
1492
|
return;
|
|
1390
1493
|
}
|
|
1494
|
+
let unsettled = false;
|
|
1391
1495
|
const bindings = new Map();
|
|
1392
1496
|
let epoch = 0;
|
|
1393
1497
|
let sweepScheduled = false;
|
|
@@ -1395,7 +1499,7 @@ function armDocumentLiveHoles(ctx) {
|
|
|
1395
1499
|
let swept = null;
|
|
1396
1500
|
const sweep = () => {
|
|
1397
1501
|
epoch++;
|
|
1398
|
-
const
|
|
1502
|
+
const r = swept = {};
|
|
1399
1503
|
try {
|
|
1400
1504
|
for (const b of [...bindings.values()]) {
|
|
1401
1505
|
try {
|
|
@@ -1406,12 +1510,8 @@ function armDocumentLiveHoles(ctx) {
|
|
|
1406
1510
|
} finally {
|
|
1407
1511
|
swept = null;
|
|
1408
1512
|
}
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
const pushOps = ops => {
|
|
1412
|
-
if (ops.length === 1) push(ops[0]);else if (ops.length) push({
|
|
1413
|
-
type: "ops",
|
|
1414
|
-
ops
|
|
1513
|
+
for (const _ in r) return push({
|
|
1514
|
+
r
|
|
1415
1515
|
});
|
|
1416
1516
|
};
|
|
1417
1517
|
const scheduleSweep = () => {
|
|
@@ -1431,49 +1531,57 @@ function armDocumentLiveHoles(ctx) {
|
|
|
1431
1531
|
closed = true;
|
|
1432
1532
|
}
|
|
1433
1533
|
}));
|
|
1434
|
-
const push =
|
|
1435
|
-
if (!closed) channel.enqueue(
|
|
1534
|
+
const push = batch => {
|
|
1535
|
+
if (!closed) channel.enqueue(batch);
|
|
1436
1536
|
};
|
|
1537
|
+
const write = r => swept ? Object.assign(swept, r) : push({
|
|
1538
|
+
r
|
|
1539
|
+
});
|
|
1437
1540
|
ctx.liveHoles = live.holes = createLiveHoles({
|
|
1438
1541
|
openBinding(key, b) {
|
|
1542
|
+
documentNeeds("wire");
|
|
1439
1543
|
bindings.set(key, b);
|
|
1440
1544
|
},
|
|
1441
1545
|
closeBinding(key) {
|
|
1442
1546
|
bindings.delete(key);
|
|
1443
1547
|
},
|
|
1444
|
-
hole(key,
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1548
|
+
hole(key, value) {
|
|
1549
|
+
write({
|
|
1550
|
+
["hole:" + key]: {
|
|
1551
|
+
kind: "html",
|
|
1552
|
+
value,
|
|
1553
|
+
digest: textDigest(value)
|
|
1554
|
+
}
|
|
1555
|
+
});
|
|
1452
1556
|
},
|
|
1453
|
-
attr(key,
|
|
1454
|
-
const
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
digest: textDigest(attrs)
|
|
1557
|
+
attr(key, value, removed) {
|
|
1558
|
+
const record = {
|
|
1559
|
+
kind: "attrs",
|
|
1560
|
+
value,
|
|
1561
|
+
digest: textDigest(value)
|
|
1459
1562
|
};
|
|
1460
|
-
if (removed && removed.length)
|
|
1461
|
-
|
|
1563
|
+
if (removed && removed.length) record.removed = removed;
|
|
1564
|
+
write({
|
|
1565
|
+
["attr:" + key]: record
|
|
1566
|
+
});
|
|
1462
1567
|
},
|
|
1463
1568
|
error(key, error) {
|
|
1464
1569
|
push({
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1570
|
+
r: {
|
|
1571
|
+
[`hole:${key}:error`]: error
|
|
1572
|
+
}
|
|
1468
1573
|
});
|
|
1469
1574
|
},
|
|
1470
1575
|
commit: scheduleSweep,
|
|
1471
1576
|
get epoch() {
|
|
1472
1577
|
return epoch;
|
|
1473
1578
|
}
|
|
1474
|
-
}, true);
|
|
1579
|
+
}, true, () => !unsettled, ctx._errorScope);
|
|
1475
1580
|
ctx.commit = live.commit = scheduleSweep;
|
|
1476
1581
|
ctx.commitEpoch = live.commitEpoch = () => epoch;
|
|
1582
|
+
ctx.unsettled = live.unsettled = () => {
|
|
1583
|
+
unsettled = true;
|
|
1584
|
+
};
|
|
1477
1585
|
live.args = {
|
|
1478
1586
|
openBinding(key, b) {
|
|
1479
1587
|
bindings.set(key, b);
|
|
@@ -1483,19 +1591,23 @@ function armDocumentLiveHoles(ctx) {
|
|
|
1483
1591
|
},
|
|
1484
1592
|
slot(fid, occurrence, args) {
|
|
1485
1593
|
push({
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1594
|
+
r: {
|
|
1595
|
+
[`slot:${occurrence}`]: {
|
|
1596
|
+
kind: "slot",
|
|
1597
|
+
args
|
|
1598
|
+
}
|
|
1599
|
+
},
|
|
1600
|
+
fid
|
|
1490
1601
|
});
|
|
1491
1602
|
},
|
|
1492
1603
|
commit: scheduleSweep
|
|
1493
1604
|
};
|
|
1494
1605
|
live.error = (fid, error) => {
|
|
1495
1606
|
push({
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1607
|
+
r: {
|
|
1608
|
+
":error": error
|
|
1609
|
+
},
|
|
1610
|
+
fid
|
|
1499
1611
|
});
|
|
1500
1612
|
};
|
|
1501
1613
|
live.end = () => {
|
|
@@ -1512,17 +1624,17 @@ function frameTransformDirectResult(value, {
|
|
|
1512
1624
|
}) {
|
|
1513
1625
|
if (typeof value !== "function") return value;
|
|
1514
1626
|
const component = value;
|
|
1627
|
+
const address = frameAddress(id, args);
|
|
1515
1628
|
const wrapped = props => {
|
|
1516
1629
|
const siteId = documentSiteId(id);
|
|
1517
1630
|
return [{
|
|
1518
|
-
t: frameElementOpen(siteId)
|
|
1631
|
+
t: frameElementOpen(siteId, address.slice(id.length + 1))
|
|
1519
1632
|
},
|
|
1520
1633
|
serverOwned(() => {
|
|
1521
1634
|
const page = sharedConfig.context;
|
|
1522
1635
|
armDocumentLiveHoles(page);
|
|
1523
1636
|
if (tierUrls && page && page.live && !page.live.tierUrls) page.live.tierUrls = tierUrls;
|
|
1524
1637
|
const ctx = Object.create(page);
|
|
1525
|
-
ctx.claims = CLAIMS_DOCUMENT;
|
|
1526
1638
|
ctx.frameId = siteId;
|
|
1527
1639
|
sharedConfig.context = ctx;
|
|
1528
1640
|
try {
|
|
@@ -1539,7 +1651,7 @@ function frameTransformDirectResult(value, {
|
|
|
1539
1651
|
};
|
|
1540
1652
|
wrapped[SERVER_COMPONENT] = id;
|
|
1541
1653
|
wrapped[SERVER_COMPONENT_SOURCE] = component;
|
|
1542
|
-
wrapped[SERVER_COMPONENT_ADDRESS] =
|
|
1654
|
+
wrapped[SERVER_COMPONENT_ADDRESS] = address;
|
|
1543
1655
|
return wrapped;
|
|
1544
1656
|
}
|
|
1545
1657
|
function resolveRegionHtml(ctx, node) {
|
|
@@ -1642,6 +1754,15 @@ function createSlotProps(sink, frame) {
|
|
|
1642
1754
|
const counts = Object.create(null);
|
|
1643
1755
|
const getters = new Map();
|
|
1644
1756
|
const repeats = new Map();
|
|
1757
|
+
let pass = null;
|
|
1758
|
+
let passRepeats = null;
|
|
1759
|
+
const recs = new Map();
|
|
1760
|
+
const forget = occurrence => {
|
|
1761
|
+
const rec = recs.get(occurrence);
|
|
1762
|
+
if (!rec) return;
|
|
1763
|
+
recs.delete(occurrence);
|
|
1764
|
+
for (const key in rec.vals) sink.closeBinding(`${occurrence}:${key}`);
|
|
1765
|
+
};
|
|
1645
1766
|
const needs = sink.needs || (() => {});
|
|
1646
1767
|
return new Proxy(Object.create(null), {
|
|
1647
1768
|
has() {
|
|
@@ -1654,25 +1775,38 @@ function createSlotProps(sink, frame) {
|
|
|
1654
1775
|
if (!fn) {
|
|
1655
1776
|
fn = (...callArgs) => {
|
|
1656
1777
|
if (callArgs.length === 0 || callArgs[0] === undefined) {
|
|
1657
|
-
return
|
|
1778
|
+
return slotRange(prop);
|
|
1658
1779
|
}
|
|
1659
|
-
const rk = repeatKey(prop, callArgs[0]);
|
|
1660
|
-
const repeat = rk !== undefined && repeats.get(rk);
|
|
1661
|
-
if (repeat) return repeat;
|
|
1662
1780
|
const live = sharedConfig.context && sharedConfig.context.liveHoles;
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1781
|
+
const sweeping = !!live && live.sweeping;
|
|
1782
|
+
let rmap = repeats;
|
|
1783
|
+
if (sweeping) {
|
|
1784
|
+
if (pass !== live.visit) passRepeats = new Map();
|
|
1785
|
+
pass = live.visit;
|
|
1786
|
+
rmap = passRepeats;
|
|
1787
|
+
}
|
|
1788
|
+
const rk = keyedId(prop, callArgs[0]);
|
|
1789
|
+
const repeat = rk !== undefined && rmap.get(rk);
|
|
1790
|
+
if (repeat) return repeat;
|
|
1791
|
+
if (sweeping && !live.scope) {
|
|
1792
|
+
live.gateHit = true;
|
|
1793
|
+
return {
|
|
1794
|
+
t: "",
|
|
1795
|
+
$slot: true
|
|
1796
|
+
};
|
|
1672
1797
|
}
|
|
1673
1798
|
const raw = callArgs[0];
|
|
1674
|
-
|
|
1799
|
+
let occurrence = keyedId(prop, raw);
|
|
1800
|
+
if (occurrence === undefined) {
|
|
1801
|
+
const positional = sweeping ? undefined : occurrenceId(prop, raw, counts);
|
|
1802
|
+
occurrence = live ? live.slotId(prop, positional) : positional;
|
|
1803
|
+
}
|
|
1804
|
+
if (sweeping && live.dry) return slotRange(occurrence);
|
|
1805
|
+
const prev = recs.get(occurrence);
|
|
1806
|
+
let changed = !prev;
|
|
1807
|
+
const digest = live && live.scope ? argDigest : noDigest;
|
|
1675
1808
|
const args = {};
|
|
1809
|
+
const vals = {};
|
|
1676
1810
|
const opened = [];
|
|
1677
1811
|
for (const key of Object.keys(raw)) {
|
|
1678
1812
|
if (key === "$key") continue;
|
|
@@ -1688,6 +1822,7 @@ function createSlotProps(sink, frame) {
|
|
|
1688
1822
|
let evaluate = null;
|
|
1689
1823
|
let value;
|
|
1690
1824
|
let state = null;
|
|
1825
|
+
let pending = false;
|
|
1691
1826
|
const stampBefore = scopeStamp();
|
|
1692
1827
|
try {
|
|
1693
1828
|
if (desc.get) {
|
|
@@ -1709,6 +1844,7 @@ function createSlotProps(sink, frame) {
|
|
|
1709
1844
|
settled: false,
|
|
1710
1845
|
last: undefined
|
|
1711
1846
|
};
|
|
1847
|
+
pending = true;
|
|
1712
1848
|
const pendingState = state;
|
|
1713
1849
|
value = retryArgUntilSettled(evaluate, blocked, key, occurrence, v => {
|
|
1714
1850
|
pendingState.settled = true;
|
|
@@ -1720,6 +1856,7 @@ function createSlotProps(sink, frame) {
|
|
|
1720
1856
|
const t = typeof value;
|
|
1721
1857
|
if (value == null || t === "string" || t === "number" || t === "boolean") {
|
|
1722
1858
|
args[key] = value;
|
|
1859
|
+
vals[key] = digest(value);
|
|
1723
1860
|
if (evaluate) state = {
|
|
1724
1861
|
settled: true,
|
|
1725
1862
|
last: value
|
|
@@ -1729,21 +1866,27 @@ function createSlotProps(sink, frame) {
|
|
|
1729
1866
|
if (resolved.h.length) {
|
|
1730
1867
|
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.");
|
|
1731
1868
|
}
|
|
1732
|
-
|
|
1869
|
+
vals[key] = "<" + resolved.t[0];
|
|
1870
|
+
if (!prev || prev.vals[key] !== vals[key]) sink.region(childId, resolved.t[0]);
|
|
1733
1871
|
args[key] = {
|
|
1734
1872
|
$frame: childId
|
|
1735
1873
|
};
|
|
1736
1874
|
} else {
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1875
|
+
vals[key] = pending ? PENDING_ARG : digest(value);
|
|
1876
|
+
if (prev && prev.vals[key] === vals[key]) args[key] = prev.args[key];else {
|
|
1877
|
+
const ref = prev ? `arg:${occurrence}:${key}@${sink.nextArgRef(`${occurrence}:${key}`)}` : `arg:${occurrence}:${key}`;
|
|
1878
|
+
if (prev) sink.mintRef(ref);
|
|
1879
|
+
ctx.serialize(ref, argBorderForm(value, needs));
|
|
1880
|
+
args[key] = {
|
|
1881
|
+
$ref: ref
|
|
1882
|
+
};
|
|
1883
|
+
}
|
|
1742
1884
|
if (evaluate && !state) state = {
|
|
1743
1885
|
settled: true,
|
|
1744
1886
|
last: value
|
|
1745
1887
|
};
|
|
1746
1888
|
}
|
|
1889
|
+
if (prev && prev.vals[key] !== vals[key]) changed = true;
|
|
1747
1890
|
if (evaluate && state && !mintedEval) opened.push({
|
|
1748
1891
|
key,
|
|
1749
1892
|
evaluate,
|
|
@@ -1753,9 +1896,18 @@ function createSlotProps(sink, frame) {
|
|
|
1753
1896
|
ctx.registerFragment = origRegister;
|
|
1754
1897
|
}
|
|
1755
1898
|
}
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1899
|
+
if (prev) for (const key in prev.vals) if (!(key in vals)) changed = true;
|
|
1900
|
+
const rec = changed ? {
|
|
1901
|
+
args,
|
|
1902
|
+
vals
|
|
1903
|
+
} : prev;
|
|
1904
|
+
if (changed) {
|
|
1905
|
+
recs.set(occurrence, rec);
|
|
1906
|
+
sink.slot(occurrence, {
|
|
1907
|
+
...args
|
|
1908
|
+
});
|
|
1909
|
+
}
|
|
1910
|
+
if (live && live.visit) live.seen(occurrence, () => recs.get(occurrence) === rec && forget(occurrence));
|
|
1759
1911
|
const ctx = sharedConfig.context;
|
|
1760
1912
|
for (const b of opened) {
|
|
1761
1913
|
const key = b.key;
|
|
@@ -1763,23 +1915,23 @@ function createSlotProps(sink, frame) {
|
|
|
1763
1915
|
openArgBinding(sink, ledgerKey, occurrence, key, b.evaluate, b.state, value => {
|
|
1764
1916
|
const t = typeof value;
|
|
1765
1917
|
if (value == null || t === "string" || t === "number" || t === "boolean") {
|
|
1766
|
-
args[key] = value;
|
|
1918
|
+
rec.args[key] = value;
|
|
1767
1919
|
} else {
|
|
1768
1920
|
const ref = `arg:${occurrence}:${key}@${sink.nextArgRef(ledgerKey)}`;
|
|
1769
1921
|
sink.mintRef(ref);
|
|
1770
|
-
ctx.serialize(ref, argBorderForm(value,
|
|
1771
|
-
args[key] = {
|
|
1922
|
+
ctx.serialize(ref, argBorderForm(value, needs));
|
|
1923
|
+
rec.args[key] = {
|
|
1772
1924
|
$ref: ref
|
|
1773
1925
|
};
|
|
1774
1926
|
}
|
|
1927
|
+
rec.vals[key] = digest(value);
|
|
1775
1928
|
sink.slot(occurrence, {
|
|
1776
|
-
...args
|
|
1929
|
+
...rec.args
|
|
1777
1930
|
});
|
|
1778
1931
|
});
|
|
1779
1932
|
}
|
|
1780
|
-
const
|
|
1781
|
-
|
|
1782
|
-
if (keyed) repeats.set(rk, out);
|
|
1933
|
+
const out = slotRange(occurrence);
|
|
1934
|
+
if (rk !== undefined && rk === occurrence) rmap.set(rk, out);
|
|
1783
1935
|
return out;
|
|
1784
1936
|
};
|
|
1785
1937
|
fn.$lhSkip = true;
|
|
@@ -1844,11 +1996,11 @@ function serverComponentResponse(component, options = {}, init = {}) {
|
|
|
1844
1996
|
teardown.abort();
|
|
1845
1997
|
});
|
|
1846
1998
|
stream.pipe({
|
|
1847
|
-
write(
|
|
1848
|
-
if (
|
|
1999
|
+
write(message) {
|
|
2000
|
+
if (message.r && ":error" in message.r) failed = true;
|
|
1849
2001
|
if (closed) return;
|
|
1850
2002
|
try {
|
|
1851
|
-
controller.enqueue(frame(JSON.stringify(
|
|
2003
|
+
controller.enqueue(frame(JSON.stringify(message)));
|
|
1852
2004
|
} catch (_) {
|
|
1853
2005
|
closed = true;
|
|
1854
2006
|
}
|
|
@@ -1911,6 +2063,12 @@ function frameTransformResult(event, result, context) {
|
|
|
1911
2063
|
const invocation = getEventServerFunctionInvocation(event);
|
|
1912
2064
|
const live = !!(invocation && invocation.live);
|
|
1913
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);
|
|
1914
2072
|
return serverComponentResponse(result, {
|
|
1915
2073
|
frame: {
|
|
1916
2074
|
id: invocation && invocation.id || ""
|
|
@@ -1922,6 +2080,269 @@ function frameTransformResult(event, result, context) {
|
|
|
1922
2080
|
}
|
|
1923
2081
|
}, init);
|
|
1924
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
|
+
}
|
|
1925
2346
|
function requestSignal(event) {
|
|
1926
2347
|
const request = event && event.request;
|
|
1927
2348
|
return request && request.signal instanceof AbortSignal ? request.signal : undefined;
|
|
@@ -2006,10 +2427,10 @@ function frameFlightResponse({
|
|
|
2006
2427
|
let closed = false;
|
|
2007
2428
|
const body = new ReadableStream({
|
|
2008
2429
|
async start(controller) {
|
|
2009
|
-
const write =
|
|
2430
|
+
const write = message => {
|
|
2010
2431
|
if (closed) return;
|
|
2011
2432
|
try {
|
|
2012
|
-
controller.enqueue(createChunk(JSON.stringify(
|
|
2433
|
+
controller.enqueue(createChunk(JSON.stringify(message)));
|
|
2013
2434
|
} catch (_) {
|
|
2014
2435
|
closed = true;
|
|
2015
2436
|
}
|