@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 {
|
|
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';
|
|
@@ -186,15 +186,6 @@ const ContainerTracePlugin = {
|
|
|
186
186
|
}
|
|
187
187
|
};
|
|
188
188
|
|
|
189
|
-
function emitFinding(finding, subject = getOwner()) {
|
|
190
|
-
if (OBSERVE === undefined) return;
|
|
191
|
-
const entry = OBSERVE.diagnostics.emit(finding, subject);
|
|
192
|
-
if (DEV !== undefined) DEV.report(entry);
|
|
193
|
-
}
|
|
194
|
-
function devCheck(finding, subject) {
|
|
195
|
-
emitFinding(finding, subject);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
189
|
setContainerTraceStreamMint(iterable => {
|
|
199
190
|
const stream = createStream();
|
|
200
191
|
(async () => {
|
|
@@ -216,14 +207,16 @@ function resolveSerializerPlugins(customPlugins) {
|
|
|
216
207
|
}
|
|
217
208
|
const jsonCodecDisabledFeatures = () => Feature.RegExp;
|
|
218
209
|
const JSON_CODEC_DEPTH_LIMIT = 64;
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
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;
|
|
225
218
|
return {
|
|
226
|
-
plugins: resolveSerializerPlugins(plugins),
|
|
219
|
+
plugins: options[RESOLVED_PLUGINS] || resolveSerializerPlugins(plugins),
|
|
227
220
|
disabledFeatures: disabledFeatures === undefined ? jsonCodecDisabledFeatures() : disabledFeatures,
|
|
228
221
|
depthLimit: depthLimit === undefined ? JSON_CODEC_DEPTH_LIMIT : depthLimit,
|
|
229
222
|
serializeErrorStacks
|
|
@@ -303,8 +296,17 @@ const RECORDS = Symbol.for("@solidjs/signals/observe/records");
|
|
|
303
296
|
function records() {
|
|
304
297
|
return globalThis[RECORDS];
|
|
305
298
|
}
|
|
306
|
-
function
|
|
307
|
-
|
|
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) {
|
|
308
310
|
switch (type) {
|
|
309
311
|
case "html":
|
|
310
312
|
if (!own) event.regions++;else if (event.shellMs === undefined) event.shellMs = performance.now() - event.at;
|
|
@@ -339,9 +341,8 @@ function observeFrame(frame) {
|
|
|
339
341
|
};
|
|
340
342
|
let settled = false;
|
|
341
343
|
return {
|
|
342
|
-
chunk(
|
|
343
|
-
|
|
344
|
-
frameCensus(event, chunk.type, chunk.id === frame.id);
|
|
344
|
+
chunk(message) {
|
|
345
|
+
frameRecordCensus(event, message, message.id === frame.id);
|
|
345
346
|
},
|
|
346
347
|
settle(outcome, error) {
|
|
347
348
|
if (settled) return;
|
|
@@ -494,14 +495,41 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
494
495
|
} = frame;
|
|
495
496
|
const tiers = new Set();
|
|
496
497
|
let staged = [];
|
|
497
|
-
const
|
|
498
|
-
if (swept) swept.emitted = true;
|
|
498
|
+
const send = message => {
|
|
499
499
|
if (staged.length) {
|
|
500
|
-
|
|
500
|
+
message.tiers = staged;
|
|
501
501
|
staged = [];
|
|
502
502
|
}
|
|
503
|
-
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);
|
|
504
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
|
+
});
|
|
505
533
|
const needs = name => {
|
|
506
534
|
if (!tiers.has(name)) {
|
|
507
535
|
tiers.add(name);
|
|
@@ -511,36 +539,44 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
511
539
|
let conditional = false;
|
|
512
540
|
const skipped = new Set();
|
|
513
541
|
const attrText = new Map();
|
|
514
|
-
const
|
|
515
|
-
|
|
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)) {
|
|
516
559
|
const key = "lh:" + m[1];
|
|
517
560
|
const digest = textDigest(stripHoleMarkers(m[2]));
|
|
518
561
|
if (have[key] === digest) continue;
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
version,
|
|
523
|
-
key,
|
|
524
|
-
html: m[2],
|
|
525
|
-
digest
|
|
526
|
-
}, holeDigests(m[2], null)));
|
|
562
|
+
put(id, {
|
|
563
|
+
["hole:" + key]: html(m[2], digest, holeDigests(m[2], null))
|
|
564
|
+
});
|
|
527
565
|
}
|
|
528
|
-
for (const m of
|
|
566
|
+
for (const m of source.matchAll(ATTR_ADDRESS)) {
|
|
529
567
|
const text = attrText.get("lha:" + m[1]);
|
|
530
568
|
if (text === undefined) continue;
|
|
531
569
|
const digest = textDigest(text);
|
|
532
570
|
if (have["lha:" + m[1]] === digest) continue;
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
digest
|
|
571
|
+
put(id, {
|
|
572
|
+
["attr:" + m[1]]: {
|
|
573
|
+
kind: "attrs",
|
|
574
|
+
value: text,
|
|
575
|
+
digest
|
|
576
|
+
}
|
|
540
577
|
});
|
|
541
578
|
}
|
|
542
579
|
};
|
|
543
|
-
const styledKeys = new Set();
|
|
544
580
|
const bindings = new Map();
|
|
545
581
|
const sweepMinted = new Set();
|
|
546
582
|
const argRefVersions = new Map();
|
|
@@ -551,34 +587,27 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
551
587
|
const sweep = () => {
|
|
552
588
|
epoch++;
|
|
553
589
|
const pass = swept = {
|
|
554
|
-
|
|
590
|
+
r: {},
|
|
555
591
|
emitted: false
|
|
556
592
|
};
|
|
557
593
|
try {
|
|
558
|
-
for (const b of [...bindings
|
|
594
|
+
for (const [key, b] of [...bindings]) {
|
|
595
|
+
if (bindings.get(key) !== b) continue;
|
|
559
596
|
try {
|
|
560
597
|
b.sweep();
|
|
561
598
|
} catch (_) {
|
|
562
599
|
}
|
|
563
600
|
}
|
|
564
|
-
|
|
601
|
+
for (const _ in pass.r) {
|
|
602
|
+
put(id, pass.r);
|
|
603
|
+
break;
|
|
604
|
+
}
|
|
605
|
+
flush();
|
|
565
606
|
if (pass.emitted && hooks && hooks.onYield) hooks.onYield();
|
|
566
607
|
} finally {
|
|
567
608
|
swept = null;
|
|
568
609
|
}
|
|
569
610
|
};
|
|
570
|
-
const emitOps = ops => {
|
|
571
|
-
if (ops.length === 1) emit(Object.assign({
|
|
572
|
-
type: ops[0].type,
|
|
573
|
-
id,
|
|
574
|
-
version
|
|
575
|
-
}, ops[0]));else if (ops.length) emit({
|
|
576
|
-
type: "ops",
|
|
577
|
-
id,
|
|
578
|
-
version,
|
|
579
|
-
ops
|
|
580
|
-
});
|
|
581
|
-
};
|
|
582
611
|
const scheduleSweep = () => {
|
|
583
612
|
if (closed || sweepScheduled || !bindings.size) return;
|
|
584
613
|
sweepScheduled = true;
|
|
@@ -593,52 +622,47 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
593
622
|
tagRegion(key, childId) {
|
|
594
623
|
if (!regionKeys.has(key)) regionKeys.set(key, childId);
|
|
595
624
|
},
|
|
596
|
-
shell(
|
|
597
|
-
const digest = textDigest(frameSkeleton(
|
|
625
|
+
shell(source, meta = {}) {
|
|
626
|
+
const digest = textDigest(frameSkeleton(source));
|
|
598
627
|
if (have && have[""] === digest) {
|
|
599
628
|
conditional = true;
|
|
600
|
-
emitDiffering(
|
|
629
|
+
emitDiffering(source);
|
|
601
630
|
return;
|
|
602
631
|
}
|
|
603
632
|
if (meta.preloads && meta.preloads.size || meta.preloadLinks) {
|
|
604
|
-
const
|
|
605
|
-
type: "assets",
|
|
606
|
-
id,
|
|
607
|
-
version,
|
|
608
|
-
key: ""
|
|
609
|
-
};
|
|
633
|
+
const record = {};
|
|
610
634
|
if (meta.preloads && meta.preloads.size) {
|
|
611
635
|
const styles = [];
|
|
612
636
|
const modules = [];
|
|
613
637
|
for (const url of meta.preloads) {
|
|
614
638
|
(url.endsWith(".css") ? styles : modules).push(url);
|
|
615
639
|
}
|
|
616
|
-
if (styles.length)
|
|
617
|
-
if (modules.length)
|
|
640
|
+
if (styles.length) record.styles = styles;
|
|
641
|
+
if (modules.length) record.modules = modules;
|
|
618
642
|
}
|
|
619
643
|
if (meta.preloadLinks) {
|
|
620
|
-
|
|
644
|
+
record.preloads = [];
|
|
621
645
|
for (const entry of meta.preloadLinks) {
|
|
622
|
-
|
|
646
|
+
record.preloads.push(wirePreload(entry));
|
|
623
647
|
}
|
|
624
648
|
}
|
|
625
649
|
needs("assets");
|
|
626
|
-
|
|
650
|
+
put(id, {
|
|
651
|
+
"seg::assets": record
|
|
652
|
+
});
|
|
627
653
|
}
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
version,
|
|
632
|
-
html,
|
|
633
|
-
digest
|
|
634
|
-
}, holeDigests(html, attrText)));
|
|
654
|
+
put(id, {
|
|
655
|
+
"": html(source, digest, holeDigests(source, attrText))
|
|
656
|
+
});
|
|
635
657
|
},
|
|
636
658
|
data(record) {
|
|
637
659
|
if (record && typeof record.key === "string" && (record.key.endsWith("_fr") || /^\d+$/.test(record.key))) {
|
|
638
660
|
return;
|
|
639
661
|
}
|
|
662
|
+
if (swept) swept.emitted = true;
|
|
663
|
+
flush();
|
|
640
664
|
if (typeof record === "string") {
|
|
641
|
-
|
|
665
|
+
send({
|
|
642
666
|
type: "data",
|
|
643
667
|
id,
|
|
644
668
|
version,
|
|
@@ -646,7 +670,7 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
646
670
|
});
|
|
647
671
|
scheduleSweep();
|
|
648
672
|
} else {
|
|
649
|
-
|
|
673
|
+
send({
|
|
650
674
|
type: "data",
|
|
651
675
|
id,
|
|
652
676
|
version,
|
|
@@ -663,73 +687,40 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
663
687
|
skipped.add(key);
|
|
664
688
|
scheduleSweep();
|
|
665
689
|
if (meta.error) {
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
id: fid,
|
|
669
|
-
version,
|
|
670
|
-
key,
|
|
671
|
-
error: {
|
|
672
|
-
message: String(meta.error && meta.error.message || meta.error)
|
|
673
|
-
}
|
|
690
|
+
putError(fid, key, {
|
|
691
|
+
message: String(meta.error && meta.error.message || meta.error)
|
|
674
692
|
});
|
|
675
693
|
} else emitDiffering(value);
|
|
676
694
|
return;
|
|
677
695
|
}
|
|
678
696
|
const links = meta.styles && meta.styles.links || [];
|
|
679
697
|
const inline = meta.styles && meta.styles.inline || [];
|
|
698
|
+
const r = {};
|
|
680
699
|
if (links.length || inline.length) {
|
|
681
|
-
|
|
682
|
-
const chunk = {
|
|
683
|
-
type: "assets",
|
|
684
|
-
id: fid,
|
|
685
|
-
version,
|
|
686
|
-
key
|
|
687
|
-
};
|
|
700
|
+
const record = {};
|
|
688
701
|
if (links.length) {
|
|
689
|
-
|
|
702
|
+
record.styles = links.map(e => typeof e === "string" ? e : e.attrs ? {
|
|
690
703
|
href: e.href,
|
|
691
704
|
attrs: e.attrs
|
|
692
705
|
} : e.href);
|
|
693
706
|
}
|
|
694
707
|
if (inline.length) {
|
|
695
|
-
|
|
708
|
+
record.inlineStyles = inline.map(e => ({
|
|
696
709
|
id: e.id,
|
|
697
710
|
content: e.content,
|
|
698
711
|
attrs: e.attrs
|
|
699
712
|
}));
|
|
700
713
|
}
|
|
701
714
|
needs("assets");
|
|
702
|
-
|
|
715
|
+
r[`seg:${key}:assets`] = record;
|
|
703
716
|
}
|
|
704
|
-
|
|
705
|
-
type: "fragment",
|
|
706
|
-
id: fid,
|
|
707
|
-
version,
|
|
708
|
-
key,
|
|
709
|
-
html: value,
|
|
710
|
-
digest: textDigest(value)
|
|
711
|
-
}, holeDigests(value, attrText)));
|
|
717
|
+
r[`seg:${key}`] = html(value, textDigest(value), holeDigests(value, attrText));
|
|
712
718
|
scheduleSweep();
|
|
713
|
-
if (meta.error) {
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
key,
|
|
719
|
-
error: {
|
|
720
|
-
message: String(meta.error && meta.error.message || meta.error)
|
|
721
|
-
}
|
|
722
|
-
});
|
|
723
|
-
}
|
|
724
|
-
if (!meta.revealGroup) {
|
|
725
|
-
emit({
|
|
726
|
-
type: "reveal",
|
|
727
|
-
id: fid,
|
|
728
|
-
version,
|
|
729
|
-
keys: [key],
|
|
730
|
-
waitForStyles: !!links.length
|
|
731
|
-
});
|
|
732
|
-
}
|
|
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);
|
|
733
724
|
},
|
|
734
725
|
reveal(keys, meta = {}) {
|
|
735
726
|
const byFrame = new Map();
|
|
@@ -740,38 +731,27 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
740
731
|
if (!group) byFrame.set(fid, group = []);
|
|
741
732
|
group.push(key);
|
|
742
733
|
}
|
|
734
|
+
const gate = meta.fallback ? "fallback" : "reveal";
|
|
743
735
|
for (const [fid, groupKeys] of byFrame) {
|
|
744
|
-
|
|
745
|
-
for (const key of groupKeys)
|
|
746
|
-
|
|
747
|
-
type: "reveal",
|
|
748
|
-
id: fid,
|
|
749
|
-
version,
|
|
750
|
-
keys: groupKeys,
|
|
751
|
-
waitForStyles
|
|
752
|
-
};
|
|
753
|
-
if (meta.fallback) chunk.fallback = true;
|
|
754
|
-
emit(chunk);
|
|
736
|
+
const r = {};
|
|
737
|
+
for (const key of groupKeys) r[`seg:${key}:${gate}`] = true;
|
|
738
|
+
put(fid, r);
|
|
755
739
|
}
|
|
756
740
|
},
|
|
757
741
|
asset(type, value) {
|
|
758
742
|
if (type === "module") {
|
|
759
743
|
needs("assets");
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
key: "",
|
|
765
|
-
modules: [value]
|
|
744
|
+
put(id, {
|
|
745
|
+
"seg::assets": {
|
|
746
|
+
modules: [value]
|
|
747
|
+
}
|
|
766
748
|
});
|
|
767
749
|
} else if (type === "preload") {
|
|
768
750
|
needs("assets");
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
key: "",
|
|
774
|
-
preloads: [wirePreload(value)]
|
|
751
|
+
put(id, {
|
|
752
|
+
"seg::assets": {
|
|
753
|
+
preloads: [wirePreload(value)]
|
|
754
|
+
}
|
|
775
755
|
});
|
|
776
756
|
}
|
|
777
757
|
},
|
|
@@ -779,64 +759,76 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
779
759
|
if (closed) return;
|
|
780
760
|
if (bindings.size && !swept) sweep();
|
|
781
761
|
closed = true;
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
762
|
+
put(id, bound ? {
|
|
763
|
+
":complete": true,
|
|
764
|
+
":bound": bound
|
|
765
|
+
} : {
|
|
766
|
+
":complete": true
|
|
767
|
+
});
|
|
768
|
+
flush();
|
|
789
769
|
},
|
|
790
770
|
error(errorId, error) {
|
|
791
|
-
|
|
792
|
-
type: "error",
|
|
793
|
-
id,
|
|
794
|
-
version,
|
|
795
|
-
key: errorId,
|
|
796
|
-
error
|
|
797
|
-
});
|
|
771
|
+
putError(id, errorId, error);
|
|
798
772
|
},
|
|
773
|
+
flush,
|
|
799
774
|
slot(key, args) {
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
775
|
+
const r = {
|
|
776
|
+
[`slot:${key}`]: {
|
|
777
|
+
kind: "slot",
|
|
778
|
+
args
|
|
779
|
+
}
|
|
780
|
+
};
|
|
781
|
+
swept ? Object.assign(swept.r, r) : put(id, r);
|
|
807
782
|
},
|
|
808
|
-
region(childId,
|
|
783
|
+
region(childId, value) {
|
|
809
784
|
needs("regions");
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
785
|
+
put(childId, {
|
|
786
|
+
"": {
|
|
787
|
+
kind: "html",
|
|
788
|
+
value
|
|
789
|
+
}
|
|
815
790
|
});
|
|
816
791
|
},
|
|
817
|
-
hole(key,
|
|
818
|
-
const
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
html,
|
|
822
|
-
digest: textDigest(html)
|
|
792
|
+
hole(key, source, rows) {
|
|
793
|
+
const record = {
|
|
794
|
+
kind: "html",
|
|
795
|
+
digest: textDigest(source)
|
|
823
796
|
};
|
|
824
|
-
|
|
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);
|
|
825
813
|
},
|
|
826
814
|
attr(key, attrs, removed) {
|
|
827
|
-
const
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
attrs,
|
|
815
|
+
const record = {
|
|
816
|
+
kind: "attrs",
|
|
817
|
+
value: attrs,
|
|
831
818
|
digest: textDigest(attrs)
|
|
832
819
|
};
|
|
833
|
-
if (removed && removed.length)
|
|
834
|
-
|
|
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);
|
|
835
825
|
},
|
|
836
826
|
attrBaseline(key, text) {
|
|
837
827
|
attrText.set(key, text);
|
|
828
|
+
if (hooks && hooks.retain) hooks.retain(key, text);
|
|
838
829
|
},
|
|
839
830
|
openBinding(key, b) {
|
|
831
|
+
if (/^lha?:/.test(key)) needs("wire");
|
|
840
832
|
bindings.set(key, b);
|
|
841
833
|
},
|
|
842
834
|
closeBinding(key) {
|
|
@@ -869,8 +861,9 @@ function renderServerComponent(component, options = {}) {
|
|
|
869
861
|
if (ctx) {
|
|
870
862
|
ctx.commit = sink.commit;
|
|
871
863
|
ctx.commitEpoch = () => sink.epoch;
|
|
872
|
-
|
|
873
|
-
ctx.
|
|
864
|
+
let unsettled = !!options.live;
|
|
865
|
+
if (!unsettled) ctx.unsettled = () => void (unsettled = true);
|
|
866
|
+
ctx.liveHoles = createLiveHoles(sink, false, () => !unsettled, ctx._errorScope);
|
|
874
867
|
}
|
|
875
868
|
return serverComponentScope(() => component(props));
|
|
876
869
|
};
|
|
@@ -903,6 +896,7 @@ function frameStream(makeCode, options) {
|
|
|
903
896
|
function finish() {
|
|
904
897
|
if (ended) return;
|
|
905
898
|
ended = true;
|
|
899
|
+
sink.flush();
|
|
906
900
|
if (timer) clearTimeout(timer);
|
|
907
901
|
if (upstream) upstream.removeEventListener("abort", onSignal);
|
|
908
902
|
w.end && w.end();
|
|
@@ -923,19 +917,21 @@ function frameStream(makeCode, options) {
|
|
|
923
917
|
finish();
|
|
924
918
|
render.abort(upstream.reason);
|
|
925
919
|
}
|
|
926
|
-
const emit =
|
|
927
|
-
if (observation) observation.chunk(
|
|
928
|
-
w.write(
|
|
929
|
-
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) {
|
|
930
924
|
flushed = true;
|
|
931
925
|
if (maxDurationMs > 0 && maxDurationMs !== Infinity) timer = setTimeout(() => cut("time"), maxDurationMs);
|
|
932
926
|
}
|
|
933
927
|
};
|
|
934
|
-
const sink = createFrameSink(emit, frame, options.resume && options.resume.have,
|
|
935
|
-
|
|
928
|
+
const sink = createFrameSink(emit, frame, options.resume && options.resume.have, {
|
|
929
|
+
live: options.live,
|
|
930
|
+
retain: options.broadcast,
|
|
931
|
+
onYield: bounded ? () => {
|
|
936
932
|
if (flushed && maxYields > 0 && ++yields >= maxYields) cut("yields");
|
|
937
|
-
}
|
|
938
|
-
}
|
|
933
|
+
} : undefined
|
|
934
|
+
});
|
|
939
935
|
if (options.live) sink.needs("wire");
|
|
940
936
|
w.write({
|
|
941
937
|
type: "start",
|
|
@@ -970,6 +966,7 @@ function frameStream(makeCode, options) {
|
|
|
970
966
|
finish();
|
|
971
967
|
}
|
|
972
968
|
if (w[ANNOUNCE]) w[ANNOUNCE](sink.announce());
|
|
969
|
+
sink.flush();
|
|
973
970
|
}
|
|
974
971
|
return {
|
|
975
972
|
pipe: stream,
|
|
@@ -991,100 +988,21 @@ function frameStream(makeCode, options) {
|
|
|
991
988
|
function slotRange(occurrence) {
|
|
992
989
|
return {
|
|
993
990
|
t: `<!--slot:${occurrence}:start--><!--slot:${occurrence}:end-->`,
|
|
994
|
-
$slot: true
|
|
995
|
-
$occurrence: occurrence
|
|
991
|
+
$slot: true
|
|
996
992
|
};
|
|
997
993
|
}
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
function isRangeKey(key) {
|
|
1001
|
-
const c = key.charCodeAt(0);
|
|
1002
|
-
return c === 36 || c >= 48 && c <= 57 || RANGE_KEYS.has(key);
|
|
1003
|
-
}
|
|
1004
|
-
function slotProxy(range, occurrence, face, content, onData, needs) {
|
|
1005
|
-
return new Proxy(range, {
|
|
1006
|
-
get(target, key, receiver) {
|
|
1007
|
-
if (typeof key !== "string" || isRangeKey(key)) return Reflect.get(target, key, receiver);
|
|
1008
|
-
if (onData) onData = void onData();
|
|
1009
|
-
if (face !== SLOT_FACE_MARKUP) needs("bind");
|
|
1010
|
-
return slotValue(occurrence, key, content ? content[key] : undefined, face);
|
|
1011
|
-
}
|
|
1012
|
-
});
|
|
1013
|
-
}
|
|
1014
|
-
function argBorderForm(value, key, occurrence, needs) {
|
|
1015
|
-
return toBorderForm(withoutStandIns(value, key, occurrence, needs));
|
|
994
|
+
function argBorderForm(value, needs) {
|
|
995
|
+
return toBorderForm(noteTraces(value, needs));
|
|
1016
996
|
}
|
|
1017
|
-
function
|
|
1018
|
-
return rewriteTree(value,
|
|
997
|
+
function noteTraces(value, needs) {
|
|
998
|
+
return rewriteTree(value, v => {
|
|
1019
999
|
if (isContainerTraced(v)) {
|
|
1020
1000
|
needs("trace");
|
|
1021
1001
|
return v;
|
|
1022
1002
|
}
|
|
1023
|
-
if (Object.getPrototypeOf(v) === Object.prototype && isSlotValue(v)) {
|
|
1024
|
-
standInArgFinding(v, key, occurrence, path);
|
|
1025
|
-
return undefined;
|
|
1026
|
-
}
|
|
1027
1003
|
return DESCEND;
|
|
1028
1004
|
}, true);
|
|
1029
1005
|
}
|
|
1030
|
-
function standInArgFinding(sv, key, occurrence, path) {
|
|
1031
|
-
{
|
|
1032
|
-
const ctx = sharedConfig.context;
|
|
1033
|
-
if (ctx) {
|
|
1034
|
-
const id = `${occurrence}\u0000${key}${path}\u0000arg`;
|
|
1035
|
-
const seen = ctx.slotFindings || (ctx.slotFindings = new Set());
|
|
1036
|
-
if (seen.has(id)) return;
|
|
1037
|
-
seen.add(id);
|
|
1038
|
-
}
|
|
1039
|
-
const where = path === "" ? `Arg \`${key}\`` : `Arg \`${key}${path}\``;
|
|
1040
|
-
devCheck({
|
|
1041
|
-
code: "BINDING_SLOT_POSITION",
|
|
1042
|
-
kind: "ssr",
|
|
1043
|
-
severity: "warn",
|
|
1044
|
-
message: `[BINDING_SLOT_POSITION] ${where} of \`${occurrence}\` is another slot's value ` + `(\`${sv.k}\` of \`${sv[SLOT_VALUE]}\`). The server does not have it — the client owns ` + `it — so it cannot be passed as data; the arg carries \`undefined\` there on both faces. ` + `Pass the server's own value, or have the client fill read it from its own state.`,
|
|
1045
|
-
data: {
|
|
1046
|
-
reason: "arg",
|
|
1047
|
-
occurrence,
|
|
1048
|
-
key,
|
|
1049
|
-
path: path === "" ? undefined : path,
|
|
1050
|
-
from: sv[SLOT_VALUE],
|
|
1051
|
-
fromKey: sv.k
|
|
1052
|
-
}
|
|
1053
|
-
});
|
|
1054
|
-
}
|
|
1055
|
-
}
|
|
1056
|
-
function slotFace(range, content) {
|
|
1057
|
-
if (content == null) return SLOT_FACE_DATA;
|
|
1058
|
-
if (typeof content !== "object" || Array.isArray(content)) return SLOT_FACE_MARKUP;
|
|
1059
|
-
if (isServerContent(content)) {
|
|
1060
|
-
let data = false;
|
|
1061
|
-
for (const key in content) {
|
|
1062
|
-
if (!NODE_KEYS.has(key)) {
|
|
1063
|
-
data = true;
|
|
1064
|
-
break;
|
|
1065
|
-
}
|
|
1066
|
-
}
|
|
1067
|
-
if (!data) return SLOT_FACE_MARKUP;
|
|
1068
|
-
}
|
|
1069
|
-
{
|
|
1070
|
-
for (const key of Object.keys(content)) {
|
|
1071
|
-
if (isRangeKey(key)) {
|
|
1072
|
-
devCheck({
|
|
1073
|
-
code: "BINDING_SLOT_POSITION",
|
|
1074
|
-
kind: "ssr",
|
|
1075
|
-
severity: "warn",
|
|
1076
|
-
message: `[BINDING_SLOT_POSITION] The fill for \`${range.$occurrence}\` returned a key named \`${key}\`, ` + `which is reserved (keys beginning with \`$\` or a digit, \`length\`, \`slice\`, the node keys \`t\`/\`h\`/\`p\`, ` + `\`then\`, \`constructor\`, \`toString\`, \`valueOf\`, \`toJSON\`): the server reads it as the ` + `slot's range, not as a value. Rename it.`,
|
|
1077
|
-
data: {
|
|
1078
|
-
reason: "reserved-key",
|
|
1079
|
-
occurrence: range.$occurrence,
|
|
1080
|
-
key
|
|
1081
|
-
}
|
|
1082
|
-
});
|
|
1083
|
-
}
|
|
1084
|
-
}
|
|
1085
|
-
}
|
|
1086
|
-
return SLOT_FACE_DATA;
|
|
1087
|
-
}
|
|
1088
1006
|
const OCCURRENCE_UNSAFE = /[^A-Za-z0-9_.-]/g;
|
|
1089
1007
|
function encodeOccurrenceKey(key) {
|
|
1090
1008
|
return String(key).replace(OCCURRENCE_UNSAFE, c => {
|
|
@@ -1139,12 +1057,19 @@ function structuralArgsKey(raw) {
|
|
|
1139
1057
|
};
|
|
1140
1058
|
return walk(raw, true) ? out : undefined;
|
|
1141
1059
|
}
|
|
1142
|
-
function
|
|
1143
|
-
const
|
|
1144
|
-
if (
|
|
1145
|
-
|
|
1146
|
-
|
|
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
|
+
}
|
|
1147
1070
|
}
|
|
1071
|
+
const PENDING_ARG = {};
|
|
1072
|
+
const noDigest = () => NaN;
|
|
1148
1073
|
function isAsyncValue(v) {
|
|
1149
1074
|
return !!v && typeof v === "object" && (typeof v.then === "function" || typeof v[Symbol.asyncIterator] === "function");
|
|
1150
1075
|
}
|
|
@@ -1160,6 +1085,37 @@ function tapFirstYield(iterable) {
|
|
|
1160
1085
|
rest
|
|
1161
1086
|
};
|
|
1162
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
|
+
}
|
|
1163
1119
|
function suppressedFill(render) {
|
|
1164
1120
|
const live = sharedConfig.context && sharedConfig.context.liveHoles;
|
|
1165
1121
|
if (!live) return render();
|
|
@@ -1170,25 +1126,96 @@ function suppressedFill(render) {
|
|
|
1170
1126
|
live.suppressed--;
|
|
1171
1127
|
}
|
|
1172
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
|
+
}
|
|
1173
1176
|
function createDocumentSlotProps(clientProps, frameId) {
|
|
1174
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
|
+
};
|
|
1175
1204
|
const getters = new Map();
|
|
1176
1205
|
const repeats = new Map();
|
|
1177
|
-
const range = (occurrence, content) => {
|
|
1206
|
+
const range = (occurrence, content, tail) => {
|
|
1178
1207
|
const r = [{
|
|
1179
1208
|
t: `<!--slot:${occurrence}:start-->`
|
|
1180
|
-
}, content, {
|
|
1209
|
+
}, content, tail, {
|
|
1181
1210
|
t: `<!--slot:${occurrence}:end-->`
|
|
1182
1211
|
}];
|
|
1183
1212
|
r.$slot = true;
|
|
1184
|
-
r
|
|
1185
|
-
const face = slotFace(r, content);
|
|
1186
|
-
r.$face = face;
|
|
1187
|
-
return slotProxy(r, occurrence, face, face === SLOT_FACE_DATA ? content : undefined, undefined, documentNeeds);
|
|
1213
|
+
return r;
|
|
1188
1214
|
};
|
|
1189
1215
|
const zoneOwner = getOwner ? getOwner() : null;
|
|
1190
|
-
const scoped = (occurrence, render) => {
|
|
1216
|
+
const scoped = (occurrence, render, owner) => {
|
|
1191
1217
|
const id = `sc-${frameId}-${occurrence}-`;
|
|
1218
|
+
if (owner) return runWithOwner(owner, () => runWithHydrationScope(id, render));
|
|
1192
1219
|
const run = () => Hydration ? Hydration({
|
|
1193
1220
|
id,
|
|
1194
1221
|
get children() {
|
|
@@ -1208,18 +1235,13 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1208
1235
|
if (!fn) {
|
|
1209
1236
|
fn = (...callArgs) => {
|
|
1210
1237
|
if (callArgs.length === 0 || callArgs[0] === undefined) {
|
|
1211
|
-
|
|
1212
|
-
const repeat = repeats.get(rk);
|
|
1213
|
-
if (repeat) return repeat;
|
|
1214
|
-
const out = suppressedFill(() => scoped(prop, () => {
|
|
1238
|
+
return park(owner => suppressedFill(() => scoped(prop, () => {
|
|
1215
1239
|
const value = clientProps[prop];
|
|
1216
1240
|
return range(prop, typeof value === "function" ? value() : value);
|
|
1217
|
-
}));
|
|
1218
|
-
if (out.$face === SLOT_FACE_DATA) repeats.set(rk, out);
|
|
1219
|
-
return out;
|
|
1241
|
+
}, owner)));
|
|
1220
1242
|
}
|
|
1221
1243
|
const raw = callArgs[0];
|
|
1222
|
-
const rk =
|
|
1244
|
+
const rk = keyedId(prop, raw);
|
|
1223
1245
|
const repeat = rk !== undefined && repeats.get(rk);
|
|
1224
1246
|
if (repeat) return repeat;
|
|
1225
1247
|
const occurrence = occurrenceId(prop, raw, counts);
|
|
@@ -1227,10 +1249,10 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1227
1249
|
if (typeof slot !== "function") return range(occurrence, undefined);
|
|
1228
1250
|
const context = sharedConfig.context;
|
|
1229
1251
|
const recordKey = `sc:slot:${frameId}:${occurrence}`;
|
|
1252
|
+
const deferred = !!parked;
|
|
1230
1253
|
let settleRecord;
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
}
|
|
1254
|
+
const declare = () => context && context.async && context.serialize(recordKey, new Promise(resolve => settleRecord = resolve));
|
|
1255
|
+
deferred || declare();
|
|
1234
1256
|
try {
|
|
1235
1257
|
const resolved = {};
|
|
1236
1258
|
const liveArgs = sharedConfig.context && sharedConfig.context.live && sharedConfig.context.live.args;
|
|
@@ -1238,6 +1260,7 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1238
1260
|
const evals = {};
|
|
1239
1261
|
const states = {};
|
|
1240
1262
|
const minted = {};
|
|
1263
|
+
const nestedOf = {};
|
|
1241
1264
|
for (const key of Object.keys(raw)) {
|
|
1242
1265
|
if (key === "$key") continue;
|
|
1243
1266
|
const desc = Object.getOwnPropertyDescriptor(raw, key);
|
|
@@ -1256,6 +1279,8 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1256
1279
|
if (evaluate) {
|
|
1257
1280
|
evals[key] = evaluate;
|
|
1258
1281
|
const stampBefore = scopeStamp();
|
|
1282
|
+
const outer = parked;
|
|
1283
|
+
const nested = nestedOf[key] = parked = new Map();
|
|
1259
1284
|
try {
|
|
1260
1285
|
value = evaluate();
|
|
1261
1286
|
states[key] = {
|
|
@@ -1263,6 +1288,9 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1263
1288
|
last: value
|
|
1264
1289
|
};
|
|
1265
1290
|
} catch (err) {
|
|
1291
|
+
parked = outer;
|
|
1292
|
+
for (const entry of nested.values()) runParked(entry);
|
|
1293
|
+
nested.clear();
|
|
1266
1294
|
const blocked = ssrHandleError && ssrHandleError(err);
|
|
1267
1295
|
if (!blocked) throw err;
|
|
1268
1296
|
const state = states[key] = {
|
|
@@ -1275,6 +1303,7 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1275
1303
|
if (liveArgs) liveArgs.commit();
|
|
1276
1304
|
});
|
|
1277
1305
|
}
|
|
1306
|
+
parked = outer;
|
|
1278
1307
|
if (scopeStamp() !== stampBefore) minted[key] = true;
|
|
1279
1308
|
}
|
|
1280
1309
|
vals[key] = value;
|
|
@@ -1291,6 +1320,7 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1291
1320
|
key,
|
|
1292
1321
|
childId,
|
|
1293
1322
|
value,
|
|
1323
|
+
nested: nestedOf[key],
|
|
1294
1324
|
used: false,
|
|
1295
1325
|
locked: false
|
|
1296
1326
|
};
|
|
@@ -1301,7 +1331,7 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1301
1331
|
region.used = true;
|
|
1302
1332
|
return [{
|
|
1303
1333
|
t: frameElementOpen(childId)
|
|
1304
|
-
}, value, {
|
|
1334
|
+
}, region.nested && region.nested.size ? placeParked(value, region.nested, getOwner()) : value, {
|
|
1305
1335
|
t: FRAME_ELEMENT_CLOSE
|
|
1306
1336
|
}];
|
|
1307
1337
|
};
|
|
@@ -1322,49 +1352,67 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1322
1352
|
configurable: true
|
|
1323
1353
|
});
|
|
1324
1354
|
} else {
|
|
1325
|
-
resolved[key] = vals[key] =
|
|
1355
|
+
resolved[key] = vals[key] = noteTraces(value, documentNeeds);
|
|
1326
1356
|
}
|
|
1327
1357
|
}
|
|
1328
|
-
const
|
|
1329
|
-
const
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
for (const
|
|
1333
|
-
|
|
1334
|
-
const region = regions.find(r => r.key === key);
|
|
1335
|
-
if (region) {
|
|
1336
|
-
args[key] = {
|
|
1337
|
-
$frame: region.childId
|
|
1338
|
-
};
|
|
1339
|
-
continue;
|
|
1340
|
-
}
|
|
1341
|
-
if (!isContainerTraced(value) && isServerContent(value)) continue;
|
|
1342
|
-
args[key] = argBorderForm(value, key, occurrence, documentNeeds);
|
|
1343
|
-
}
|
|
1344
|
-
settleRecord ? settleRecord({
|
|
1345
|
-
...args
|
|
1346
|
-
}) : context.serialize(recordKey, {
|
|
1347
|
-
...args
|
|
1348
|
-
});
|
|
1349
|
-
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;
|
|
1350
1364
|
region.locked = true;
|
|
1351
|
-
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));
|
|
1352
1366
|
}
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
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
|
|
1363
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
|
+
}
|
|
1364
1407
|
}
|
|
1408
|
+
return out;
|
|
1409
|
+
} catch (error) {
|
|
1410
|
+
settleRecord && settleRecord(undefined);
|
|
1411
|
+
throw error;
|
|
1365
1412
|
}
|
|
1366
|
-
}
|
|
1367
|
-
|
|
1413
|
+
};
|
|
1414
|
+
const out = park(finish);
|
|
1415
|
+
if (rk !== undefined && rk === occurrence) repeats.has(rk) || repeats.set(rk, out);
|
|
1368
1416
|
return out;
|
|
1369
1417
|
} catch (error) {
|
|
1370
1418
|
settleRecord && settleRecord(undefined);
|
|
@@ -1380,9 +1428,10 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1380
1428
|
}
|
|
1381
1429
|
const FRAME_TAG = "solid-frame";
|
|
1382
1430
|
const FRAME_ID_ATTR = "data-fid";
|
|
1383
|
-
|
|
1431
|
+
const FRAME_ARGS_ATTR = "data-fa";
|
|
1432
|
+
function frameElementOpen(id, args) {
|
|
1384
1433
|
const escaped = sharedConfig.context ? sharedConfig.context.escape(String(id), true) : String(id);
|
|
1385
|
-
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">`;
|
|
1386
1435
|
}
|
|
1387
1436
|
const DOCUMENT_SITES = Symbol();
|
|
1388
1437
|
function contextSites(ctx) {
|
|
@@ -1434,6 +1483,7 @@ function armDocumentLiveHoles(ctx) {
|
|
|
1434
1483
|
if (live.holes) {
|
|
1435
1484
|
ctx.commit = live.commit;
|
|
1436
1485
|
ctx.commitEpoch = live.commitEpoch;
|
|
1486
|
+
ctx.unsettled = live.unsettled;
|
|
1437
1487
|
}
|
|
1438
1488
|
return;
|
|
1439
1489
|
}
|
|
@@ -1442,6 +1492,7 @@ function armDocumentLiveHoles(ctx) {
|
|
|
1442
1492
|
if (live) live.holes = null;
|
|
1443
1493
|
return;
|
|
1444
1494
|
}
|
|
1495
|
+
let unsettled = false;
|
|
1445
1496
|
const bindings = new Map();
|
|
1446
1497
|
let epoch = 0;
|
|
1447
1498
|
let sweepScheduled = false;
|
|
@@ -1449,7 +1500,7 @@ function armDocumentLiveHoles(ctx) {
|
|
|
1449
1500
|
let swept = null;
|
|
1450
1501
|
const sweep = () => {
|
|
1451
1502
|
epoch++;
|
|
1452
|
-
const
|
|
1503
|
+
const r = swept = {};
|
|
1453
1504
|
try {
|
|
1454
1505
|
for (const b of [...bindings.values()]) {
|
|
1455
1506
|
try {
|
|
@@ -1460,12 +1511,8 @@ function armDocumentLiveHoles(ctx) {
|
|
|
1460
1511
|
} finally {
|
|
1461
1512
|
swept = null;
|
|
1462
1513
|
}
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
const pushOps = ops => {
|
|
1466
|
-
if (ops.length === 1) push(ops[0]);else if (ops.length) push({
|
|
1467
|
-
type: "ops",
|
|
1468
|
-
ops
|
|
1514
|
+
for (const _ in r) return push({
|
|
1515
|
+
r
|
|
1469
1516
|
});
|
|
1470
1517
|
};
|
|
1471
1518
|
const scheduleSweep = () => {
|
|
@@ -1485,49 +1532,57 @@ function armDocumentLiveHoles(ctx) {
|
|
|
1485
1532
|
closed = true;
|
|
1486
1533
|
}
|
|
1487
1534
|
}));
|
|
1488
|
-
const push =
|
|
1489
|
-
if (!closed) channel.enqueue(
|
|
1535
|
+
const push = batch => {
|
|
1536
|
+
if (!closed) channel.enqueue(batch);
|
|
1490
1537
|
};
|
|
1538
|
+
const write = r => swept ? Object.assign(swept, r) : push({
|
|
1539
|
+
r
|
|
1540
|
+
});
|
|
1491
1541
|
ctx.liveHoles = live.holes = createLiveHoles({
|
|
1492
1542
|
openBinding(key, b) {
|
|
1543
|
+
documentNeeds("wire");
|
|
1493
1544
|
bindings.set(key, b);
|
|
1494
1545
|
},
|
|
1495
1546
|
closeBinding(key) {
|
|
1496
1547
|
bindings.delete(key);
|
|
1497
1548
|
},
|
|
1498
|
-
hole(key,
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1549
|
+
hole(key, value) {
|
|
1550
|
+
write({
|
|
1551
|
+
["hole:" + key]: {
|
|
1552
|
+
kind: "html",
|
|
1553
|
+
value,
|
|
1554
|
+
digest: textDigest(value)
|
|
1555
|
+
}
|
|
1556
|
+
});
|
|
1506
1557
|
},
|
|
1507
|
-
attr(key,
|
|
1508
|
-
const
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
digest: textDigest(attrs)
|
|
1558
|
+
attr(key, value, removed) {
|
|
1559
|
+
const record = {
|
|
1560
|
+
kind: "attrs",
|
|
1561
|
+
value,
|
|
1562
|
+
digest: textDigest(value)
|
|
1513
1563
|
};
|
|
1514
|
-
if (removed && removed.length)
|
|
1515
|
-
|
|
1564
|
+
if (removed && removed.length) record.removed = removed;
|
|
1565
|
+
write({
|
|
1566
|
+
["attr:" + key]: record
|
|
1567
|
+
});
|
|
1516
1568
|
},
|
|
1517
1569
|
error(key, error) {
|
|
1518
1570
|
push({
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1571
|
+
r: {
|
|
1572
|
+
[`hole:${key}:error`]: error
|
|
1573
|
+
}
|
|
1522
1574
|
});
|
|
1523
1575
|
},
|
|
1524
1576
|
commit: scheduleSweep,
|
|
1525
1577
|
get epoch() {
|
|
1526
1578
|
return epoch;
|
|
1527
1579
|
}
|
|
1528
|
-
}, true);
|
|
1580
|
+
}, true, () => !unsettled, ctx._errorScope);
|
|
1529
1581
|
ctx.commit = live.commit = scheduleSweep;
|
|
1530
1582
|
ctx.commitEpoch = live.commitEpoch = () => epoch;
|
|
1583
|
+
ctx.unsettled = live.unsettled = () => {
|
|
1584
|
+
unsettled = true;
|
|
1585
|
+
};
|
|
1531
1586
|
live.args = {
|
|
1532
1587
|
openBinding(key, b) {
|
|
1533
1588
|
bindings.set(key, b);
|
|
@@ -1537,19 +1592,23 @@ function armDocumentLiveHoles(ctx) {
|
|
|
1537
1592
|
},
|
|
1538
1593
|
slot(fid, occurrence, args) {
|
|
1539
1594
|
push({
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1595
|
+
r: {
|
|
1596
|
+
[`slot:${occurrence}`]: {
|
|
1597
|
+
kind: "slot",
|
|
1598
|
+
args
|
|
1599
|
+
}
|
|
1600
|
+
},
|
|
1601
|
+
fid
|
|
1544
1602
|
});
|
|
1545
1603
|
},
|
|
1546
1604
|
commit: scheduleSweep
|
|
1547
1605
|
};
|
|
1548
1606
|
live.error = (fid, error) => {
|
|
1549
1607
|
push({
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1608
|
+
r: {
|
|
1609
|
+
":error": error
|
|
1610
|
+
},
|
|
1611
|
+
fid
|
|
1553
1612
|
});
|
|
1554
1613
|
};
|
|
1555
1614
|
live.end = () => {
|
|
@@ -1566,17 +1625,17 @@ function frameTransformDirectResult(value, {
|
|
|
1566
1625
|
}) {
|
|
1567
1626
|
if (typeof value !== "function") return value;
|
|
1568
1627
|
const component = value;
|
|
1628
|
+
const address = frameAddress(id, args);
|
|
1569
1629
|
const wrapped = props => {
|
|
1570
1630
|
const siteId = documentSiteId(id);
|
|
1571
1631
|
return [{
|
|
1572
|
-
t: frameElementOpen(siteId)
|
|
1632
|
+
t: frameElementOpen(siteId, address.slice(id.length + 1))
|
|
1573
1633
|
},
|
|
1574
1634
|
serverOwned(() => {
|
|
1575
1635
|
const page = sharedConfig.context;
|
|
1576
1636
|
armDocumentLiveHoles(page);
|
|
1577
1637
|
if (tierUrls && page && page.live && !page.live.tierUrls) page.live.tierUrls = tierUrls;
|
|
1578
1638
|
const ctx = Object.create(page);
|
|
1579
|
-
ctx.claims = CLAIMS_DOCUMENT;
|
|
1580
1639
|
ctx.frameId = siteId;
|
|
1581
1640
|
sharedConfig.context = ctx;
|
|
1582
1641
|
try {
|
|
@@ -1593,7 +1652,7 @@ function frameTransformDirectResult(value, {
|
|
|
1593
1652
|
};
|
|
1594
1653
|
wrapped[SERVER_COMPONENT] = id;
|
|
1595
1654
|
wrapped[SERVER_COMPONENT_SOURCE] = component;
|
|
1596
|
-
wrapped[SERVER_COMPONENT_ADDRESS] =
|
|
1655
|
+
wrapped[SERVER_COMPONENT_ADDRESS] = address;
|
|
1597
1656
|
return wrapped;
|
|
1598
1657
|
}
|
|
1599
1658
|
function resolveRegionHtml(ctx, node) {
|
|
@@ -1696,6 +1755,15 @@ function createSlotProps(sink, frame) {
|
|
|
1696
1755
|
const counts = Object.create(null);
|
|
1697
1756
|
const getters = new Map();
|
|
1698
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
|
+
};
|
|
1699
1767
|
const needs = sink.needs || (() => {});
|
|
1700
1768
|
return new Proxy(Object.create(null), {
|
|
1701
1769
|
has() {
|
|
@@ -1708,25 +1776,38 @@ function createSlotProps(sink, frame) {
|
|
|
1708
1776
|
if (!fn) {
|
|
1709
1777
|
fn = (...callArgs) => {
|
|
1710
1778
|
if (callArgs.length === 0 || callArgs[0] === undefined) {
|
|
1711
|
-
return
|
|
1779
|
+
return slotRange(prop);
|
|
1712
1780
|
}
|
|
1713
|
-
const rk = repeatKey(prop, callArgs[0]);
|
|
1714
|
-
const repeat = rk !== undefined && repeats.get(rk);
|
|
1715
|
-
if (repeat) return repeat;
|
|
1716
1781
|
const live = sharedConfig.context && sharedConfig.context.liveHoles;
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
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
|
+
};
|
|
1726
1798
|
}
|
|
1727
1799
|
const raw = callArgs[0];
|
|
1728
|
-
|
|
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;
|
|
1729
1809
|
const args = {};
|
|
1810
|
+
const vals = {};
|
|
1730
1811
|
const opened = [];
|
|
1731
1812
|
for (const key of Object.keys(raw)) {
|
|
1732
1813
|
if (key === "$key") continue;
|
|
@@ -1742,6 +1823,7 @@ function createSlotProps(sink, frame) {
|
|
|
1742
1823
|
let evaluate = null;
|
|
1743
1824
|
let value;
|
|
1744
1825
|
let state = null;
|
|
1826
|
+
let pending = false;
|
|
1745
1827
|
const stampBefore = scopeStamp();
|
|
1746
1828
|
try {
|
|
1747
1829
|
if (desc.get) {
|
|
@@ -1763,6 +1845,7 @@ function createSlotProps(sink, frame) {
|
|
|
1763
1845
|
settled: false,
|
|
1764
1846
|
last: undefined
|
|
1765
1847
|
};
|
|
1848
|
+
pending = true;
|
|
1766
1849
|
const pendingState = state;
|
|
1767
1850
|
value = retryArgUntilSettled(evaluate, blocked, key, occurrence, v => {
|
|
1768
1851
|
pendingState.settled = true;
|
|
@@ -1774,6 +1857,7 @@ function createSlotProps(sink, frame) {
|
|
|
1774
1857
|
const t = typeof value;
|
|
1775
1858
|
if (value == null || t === "string" || t === "number" || t === "boolean") {
|
|
1776
1859
|
args[key] = value;
|
|
1860
|
+
vals[key] = digest(value);
|
|
1777
1861
|
if (evaluate) state = {
|
|
1778
1862
|
settled: true,
|
|
1779
1863
|
last: value
|
|
@@ -1783,21 +1867,27 @@ function createSlotProps(sink, frame) {
|
|
|
1783
1867
|
if (resolved.h.length) {
|
|
1784
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.");
|
|
1785
1869
|
}
|
|
1786
|
-
|
|
1870
|
+
vals[key] = "<" + resolved.t[0];
|
|
1871
|
+
if (!prev || prev.vals[key] !== vals[key]) sink.region(childId, resolved.t[0]);
|
|
1787
1872
|
args[key] = {
|
|
1788
1873
|
$frame: childId
|
|
1789
1874
|
};
|
|
1790
1875
|
} else {
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
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
|
+
}
|
|
1796
1885
|
if (evaluate && !state) state = {
|
|
1797
1886
|
settled: true,
|
|
1798
1887
|
last: value
|
|
1799
1888
|
};
|
|
1800
1889
|
}
|
|
1890
|
+
if (prev && prev.vals[key] !== vals[key]) changed = true;
|
|
1801
1891
|
if (evaluate && state && !mintedEval) opened.push({
|
|
1802
1892
|
key,
|
|
1803
1893
|
evaluate,
|
|
@@ -1807,9 +1897,18 @@ function createSlotProps(sink, frame) {
|
|
|
1807
1897
|
ctx.registerFragment = origRegister;
|
|
1808
1898
|
}
|
|
1809
1899
|
}
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
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));
|
|
1813
1912
|
const ctx = sharedConfig.context;
|
|
1814
1913
|
for (const b of opened) {
|
|
1815
1914
|
const key = b.key;
|
|
@@ -1817,23 +1916,23 @@ function createSlotProps(sink, frame) {
|
|
|
1817
1916
|
openArgBinding(sink, ledgerKey, occurrence, key, b.evaluate, b.state, value => {
|
|
1818
1917
|
const t = typeof value;
|
|
1819
1918
|
if (value == null || t === "string" || t === "number" || t === "boolean") {
|
|
1820
|
-
args[key] = value;
|
|
1919
|
+
rec.args[key] = value;
|
|
1821
1920
|
} else {
|
|
1822
1921
|
const ref = `arg:${occurrence}:${key}@${sink.nextArgRef(ledgerKey)}`;
|
|
1823
1922
|
sink.mintRef(ref);
|
|
1824
|
-
ctx.serialize(ref, argBorderForm(value,
|
|
1825
|
-
args[key] = {
|
|
1923
|
+
ctx.serialize(ref, argBorderForm(value, needs));
|
|
1924
|
+
rec.args[key] = {
|
|
1826
1925
|
$ref: ref
|
|
1827
1926
|
};
|
|
1828
1927
|
}
|
|
1928
|
+
rec.vals[key] = digest(value);
|
|
1829
1929
|
sink.slot(occurrence, {
|
|
1830
|
-
...args
|
|
1930
|
+
...rec.args
|
|
1831
1931
|
});
|
|
1832
1932
|
});
|
|
1833
1933
|
}
|
|
1834
|
-
const
|
|
1835
|
-
|
|
1836
|
-
if (keyed) repeats.set(rk, out);
|
|
1934
|
+
const out = slotRange(occurrence);
|
|
1935
|
+
if (rk !== undefined && rk === occurrence) rmap.set(rk, out);
|
|
1837
1936
|
return out;
|
|
1838
1937
|
};
|
|
1839
1938
|
fn.$lhSkip = true;
|
|
@@ -1898,11 +1997,11 @@ function serverComponentResponse(component, options = {}, init = {}) {
|
|
|
1898
1997
|
teardown.abort();
|
|
1899
1998
|
});
|
|
1900
1999
|
stream.pipe({
|
|
1901
|
-
write(
|
|
1902
|
-
if (
|
|
2000
|
+
write(message) {
|
|
2001
|
+
if (message.r && ":error" in message.r) failed = true;
|
|
1903
2002
|
if (closed) return;
|
|
1904
2003
|
try {
|
|
1905
|
-
controller.enqueue(frame(JSON.stringify(
|
|
2004
|
+
controller.enqueue(frame(JSON.stringify(message)));
|
|
1906
2005
|
} catch (_) {
|
|
1907
2006
|
closed = true;
|
|
1908
2007
|
}
|
|
@@ -1965,6 +2064,12 @@ function frameTransformResult(event, result, context) {
|
|
|
1965
2064
|
const invocation = getEventServerFunctionInvocation(event);
|
|
1966
2065
|
const live = !!(invocation && invocation.live);
|
|
1967
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);
|
|
1968
2073
|
return serverComponentResponse(result, {
|
|
1969
2074
|
frame: {
|
|
1970
2075
|
id: invocation && invocation.id || ""
|
|
@@ -1976,6 +2081,270 @@ function frameTransformResult(event, result, context) {
|
|
|
1976
2081
|
}
|
|
1977
2082
|
}, init);
|
|
1978
2083
|
}
|
|
2084
|
+
const HOLE_SOURCE = Symbol("solid.frames.holeSource");
|
|
2085
|
+
const BROADCASTS = new Map();
|
|
2086
|
+
function broadcastResponse(key, component, options, signal, have, init) {
|
|
2087
|
+
let shared = BROADCASTS.get(key);
|
|
2088
|
+
if (!shared || shared.ended) shared = startBroadcast(key, component, options);
|
|
2089
|
+
return tapResponse(shared, signal, have, init);
|
|
2090
|
+
}
|
|
2091
|
+
function startBroadcast(key, component, options) {
|
|
2092
|
+
const shared = {
|
|
2093
|
+
key,
|
|
2094
|
+
id: options.frame.id,
|
|
2095
|
+
start: null,
|
|
2096
|
+
taps: new Set(),
|
|
2097
|
+
records: new Map(),
|
|
2098
|
+
data: [],
|
|
2099
|
+
kept: 0,
|
|
2100
|
+
attrs: new Map(),
|
|
2101
|
+
tiers: new Set(["wire"]),
|
|
2102
|
+
failed: false,
|
|
2103
|
+
ended: false,
|
|
2104
|
+
teardown: new AbortController()
|
|
2105
|
+
};
|
|
2106
|
+
BROADCASTS.set(key, shared);
|
|
2107
|
+
const stream = renderServerComponent(component, {
|
|
2108
|
+
...options,
|
|
2109
|
+
broadcast: (key, text) => shared.attrs.set(key, text),
|
|
2110
|
+
signal: shared.teardown.signal
|
|
2111
|
+
});
|
|
2112
|
+
const run = () => stream.pipe({
|
|
2113
|
+
write(message) {
|
|
2114
|
+
const bytes = createEventChunk(JSON.stringify(message));
|
|
2115
|
+
if (message.type === "start") return void (shared.start = bytes);
|
|
2116
|
+
retain(shared, message);
|
|
2117
|
+
for (const tap of shared.taps) tap.write(bytes);
|
|
2118
|
+
},
|
|
2119
|
+
end() {
|
|
2120
|
+
shared.ended = true;
|
|
2121
|
+
if (BROADCASTS.get(key) === shared) BROADCASTS.delete(key);
|
|
2122
|
+
for (const tap of [...shared.taps]) tap.end();
|
|
2123
|
+
},
|
|
2124
|
+
[ANNOUNCE](tiers) {
|
|
2125
|
+
for (const tier of tiers) shared.tiers.add(tier);
|
|
2126
|
+
}
|
|
2127
|
+
});
|
|
2128
|
+
const store = globalThis[RequestContext];
|
|
2129
|
+
store ? store.run(broadcastEvent(), run) : run();
|
|
2130
|
+
return shared;
|
|
2131
|
+
}
|
|
2132
|
+
function broadcastEvent() {
|
|
2133
|
+
const event = {
|
|
2134
|
+
broadcast: true
|
|
2135
|
+
};
|
|
2136
|
+
for (const name of ["request", "locals", "clientAddress", "nativeEvent"]) Object.defineProperty(event, name, {
|
|
2137
|
+
get() {
|
|
2138
|
+
console.warn(`A broadcast server component read the request (\`event.${name}\`). Its answer is ` + "shared by every viewer; read per-viewer state in the server function body instead.");
|
|
2139
|
+
return undefined;
|
|
2140
|
+
}
|
|
2141
|
+
});
|
|
2142
|
+
return event;
|
|
2143
|
+
}
|
|
2144
|
+
function retain(shared, message) {
|
|
2145
|
+
if (message.tiers) for (const tier of message.tiers) shared.tiers.add(tier);
|
|
2146
|
+
if (!message.r) {
|
|
2147
|
+
shared.data.push(message);
|
|
2148
|
+
if (shared.data.length > 64 && shared.data.length > 2 * shared.kept) shared.kept = (shared.data = referencedData(shared)).length;
|
|
2149
|
+
return;
|
|
2150
|
+
}
|
|
2151
|
+
const {
|
|
2152
|
+
id,
|
|
2153
|
+
version
|
|
2154
|
+
} = message;
|
|
2155
|
+
for (const k in message.r) {
|
|
2156
|
+
let record = message.r[k];
|
|
2157
|
+
if (k === ":error") shared.failed = true;
|
|
2158
|
+
if (k === "") for (const [rk, e] of shared.records) if (e.id === id) shared.records.delete(rk);
|
|
2159
|
+
if (record && record[HOLE_SOURCE]) record = record[HOLE_SOURCE];
|
|
2160
|
+
const rk = id + "\0" + k;
|
|
2161
|
+
const prev = shared.records.get(rk);
|
|
2162
|
+
if (prev && record && record.kind === "attrs" && prev.record.removed) {
|
|
2163
|
+
const removed = new Set(prev.record.removed);
|
|
2164
|
+
if (record.removed) for (const name of record.removed) removed.add(name);
|
|
2165
|
+
record = {
|
|
2166
|
+
...record,
|
|
2167
|
+
removed: [...removed]
|
|
2168
|
+
};
|
|
2169
|
+
}
|
|
2170
|
+
shared.records.delete(rk);
|
|
2171
|
+
shared.records.set(rk, {
|
|
2172
|
+
id,
|
|
2173
|
+
version,
|
|
2174
|
+
k,
|
|
2175
|
+
record
|
|
2176
|
+
});
|
|
2177
|
+
}
|
|
2178
|
+
}
|
|
2179
|
+
function referencedData(shared) {
|
|
2180
|
+
const refs = new Set();
|
|
2181
|
+
for (const {
|
|
2182
|
+
record
|
|
2183
|
+
} of shared.records.values()) if (record && typeof record === "object") for (const m of JSON.stringify(record).matchAll(/"\$ref":"((?:[^"\\]|\\.)*)"/g)) refs.add(JSON.parse(`"${m[1]}"`));
|
|
2184
|
+
return shared.data.filter(m => typeof m.key !== "string" || refs.has(m.key));
|
|
2185
|
+
}
|
|
2186
|
+
function snapshot(shared, have) {
|
|
2187
|
+
const out = referencedData(shared);
|
|
2188
|
+
const root = shared.records.get(shared.id + "\0");
|
|
2189
|
+
const conditional = !!(have && root && root.record && have[""] === root.record.digest);
|
|
2190
|
+
let open = null;
|
|
2191
|
+
const put = (id, version, k, record) => {
|
|
2192
|
+
if (!open || open.id !== id) out.push(open = {
|
|
2193
|
+
id,
|
|
2194
|
+
version,
|
|
2195
|
+
r: {}
|
|
2196
|
+
});
|
|
2197
|
+
open.r[k] = record;
|
|
2198
|
+
};
|
|
2199
|
+
if (!conditional) {
|
|
2200
|
+
for (const {
|
|
2201
|
+
id,
|
|
2202
|
+
version,
|
|
2203
|
+
k,
|
|
2204
|
+
record
|
|
2205
|
+
} of shared.records.values()) put(id, version, k, record);
|
|
2206
|
+
return out;
|
|
2207
|
+
}
|
|
2208
|
+
const containers = [];
|
|
2209
|
+
for (const e of shared.records.values()) if (e.id === shared.id && (e.k === "" || /^seg:[^:]+$/.test(e.k)) && e.record) containers.push({
|
|
2210
|
+
e,
|
|
2211
|
+
value: e.record.value
|
|
2212
|
+
});
|
|
2213
|
+
for (const {
|
|
2214
|
+
k,
|
|
2215
|
+
record
|
|
2216
|
+
} of shared.records.values()) {
|
|
2217
|
+
if (!k.startsWith("hole:lh:") || k.endsWith(":error") || !record || record.value == null) continue;
|
|
2218
|
+
const n = k.slice(8);
|
|
2219
|
+
const startMark = `<!--lh:${n}-->`;
|
|
2220
|
+
const endMark = `<!--lh:/${n}-->`;
|
|
2221
|
+
for (const c of containers) {
|
|
2222
|
+
const start = c.value.indexOf(startMark);
|
|
2223
|
+
if (start < 0) continue;
|
|
2224
|
+
const end = c.value.indexOf(endMark, start);
|
|
2225
|
+
if (end < 0) continue;
|
|
2226
|
+
c.value = c.value.slice(0, start + startMark.length) + record.value + c.value.slice(end);
|
|
2227
|
+
break;
|
|
2228
|
+
}
|
|
2229
|
+
}
|
|
2230
|
+
for (const e of shared.records.values()) {
|
|
2231
|
+
const {
|
|
2232
|
+
id,
|
|
2233
|
+
version,
|
|
2234
|
+
k,
|
|
2235
|
+
record
|
|
2236
|
+
} = e;
|
|
2237
|
+
if (id !== shared.id) {
|
|
2238
|
+
put(id, version, k, record);
|
|
2239
|
+
continue;
|
|
2240
|
+
}
|
|
2241
|
+
if (k === "" || k === "seg::assets" || k.startsWith("hole:lh:") && !k.endsWith(":error")) continue;
|
|
2242
|
+
const seg = /^seg:([^:]+)(?::(.*))?$/.exec(k);
|
|
2243
|
+
if (seg && have[seg[1]] !== undefined && seg[2] !== "error") continue;
|
|
2244
|
+
if (seg && seg[2] === undefined) {
|
|
2245
|
+
const c = containers.find(c => c.e === e);
|
|
2246
|
+
if (c && c.value !== record.value) {
|
|
2247
|
+
put(id, version, k, withHoles({
|
|
2248
|
+
...record,
|
|
2249
|
+
value: c.value,
|
|
2250
|
+
digest: textDigest(c.value)
|
|
2251
|
+
}, holeDigests(c.value, null)));
|
|
2252
|
+
continue;
|
|
2253
|
+
}
|
|
2254
|
+
}
|
|
2255
|
+
if (k.startsWith("attr:")) continue;
|
|
2256
|
+
put(id, version, k, record);
|
|
2257
|
+
}
|
|
2258
|
+
for (const c of containers) {
|
|
2259
|
+
const seg = c.e.k && /^seg:([^:]+)$/.exec(c.e.k);
|
|
2260
|
+
if (seg && have[seg[1]] === undefined) continue;
|
|
2261
|
+
for (const m of c.value.matchAll(HOLE_RANGE)) {
|
|
2262
|
+
const key = "lh:" + m[1];
|
|
2263
|
+
const digest = textDigest(stripHoleMarkers(m[2]));
|
|
2264
|
+
if (have[key] === digest) continue;
|
|
2265
|
+
put(shared.id, c.e.version, "hole:" + key, withHoles({
|
|
2266
|
+
kind: "html",
|
|
2267
|
+
value: m[2],
|
|
2268
|
+
digest
|
|
2269
|
+
}, holeDigests(m[2], null)));
|
|
2270
|
+
}
|
|
2271
|
+
for (const m of c.value.matchAll(ATTR_ADDRESS)) {
|
|
2272
|
+
const latest = shared.records.get(shared.id + "\0attr:" + m[1]);
|
|
2273
|
+
const text = latest ? latest.record.value : shared.attrs.get("lha:" + m[1]);
|
|
2274
|
+
if (text === undefined) continue;
|
|
2275
|
+
const digest = latest ? latest.record.digest : textDigest(text);
|
|
2276
|
+
if (have["lha:" + m[1]] === digest) continue;
|
|
2277
|
+
put(shared.id, c.e.version, "attr:" + m[1], latest ? latest.record : {
|
|
2278
|
+
kind: "attrs",
|
|
2279
|
+
value: text,
|
|
2280
|
+
digest
|
|
2281
|
+
});
|
|
2282
|
+
}
|
|
2283
|
+
}
|
|
2284
|
+
return out;
|
|
2285
|
+
}
|
|
2286
|
+
function tapResponse(shared, signal, have, init = {}) {
|
|
2287
|
+
const headers = copyInitHeaders(init.headers);
|
|
2288
|
+
headers.set(FRAME_STREAM_HEADER, shared.id);
|
|
2289
|
+
headers.set("X-Content-Raw", "1");
|
|
2290
|
+
headers.set("Content-Type", "text/event-stream");
|
|
2291
|
+
headers.set("Cache-Control", "no-store");
|
|
2292
|
+
headers.set("X-Accel-Buffering", "no");
|
|
2293
|
+
headers.set(FRAME_TIERS_HEADER, [...shared.tiers].join(","));
|
|
2294
|
+
let closed = false;
|
|
2295
|
+
let stopLive = null;
|
|
2296
|
+
let tap = null;
|
|
2297
|
+
const leave = () => {
|
|
2298
|
+
if (closed) return;
|
|
2299
|
+
closed = true;
|
|
2300
|
+
if (stopLive) stopLive();
|
|
2301
|
+
if (signal) signal.removeEventListener("abort", leave);
|
|
2302
|
+
shared.taps.delete(tap);
|
|
2303
|
+
if (!shared.taps.size && !shared.ended) {
|
|
2304
|
+
shared.ended = true;
|
|
2305
|
+
if (BROADCASTS.get(shared.key) === shared) BROADCASTS.delete(shared.key);
|
|
2306
|
+
shared.teardown.abort({
|
|
2307
|
+
[DISCONNECTED]: true
|
|
2308
|
+
});
|
|
2309
|
+
}
|
|
2310
|
+
};
|
|
2311
|
+
const body = new ReadableStream({
|
|
2312
|
+
start(controller) {
|
|
2313
|
+
tap = {
|
|
2314
|
+
write(bytes) {
|
|
2315
|
+
if (closed) return;
|
|
2316
|
+
try {
|
|
2317
|
+
controller.enqueue(bytes);
|
|
2318
|
+
} catch (_) {
|
|
2319
|
+
leave();
|
|
2320
|
+
}
|
|
2321
|
+
},
|
|
2322
|
+
end() {
|
|
2323
|
+
leave();
|
|
2324
|
+
try {
|
|
2325
|
+
controller.close();
|
|
2326
|
+
} catch (_) {}
|
|
2327
|
+
}
|
|
2328
|
+
};
|
|
2329
|
+
if (shared.start) controller.enqueue(shared.start);
|
|
2330
|
+
for (const message of snapshot(shared, have)) controller.enqueue(createEventChunk(JSON.stringify(message)));
|
|
2331
|
+
if (shared.ended || signal && signal.aborted) return tap.end();
|
|
2332
|
+
shared.taps.add(tap);
|
|
2333
|
+
stopLive = armLiveBody(controller, leave);
|
|
2334
|
+
if (signal) signal.addEventListener("abort", leave, {
|
|
2335
|
+
once: true
|
|
2336
|
+
});
|
|
2337
|
+
},
|
|
2338
|
+
cancel() {
|
|
2339
|
+
leave();
|
|
2340
|
+
}
|
|
2341
|
+
});
|
|
2342
|
+
if (shared.failed) headers.set("Cache-Control", "no-store");
|
|
2343
|
+
return new Response(body, {
|
|
2344
|
+
status: init.status || 200,
|
|
2345
|
+
headers
|
|
2346
|
+
});
|
|
2347
|
+
}
|
|
1979
2348
|
function requestSignal(event) {
|
|
1980
2349
|
const request = event && event.request;
|
|
1981
2350
|
return request && request.signal instanceof AbortSignal ? request.signal : undefined;
|
|
@@ -2060,10 +2429,10 @@ function frameFlightResponse({
|
|
|
2060
2429
|
let closed = false;
|
|
2061
2430
|
const body = new ReadableStream({
|
|
2062
2431
|
async start(controller) {
|
|
2063
|
-
const write =
|
|
2432
|
+
const write = message => {
|
|
2064
2433
|
if (closed) return;
|
|
2065
2434
|
try {
|
|
2066
|
-
controller.enqueue(createChunk(JSON.stringify(
|
|
2435
|
+
controller.enqueue(createChunk(JSON.stringify(message)));
|
|
2067
2436
|
} catch (_) {
|
|
2068
2437
|
closed = true;
|
|
2069
2438
|
}
|