@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
|
@@ -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
|
|
@@ -294,8 +296,17 @@ const RECORDS = Symbol.for("@solidjs/signals/observe/records");
|
|
|
294
296
|
function records() {
|
|
295
297
|
return globalThis[RECORDS];
|
|
296
298
|
}
|
|
297
|
-
function
|
|
298
|
-
|
|
299
|
+
function frameRecordCensus(event, message, own) {
|
|
300
|
+
const r = message.r;
|
|
301
|
+
let counted = !r;
|
|
302
|
+
for (const key in r) {
|
|
303
|
+
if (key === ":complete" || key === ":bound") continue;
|
|
304
|
+
counted = true;
|
|
305
|
+
countEvent(event, key === "" ? "html" : key.endsWith(":error") ? "error" : key.startsWith("slot:") ? "slot" : key.startsWith("seg:") && r[key] && r[key].kind === "html" ? "fragment" : key, own);
|
|
306
|
+
}
|
|
307
|
+
if (counted) event.chunks++;
|
|
308
|
+
}
|
|
309
|
+
function countEvent(event, type, own) {
|
|
299
310
|
switch (type) {
|
|
300
311
|
case "html":
|
|
301
312
|
if (!own) event.regions++;else if (event.shellMs === undefined) event.shellMs = performance.now() - event.at;
|
|
@@ -330,9 +341,8 @@ function observeFrame(frame) {
|
|
|
330
341
|
};
|
|
331
342
|
let settled = false;
|
|
332
343
|
return {
|
|
333
|
-
chunk(
|
|
334
|
-
|
|
335
|
-
frameCensus(event, chunk.type, chunk.id === frame.id);
|
|
344
|
+
chunk(message) {
|
|
345
|
+
frameRecordCensus(event, message, message.id === frame.id);
|
|
336
346
|
},
|
|
337
347
|
settle(outcome, error) {
|
|
338
348
|
if (settled) return;
|
|
@@ -485,14 +495,41 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
485
495
|
} = frame;
|
|
486
496
|
const tiers = new Set();
|
|
487
497
|
let staged = [];
|
|
488
|
-
const
|
|
489
|
-
if (swept) swept.emitted = true;
|
|
498
|
+
const send = message => {
|
|
490
499
|
if (staged.length) {
|
|
491
|
-
|
|
500
|
+
message.tiers = staged;
|
|
492
501
|
staged = [];
|
|
493
502
|
}
|
|
494
|
-
write(
|
|
503
|
+
write(message);
|
|
504
|
+
};
|
|
505
|
+
let queue = [];
|
|
506
|
+
let open = null;
|
|
507
|
+
let scheduled = false;
|
|
508
|
+
const flush = () => {
|
|
509
|
+
scheduled = false;
|
|
510
|
+
open = null;
|
|
511
|
+
const out = queue;
|
|
512
|
+
queue = [];
|
|
513
|
+
for (const message of out) send(message);
|
|
495
514
|
};
|
|
515
|
+
const put = (fid, r) => {
|
|
516
|
+
if (swept) swept.emitted = true;
|
|
517
|
+
showing(r);
|
|
518
|
+
let merge = open && open.id === fid;
|
|
519
|
+
if (merge) for (const key in r) if (key in open.r) merge = false;
|
|
520
|
+
if (merge) Object.assign(open.r, r);else queue.push(open = {
|
|
521
|
+
id: fid,
|
|
522
|
+
version,
|
|
523
|
+
r
|
|
524
|
+
});
|
|
525
|
+
if (!scheduled) {
|
|
526
|
+
scheduled = true;
|
|
527
|
+
queueMicrotask(flush);
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
const putError = (fid, key, error) => put(fid, {
|
|
531
|
+
[key ? `${/^lha?:/.test(key) ? "hole" : "seg"}:${key}:error` : ":error"]: error
|
|
532
|
+
});
|
|
496
533
|
const needs = name => {
|
|
497
534
|
if (!tiers.has(name)) {
|
|
498
535
|
tiers.add(name);
|
|
@@ -502,36 +539,44 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
502
539
|
let conditional = false;
|
|
503
540
|
const skipped = new Set();
|
|
504
541
|
const attrText = new Map();
|
|
505
|
-
const
|
|
506
|
-
|
|
542
|
+
const holeDigest = new Map();
|
|
543
|
+
if (have) for (const key in have) key.startsWith("lh:") && holeDigest.set(key, have[key]);
|
|
544
|
+
function showing(r) {
|
|
545
|
+
if ("" in r) holeDigest.clear();
|
|
546
|
+
for (const k in r) {
|
|
547
|
+
const record = r[k];
|
|
548
|
+
if (k.startsWith("hole:lh:") && !k.endsWith(":error")) holeDigest.set(k.slice(5), record.digest);
|
|
549
|
+
if (record) for (const key in record.holes) key.startsWith("lh:") && holeDigest.set(key, record.holes[key]);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
const html = (value, digest, holes) => withHoles({
|
|
553
|
+
kind: "html",
|
|
554
|
+
value,
|
|
555
|
+
digest
|
|
556
|
+
}, holes);
|
|
557
|
+
const emitDiffering = source => {
|
|
558
|
+
for (const m of source.matchAll(HOLE_RANGE)) {
|
|
507
559
|
const key = "lh:" + m[1];
|
|
508
560
|
const digest = textDigest(stripHoleMarkers(m[2]));
|
|
509
561
|
if (have[key] === digest) continue;
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
version,
|
|
514
|
-
key,
|
|
515
|
-
html: m[2],
|
|
516
|
-
digest
|
|
517
|
-
}, holeDigests(m[2], null)));
|
|
562
|
+
put(id, {
|
|
563
|
+
["hole:" + key]: html(m[2], digest, holeDigests(m[2], null))
|
|
564
|
+
});
|
|
518
565
|
}
|
|
519
|
-
for (const m of
|
|
566
|
+
for (const m of source.matchAll(ATTR_ADDRESS)) {
|
|
520
567
|
const text = attrText.get("lha:" + m[1]);
|
|
521
568
|
if (text === undefined) continue;
|
|
522
569
|
const digest = textDigest(text);
|
|
523
570
|
if (have["lha:" + m[1]] === digest) continue;
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
digest
|
|
571
|
+
put(id, {
|
|
572
|
+
["attr:" + m[1]]: {
|
|
573
|
+
kind: "attrs",
|
|
574
|
+
value: text,
|
|
575
|
+
digest
|
|
576
|
+
}
|
|
531
577
|
});
|
|
532
578
|
}
|
|
533
579
|
};
|
|
534
|
-
const styledKeys = new Set();
|
|
535
580
|
const bindings = new Map();
|
|
536
581
|
const sweepMinted = new Set();
|
|
537
582
|
const argRefVersions = new Map();
|
|
@@ -542,34 +587,27 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
542
587
|
const sweep = () => {
|
|
543
588
|
epoch++;
|
|
544
589
|
const pass = swept = {
|
|
545
|
-
|
|
590
|
+
r: {},
|
|
546
591
|
emitted: false
|
|
547
592
|
};
|
|
548
593
|
try {
|
|
549
|
-
for (const b of [...bindings
|
|
594
|
+
for (const [key, b] of [...bindings]) {
|
|
595
|
+
if (bindings.get(key) !== b) continue;
|
|
550
596
|
try {
|
|
551
597
|
b.sweep();
|
|
552
598
|
} catch (_) {
|
|
553
599
|
}
|
|
554
600
|
}
|
|
555
|
-
|
|
601
|
+
for (const _ in pass.r) {
|
|
602
|
+
put(id, pass.r);
|
|
603
|
+
break;
|
|
604
|
+
}
|
|
605
|
+
flush();
|
|
556
606
|
if (pass.emitted && hooks && hooks.onYield) hooks.onYield();
|
|
557
607
|
} finally {
|
|
558
608
|
swept = null;
|
|
559
609
|
}
|
|
560
610
|
};
|
|
561
|
-
const emitOps = ops => {
|
|
562
|
-
if (ops.length === 1) emit(Object.assign({
|
|
563
|
-
type: ops[0].type,
|
|
564
|
-
id,
|
|
565
|
-
version
|
|
566
|
-
}, ops[0]));else if (ops.length) emit({
|
|
567
|
-
type: "ops",
|
|
568
|
-
id,
|
|
569
|
-
version,
|
|
570
|
-
ops
|
|
571
|
-
});
|
|
572
|
-
};
|
|
573
611
|
const scheduleSweep = () => {
|
|
574
612
|
if (closed || sweepScheduled || !bindings.size) return;
|
|
575
613
|
sweepScheduled = true;
|
|
@@ -584,52 +622,47 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
584
622
|
tagRegion(key, childId) {
|
|
585
623
|
if (!regionKeys.has(key)) regionKeys.set(key, childId);
|
|
586
624
|
},
|
|
587
|
-
shell(
|
|
588
|
-
const digest = textDigest(frameSkeleton(
|
|
625
|
+
shell(source, meta = {}) {
|
|
626
|
+
const digest = textDigest(frameSkeleton(source));
|
|
589
627
|
if (have && have[""] === digest) {
|
|
590
628
|
conditional = true;
|
|
591
|
-
emitDiffering(
|
|
629
|
+
emitDiffering(source);
|
|
592
630
|
return;
|
|
593
631
|
}
|
|
594
632
|
if (meta.preloads && meta.preloads.size || meta.preloadLinks) {
|
|
595
|
-
const
|
|
596
|
-
type: "assets",
|
|
597
|
-
id,
|
|
598
|
-
version,
|
|
599
|
-
key: ""
|
|
600
|
-
};
|
|
633
|
+
const record = {};
|
|
601
634
|
if (meta.preloads && meta.preloads.size) {
|
|
602
635
|
const styles = [];
|
|
603
636
|
const modules = [];
|
|
604
637
|
for (const url of meta.preloads) {
|
|
605
638
|
(url.endsWith(".css") ? styles : modules).push(url);
|
|
606
639
|
}
|
|
607
|
-
if (styles.length)
|
|
608
|
-
if (modules.length)
|
|
640
|
+
if (styles.length) record.styles = styles;
|
|
641
|
+
if (modules.length) record.modules = modules;
|
|
609
642
|
}
|
|
610
643
|
if (meta.preloadLinks) {
|
|
611
|
-
|
|
644
|
+
record.preloads = [];
|
|
612
645
|
for (const entry of meta.preloadLinks) {
|
|
613
|
-
|
|
646
|
+
record.preloads.push(wirePreload(entry));
|
|
614
647
|
}
|
|
615
648
|
}
|
|
616
649
|
needs("assets");
|
|
617
|
-
|
|
650
|
+
put(id, {
|
|
651
|
+
"seg::assets": record
|
|
652
|
+
});
|
|
618
653
|
}
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
version,
|
|
623
|
-
html,
|
|
624
|
-
digest
|
|
625
|
-
}, holeDigests(html, attrText)));
|
|
654
|
+
put(id, {
|
|
655
|
+
"": html(source, digest, holeDigests(source, attrText))
|
|
656
|
+
});
|
|
626
657
|
},
|
|
627
658
|
data(record) {
|
|
628
659
|
if (record && typeof record.key === "string" && (record.key.endsWith("_fr") || /^\d+$/.test(record.key))) {
|
|
629
660
|
return;
|
|
630
661
|
}
|
|
662
|
+
if (swept) swept.emitted = true;
|
|
663
|
+
flush();
|
|
631
664
|
if (typeof record === "string") {
|
|
632
|
-
|
|
665
|
+
send({
|
|
633
666
|
type: "data",
|
|
634
667
|
id,
|
|
635
668
|
version,
|
|
@@ -637,7 +670,7 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
637
670
|
});
|
|
638
671
|
scheduleSweep();
|
|
639
672
|
} else {
|
|
640
|
-
|
|
673
|
+
send({
|
|
641
674
|
type: "data",
|
|
642
675
|
id,
|
|
643
676
|
version,
|
|
@@ -654,73 +687,40 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
654
687
|
skipped.add(key);
|
|
655
688
|
scheduleSweep();
|
|
656
689
|
if (meta.error) {
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
id: fid,
|
|
660
|
-
version,
|
|
661
|
-
key,
|
|
662
|
-
error: {
|
|
663
|
-
message: String(meta.error && meta.error.message || meta.error)
|
|
664
|
-
}
|
|
690
|
+
putError(fid, key, {
|
|
691
|
+
message: String(meta.error && meta.error.message || meta.error)
|
|
665
692
|
});
|
|
666
693
|
} else emitDiffering(value);
|
|
667
694
|
return;
|
|
668
695
|
}
|
|
669
696
|
const links = meta.styles && meta.styles.links || [];
|
|
670
697
|
const inline = meta.styles && meta.styles.inline || [];
|
|
698
|
+
const r = {};
|
|
671
699
|
if (links.length || inline.length) {
|
|
672
|
-
|
|
673
|
-
const chunk = {
|
|
674
|
-
type: "assets",
|
|
675
|
-
id: fid,
|
|
676
|
-
version,
|
|
677
|
-
key
|
|
678
|
-
};
|
|
700
|
+
const record = {};
|
|
679
701
|
if (links.length) {
|
|
680
|
-
|
|
702
|
+
record.styles = links.map(e => typeof e === "string" ? e : e.attrs ? {
|
|
681
703
|
href: e.href,
|
|
682
704
|
attrs: e.attrs
|
|
683
705
|
} : e.href);
|
|
684
706
|
}
|
|
685
707
|
if (inline.length) {
|
|
686
|
-
|
|
708
|
+
record.inlineStyles = inline.map(e => ({
|
|
687
709
|
id: e.id,
|
|
688
710
|
content: e.content,
|
|
689
711
|
attrs: e.attrs
|
|
690
712
|
}));
|
|
691
713
|
}
|
|
692
714
|
needs("assets");
|
|
693
|
-
|
|
715
|
+
r[`seg:${key}:assets`] = record;
|
|
694
716
|
}
|
|
695
|
-
|
|
696
|
-
type: "fragment",
|
|
697
|
-
id: fid,
|
|
698
|
-
version,
|
|
699
|
-
key,
|
|
700
|
-
html: value,
|
|
701
|
-
digest: textDigest(value)
|
|
702
|
-
}, holeDigests(value, attrText)));
|
|
717
|
+
r[`seg:${key}`] = html(value, textDigest(value), holeDigests(value, attrText));
|
|
703
718
|
scheduleSweep();
|
|
704
|
-
if (meta.error) {
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
key,
|
|
710
|
-
error: {
|
|
711
|
-
message: String(meta.error && meta.error.message || meta.error)
|
|
712
|
-
}
|
|
713
|
-
});
|
|
714
|
-
}
|
|
715
|
-
if (!meta.revealGroup) {
|
|
716
|
-
emit({
|
|
717
|
-
type: "reveal",
|
|
718
|
-
id: fid,
|
|
719
|
-
version,
|
|
720
|
-
keys: [key],
|
|
721
|
-
waitForStyles: !!links.length
|
|
722
|
-
});
|
|
723
|
-
}
|
|
719
|
+
if (meta.error) r[`seg:${key}:error`] = {
|
|
720
|
+
message: String(meta.error && meta.error.message || meta.error)
|
|
721
|
+
};
|
|
722
|
+
if (!meta.revealGroup) r[`seg:${key}:reveal`] = true;
|
|
723
|
+
put(fid, r);
|
|
724
724
|
},
|
|
725
725
|
reveal(keys, meta = {}) {
|
|
726
726
|
const byFrame = new Map();
|
|
@@ -731,38 +731,27 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
731
731
|
if (!group) byFrame.set(fid, group = []);
|
|
732
732
|
group.push(key);
|
|
733
733
|
}
|
|
734
|
+
const gate = meta.fallback ? "fallback" : "reveal";
|
|
734
735
|
for (const [fid, groupKeys] of byFrame) {
|
|
735
|
-
|
|
736
|
-
for (const key of groupKeys)
|
|
737
|
-
|
|
738
|
-
type: "reveal",
|
|
739
|
-
id: fid,
|
|
740
|
-
version,
|
|
741
|
-
keys: groupKeys,
|
|
742
|
-
waitForStyles
|
|
743
|
-
};
|
|
744
|
-
if (meta.fallback) chunk.fallback = true;
|
|
745
|
-
emit(chunk);
|
|
736
|
+
const r = {};
|
|
737
|
+
for (const key of groupKeys) r[`seg:${key}:${gate}`] = true;
|
|
738
|
+
put(fid, r);
|
|
746
739
|
}
|
|
747
740
|
},
|
|
748
741
|
asset(type, value) {
|
|
749
742
|
if (type === "module") {
|
|
750
743
|
needs("assets");
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
key: "",
|
|
756
|
-
modules: [value]
|
|
744
|
+
put(id, {
|
|
745
|
+
"seg::assets": {
|
|
746
|
+
modules: [value]
|
|
747
|
+
}
|
|
757
748
|
});
|
|
758
749
|
} else if (type === "preload") {
|
|
759
750
|
needs("assets");
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
key: "",
|
|
765
|
-
preloads: [wirePreload(value)]
|
|
751
|
+
put(id, {
|
|
752
|
+
"seg::assets": {
|
|
753
|
+
preloads: [wirePreload(value)]
|
|
754
|
+
}
|
|
766
755
|
});
|
|
767
756
|
}
|
|
768
757
|
},
|
|
@@ -770,64 +759,76 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
770
759
|
if (closed) return;
|
|
771
760
|
if (bindings.size && !swept) sweep();
|
|
772
761
|
closed = true;
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
762
|
+
put(id, bound ? {
|
|
763
|
+
":complete": true,
|
|
764
|
+
":bound": bound
|
|
765
|
+
} : {
|
|
766
|
+
":complete": true
|
|
767
|
+
});
|
|
768
|
+
flush();
|
|
780
769
|
},
|
|
781
770
|
error(errorId, error) {
|
|
782
|
-
|
|
783
|
-
type: "error",
|
|
784
|
-
id,
|
|
785
|
-
version,
|
|
786
|
-
key: errorId,
|
|
787
|
-
error
|
|
788
|
-
});
|
|
771
|
+
putError(id, errorId, error);
|
|
789
772
|
},
|
|
773
|
+
flush,
|
|
790
774
|
slot(key, args) {
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
775
|
+
const r = {
|
|
776
|
+
[`slot:${key}`]: {
|
|
777
|
+
kind: "slot",
|
|
778
|
+
args
|
|
779
|
+
}
|
|
780
|
+
};
|
|
781
|
+
swept ? Object.assign(swept.r, r) : put(id, r);
|
|
798
782
|
},
|
|
799
|
-
region(childId,
|
|
783
|
+
region(childId, value) {
|
|
800
784
|
needs("regions");
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
785
|
+
put(childId, {
|
|
786
|
+
"": {
|
|
787
|
+
kind: "html",
|
|
788
|
+
value
|
|
789
|
+
}
|
|
806
790
|
});
|
|
807
791
|
},
|
|
808
|
-
hole(key,
|
|
809
|
-
const
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
html,
|
|
813
|
-
digest: textDigest(html)
|
|
792
|
+
hole(key, source, rows) {
|
|
793
|
+
const record = {
|
|
794
|
+
kind: "html",
|
|
795
|
+
digest: textDigest(source)
|
|
814
796
|
};
|
|
815
|
-
|
|
797
|
+
const base = holeDigest.get(key);
|
|
798
|
+
if (rows && base && hooks && hooks.live) {
|
|
799
|
+
record.rows = rows;
|
|
800
|
+
record.base = base;
|
|
801
|
+
} else record.value = source;
|
|
802
|
+
withHoles(record, holeDigests(record.rows ? rows.r.map(r => r[1]).join("") : source, null));
|
|
803
|
+
if (record.rows && hooks && hooks.retain) record[HOLE_SOURCE] = withHoles({
|
|
804
|
+
kind: "html",
|
|
805
|
+
value: source,
|
|
806
|
+
digest: record.digest
|
|
807
|
+
}, holeDigests(source, null));
|
|
808
|
+
const r = {
|
|
809
|
+
["hole:" + key]: record
|
|
810
|
+
};
|
|
811
|
+
showing(r);
|
|
812
|
+
swept ? Object.assign(swept.r, r) : put(id, r);
|
|
816
813
|
},
|
|
817
814
|
attr(key, attrs, removed) {
|
|
818
|
-
const
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
attrs,
|
|
815
|
+
const record = {
|
|
816
|
+
kind: "attrs",
|
|
817
|
+
value: attrs,
|
|
822
818
|
digest: textDigest(attrs)
|
|
823
819
|
};
|
|
824
|
-
if (removed && removed.length)
|
|
825
|
-
|
|
820
|
+
if (removed && removed.length) record.removed = removed;
|
|
821
|
+
const r = {
|
|
822
|
+
["attr:" + key]: record
|
|
823
|
+
};
|
|
824
|
+
swept ? Object.assign(swept.r, r) : put(id, r);
|
|
826
825
|
},
|
|
827
826
|
attrBaseline(key, text) {
|
|
828
827
|
attrText.set(key, text);
|
|
828
|
+
if (hooks && hooks.retain) hooks.retain(key, text);
|
|
829
829
|
},
|
|
830
830
|
openBinding(key, b) {
|
|
831
|
+
if (/^lha?:/.test(key)) needs("wire");
|
|
831
832
|
bindings.set(key, b);
|
|
832
833
|
},
|
|
833
834
|
closeBinding(key) {
|
|
@@ -860,8 +861,9 @@ function renderServerComponent(component, options = {}) {
|
|
|
860
861
|
if (ctx) {
|
|
861
862
|
ctx.commit = sink.commit;
|
|
862
863
|
ctx.commitEpoch = () => sink.epoch;
|
|
863
|
-
|
|
864
|
-
ctx.
|
|
864
|
+
let unsettled = !!options.live;
|
|
865
|
+
if (!unsettled) ctx.unsettled = () => void (unsettled = true);
|
|
866
|
+
ctx.liveHoles = createLiveHoles(sink, false, () => !unsettled, ctx._errorScope);
|
|
865
867
|
}
|
|
866
868
|
return serverComponentScope(() => component(props));
|
|
867
869
|
};
|
|
@@ -894,6 +896,7 @@ function frameStream(makeCode, options) {
|
|
|
894
896
|
function finish() {
|
|
895
897
|
if (ended) return;
|
|
896
898
|
ended = true;
|
|
899
|
+
sink.flush();
|
|
897
900
|
if (timer) clearTimeout(timer);
|
|
898
901
|
if (upstream) upstream.removeEventListener("abort", onSignal);
|
|
899
902
|
w.end && w.end();
|
|
@@ -914,19 +917,21 @@ function frameStream(makeCode, options) {
|
|
|
914
917
|
finish();
|
|
915
918
|
render.abort(upstream.reason);
|
|
916
919
|
}
|
|
917
|
-
const emit =
|
|
918
|
-
if (observation) observation.chunk(
|
|
919
|
-
w.write(
|
|
920
|
-
if (bounded && !flushed &&
|
|
920
|
+
const emit = message => {
|
|
921
|
+
if (observation) observation.chunk(message);
|
|
922
|
+
w.write(message);
|
|
923
|
+
if (bounded && !flushed && message.id === id && message.r && "" in message.r) {
|
|
921
924
|
flushed = true;
|
|
922
925
|
if (maxDurationMs > 0 && maxDurationMs !== Infinity) timer = setTimeout(() => cut("time"), maxDurationMs);
|
|
923
926
|
}
|
|
924
927
|
};
|
|
925
|
-
const sink = createFrameSink(emit, frame, options.resume && options.resume.have,
|
|
926
|
-
|
|
928
|
+
const sink = createFrameSink(emit, frame, options.resume && options.resume.have, {
|
|
929
|
+
live: options.live,
|
|
930
|
+
retain: options.broadcast,
|
|
931
|
+
onYield: bounded ? () => {
|
|
927
932
|
if (flushed && maxYields > 0 && ++yields >= maxYields) cut("yields");
|
|
928
|
-
}
|
|
929
|
-
}
|
|
933
|
+
} : undefined
|
|
934
|
+
});
|
|
930
935
|
if (options.live) sink.needs("wire");
|
|
931
936
|
w.write({
|
|
932
937
|
type: "start",
|
|
@@ -961,6 +966,7 @@ function frameStream(makeCode, options) {
|
|
|
961
966
|
finish();
|
|
962
967
|
}
|
|
963
968
|
if (w[ANNOUNCE]) w[ANNOUNCE](sink.announce());
|
|
969
|
+
sink.flush();
|
|
964
970
|
}
|
|
965
971
|
return {
|
|
966
972
|
pipe: stream,
|
|
@@ -982,56 +988,21 @@ function frameStream(makeCode, options) {
|
|
|
982
988
|
function slotRange(occurrence) {
|
|
983
989
|
return {
|
|
984
990
|
t: `<!--slot:${occurrence}:start--><!--slot:${occurrence}:end-->`,
|
|
985
|
-
$slot: true
|
|
986
|
-
$occurrence: occurrence
|
|
991
|
+
$slot: true
|
|
987
992
|
};
|
|
988
993
|
}
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
function isRangeKey(key) {
|
|
992
|
-
const c = key.charCodeAt(0);
|
|
993
|
-
return c === 36 || c >= 48 && c <= 57 || RANGE_KEYS.has(key);
|
|
994
|
-
}
|
|
995
|
-
function slotProxy(range, occurrence, face, content, onData, needs) {
|
|
996
|
-
return new Proxy(range, {
|
|
997
|
-
get(target, key, receiver) {
|
|
998
|
-
if (typeof key !== "string" || isRangeKey(key)) return Reflect.get(target, key, receiver);
|
|
999
|
-
if (onData) onData = void onData();
|
|
1000
|
-
if (face !== SLOT_FACE_MARKUP) needs("bind");
|
|
1001
|
-
return slotValue(occurrence, key, content ? content[key] : undefined, face);
|
|
1002
|
-
}
|
|
1003
|
-
});
|
|
1004
|
-
}
|
|
1005
|
-
function argBorderForm(value, key, occurrence, needs) {
|
|
1006
|
-
return toBorderForm(withoutStandIns(value, key, occurrence, needs));
|
|
994
|
+
function argBorderForm(value, needs) {
|
|
995
|
+
return toBorderForm(noteTraces(value, needs));
|
|
1007
996
|
}
|
|
1008
|
-
function
|
|
1009
|
-
return rewriteTree(value,
|
|
997
|
+
function noteTraces(value, needs) {
|
|
998
|
+
return rewriteTree(value, v => {
|
|
1010
999
|
if (isContainerTraced(v)) {
|
|
1011
1000
|
needs("trace");
|
|
1012
1001
|
return v;
|
|
1013
1002
|
}
|
|
1014
|
-
if (Object.getPrototypeOf(v) === Object.prototype && isSlotValue(v)) {
|
|
1015
|
-
return undefined;
|
|
1016
|
-
}
|
|
1017
1003
|
return DESCEND;
|
|
1018
1004
|
}, true);
|
|
1019
1005
|
}
|
|
1020
|
-
function slotFace(range, content) {
|
|
1021
|
-
if (content == null) return SLOT_FACE_DATA;
|
|
1022
|
-
if (typeof content !== "object" || Array.isArray(content)) return SLOT_FACE_MARKUP;
|
|
1023
|
-
if (isServerContent(content)) {
|
|
1024
|
-
let data = false;
|
|
1025
|
-
for (const key in content) {
|
|
1026
|
-
if (!NODE_KEYS.has(key)) {
|
|
1027
|
-
data = true;
|
|
1028
|
-
break;
|
|
1029
|
-
}
|
|
1030
|
-
}
|
|
1031
|
-
if (!data) return SLOT_FACE_MARKUP;
|
|
1032
|
-
}
|
|
1033
|
-
return SLOT_FACE_DATA;
|
|
1034
|
-
}
|
|
1035
1006
|
const OCCURRENCE_UNSAFE = /[^A-Za-z0-9_.-]/g;
|
|
1036
1007
|
function encodeOccurrenceKey(key) {
|
|
1037
1008
|
return String(key).replace(OCCURRENCE_UNSAFE, c => {
|
|
@@ -1086,12 +1057,19 @@ function structuralArgsKey(raw) {
|
|
|
1086
1057
|
};
|
|
1087
1058
|
return walk(raw, true) ? out : undefined;
|
|
1088
1059
|
}
|
|
1089
|
-
function
|
|
1090
|
-
const
|
|
1091
|
-
if (
|
|
1092
|
-
|
|
1093
|
-
|
|
1060
|
+
function argDigest(value) {
|
|
1061
|
+
const t = typeof value;
|
|
1062
|
+
if (value == null || t !== "object" && t !== "function" && value === value) return value;
|
|
1063
|
+
if (isContainerTraced(value)) return value;
|
|
1064
|
+
try {
|
|
1065
|
+
const key = structuralArgsKey([value]);
|
|
1066
|
+
return key === undefined ? value : key;
|
|
1067
|
+
} catch (_) {
|
|
1068
|
+
return value;
|
|
1069
|
+
}
|
|
1094
1070
|
}
|
|
1071
|
+
const PENDING_ARG = {};
|
|
1072
|
+
const noDigest = () => NaN;
|
|
1095
1073
|
function isAsyncValue(v) {
|
|
1096
1074
|
return !!v && typeof v === "object" && (typeof v.then === "function" || typeof v[Symbol.asyncIterator] === "function");
|
|
1097
1075
|
}
|
|
@@ -1107,6 +1085,37 @@ function tapFirstYield(iterable) {
|
|
|
1107
1085
|
rest
|
|
1108
1086
|
};
|
|
1109
1087
|
}
|
|
1088
|
+
function packOccurrences(occs) {
|
|
1089
|
+
const out = [];
|
|
1090
|
+
let prop = "",
|
|
1091
|
+
a = -1,
|
|
1092
|
+
b = -1;
|
|
1093
|
+
const flush = () => a >= 0 && out.push(prop + "#" + (a === b ? a : a + "-" + b));
|
|
1094
|
+
for (const o of occs) {
|
|
1095
|
+
const m = /^(.*)#(\d+)$/.exec(o);
|
|
1096
|
+
if (m && m[1] === prop && +m[2] === b + 1 && a >= 0) {
|
|
1097
|
+
b++;
|
|
1098
|
+
continue;
|
|
1099
|
+
}
|
|
1100
|
+
flush();
|
|
1101
|
+
a = b = -1;
|
|
1102
|
+
if (m) {
|
|
1103
|
+
prop = m[1];
|
|
1104
|
+
a = b = +m[2];
|
|
1105
|
+
} else out.push(o);
|
|
1106
|
+
}
|
|
1107
|
+
flush();
|
|
1108
|
+
return out.join(" ");
|
|
1109
|
+
}
|
|
1110
|
+
function hasAsyncHoles(node, depth = 0) {
|
|
1111
|
+
if (!node || typeof node !== "object" || depth > 64) return false;
|
|
1112
|
+
if (Array.isArray(node)) {
|
|
1113
|
+
for (const n of node) if (hasAsyncHoles(n, depth + 1)) return true;
|
|
1114
|
+
return false;
|
|
1115
|
+
}
|
|
1116
|
+
if (node.h && node.h.length) return true;
|
|
1117
|
+
return false;
|
|
1118
|
+
}
|
|
1110
1119
|
function suppressedFill(render) {
|
|
1111
1120
|
const live = sharedConfig.context && sharedConfig.context.liveHoles;
|
|
1112
1121
|
if (!live) return render();
|
|
@@ -1117,25 +1126,96 @@ function suppressedFill(render) {
|
|
|
1117
1126
|
live.suppressed--;
|
|
1118
1127
|
}
|
|
1119
1128
|
}
|
|
1129
|
+
let parked = null;
|
|
1130
|
+
let parkedIds = 0;
|
|
1131
|
+
const PARKED = /<!--sc-n:(\d+)-->/;
|
|
1132
|
+
function park(render) {
|
|
1133
|
+
if (!parked) return render();
|
|
1134
|
+
const id = ++parkedIds;
|
|
1135
|
+
parked.set(id, {
|
|
1136
|
+
render,
|
|
1137
|
+
out: undefined
|
|
1138
|
+
});
|
|
1139
|
+
return {
|
|
1140
|
+
t: `<!--sc-n:${id}-->`
|
|
1141
|
+
};
|
|
1142
|
+
}
|
|
1143
|
+
const runParked = (entry, owner) => entry.out || (entry.out = entry.render(owner));
|
|
1144
|
+
function placeParked(node, nested, owner) {
|
|
1145
|
+
const out = expandParked(node, nested, owner);
|
|
1146
|
+
for (const entry of nested.values()) runParked(entry, owner);
|
|
1147
|
+
return out;
|
|
1148
|
+
}
|
|
1149
|
+
function expandParked(node, nested, owner) {
|
|
1150
|
+
if (Array.isArray(node)) {
|
|
1151
|
+
const out = node.map(n => expandParked(n, nested, owner));
|
|
1152
|
+
out.$slot = node.$slot;
|
|
1153
|
+
return out;
|
|
1154
|
+
}
|
|
1155
|
+
if (!node || node.t === undefined) return node;
|
|
1156
|
+
if (!node.h) return splitParked(node.t, nested, owner) || node;
|
|
1157
|
+
const out = [];
|
|
1158
|
+
node.t.forEach((t, i) => {
|
|
1159
|
+
out.push(splitParked(t, nested, owner) || {
|
|
1160
|
+
t
|
|
1161
|
+
});
|
|
1162
|
+
if (i < node.h.length) out.push({
|
|
1163
|
+
t: ["", ""],
|
|
1164
|
+
h: [node.h[i]],
|
|
1165
|
+
p: [node.p[i]]
|
|
1166
|
+
});
|
|
1167
|
+
});
|
|
1168
|
+
return out;
|
|
1169
|
+
}
|
|
1170
|
+
function splitParked(t, nested, owner) {
|
|
1171
|
+
const parts = typeof t === "string" ? t.split(PARKED) : [t];
|
|
1172
|
+
return parts.length > 1 ? parts.map((part, i) => i & 1 ? runParked(nested.get(+part), owner) : {
|
|
1173
|
+
t: part
|
|
1174
|
+
}) : undefined;
|
|
1175
|
+
}
|
|
1120
1176
|
function createDocumentSlotProps(clientProps, frameId) {
|
|
1121
1177
|
const counts = Object.create(null);
|
|
1178
|
+
let depsBatch = null;
|
|
1179
|
+
let depsN = 0;
|
|
1180
|
+
let wideSent = 0;
|
|
1181
|
+
const depsContext = sharedConfig.context;
|
|
1182
|
+
const noteDeps = (occurrence, reads, untracked) => {
|
|
1183
|
+
if (!depsContext || !depsContext.serialize || !depsContext.edges) return;
|
|
1184
|
+
const own = `sc-${frameId}-${occurrence}-`;
|
|
1185
|
+
const batch = () => {
|
|
1186
|
+
if (depsBatch) return depsBatch;
|
|
1187
|
+
queueMicrotask(() => {
|
|
1188
|
+
const b = {};
|
|
1189
|
+
for (const sid in depsBatch) b[sid] = packOccurrences(depsBatch[sid]);
|
|
1190
|
+
depsBatch = null;
|
|
1191
|
+
const wide = depsContext.edgeWide?.s || null;
|
|
1192
|
+
if (wide && wide.size > wideSent) {
|
|
1193
|
+
b["*"] = [...wide].slice(wideSent).join(" ");
|
|
1194
|
+
wideSent = wide.size;
|
|
1195
|
+
}
|
|
1196
|
+
if (depsN === 0 || Object.keys(b).length) depsContext.serialize(`sc:deps:${frameId}:${depsN++}`, b);
|
|
1197
|
+
});
|
|
1198
|
+
return depsBatch = Object.create(null);
|
|
1199
|
+
};
|
|
1200
|
+
const b = batch();
|
|
1201
|
+
if (reads) for (const sid of reads) if (!sid.startsWith(own)) (b[sid] ||= []).push(occurrence);
|
|
1202
|
+
if (untracked) (b["!"] ||= []).push(occurrence);
|
|
1203
|
+
};
|
|
1122
1204
|
const getters = new Map();
|
|
1123
1205
|
const repeats = new Map();
|
|
1124
|
-
const range = (occurrence, content) => {
|
|
1206
|
+
const range = (occurrence, content, tail) => {
|
|
1125
1207
|
const r = [{
|
|
1126
1208
|
t: `<!--slot:${occurrence}:start-->`
|
|
1127
|
-
}, content, {
|
|
1209
|
+
}, content, tail, {
|
|
1128
1210
|
t: `<!--slot:${occurrence}:end-->`
|
|
1129
1211
|
}];
|
|
1130
1212
|
r.$slot = true;
|
|
1131
|
-
r
|
|
1132
|
-
const face = slotFace(r, content);
|
|
1133
|
-
r.$face = face;
|
|
1134
|
-
return slotProxy(r, occurrence, face, face === SLOT_FACE_DATA ? content : undefined, undefined, documentNeeds);
|
|
1213
|
+
return r;
|
|
1135
1214
|
};
|
|
1136
1215
|
const zoneOwner = getOwner ? getOwner() : null;
|
|
1137
|
-
const scoped = (occurrence, render) => {
|
|
1216
|
+
const scoped = (occurrence, render, owner) => {
|
|
1138
1217
|
const id = `sc-${frameId}-${occurrence}-`;
|
|
1218
|
+
if (owner) return runWithOwner(owner, () => runWithHydrationScope(id, render));
|
|
1139
1219
|
const run = () => Hydration ? Hydration({
|
|
1140
1220
|
id,
|
|
1141
1221
|
get children() {
|
|
@@ -1155,18 +1235,13 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1155
1235
|
if (!fn) {
|
|
1156
1236
|
fn = (...callArgs) => {
|
|
1157
1237
|
if (callArgs.length === 0 || callArgs[0] === undefined) {
|
|
1158
|
-
|
|
1159
|
-
const repeat = repeats.get(rk);
|
|
1160
|
-
if (repeat) return repeat;
|
|
1161
|
-
const out = suppressedFill(() => scoped(prop, () => {
|
|
1238
|
+
return park(owner => suppressedFill(() => scoped(prop, () => {
|
|
1162
1239
|
const value = clientProps[prop];
|
|
1163
1240
|
return range(prop, typeof value === "function" ? value() : value);
|
|
1164
|
-
}));
|
|
1165
|
-
if (out.$face === SLOT_FACE_DATA) repeats.set(rk, out);
|
|
1166
|
-
return out;
|
|
1241
|
+
}, owner)));
|
|
1167
1242
|
}
|
|
1168
1243
|
const raw = callArgs[0];
|
|
1169
|
-
const rk =
|
|
1244
|
+
const rk = keyedId(prop, raw);
|
|
1170
1245
|
const repeat = rk !== undefined && repeats.get(rk);
|
|
1171
1246
|
if (repeat) return repeat;
|
|
1172
1247
|
const occurrence = occurrenceId(prop, raw, counts);
|
|
@@ -1174,10 +1249,10 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1174
1249
|
if (typeof slot !== "function") return range(occurrence, undefined);
|
|
1175
1250
|
const context = sharedConfig.context;
|
|
1176
1251
|
const recordKey = `sc:slot:${frameId}:${occurrence}`;
|
|
1252
|
+
const deferred = !!parked;
|
|
1177
1253
|
let settleRecord;
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
}
|
|
1254
|
+
const declare = () => context && context.async && context.serialize(recordKey, new Promise(resolve => settleRecord = resolve));
|
|
1255
|
+
deferred || declare();
|
|
1181
1256
|
try {
|
|
1182
1257
|
const resolved = {};
|
|
1183
1258
|
const liveArgs = sharedConfig.context && sharedConfig.context.live && sharedConfig.context.live.args;
|
|
@@ -1185,6 +1260,7 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1185
1260
|
const evals = {};
|
|
1186
1261
|
const states = {};
|
|
1187
1262
|
const minted = {};
|
|
1263
|
+
const nestedOf = {};
|
|
1188
1264
|
for (const key of Object.keys(raw)) {
|
|
1189
1265
|
if (key === "$key") continue;
|
|
1190
1266
|
const desc = Object.getOwnPropertyDescriptor(raw, key);
|
|
@@ -1203,6 +1279,8 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1203
1279
|
if (evaluate) {
|
|
1204
1280
|
evals[key] = evaluate;
|
|
1205
1281
|
const stampBefore = scopeStamp();
|
|
1282
|
+
const outer = parked;
|
|
1283
|
+
const nested = nestedOf[key] = parked = new Map();
|
|
1206
1284
|
try {
|
|
1207
1285
|
value = evaluate();
|
|
1208
1286
|
states[key] = {
|
|
@@ -1210,6 +1288,9 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1210
1288
|
last: value
|
|
1211
1289
|
};
|
|
1212
1290
|
} catch (err) {
|
|
1291
|
+
parked = outer;
|
|
1292
|
+
for (const entry of nested.values()) runParked(entry);
|
|
1293
|
+
nested.clear();
|
|
1213
1294
|
const blocked = ssrHandleError && ssrHandleError(err);
|
|
1214
1295
|
if (!blocked) throw err;
|
|
1215
1296
|
const state = states[key] = {
|
|
@@ -1222,6 +1303,7 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1222
1303
|
if (liveArgs) liveArgs.commit();
|
|
1223
1304
|
});
|
|
1224
1305
|
}
|
|
1306
|
+
parked = outer;
|
|
1225
1307
|
if (scopeStamp() !== stampBefore) minted[key] = true;
|
|
1226
1308
|
}
|
|
1227
1309
|
vals[key] = value;
|
|
@@ -1238,6 +1320,7 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1238
1320
|
key,
|
|
1239
1321
|
childId,
|
|
1240
1322
|
value,
|
|
1323
|
+
nested: nestedOf[key],
|
|
1241
1324
|
used: false,
|
|
1242
1325
|
locked: false
|
|
1243
1326
|
};
|
|
@@ -1248,7 +1331,7 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1248
1331
|
region.used = true;
|
|
1249
1332
|
return [{
|
|
1250
1333
|
t: frameElementOpen(childId)
|
|
1251
|
-
}, value, {
|
|
1334
|
+
}, region.nested && region.nested.size ? placeParked(value, region.nested, getOwner()) : value, {
|
|
1252
1335
|
t: FRAME_ELEMENT_CLOSE
|
|
1253
1336
|
}];
|
|
1254
1337
|
};
|
|
@@ -1269,49 +1352,67 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1269
1352
|
configurable: true
|
|
1270
1353
|
});
|
|
1271
1354
|
} else {
|
|
1272
|
-
resolved[key] = vals[key] =
|
|
1355
|
+
resolved[key] = vals[key] = noteTraces(value, documentNeeds);
|
|
1273
1356
|
}
|
|
1274
1357
|
}
|
|
1275
|
-
const
|
|
1276
|
-
const
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
for (const
|
|
1280
|
-
|
|
1281
|
-
const region = regions.find(r => r.key === key);
|
|
1282
|
-
if (region) {
|
|
1283
|
-
args[key] = {
|
|
1284
|
-
$frame: region.childId
|
|
1285
|
-
};
|
|
1286
|
-
continue;
|
|
1287
|
-
}
|
|
1288
|
-
if (!isContainerTraced(value) && isServerContent(value)) continue;
|
|
1289
|
-
args[key] = argBorderForm(value, key, occurrence, documentNeeds);
|
|
1290
|
-
}
|
|
1291
|
-
settleRecord ? settleRecord({
|
|
1292
|
-
...args
|
|
1293
|
-
}) : context.serialize(recordKey, {
|
|
1294
|
-
...args
|
|
1295
|
-
});
|
|
1296
|
-
for (const region of unused) {
|
|
1358
|
+
for (const key in nestedOf) if (!regions.some(r => r.key === key)) for (const entry of nestedOf[key].values()) runParked(entry);
|
|
1359
|
+
const flip = () => {
|
|
1360
|
+
if (flip.done || !context) return;
|
|
1361
|
+
flip.done = true;
|
|
1362
|
+
for (const region of regions) {
|
|
1363
|
+
if (region.used) continue;
|
|
1297
1364
|
region.locked = true;
|
|
1298
|
-
context.serialize(`sc:region:${region.childId}`, resolveRegionHtml(context, region.value));
|
|
1365
|
+
context.serialize(`sc:region:${region.childId}`, resolveRegionHtml(context, region.nested && region.nested.size ? placeParked(region.value, region.nested) : region.value));
|
|
1299
1366
|
}
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1367
|
+
};
|
|
1368
|
+
flip.$lhSkip = true;
|
|
1369
|
+
const finish = owner => {
|
|
1370
|
+
if (deferred) declare();
|
|
1371
|
+
try {
|
|
1372
|
+
const tracked = trackFillReads(() => suppressedFill(() => scoped(occurrence, () => range(occurrence, slot(resolved), flip), owner)));
|
|
1373
|
+
const out = tracked.result;
|
|
1374
|
+
noteDeps(occurrence, tracked.reads, tracked.untracked || hasAsyncHoles(out));
|
|
1375
|
+
if (context) {
|
|
1376
|
+
const args = {};
|
|
1377
|
+
for (const key of Object.keys(vals)) {
|
|
1378
|
+
const value = vals[key];
|
|
1379
|
+
const region = regions.find(r => r.key === key);
|
|
1380
|
+
if (region) {
|
|
1381
|
+
args[key] = {
|
|
1382
|
+
$frame: region.childId
|
|
1383
|
+
};
|
|
1384
|
+
continue;
|
|
1385
|
+
}
|
|
1386
|
+
if (!isContainerTraced(value) && isServerContent(value)) continue;
|
|
1387
|
+
args[key] = argBorderForm(value, documentNeeds);
|
|
1388
|
+
}
|
|
1389
|
+
settleRecord ? settleRecord({
|
|
1390
|
+
...args
|
|
1391
|
+
}) : context.serialize(recordKey, {
|
|
1392
|
+
...args
|
|
1310
1393
|
});
|
|
1394
|
+
if (liveArgs) {
|
|
1395
|
+
for (const key of Object.keys(evals)) {
|
|
1396
|
+
if (regions.some(r => r.key === key)) continue;
|
|
1397
|
+
if (minted[key]) continue;
|
|
1398
|
+
const ledgerKey = `${frameId}:${occurrence}:${key}`;
|
|
1399
|
+
openArgBinding(liveArgs, ledgerKey, occurrence, key, evals[key], states[key], value => {
|
|
1400
|
+
args[key] = argBorderForm(value, documentNeeds);
|
|
1401
|
+
liveArgs.slot(frameId, occurrence, {
|
|
1402
|
+
...args
|
|
1403
|
+
});
|
|
1404
|
+
});
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1311
1407
|
}
|
|
1408
|
+
return out;
|
|
1409
|
+
} catch (error) {
|
|
1410
|
+
settleRecord && settleRecord(undefined);
|
|
1411
|
+
throw error;
|
|
1312
1412
|
}
|
|
1313
|
-
}
|
|
1314
|
-
|
|
1413
|
+
};
|
|
1414
|
+
const out = park(finish);
|
|
1415
|
+
if (rk !== undefined && rk === occurrence) repeats.has(rk) || repeats.set(rk, out);
|
|
1315
1416
|
return out;
|
|
1316
1417
|
} catch (error) {
|
|
1317
1418
|
settleRecord && settleRecord(undefined);
|
|
@@ -1327,9 +1428,10 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1327
1428
|
}
|
|
1328
1429
|
const FRAME_TAG = "solid-frame";
|
|
1329
1430
|
const FRAME_ID_ATTR = "data-fid";
|
|
1330
|
-
|
|
1431
|
+
const FRAME_ARGS_ATTR = "data-fa";
|
|
1432
|
+
function frameElementOpen(id, args) {
|
|
1331
1433
|
const escaped = sharedConfig.context ? sharedConfig.context.escape(String(id), true) : String(id);
|
|
1332
|
-
return `<${FRAME_TAG} ${FRAME_ID_ATTR}="${escaped}" style="display:contents">`;
|
|
1434
|
+
return `<${FRAME_TAG} ${FRAME_ID_ATTR}="${escaped}"${args ? ` ${FRAME_ARGS_ATTR}="${args}"` : ""} style="display:contents">`;
|
|
1333
1435
|
}
|
|
1334
1436
|
const DOCUMENT_SITES = Symbol();
|
|
1335
1437
|
function contextSites(ctx) {
|
|
@@ -1381,6 +1483,7 @@ function armDocumentLiveHoles(ctx) {
|
|
|
1381
1483
|
if (live.holes) {
|
|
1382
1484
|
ctx.commit = live.commit;
|
|
1383
1485
|
ctx.commitEpoch = live.commitEpoch;
|
|
1486
|
+
ctx.unsettled = live.unsettled;
|
|
1384
1487
|
}
|
|
1385
1488
|
return;
|
|
1386
1489
|
}
|
|
@@ -1389,6 +1492,7 @@ function armDocumentLiveHoles(ctx) {
|
|
|
1389
1492
|
if (live) live.holes = null;
|
|
1390
1493
|
return;
|
|
1391
1494
|
}
|
|
1495
|
+
let unsettled = false;
|
|
1392
1496
|
const bindings = new Map();
|
|
1393
1497
|
let epoch = 0;
|
|
1394
1498
|
let sweepScheduled = false;
|
|
@@ -1396,7 +1500,7 @@ function armDocumentLiveHoles(ctx) {
|
|
|
1396
1500
|
let swept = null;
|
|
1397
1501
|
const sweep = () => {
|
|
1398
1502
|
epoch++;
|
|
1399
|
-
const
|
|
1503
|
+
const r = swept = {};
|
|
1400
1504
|
try {
|
|
1401
1505
|
for (const b of [...bindings.values()]) {
|
|
1402
1506
|
try {
|
|
@@ -1407,12 +1511,8 @@ function armDocumentLiveHoles(ctx) {
|
|
|
1407
1511
|
} finally {
|
|
1408
1512
|
swept = null;
|
|
1409
1513
|
}
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
const pushOps = ops => {
|
|
1413
|
-
if (ops.length === 1) push(ops[0]);else if (ops.length) push({
|
|
1414
|
-
type: "ops",
|
|
1415
|
-
ops
|
|
1514
|
+
for (const _ in r) return push({
|
|
1515
|
+
r
|
|
1416
1516
|
});
|
|
1417
1517
|
};
|
|
1418
1518
|
const scheduleSweep = () => {
|
|
@@ -1432,49 +1532,57 @@ function armDocumentLiveHoles(ctx) {
|
|
|
1432
1532
|
closed = true;
|
|
1433
1533
|
}
|
|
1434
1534
|
}));
|
|
1435
|
-
const push =
|
|
1436
|
-
if (!closed) channel.enqueue(
|
|
1535
|
+
const push = batch => {
|
|
1536
|
+
if (!closed) channel.enqueue(batch);
|
|
1437
1537
|
};
|
|
1538
|
+
const write = r => swept ? Object.assign(swept, r) : push({
|
|
1539
|
+
r
|
|
1540
|
+
});
|
|
1438
1541
|
ctx.liveHoles = live.holes = createLiveHoles({
|
|
1439
1542
|
openBinding(key, b) {
|
|
1543
|
+
documentNeeds("wire");
|
|
1440
1544
|
bindings.set(key, b);
|
|
1441
1545
|
},
|
|
1442
1546
|
closeBinding(key) {
|
|
1443
1547
|
bindings.delete(key);
|
|
1444
1548
|
},
|
|
1445
|
-
hole(key,
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1549
|
+
hole(key, value) {
|
|
1550
|
+
write({
|
|
1551
|
+
["hole:" + key]: {
|
|
1552
|
+
kind: "html",
|
|
1553
|
+
value,
|
|
1554
|
+
digest: textDigest(value)
|
|
1555
|
+
}
|
|
1556
|
+
});
|
|
1453
1557
|
},
|
|
1454
|
-
attr(key,
|
|
1455
|
-
const
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
digest: textDigest(attrs)
|
|
1558
|
+
attr(key, value, removed) {
|
|
1559
|
+
const record = {
|
|
1560
|
+
kind: "attrs",
|
|
1561
|
+
value,
|
|
1562
|
+
digest: textDigest(value)
|
|
1460
1563
|
};
|
|
1461
|
-
if (removed && removed.length)
|
|
1462
|
-
|
|
1564
|
+
if (removed && removed.length) record.removed = removed;
|
|
1565
|
+
write({
|
|
1566
|
+
["attr:" + key]: record
|
|
1567
|
+
});
|
|
1463
1568
|
},
|
|
1464
1569
|
error(key, error) {
|
|
1465
1570
|
push({
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1571
|
+
r: {
|
|
1572
|
+
[`hole:${key}:error`]: error
|
|
1573
|
+
}
|
|
1469
1574
|
});
|
|
1470
1575
|
},
|
|
1471
1576
|
commit: scheduleSweep,
|
|
1472
1577
|
get epoch() {
|
|
1473
1578
|
return epoch;
|
|
1474
1579
|
}
|
|
1475
|
-
}, true);
|
|
1580
|
+
}, true, () => !unsettled, ctx._errorScope);
|
|
1476
1581
|
ctx.commit = live.commit = scheduleSweep;
|
|
1477
1582
|
ctx.commitEpoch = live.commitEpoch = () => epoch;
|
|
1583
|
+
ctx.unsettled = live.unsettled = () => {
|
|
1584
|
+
unsettled = true;
|
|
1585
|
+
};
|
|
1478
1586
|
live.args = {
|
|
1479
1587
|
openBinding(key, b) {
|
|
1480
1588
|
bindings.set(key, b);
|
|
@@ -1484,19 +1592,23 @@ function armDocumentLiveHoles(ctx) {
|
|
|
1484
1592
|
},
|
|
1485
1593
|
slot(fid, occurrence, args) {
|
|
1486
1594
|
push({
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1595
|
+
r: {
|
|
1596
|
+
[`slot:${occurrence}`]: {
|
|
1597
|
+
kind: "slot",
|
|
1598
|
+
args
|
|
1599
|
+
}
|
|
1600
|
+
},
|
|
1601
|
+
fid
|
|
1491
1602
|
});
|
|
1492
1603
|
},
|
|
1493
1604
|
commit: scheduleSweep
|
|
1494
1605
|
};
|
|
1495
1606
|
live.error = (fid, error) => {
|
|
1496
1607
|
push({
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1608
|
+
r: {
|
|
1609
|
+
":error": error
|
|
1610
|
+
},
|
|
1611
|
+
fid
|
|
1500
1612
|
});
|
|
1501
1613
|
};
|
|
1502
1614
|
live.end = () => {
|
|
@@ -1513,17 +1625,17 @@ function frameTransformDirectResult(value, {
|
|
|
1513
1625
|
}) {
|
|
1514
1626
|
if (typeof value !== "function") return value;
|
|
1515
1627
|
const component = value;
|
|
1628
|
+
const address = frameAddress(id, args);
|
|
1516
1629
|
const wrapped = props => {
|
|
1517
1630
|
const siteId = documentSiteId(id);
|
|
1518
1631
|
return [{
|
|
1519
|
-
t: frameElementOpen(siteId)
|
|
1632
|
+
t: frameElementOpen(siteId, address.slice(id.length + 1))
|
|
1520
1633
|
},
|
|
1521
1634
|
serverOwned(() => {
|
|
1522
1635
|
const page = sharedConfig.context;
|
|
1523
1636
|
armDocumentLiveHoles(page);
|
|
1524
1637
|
if (tierUrls && page && page.live && !page.live.tierUrls) page.live.tierUrls = tierUrls;
|
|
1525
1638
|
const ctx = Object.create(page);
|
|
1526
|
-
ctx.claims = CLAIMS_DOCUMENT;
|
|
1527
1639
|
ctx.frameId = siteId;
|
|
1528
1640
|
sharedConfig.context = ctx;
|
|
1529
1641
|
try {
|
|
@@ -1540,7 +1652,7 @@ function frameTransformDirectResult(value, {
|
|
|
1540
1652
|
};
|
|
1541
1653
|
wrapped[SERVER_COMPONENT] = id;
|
|
1542
1654
|
wrapped[SERVER_COMPONENT_SOURCE] = component;
|
|
1543
|
-
wrapped[SERVER_COMPONENT_ADDRESS] =
|
|
1655
|
+
wrapped[SERVER_COMPONENT_ADDRESS] = address;
|
|
1544
1656
|
return wrapped;
|
|
1545
1657
|
}
|
|
1546
1658
|
function resolveRegionHtml(ctx, node) {
|
|
@@ -1643,6 +1755,15 @@ function createSlotProps(sink, frame) {
|
|
|
1643
1755
|
const counts = Object.create(null);
|
|
1644
1756
|
const getters = new Map();
|
|
1645
1757
|
const repeats = new Map();
|
|
1758
|
+
let pass = null;
|
|
1759
|
+
let passRepeats = null;
|
|
1760
|
+
const recs = new Map();
|
|
1761
|
+
const forget = occurrence => {
|
|
1762
|
+
const rec = recs.get(occurrence);
|
|
1763
|
+
if (!rec) return;
|
|
1764
|
+
recs.delete(occurrence);
|
|
1765
|
+
for (const key in rec.vals) sink.closeBinding(`${occurrence}:${key}`);
|
|
1766
|
+
};
|
|
1646
1767
|
const needs = sink.needs || (() => {});
|
|
1647
1768
|
return new Proxy(Object.create(null), {
|
|
1648
1769
|
has() {
|
|
@@ -1655,25 +1776,38 @@ function createSlotProps(sink, frame) {
|
|
|
1655
1776
|
if (!fn) {
|
|
1656
1777
|
fn = (...callArgs) => {
|
|
1657
1778
|
if (callArgs.length === 0 || callArgs[0] === undefined) {
|
|
1658
|
-
return
|
|
1779
|
+
return slotRange(prop);
|
|
1659
1780
|
}
|
|
1660
|
-
const rk = repeatKey(prop, callArgs[0]);
|
|
1661
|
-
const repeat = rk !== undefined && repeats.get(rk);
|
|
1662
|
-
if (repeat) return repeat;
|
|
1663
1781
|
const live = sharedConfig.context && sharedConfig.context.liveHoles;
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1782
|
+
const sweeping = !!live && live.sweeping;
|
|
1783
|
+
let rmap = repeats;
|
|
1784
|
+
if (sweeping) {
|
|
1785
|
+
if (pass !== live.visit) passRepeats = new Map();
|
|
1786
|
+
pass = live.visit;
|
|
1787
|
+
rmap = passRepeats;
|
|
1788
|
+
}
|
|
1789
|
+
const rk = keyedId(prop, callArgs[0]);
|
|
1790
|
+
const repeat = rk !== undefined && rmap.get(rk);
|
|
1791
|
+
if (repeat) return repeat;
|
|
1792
|
+
if (sweeping && !live.scope) {
|
|
1793
|
+
live.gateHit = true;
|
|
1794
|
+
return {
|
|
1795
|
+
t: "",
|
|
1796
|
+
$slot: true
|
|
1797
|
+
};
|
|
1673
1798
|
}
|
|
1674
1799
|
const raw = callArgs[0];
|
|
1675
|
-
|
|
1800
|
+
let occurrence = keyedId(prop, raw);
|
|
1801
|
+
if (occurrence === undefined) {
|
|
1802
|
+
const positional = sweeping ? undefined : occurrenceId(prop, raw, counts);
|
|
1803
|
+
occurrence = live ? live.slotId(prop, positional) : positional;
|
|
1804
|
+
}
|
|
1805
|
+
if (sweeping && live.dry) return slotRange(occurrence);
|
|
1806
|
+
const prev = recs.get(occurrence);
|
|
1807
|
+
let changed = !prev;
|
|
1808
|
+
const digest = live && live.scope ? argDigest : noDigest;
|
|
1676
1809
|
const args = {};
|
|
1810
|
+
const vals = {};
|
|
1677
1811
|
const opened = [];
|
|
1678
1812
|
for (const key of Object.keys(raw)) {
|
|
1679
1813
|
if (key === "$key") continue;
|
|
@@ -1689,6 +1823,7 @@ function createSlotProps(sink, frame) {
|
|
|
1689
1823
|
let evaluate = null;
|
|
1690
1824
|
let value;
|
|
1691
1825
|
let state = null;
|
|
1826
|
+
let pending = false;
|
|
1692
1827
|
const stampBefore = scopeStamp();
|
|
1693
1828
|
try {
|
|
1694
1829
|
if (desc.get) {
|
|
@@ -1710,6 +1845,7 @@ function createSlotProps(sink, frame) {
|
|
|
1710
1845
|
settled: false,
|
|
1711
1846
|
last: undefined
|
|
1712
1847
|
};
|
|
1848
|
+
pending = true;
|
|
1713
1849
|
const pendingState = state;
|
|
1714
1850
|
value = retryArgUntilSettled(evaluate, blocked, key, occurrence, v => {
|
|
1715
1851
|
pendingState.settled = true;
|
|
@@ -1721,6 +1857,7 @@ function createSlotProps(sink, frame) {
|
|
|
1721
1857
|
const t = typeof value;
|
|
1722
1858
|
if (value == null || t === "string" || t === "number" || t === "boolean") {
|
|
1723
1859
|
args[key] = value;
|
|
1860
|
+
vals[key] = digest(value);
|
|
1724
1861
|
if (evaluate) state = {
|
|
1725
1862
|
settled: true,
|
|
1726
1863
|
last: value
|
|
@@ -1730,21 +1867,27 @@ function createSlotProps(sink, frame) {
|
|
|
1730
1867
|
if (resolved.h.length) {
|
|
1731
1868
|
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.");
|
|
1732
1869
|
}
|
|
1733
|
-
|
|
1870
|
+
vals[key] = "<" + resolved.t[0];
|
|
1871
|
+
if (!prev || prev.vals[key] !== vals[key]) sink.region(childId, resolved.t[0]);
|
|
1734
1872
|
args[key] = {
|
|
1735
1873
|
$frame: childId
|
|
1736
1874
|
};
|
|
1737
1875
|
} else {
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1876
|
+
vals[key] = pending ? PENDING_ARG : digest(value);
|
|
1877
|
+
if (prev && prev.vals[key] === vals[key]) args[key] = prev.args[key];else {
|
|
1878
|
+
const ref = prev ? `arg:${occurrence}:${key}@${sink.nextArgRef(`${occurrence}:${key}`)}` : `arg:${occurrence}:${key}`;
|
|
1879
|
+
if (prev) sink.mintRef(ref);
|
|
1880
|
+
ctx.serialize(ref, argBorderForm(value, needs));
|
|
1881
|
+
args[key] = {
|
|
1882
|
+
$ref: ref
|
|
1883
|
+
};
|
|
1884
|
+
}
|
|
1743
1885
|
if (evaluate && !state) state = {
|
|
1744
1886
|
settled: true,
|
|
1745
1887
|
last: value
|
|
1746
1888
|
};
|
|
1747
1889
|
}
|
|
1890
|
+
if (prev && prev.vals[key] !== vals[key]) changed = true;
|
|
1748
1891
|
if (evaluate && state && !mintedEval) opened.push({
|
|
1749
1892
|
key,
|
|
1750
1893
|
evaluate,
|
|
@@ -1754,9 +1897,18 @@ function createSlotProps(sink, frame) {
|
|
|
1754
1897
|
ctx.registerFragment = origRegister;
|
|
1755
1898
|
}
|
|
1756
1899
|
}
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1900
|
+
if (prev) for (const key in prev.vals) if (!(key in vals)) changed = true;
|
|
1901
|
+
const rec = changed ? {
|
|
1902
|
+
args,
|
|
1903
|
+
vals
|
|
1904
|
+
} : prev;
|
|
1905
|
+
if (changed) {
|
|
1906
|
+
recs.set(occurrence, rec);
|
|
1907
|
+
sink.slot(occurrence, {
|
|
1908
|
+
...args
|
|
1909
|
+
});
|
|
1910
|
+
}
|
|
1911
|
+
if (live && live.visit) live.seen(occurrence, () => recs.get(occurrence) === rec && forget(occurrence));
|
|
1760
1912
|
const ctx = sharedConfig.context;
|
|
1761
1913
|
for (const b of opened) {
|
|
1762
1914
|
const key = b.key;
|
|
@@ -1764,23 +1916,23 @@ function createSlotProps(sink, frame) {
|
|
|
1764
1916
|
openArgBinding(sink, ledgerKey, occurrence, key, b.evaluate, b.state, value => {
|
|
1765
1917
|
const t = typeof value;
|
|
1766
1918
|
if (value == null || t === "string" || t === "number" || t === "boolean") {
|
|
1767
|
-
args[key] = value;
|
|
1919
|
+
rec.args[key] = value;
|
|
1768
1920
|
} else {
|
|
1769
1921
|
const ref = `arg:${occurrence}:${key}@${sink.nextArgRef(ledgerKey)}`;
|
|
1770
1922
|
sink.mintRef(ref);
|
|
1771
|
-
ctx.serialize(ref, argBorderForm(value,
|
|
1772
|
-
args[key] = {
|
|
1923
|
+
ctx.serialize(ref, argBorderForm(value, needs));
|
|
1924
|
+
rec.args[key] = {
|
|
1773
1925
|
$ref: ref
|
|
1774
1926
|
};
|
|
1775
1927
|
}
|
|
1928
|
+
rec.vals[key] = digest(value);
|
|
1776
1929
|
sink.slot(occurrence, {
|
|
1777
|
-
...args
|
|
1930
|
+
...rec.args
|
|
1778
1931
|
});
|
|
1779
1932
|
});
|
|
1780
1933
|
}
|
|
1781
|
-
const
|
|
1782
|
-
|
|
1783
|
-
if (keyed) repeats.set(rk, out);
|
|
1934
|
+
const out = slotRange(occurrence);
|
|
1935
|
+
if (rk !== undefined && rk === occurrence) rmap.set(rk, out);
|
|
1784
1936
|
return out;
|
|
1785
1937
|
};
|
|
1786
1938
|
fn.$lhSkip = true;
|
|
@@ -1845,11 +1997,11 @@ function serverComponentResponse(component, options = {}, init = {}) {
|
|
|
1845
1997
|
teardown.abort();
|
|
1846
1998
|
});
|
|
1847
1999
|
stream.pipe({
|
|
1848
|
-
write(
|
|
1849
|
-
if (
|
|
2000
|
+
write(message) {
|
|
2001
|
+
if (message.r && ":error" in message.r) failed = true;
|
|
1850
2002
|
if (closed) return;
|
|
1851
2003
|
try {
|
|
1852
|
-
controller.enqueue(frame(JSON.stringify(
|
|
2004
|
+
controller.enqueue(frame(JSON.stringify(message)));
|
|
1853
2005
|
} catch (_) {
|
|
1854
2006
|
closed = true;
|
|
1855
2007
|
}
|
|
@@ -1912,6 +2064,12 @@ function frameTransformResult(event, result, context) {
|
|
|
1912
2064
|
const invocation = getEventServerFunctionInvocation(event);
|
|
1913
2065
|
const live = !!(invocation && invocation.live);
|
|
1914
2066
|
const have = live ? decodeHaveList(requestHeader(event, FRAME_HAVE_HEADER)) : undefined;
|
|
2067
|
+
if (live && invocation.broadcast && invocation.shareKey !== undefined) return broadcastResponse(invocation.id + "\0" + invocation.shareKey, result, {
|
|
2068
|
+
frame: {
|
|
2069
|
+
id: invocation.id || ""
|
|
2070
|
+
},
|
|
2071
|
+
live: true
|
|
2072
|
+
}, requestSignal(event), have, init);
|
|
1915
2073
|
return serverComponentResponse(result, {
|
|
1916
2074
|
frame: {
|
|
1917
2075
|
id: invocation && invocation.id || ""
|
|
@@ -1923,6 +2081,269 @@ function frameTransformResult(event, result, context) {
|
|
|
1923
2081
|
}
|
|
1924
2082
|
}, init);
|
|
1925
2083
|
}
|
|
2084
|
+
const HOLE_SOURCE = Symbol("solid.frames.holeSource");
|
|
2085
|
+
const BROADCASTS = new Map();
|
|
2086
|
+
function broadcastResponse(key, component, options, signal, have, init) {
|
|
2087
|
+
let shared = BROADCASTS.get(key);
|
|
2088
|
+
if (!shared || shared.ended) shared = startBroadcast(key, component, options);
|
|
2089
|
+
return tapResponse(shared, signal, have, init);
|
|
2090
|
+
}
|
|
2091
|
+
function startBroadcast(key, component, options) {
|
|
2092
|
+
const shared = {
|
|
2093
|
+
key,
|
|
2094
|
+
id: options.frame.id,
|
|
2095
|
+
start: null,
|
|
2096
|
+
taps: new Set(),
|
|
2097
|
+
records: new Map(),
|
|
2098
|
+
data: [],
|
|
2099
|
+
kept: 0,
|
|
2100
|
+
attrs: new Map(),
|
|
2101
|
+
tiers: new Set(["wire"]),
|
|
2102
|
+
failed: false,
|
|
2103
|
+
ended: false,
|
|
2104
|
+
teardown: new AbortController()
|
|
2105
|
+
};
|
|
2106
|
+
BROADCASTS.set(key, shared);
|
|
2107
|
+
const stream = renderServerComponent(component, {
|
|
2108
|
+
...options,
|
|
2109
|
+
broadcast: (key, text) => shared.attrs.set(key, text),
|
|
2110
|
+
signal: shared.teardown.signal
|
|
2111
|
+
});
|
|
2112
|
+
const run = () => stream.pipe({
|
|
2113
|
+
write(message) {
|
|
2114
|
+
const bytes = createEventChunk(JSON.stringify(message));
|
|
2115
|
+
if (message.type === "start") return void (shared.start = bytes);
|
|
2116
|
+
retain(shared, message);
|
|
2117
|
+
for (const tap of shared.taps) tap.write(bytes);
|
|
2118
|
+
},
|
|
2119
|
+
end() {
|
|
2120
|
+
shared.ended = true;
|
|
2121
|
+
if (BROADCASTS.get(key) === shared) BROADCASTS.delete(key);
|
|
2122
|
+
for (const tap of [...shared.taps]) tap.end();
|
|
2123
|
+
},
|
|
2124
|
+
[ANNOUNCE](tiers) {
|
|
2125
|
+
for (const tier of tiers) shared.tiers.add(tier);
|
|
2126
|
+
}
|
|
2127
|
+
});
|
|
2128
|
+
const store = globalThis[RequestContext];
|
|
2129
|
+
store ? store.run(broadcastEvent(), run) : run();
|
|
2130
|
+
return shared;
|
|
2131
|
+
}
|
|
2132
|
+
function broadcastEvent() {
|
|
2133
|
+
const event = {
|
|
2134
|
+
broadcast: true
|
|
2135
|
+
};
|
|
2136
|
+
for (const name of ["request", "locals", "clientAddress", "nativeEvent"]) Object.defineProperty(event, name, {
|
|
2137
|
+
get() {
|
|
2138
|
+
return undefined;
|
|
2139
|
+
}
|
|
2140
|
+
});
|
|
2141
|
+
return event;
|
|
2142
|
+
}
|
|
2143
|
+
function retain(shared, message) {
|
|
2144
|
+
if (message.tiers) for (const tier of message.tiers) shared.tiers.add(tier);
|
|
2145
|
+
if (!message.r) {
|
|
2146
|
+
shared.data.push(message);
|
|
2147
|
+
if (shared.data.length > 64 && shared.data.length > 2 * shared.kept) shared.kept = (shared.data = referencedData(shared)).length;
|
|
2148
|
+
return;
|
|
2149
|
+
}
|
|
2150
|
+
const {
|
|
2151
|
+
id,
|
|
2152
|
+
version
|
|
2153
|
+
} = message;
|
|
2154
|
+
for (const k in message.r) {
|
|
2155
|
+
let record = message.r[k];
|
|
2156
|
+
if (k === ":error") shared.failed = true;
|
|
2157
|
+
if (k === "") for (const [rk, e] of shared.records) if (e.id === id) shared.records.delete(rk);
|
|
2158
|
+
if (record && record[HOLE_SOURCE]) record = record[HOLE_SOURCE];
|
|
2159
|
+
const rk = id + "\0" + k;
|
|
2160
|
+
const prev = shared.records.get(rk);
|
|
2161
|
+
if (prev && record && record.kind === "attrs" && prev.record.removed) {
|
|
2162
|
+
const removed = new Set(prev.record.removed);
|
|
2163
|
+
if (record.removed) for (const name of record.removed) removed.add(name);
|
|
2164
|
+
record = {
|
|
2165
|
+
...record,
|
|
2166
|
+
removed: [...removed]
|
|
2167
|
+
};
|
|
2168
|
+
}
|
|
2169
|
+
shared.records.delete(rk);
|
|
2170
|
+
shared.records.set(rk, {
|
|
2171
|
+
id,
|
|
2172
|
+
version,
|
|
2173
|
+
k,
|
|
2174
|
+
record
|
|
2175
|
+
});
|
|
2176
|
+
}
|
|
2177
|
+
}
|
|
2178
|
+
function referencedData(shared) {
|
|
2179
|
+
const refs = new Set();
|
|
2180
|
+
for (const {
|
|
2181
|
+
record
|
|
2182
|
+
} 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]}"`));
|
|
2183
|
+
return shared.data.filter(m => typeof m.key !== "string" || refs.has(m.key));
|
|
2184
|
+
}
|
|
2185
|
+
function snapshot(shared, have) {
|
|
2186
|
+
const out = referencedData(shared);
|
|
2187
|
+
const root = shared.records.get(shared.id + "\0");
|
|
2188
|
+
const conditional = !!(have && root && root.record && have[""] === root.record.digest);
|
|
2189
|
+
let open = null;
|
|
2190
|
+
const put = (id, version, k, record) => {
|
|
2191
|
+
if (!open || open.id !== id) out.push(open = {
|
|
2192
|
+
id,
|
|
2193
|
+
version,
|
|
2194
|
+
r: {}
|
|
2195
|
+
});
|
|
2196
|
+
open.r[k] = record;
|
|
2197
|
+
};
|
|
2198
|
+
if (!conditional) {
|
|
2199
|
+
for (const {
|
|
2200
|
+
id,
|
|
2201
|
+
version,
|
|
2202
|
+
k,
|
|
2203
|
+
record
|
|
2204
|
+
} of shared.records.values()) put(id, version, k, record);
|
|
2205
|
+
return out;
|
|
2206
|
+
}
|
|
2207
|
+
const containers = [];
|
|
2208
|
+
for (const e of shared.records.values()) if (e.id === shared.id && (e.k === "" || /^seg:[^:]+$/.test(e.k)) && e.record) containers.push({
|
|
2209
|
+
e,
|
|
2210
|
+
value: e.record.value
|
|
2211
|
+
});
|
|
2212
|
+
for (const {
|
|
2213
|
+
k,
|
|
2214
|
+
record
|
|
2215
|
+
} of shared.records.values()) {
|
|
2216
|
+
if (!k.startsWith("hole:lh:") || k.endsWith(":error") || !record || record.value == null) continue;
|
|
2217
|
+
const n = k.slice(8);
|
|
2218
|
+
const startMark = `<!--lh:${n}-->`;
|
|
2219
|
+
const endMark = `<!--lh:/${n}-->`;
|
|
2220
|
+
for (const c of containers) {
|
|
2221
|
+
const start = c.value.indexOf(startMark);
|
|
2222
|
+
if (start < 0) continue;
|
|
2223
|
+
const end = c.value.indexOf(endMark, start);
|
|
2224
|
+
if (end < 0) continue;
|
|
2225
|
+
c.value = c.value.slice(0, start + startMark.length) + record.value + c.value.slice(end);
|
|
2226
|
+
break;
|
|
2227
|
+
}
|
|
2228
|
+
}
|
|
2229
|
+
for (const e of shared.records.values()) {
|
|
2230
|
+
const {
|
|
2231
|
+
id,
|
|
2232
|
+
version,
|
|
2233
|
+
k,
|
|
2234
|
+
record
|
|
2235
|
+
} = e;
|
|
2236
|
+
if (id !== shared.id) {
|
|
2237
|
+
put(id, version, k, record);
|
|
2238
|
+
continue;
|
|
2239
|
+
}
|
|
2240
|
+
if (k === "" || k === "seg::assets" || k.startsWith("hole:lh:") && !k.endsWith(":error")) continue;
|
|
2241
|
+
const seg = /^seg:([^:]+)(?::(.*))?$/.exec(k);
|
|
2242
|
+
if (seg && have[seg[1]] !== undefined && seg[2] !== "error") continue;
|
|
2243
|
+
if (seg && seg[2] === undefined) {
|
|
2244
|
+
const c = containers.find(c => c.e === e);
|
|
2245
|
+
if (c && c.value !== record.value) {
|
|
2246
|
+
put(id, version, k, withHoles({
|
|
2247
|
+
...record,
|
|
2248
|
+
value: c.value,
|
|
2249
|
+
digest: textDigest(c.value)
|
|
2250
|
+
}, holeDigests(c.value, null)));
|
|
2251
|
+
continue;
|
|
2252
|
+
}
|
|
2253
|
+
}
|
|
2254
|
+
if (k.startsWith("attr:")) continue;
|
|
2255
|
+
put(id, version, k, record);
|
|
2256
|
+
}
|
|
2257
|
+
for (const c of containers) {
|
|
2258
|
+
const seg = c.e.k && /^seg:([^:]+)$/.exec(c.e.k);
|
|
2259
|
+
if (seg && have[seg[1]] === undefined) continue;
|
|
2260
|
+
for (const m of c.value.matchAll(HOLE_RANGE)) {
|
|
2261
|
+
const key = "lh:" + m[1];
|
|
2262
|
+
const digest = textDigest(stripHoleMarkers(m[2]));
|
|
2263
|
+
if (have[key] === digest) continue;
|
|
2264
|
+
put(shared.id, c.e.version, "hole:" + key, withHoles({
|
|
2265
|
+
kind: "html",
|
|
2266
|
+
value: m[2],
|
|
2267
|
+
digest
|
|
2268
|
+
}, holeDigests(m[2], null)));
|
|
2269
|
+
}
|
|
2270
|
+
for (const m of c.value.matchAll(ATTR_ADDRESS)) {
|
|
2271
|
+
const latest = shared.records.get(shared.id + "\0attr:" + m[1]);
|
|
2272
|
+
const text = latest ? latest.record.value : shared.attrs.get("lha:" + m[1]);
|
|
2273
|
+
if (text === undefined) continue;
|
|
2274
|
+
const digest = latest ? latest.record.digest : textDigest(text);
|
|
2275
|
+
if (have["lha:" + m[1]] === digest) continue;
|
|
2276
|
+
put(shared.id, c.e.version, "attr:" + m[1], latest ? latest.record : {
|
|
2277
|
+
kind: "attrs",
|
|
2278
|
+
value: text,
|
|
2279
|
+
digest
|
|
2280
|
+
});
|
|
2281
|
+
}
|
|
2282
|
+
}
|
|
2283
|
+
return out;
|
|
2284
|
+
}
|
|
2285
|
+
function tapResponse(shared, signal, have, init = {}) {
|
|
2286
|
+
const headers = copyInitHeaders(init.headers);
|
|
2287
|
+
headers.set(FRAME_STREAM_HEADER, shared.id);
|
|
2288
|
+
headers.set("X-Content-Raw", "1");
|
|
2289
|
+
headers.set("Content-Type", "text/event-stream");
|
|
2290
|
+
headers.set("Cache-Control", "no-store");
|
|
2291
|
+
headers.set("X-Accel-Buffering", "no");
|
|
2292
|
+
headers.set(FRAME_TIERS_HEADER, [...shared.tiers].join(","));
|
|
2293
|
+
let closed = false;
|
|
2294
|
+
let stopLive = null;
|
|
2295
|
+
let tap = null;
|
|
2296
|
+
const leave = () => {
|
|
2297
|
+
if (closed) return;
|
|
2298
|
+
closed = true;
|
|
2299
|
+
if (stopLive) stopLive();
|
|
2300
|
+
if (signal) signal.removeEventListener("abort", leave);
|
|
2301
|
+
shared.taps.delete(tap);
|
|
2302
|
+
if (!shared.taps.size && !shared.ended) {
|
|
2303
|
+
shared.ended = true;
|
|
2304
|
+
if (BROADCASTS.get(shared.key) === shared) BROADCASTS.delete(shared.key);
|
|
2305
|
+
shared.teardown.abort({
|
|
2306
|
+
[DISCONNECTED]: true
|
|
2307
|
+
});
|
|
2308
|
+
}
|
|
2309
|
+
};
|
|
2310
|
+
const body = new ReadableStream({
|
|
2311
|
+
start(controller) {
|
|
2312
|
+
tap = {
|
|
2313
|
+
write(bytes) {
|
|
2314
|
+
if (closed) return;
|
|
2315
|
+
try {
|
|
2316
|
+
controller.enqueue(bytes);
|
|
2317
|
+
} catch (_) {
|
|
2318
|
+
leave();
|
|
2319
|
+
}
|
|
2320
|
+
},
|
|
2321
|
+
end() {
|
|
2322
|
+
leave();
|
|
2323
|
+
try {
|
|
2324
|
+
controller.close();
|
|
2325
|
+
} catch (_) {}
|
|
2326
|
+
}
|
|
2327
|
+
};
|
|
2328
|
+
if (shared.start) controller.enqueue(shared.start);
|
|
2329
|
+
for (const message of snapshot(shared, have)) controller.enqueue(createEventChunk(JSON.stringify(message)));
|
|
2330
|
+
if (shared.ended || signal && signal.aborted) return tap.end();
|
|
2331
|
+
shared.taps.add(tap);
|
|
2332
|
+
stopLive = armLiveBody(controller, leave);
|
|
2333
|
+
if (signal) signal.addEventListener("abort", leave, {
|
|
2334
|
+
once: true
|
|
2335
|
+
});
|
|
2336
|
+
},
|
|
2337
|
+
cancel() {
|
|
2338
|
+
leave();
|
|
2339
|
+
}
|
|
2340
|
+
});
|
|
2341
|
+
if (shared.failed) headers.set("Cache-Control", "no-store");
|
|
2342
|
+
return new Response(body, {
|
|
2343
|
+
status: init.status || 200,
|
|
2344
|
+
headers
|
|
2345
|
+
});
|
|
2346
|
+
}
|
|
1926
2347
|
function requestSignal(event) {
|
|
1927
2348
|
const request = event && event.request;
|
|
1928
2349
|
return request && request.signal instanceof AbortSignal ? request.signal : undefined;
|
|
@@ -2007,10 +2428,10 @@ function frameFlightResponse({
|
|
|
2007
2428
|
let closed = false;
|
|
2008
2429
|
const body = new ReadableStream({
|
|
2009
2430
|
async start(controller) {
|
|
2010
|
-
const write =
|
|
2431
|
+
const write = message => {
|
|
2011
2432
|
if (closed) return;
|
|
2012
2433
|
try {
|
|
2013
|
-
controller.enqueue(createChunk(JSON.stringify(
|
|
2434
|
+
controller.enqueue(createChunk(JSON.stringify(message)));
|
|
2014
2435
|
} catch (_) {
|
|
2015
2436
|
closed = true;
|
|
2016
2437
|
}
|