@solidjs/web 2.0.0-rc.14 → 2.0.0-rc.16
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 +475 -591
- package/dist/server.js +459 -489
- package/dist/server.observe.js +459 -498
- package/dist/web.dev.js +206 -220
- package/dist/web.js +196 -208
- package/dist/web.observe.js +206 -213
- package/frames/dist/client.dev.js +664 -643
- package/frames/dist/client.js +593 -582
- package/frames/dist/client.observe.js +624 -589
- package/frames/dist/regions.js +43 -2
- package/frames/dist/server.dev.js +578 -450
- package/frames/dist/server.js +578 -397
- package/frames/dist/server.observe.js +578 -397
- package/frames/dist/trace.js +4 -1
- package/frames/dist/wire.js +371 -6
- package/package.json +13 -13
- package/serialization/dist/decode.js +11 -9
- package/serialization/dist/serialization.js +11 -9
- package/serialization/types/serializer-decode.d.ts +2 -2
- package/server-functions/dist/client.dev.js +5 -2
- package/server-functions/dist/client.js +3 -2
- package/server-functions/dist/client.observe.js +5 -2
- package/server-functions/dist/rich-args.js +33 -1
- package/server-functions/dist/server.dev.js +218 -35
- package/server-functions/dist/server.js +218 -35
- package/server-functions/dist/server.observe.js +218 -35
- package/skills/server-components/SKILL.md +74 -185
- package/types/client.d.ts +112 -10
- package/types/constants.d.ts +2 -1
- 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 +1 -53
- package/types/frames/wire-tier.d.ts +54 -1
- package/types/head.d.ts +1 -0
- package/types/index.d.ts +57 -50
- package/types/index.server.d.ts +3 -27
- package/types/jsx.d.ts +14 -17
- package/types/observe.d.ts +14 -7
- package/types/render.d.ts +3 -1
- package/types/response.d.ts +31 -8
- package/types/serializer-decode.d.ts +2 -2
- package/types/server-functions/argument-codec.d.ts +21 -0
- package/types/server-functions/client.d.ts +18 -5
- package/types/server-functions/server.d.ts +6 -2
- package/types/server-functions/shared.d.ts +19 -0
- package/types/server-mock.d.ts +9 -2
- package/types/server-observe.d.ts +3 -2
- package/types/server.d.ts +124 -67
- 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,9 +1,9 @@
|
|
|
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, 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
|
-
import {
|
|
6
|
+
import { frameAddress, getEventServerFunctionInvocation, ChunkReader, serializeStream, guardFailures, armLiveBody, createEventChunk, createChunk, textDigest } from '@solidjs/web/server-functions/server';
|
|
7
7
|
|
|
8
8
|
const DESCEND = Symbol("descend");
|
|
9
9
|
const CYCLE = {};
|
|
@@ -132,9 +132,7 @@ function toBorderForm(value, envelopeContainers) {
|
|
|
132
132
|
}
|
|
133
133
|
function isShareableIterable(value) {
|
|
134
134
|
try {
|
|
135
|
-
|
|
136
|
-
if (typeof ReadableStream !== "undefined" && value instanceof ReadableStream) return false;
|
|
137
|
-
return typeof value[Symbol.asyncIterator] === "function";
|
|
135
|
+
return typeof value[Symbol.asyncIterator] === "function" && !(typeof ReadableStream !== "undefined" && value instanceof ReadableStream);
|
|
138
136
|
} catch {
|
|
139
137
|
return false;
|
|
140
138
|
}
|
|
@@ -188,15 +186,6 @@ const ContainerTracePlugin = {
|
|
|
188
186
|
}
|
|
189
187
|
};
|
|
190
188
|
|
|
191
|
-
function emitFinding(finding, subject = getOwner()) {
|
|
192
|
-
if (OBSERVE === undefined) return;
|
|
193
|
-
const entry = OBSERVE.diagnostics.emit(finding, subject);
|
|
194
|
-
if (DEV !== undefined) DEV.report(entry);
|
|
195
|
-
}
|
|
196
|
-
function devCheck(finding, subject) {
|
|
197
|
-
emitFinding(finding, subject);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
189
|
setContainerTraceStreamMint(iterable => {
|
|
201
190
|
const stream = createStream();
|
|
202
191
|
(async () => {
|
|
@@ -218,14 +207,16 @@ function resolveSerializerPlugins(customPlugins) {
|
|
|
218
207
|
}
|
|
219
208
|
const jsonCodecDisabledFeatures = () => Feature.RegExp;
|
|
220
209
|
const JSON_CODEC_DEPTH_LIMIT = 64;
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
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;
|
|
227
218
|
return {
|
|
228
|
-
plugins: resolveSerializerPlugins(plugins),
|
|
219
|
+
plugins: options[RESOLVED_PLUGINS] || resolveSerializerPlugins(plugins),
|
|
229
220
|
disabledFeatures: disabledFeatures === undefined ? jsonCodecDisabledFeatures() : disabledFeatures,
|
|
230
221
|
depthLimit: depthLimit === undefined ? JSON_CODEC_DEPTH_LIMIT : depthLimit,
|
|
231
222
|
serializeErrorStacks
|
|
@@ -305,8 +296,17 @@ const RECORDS = Symbol.for("@solidjs/signals/observe/records");
|
|
|
305
296
|
function records() {
|
|
306
297
|
return globalThis[RECORDS];
|
|
307
298
|
}
|
|
308
|
-
function
|
|
309
|
-
|
|
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) {
|
|
310
310
|
switch (type) {
|
|
311
311
|
case "html":
|
|
312
312
|
if (!own) event.regions++;else if (event.shellMs === undefined) event.shellMs = performance.now() - event.at;
|
|
@@ -341,9 +341,8 @@ function observeFrame(frame) {
|
|
|
341
341
|
};
|
|
342
342
|
let settled = false;
|
|
343
343
|
return {
|
|
344
|
-
chunk(
|
|
345
|
-
|
|
346
|
-
frameCensus(event, chunk.type, chunk.id === frame.id);
|
|
344
|
+
chunk(message) {
|
|
345
|
+
frameRecordCensus(event, message, message.id === frame.id);
|
|
347
346
|
},
|
|
348
347
|
settle(outcome, error) {
|
|
349
348
|
if (settled) return;
|
|
@@ -496,14 +495,41 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
496
495
|
} = frame;
|
|
497
496
|
const tiers = new Set();
|
|
498
497
|
let staged = [];
|
|
499
|
-
const
|
|
500
|
-
if (swept) swept.emitted = true;
|
|
498
|
+
const send = message => {
|
|
501
499
|
if (staged.length) {
|
|
502
|
-
|
|
500
|
+
message.tiers = staged;
|
|
503
501
|
staged = [];
|
|
504
502
|
}
|
|
505
|
-
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);
|
|
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
|
+
}
|
|
506
529
|
};
|
|
530
|
+
const putError = (fid, key, error) => put(fid, {
|
|
531
|
+
[key ? `${/^lha?:/.test(key) ? "hole" : "seg"}:${key}:error` : ":error"]: error
|
|
532
|
+
});
|
|
507
533
|
const needs = name => {
|
|
508
534
|
if (!tiers.has(name)) {
|
|
509
535
|
tiers.add(name);
|
|
@@ -513,36 +539,44 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
513
539
|
let conditional = false;
|
|
514
540
|
const skipped = new Set();
|
|
515
541
|
const attrText = new Map();
|
|
516
|
-
const
|
|
517
|
-
|
|
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)) {
|
|
518
559
|
const key = "lh:" + m[1];
|
|
519
560
|
const digest = textDigest(stripHoleMarkers(m[2]));
|
|
520
561
|
if (have[key] === digest) continue;
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
version,
|
|
525
|
-
key,
|
|
526
|
-
html: m[2],
|
|
527
|
-
digest
|
|
528
|
-
}, holeDigests(m[2], null)));
|
|
562
|
+
put(id, {
|
|
563
|
+
["hole:" + key]: html(m[2], digest, holeDigests(m[2], null))
|
|
564
|
+
});
|
|
529
565
|
}
|
|
530
|
-
for (const m of
|
|
566
|
+
for (const m of source.matchAll(ATTR_ADDRESS)) {
|
|
531
567
|
const text = attrText.get("lha:" + m[1]);
|
|
532
568
|
if (text === undefined) continue;
|
|
533
569
|
const digest = textDigest(text);
|
|
534
570
|
if (have["lha:" + m[1]] === digest) continue;
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
digest
|
|
571
|
+
put(id, {
|
|
572
|
+
["attr:" + m[1]]: {
|
|
573
|
+
kind: "attrs",
|
|
574
|
+
value: text,
|
|
575
|
+
digest
|
|
576
|
+
}
|
|
542
577
|
});
|
|
543
578
|
}
|
|
544
579
|
};
|
|
545
|
-
const styledKeys = new Set();
|
|
546
580
|
const bindings = new Map();
|
|
547
581
|
const sweepMinted = new Set();
|
|
548
582
|
const argRefVersions = new Map();
|
|
@@ -553,34 +587,27 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
553
587
|
const sweep = () => {
|
|
554
588
|
epoch++;
|
|
555
589
|
const pass = swept = {
|
|
556
|
-
|
|
590
|
+
r: {},
|
|
557
591
|
emitted: false
|
|
558
592
|
};
|
|
559
593
|
try {
|
|
560
|
-
for (const b of [...bindings
|
|
594
|
+
for (const [key, b] of [...bindings]) {
|
|
595
|
+
if (bindings.get(key) !== b) continue;
|
|
561
596
|
try {
|
|
562
597
|
b.sweep();
|
|
563
598
|
} catch (_) {
|
|
564
599
|
}
|
|
565
600
|
}
|
|
566
|
-
|
|
601
|
+
for (const _ in pass.r) {
|
|
602
|
+
put(id, pass.r);
|
|
603
|
+
break;
|
|
604
|
+
}
|
|
605
|
+
flush();
|
|
567
606
|
if (pass.emitted && hooks && hooks.onYield) hooks.onYield();
|
|
568
607
|
} finally {
|
|
569
608
|
swept = null;
|
|
570
609
|
}
|
|
571
610
|
};
|
|
572
|
-
const emitOps = ops => {
|
|
573
|
-
if (ops.length === 1) emit(Object.assign({
|
|
574
|
-
type: ops[0].type,
|
|
575
|
-
id,
|
|
576
|
-
version
|
|
577
|
-
}, ops[0]));else if (ops.length) emit({
|
|
578
|
-
type: "ops",
|
|
579
|
-
id,
|
|
580
|
-
version,
|
|
581
|
-
ops
|
|
582
|
-
});
|
|
583
|
-
};
|
|
584
611
|
const scheduleSweep = () => {
|
|
585
612
|
if (closed || sweepScheduled || !bindings.size) return;
|
|
586
613
|
sweepScheduled = true;
|
|
@@ -595,52 +622,47 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
595
622
|
tagRegion(key, childId) {
|
|
596
623
|
if (!regionKeys.has(key)) regionKeys.set(key, childId);
|
|
597
624
|
},
|
|
598
|
-
shell(
|
|
599
|
-
const digest = textDigest(frameSkeleton(
|
|
625
|
+
shell(source, meta = {}) {
|
|
626
|
+
const digest = textDigest(frameSkeleton(source));
|
|
600
627
|
if (have && have[""] === digest) {
|
|
601
628
|
conditional = true;
|
|
602
|
-
emitDiffering(
|
|
629
|
+
emitDiffering(source);
|
|
603
630
|
return;
|
|
604
631
|
}
|
|
605
632
|
if (meta.preloads && meta.preloads.size || meta.preloadLinks) {
|
|
606
|
-
const
|
|
607
|
-
type: "assets",
|
|
608
|
-
id,
|
|
609
|
-
version,
|
|
610
|
-
key: ""
|
|
611
|
-
};
|
|
633
|
+
const record = {};
|
|
612
634
|
if (meta.preloads && meta.preloads.size) {
|
|
613
635
|
const styles = [];
|
|
614
636
|
const modules = [];
|
|
615
637
|
for (const url of meta.preloads) {
|
|
616
638
|
(url.endsWith(".css") ? styles : modules).push(url);
|
|
617
639
|
}
|
|
618
|
-
if (styles.length)
|
|
619
|
-
if (modules.length)
|
|
640
|
+
if (styles.length) record.styles = styles;
|
|
641
|
+
if (modules.length) record.modules = modules;
|
|
620
642
|
}
|
|
621
643
|
if (meta.preloadLinks) {
|
|
622
|
-
|
|
644
|
+
record.preloads = [];
|
|
623
645
|
for (const entry of meta.preloadLinks) {
|
|
624
|
-
|
|
646
|
+
record.preloads.push(wirePreload(entry));
|
|
625
647
|
}
|
|
626
648
|
}
|
|
627
649
|
needs("assets");
|
|
628
|
-
|
|
650
|
+
put(id, {
|
|
651
|
+
"seg::assets": record
|
|
652
|
+
});
|
|
629
653
|
}
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
version,
|
|
634
|
-
html,
|
|
635
|
-
digest
|
|
636
|
-
}, holeDigests(html, attrText)));
|
|
654
|
+
put(id, {
|
|
655
|
+
"": html(source, digest, holeDigests(source, attrText))
|
|
656
|
+
});
|
|
637
657
|
},
|
|
638
658
|
data(record) {
|
|
639
659
|
if (record && typeof record.key === "string" && (record.key.endsWith("_fr") || /^\d+$/.test(record.key))) {
|
|
640
660
|
return;
|
|
641
661
|
}
|
|
662
|
+
if (swept) swept.emitted = true;
|
|
663
|
+
flush();
|
|
642
664
|
if (typeof record === "string") {
|
|
643
|
-
|
|
665
|
+
send({
|
|
644
666
|
type: "data",
|
|
645
667
|
id,
|
|
646
668
|
version,
|
|
@@ -648,7 +670,7 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
648
670
|
});
|
|
649
671
|
scheduleSweep();
|
|
650
672
|
} else {
|
|
651
|
-
|
|
673
|
+
send({
|
|
652
674
|
type: "data",
|
|
653
675
|
id,
|
|
654
676
|
version,
|
|
@@ -665,73 +687,40 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
665
687
|
skipped.add(key);
|
|
666
688
|
scheduleSweep();
|
|
667
689
|
if (meta.error) {
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
id: fid,
|
|
671
|
-
version,
|
|
672
|
-
key,
|
|
673
|
-
error: {
|
|
674
|
-
message: String(meta.error && meta.error.message || meta.error)
|
|
675
|
-
}
|
|
690
|
+
putError(fid, key, {
|
|
691
|
+
message: String(meta.error && meta.error.message || meta.error)
|
|
676
692
|
});
|
|
677
693
|
} else emitDiffering(value);
|
|
678
694
|
return;
|
|
679
695
|
}
|
|
680
696
|
const links = meta.styles && meta.styles.links || [];
|
|
681
697
|
const inline = meta.styles && meta.styles.inline || [];
|
|
698
|
+
const r = {};
|
|
682
699
|
if (links.length || inline.length) {
|
|
683
|
-
|
|
684
|
-
const chunk = {
|
|
685
|
-
type: "assets",
|
|
686
|
-
id: fid,
|
|
687
|
-
version,
|
|
688
|
-
key
|
|
689
|
-
};
|
|
700
|
+
const record = {};
|
|
690
701
|
if (links.length) {
|
|
691
|
-
|
|
702
|
+
record.styles = links.map(e => typeof e === "string" ? e : e.attrs ? {
|
|
692
703
|
href: e.href,
|
|
693
704
|
attrs: e.attrs
|
|
694
705
|
} : e.href);
|
|
695
706
|
}
|
|
696
707
|
if (inline.length) {
|
|
697
|
-
|
|
708
|
+
record.inlineStyles = inline.map(e => ({
|
|
698
709
|
id: e.id,
|
|
699
710
|
content: e.content,
|
|
700
711
|
attrs: e.attrs
|
|
701
712
|
}));
|
|
702
713
|
}
|
|
703
714
|
needs("assets");
|
|
704
|
-
|
|
715
|
+
r[`seg:${key}:assets`] = record;
|
|
705
716
|
}
|
|
706
|
-
|
|
707
|
-
type: "fragment",
|
|
708
|
-
id: fid,
|
|
709
|
-
version,
|
|
710
|
-
key,
|
|
711
|
-
html: value,
|
|
712
|
-
digest: textDigest(value)
|
|
713
|
-
}, holeDigests(value, attrText)));
|
|
717
|
+
r[`seg:${key}`] = html(value, textDigest(value), holeDigests(value, attrText));
|
|
714
718
|
scheduleSweep();
|
|
715
|
-
if (meta.error) {
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
key,
|
|
721
|
-
error: {
|
|
722
|
-
message: String(meta.error && meta.error.message || meta.error)
|
|
723
|
-
}
|
|
724
|
-
});
|
|
725
|
-
}
|
|
726
|
-
if (!meta.revealGroup) {
|
|
727
|
-
emit({
|
|
728
|
-
type: "reveal",
|
|
729
|
-
id: fid,
|
|
730
|
-
version,
|
|
731
|
-
keys: [key],
|
|
732
|
-
waitForStyles: !!links.length
|
|
733
|
-
});
|
|
734
|
-
}
|
|
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);
|
|
735
724
|
},
|
|
736
725
|
reveal(keys, meta = {}) {
|
|
737
726
|
const byFrame = new Map();
|
|
@@ -742,38 +731,27 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
742
731
|
if (!group) byFrame.set(fid, group = []);
|
|
743
732
|
group.push(key);
|
|
744
733
|
}
|
|
734
|
+
const gate = meta.fallback ? "fallback" : "reveal";
|
|
745
735
|
for (const [fid, groupKeys] of byFrame) {
|
|
746
|
-
|
|
747
|
-
for (const key of groupKeys)
|
|
748
|
-
|
|
749
|
-
type: "reveal",
|
|
750
|
-
id: fid,
|
|
751
|
-
version,
|
|
752
|
-
keys: groupKeys,
|
|
753
|
-
waitForStyles
|
|
754
|
-
};
|
|
755
|
-
if (meta.fallback) chunk.fallback = true;
|
|
756
|
-
emit(chunk);
|
|
736
|
+
const r = {};
|
|
737
|
+
for (const key of groupKeys) r[`seg:${key}:${gate}`] = true;
|
|
738
|
+
put(fid, r);
|
|
757
739
|
}
|
|
758
740
|
},
|
|
759
741
|
asset(type, value) {
|
|
760
742
|
if (type === "module") {
|
|
761
743
|
needs("assets");
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
key: "",
|
|
767
|
-
modules: [value]
|
|
744
|
+
put(id, {
|
|
745
|
+
"seg::assets": {
|
|
746
|
+
modules: [value]
|
|
747
|
+
}
|
|
768
748
|
});
|
|
769
749
|
} else if (type === "preload") {
|
|
770
750
|
needs("assets");
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
key: "",
|
|
776
|
-
preloads: [wirePreload(value)]
|
|
751
|
+
put(id, {
|
|
752
|
+
"seg::assets": {
|
|
753
|
+
preloads: [wirePreload(value)]
|
|
754
|
+
}
|
|
777
755
|
});
|
|
778
756
|
}
|
|
779
757
|
},
|
|
@@ -781,64 +759,69 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
781
759
|
if (closed) return;
|
|
782
760
|
if (bindings.size && !swept) sweep();
|
|
783
761
|
closed = true;
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
762
|
+
put(id, bound ? {
|
|
763
|
+
":complete": true,
|
|
764
|
+
":bound": bound
|
|
765
|
+
} : {
|
|
766
|
+
":complete": true
|
|
767
|
+
});
|
|
768
|
+
flush();
|
|
791
769
|
},
|
|
792
770
|
error(errorId, error) {
|
|
793
|
-
|
|
794
|
-
type: "error",
|
|
795
|
-
id,
|
|
796
|
-
version,
|
|
797
|
-
key: errorId,
|
|
798
|
-
error
|
|
799
|
-
});
|
|
771
|
+
putError(id, errorId, error);
|
|
800
772
|
},
|
|
773
|
+
flush,
|
|
801
774
|
slot(key, args) {
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
args
|
|
775
|
+
put(id, {
|
|
776
|
+
[`slot:${key}`]: {
|
|
777
|
+
kind: "slot",
|
|
778
|
+
args
|
|
779
|
+
}
|
|
808
780
|
});
|
|
809
781
|
},
|
|
810
|
-
region(childId,
|
|
782
|
+
region(childId, value) {
|
|
811
783
|
needs("regions");
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
784
|
+
put(childId, {
|
|
785
|
+
"": {
|
|
786
|
+
kind: "html",
|
|
787
|
+
value
|
|
788
|
+
}
|
|
817
789
|
});
|
|
818
790
|
},
|
|
819
|
-
hole(key,
|
|
820
|
-
const
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
791
|
+
hole(key, source, rows) {
|
|
792
|
+
const record = {
|
|
793
|
+
kind: "html",
|
|
794
|
+
digest: textDigest(source)
|
|
795
|
+
};
|
|
796
|
+
const base = holeDigest.get(key);
|
|
797
|
+
if (rows && base && hooks && hooks.live) {
|
|
798
|
+
record.rows = rows;
|
|
799
|
+
record.base = base;
|
|
800
|
+
} else record.value = source;
|
|
801
|
+
withHoles(record, holeDigests(record.rows ? rows.r.map(r => r[1]).join("") : source, null));
|
|
802
|
+
const r = {
|
|
803
|
+
["hole:" + key]: record
|
|
825
804
|
};
|
|
826
|
-
|
|
805
|
+
showing(r);
|
|
806
|
+
swept ? Object.assign(swept.r, r) : put(id, r);
|
|
827
807
|
},
|
|
828
808
|
attr(key, attrs, removed) {
|
|
829
|
-
const
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
attrs,
|
|
809
|
+
const record = {
|
|
810
|
+
kind: "attrs",
|
|
811
|
+
value: attrs,
|
|
833
812
|
digest: textDigest(attrs)
|
|
834
813
|
};
|
|
835
|
-
if (removed && removed.length)
|
|
836
|
-
|
|
814
|
+
if (removed && removed.length) record.removed = removed;
|
|
815
|
+
const r = {
|
|
816
|
+
["attr:" + key]: record
|
|
817
|
+
};
|
|
818
|
+
swept ? Object.assign(swept.r, r) : put(id, r);
|
|
837
819
|
},
|
|
838
820
|
attrBaseline(key, text) {
|
|
839
821
|
attrText.set(key, text);
|
|
840
822
|
},
|
|
841
823
|
openBinding(key, b) {
|
|
824
|
+
if (/^lha?:/.test(key)) needs("wire");
|
|
842
825
|
bindings.set(key, b);
|
|
843
826
|
},
|
|
844
827
|
closeBinding(key) {
|
|
@@ -863,9 +846,6 @@ function createFrameSink(write, frame, have, hooks) {
|
|
|
863
846
|
}
|
|
864
847
|
};
|
|
865
848
|
}
|
|
866
|
-
function renderToFrameStream(code, options = {}) {
|
|
867
|
-
return frameStream(() => code, options);
|
|
868
|
-
}
|
|
869
849
|
function renderServerComponent(component, options = {}) {
|
|
870
850
|
return frameStream((sink, frame) => {
|
|
871
851
|
const props = createSlotProps(sink, frame);
|
|
@@ -874,8 +854,9 @@ function renderServerComponent(component, options = {}) {
|
|
|
874
854
|
if (ctx) {
|
|
875
855
|
ctx.commit = sink.commit;
|
|
876
856
|
ctx.commitEpoch = () => sink.epoch;
|
|
877
|
-
|
|
878
|
-
ctx.
|
|
857
|
+
let unsettled = !!options.live;
|
|
858
|
+
if (!unsettled) ctx.unsettled = () => void (unsettled = true);
|
|
859
|
+
ctx.liveHoles = createLiveHoles(sink, false, () => !unsettled, ctx._errorScope);
|
|
879
860
|
}
|
|
880
861
|
return serverComponentScope(() => component(props));
|
|
881
862
|
};
|
|
@@ -908,6 +889,7 @@ function frameStream(makeCode, options) {
|
|
|
908
889
|
function finish() {
|
|
909
890
|
if (ended) return;
|
|
910
891
|
ended = true;
|
|
892
|
+
sink.flush();
|
|
911
893
|
if (timer) clearTimeout(timer);
|
|
912
894
|
if (upstream) upstream.removeEventListener("abort", onSignal);
|
|
913
895
|
w.end && w.end();
|
|
@@ -928,19 +910,20 @@ function frameStream(makeCode, options) {
|
|
|
928
910
|
finish();
|
|
929
911
|
render.abort(upstream.reason);
|
|
930
912
|
}
|
|
931
|
-
const emit =
|
|
932
|
-
if (observation) observation.chunk(
|
|
933
|
-
w.write(
|
|
934
|
-
if (bounded && !flushed &&
|
|
913
|
+
const emit = message => {
|
|
914
|
+
if (observation) observation.chunk(message);
|
|
915
|
+
w.write(message);
|
|
916
|
+
if (bounded && !flushed && message.id === id && message.r && "" in message.r) {
|
|
935
917
|
flushed = true;
|
|
936
918
|
if (maxDurationMs > 0 && maxDurationMs !== Infinity) timer = setTimeout(() => cut("time"), maxDurationMs);
|
|
937
919
|
}
|
|
938
920
|
};
|
|
939
|
-
const sink = createFrameSink(emit, frame, options.resume && options.resume.have,
|
|
940
|
-
|
|
921
|
+
const sink = createFrameSink(emit, frame, options.resume && options.resume.have, {
|
|
922
|
+
live: options.live,
|
|
923
|
+
onYield: bounded ? () => {
|
|
941
924
|
if (flushed && maxYields > 0 && ++yields >= maxYields) cut("yields");
|
|
942
|
-
}
|
|
943
|
-
}
|
|
925
|
+
} : undefined
|
|
926
|
+
});
|
|
944
927
|
if (options.live) sink.needs("wire");
|
|
945
928
|
w.write({
|
|
946
929
|
type: "start",
|
|
@@ -975,6 +958,7 @@ function frameStream(makeCode, options) {
|
|
|
975
958
|
finish();
|
|
976
959
|
}
|
|
977
960
|
if (w[ANNOUNCE]) w[ANNOUNCE](sink.announce());
|
|
961
|
+
sink.flush();
|
|
978
962
|
}
|
|
979
963
|
return {
|
|
980
964
|
pipe: stream,
|
|
@@ -996,100 +980,21 @@ function frameStream(makeCode, options) {
|
|
|
996
980
|
function slotRange(occurrence) {
|
|
997
981
|
return {
|
|
998
982
|
t: `<!--slot:${occurrence}:start--><!--slot:${occurrence}:end-->`,
|
|
999
|
-
$slot: true
|
|
1000
|
-
$occurrence: occurrence
|
|
983
|
+
$slot: true
|
|
1001
984
|
};
|
|
1002
985
|
}
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
function isRangeKey(key) {
|
|
1006
|
-
const c = key.charCodeAt(0);
|
|
1007
|
-
return c === 36 || c >= 48 && c <= 57 || RANGE_KEYS.has(key);
|
|
1008
|
-
}
|
|
1009
|
-
function slotProxy(range, occurrence, face, content, onData, needs) {
|
|
1010
|
-
return new Proxy(range, {
|
|
1011
|
-
get(target, key, receiver) {
|
|
1012
|
-
if (typeof key !== "string" || isRangeKey(key)) return Reflect.get(target, key, receiver);
|
|
1013
|
-
if (onData) onData = void onData();
|
|
1014
|
-
if (face !== SLOT_FACE_MARKUP) needs("bind");
|
|
1015
|
-
return slotValue(occurrence, key, content ? content[key] : undefined, face);
|
|
1016
|
-
}
|
|
1017
|
-
});
|
|
1018
|
-
}
|
|
1019
|
-
function argBorderForm(value, key, occurrence, needs) {
|
|
1020
|
-
return toBorderForm(withoutStandIns(value, key, occurrence, needs));
|
|
986
|
+
function argBorderForm(value, needs) {
|
|
987
|
+
return toBorderForm(noteTraces(value, needs));
|
|
1021
988
|
}
|
|
1022
|
-
function
|
|
1023
|
-
return rewriteTree(value,
|
|
989
|
+
function noteTraces(value, needs) {
|
|
990
|
+
return rewriteTree(value, v => {
|
|
1024
991
|
if (isContainerTraced(v)) {
|
|
1025
992
|
needs("trace");
|
|
1026
993
|
return v;
|
|
1027
994
|
}
|
|
1028
|
-
if (Object.getPrototypeOf(v) === Object.prototype && isSlotValue(v)) {
|
|
1029
|
-
standInArgFinding(v, key, occurrence, path);
|
|
1030
|
-
return undefined;
|
|
1031
|
-
}
|
|
1032
995
|
return DESCEND;
|
|
1033
996
|
}, true);
|
|
1034
997
|
}
|
|
1035
|
-
function standInArgFinding(sv, key, occurrence, path) {
|
|
1036
|
-
{
|
|
1037
|
-
const ctx = sharedConfig.context;
|
|
1038
|
-
if (ctx) {
|
|
1039
|
-
const id = `${occurrence}\u0000${key}${path}\u0000arg`;
|
|
1040
|
-
const seen = ctx.slotFindings || (ctx.slotFindings = new Set());
|
|
1041
|
-
if (seen.has(id)) return;
|
|
1042
|
-
seen.add(id);
|
|
1043
|
-
}
|
|
1044
|
-
const where = path === "" ? `Arg \`${key}\`` : `Arg \`${key}${path}\``;
|
|
1045
|
-
devCheck({
|
|
1046
|
-
code: "BINDING_SLOT_POSITION",
|
|
1047
|
-
kind: "ssr",
|
|
1048
|
-
severity: "warn",
|
|
1049
|
-
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.`,
|
|
1050
|
-
data: {
|
|
1051
|
-
reason: "arg",
|
|
1052
|
-
occurrence,
|
|
1053
|
-
key,
|
|
1054
|
-
path: path === "" ? undefined : path,
|
|
1055
|
-
from: sv[SLOT_VALUE],
|
|
1056
|
-
fromKey: sv.k
|
|
1057
|
-
}
|
|
1058
|
-
});
|
|
1059
|
-
}
|
|
1060
|
-
}
|
|
1061
|
-
function slotFace(range, content) {
|
|
1062
|
-
if (content == null) return SLOT_FACE_DATA;
|
|
1063
|
-
if (typeof content !== "object" || Array.isArray(content)) return SLOT_FACE_MARKUP;
|
|
1064
|
-
if (isServerContent(content)) {
|
|
1065
|
-
let data = false;
|
|
1066
|
-
for (const key in content) {
|
|
1067
|
-
if (!NODE_KEYS.has(key)) {
|
|
1068
|
-
data = true;
|
|
1069
|
-
break;
|
|
1070
|
-
}
|
|
1071
|
-
}
|
|
1072
|
-
if (!data) return SLOT_FACE_MARKUP;
|
|
1073
|
-
}
|
|
1074
|
-
{
|
|
1075
|
-
for (const key of Object.keys(content)) {
|
|
1076
|
-
if (isRangeKey(key)) {
|
|
1077
|
-
devCheck({
|
|
1078
|
-
code: "BINDING_SLOT_POSITION",
|
|
1079
|
-
kind: "ssr",
|
|
1080
|
-
severity: "warn",
|
|
1081
|
-
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.`,
|
|
1082
|
-
data: {
|
|
1083
|
-
reason: "reserved-key",
|
|
1084
|
-
occurrence: range.$occurrence,
|
|
1085
|
-
key
|
|
1086
|
-
}
|
|
1087
|
-
});
|
|
1088
|
-
}
|
|
1089
|
-
}
|
|
1090
|
-
}
|
|
1091
|
-
return SLOT_FACE_DATA;
|
|
1092
|
-
}
|
|
1093
998
|
const OCCURRENCE_UNSAFE = /[^A-Za-z0-9_.-]/g;
|
|
1094
999
|
function encodeOccurrenceKey(key) {
|
|
1095
1000
|
return String(key).replace(OCCURRENCE_UNSAFE, c => {
|
|
@@ -1144,12 +1049,19 @@ function structuralArgsKey(raw) {
|
|
|
1144
1049
|
};
|
|
1145
1050
|
return walk(raw, true) ? out : undefined;
|
|
1146
1051
|
}
|
|
1147
|
-
function
|
|
1148
|
-
const
|
|
1149
|
-
if (
|
|
1150
|
-
|
|
1151
|
-
|
|
1052
|
+
function argDigest(value) {
|
|
1053
|
+
const t = typeof value;
|
|
1054
|
+
if (value == null || t !== "object" && t !== "function" && value === value) return value;
|
|
1055
|
+
if (isContainerTraced(value)) return value;
|
|
1056
|
+
try {
|
|
1057
|
+
const key = structuralArgsKey([value]);
|
|
1058
|
+
return key === undefined ? value : key;
|
|
1059
|
+
} catch (_) {
|
|
1060
|
+
return value;
|
|
1061
|
+
}
|
|
1152
1062
|
}
|
|
1063
|
+
const PENDING_ARG = {};
|
|
1064
|
+
const noDigest = () => NaN;
|
|
1153
1065
|
function isAsyncValue(v) {
|
|
1154
1066
|
return !!v && typeof v === "object" && (typeof v.then === "function" || typeof v[Symbol.asyncIterator] === "function");
|
|
1155
1067
|
}
|
|
@@ -1165,6 +1077,37 @@ function tapFirstYield(iterable) {
|
|
|
1165
1077
|
rest
|
|
1166
1078
|
};
|
|
1167
1079
|
}
|
|
1080
|
+
function packOccurrences(occs) {
|
|
1081
|
+
const out = [];
|
|
1082
|
+
let prop = "",
|
|
1083
|
+
a = -1,
|
|
1084
|
+
b = -1;
|
|
1085
|
+
const flush = () => a >= 0 && out.push(prop + "#" + (a === b ? a : a + "-" + b));
|
|
1086
|
+
for (const o of occs) {
|
|
1087
|
+
const m = /^(.*)#(\d+)$/.exec(o);
|
|
1088
|
+
if (m && m[1] === prop && +m[2] === b + 1 && a >= 0) {
|
|
1089
|
+
b++;
|
|
1090
|
+
continue;
|
|
1091
|
+
}
|
|
1092
|
+
flush();
|
|
1093
|
+
a = b = -1;
|
|
1094
|
+
if (m) {
|
|
1095
|
+
prop = m[1];
|
|
1096
|
+
a = b = +m[2];
|
|
1097
|
+
} else out.push(o);
|
|
1098
|
+
}
|
|
1099
|
+
flush();
|
|
1100
|
+
return out.join(" ");
|
|
1101
|
+
}
|
|
1102
|
+
function hasAsyncHoles(node, depth = 0) {
|
|
1103
|
+
if (!node || typeof node !== "object" || depth > 64) return false;
|
|
1104
|
+
if (Array.isArray(node)) {
|
|
1105
|
+
for (const n of node) if (hasAsyncHoles(n, depth + 1)) return true;
|
|
1106
|
+
return false;
|
|
1107
|
+
}
|
|
1108
|
+
if (node.h && node.h.length) return true;
|
|
1109
|
+
return false;
|
|
1110
|
+
}
|
|
1168
1111
|
function suppressedFill(render) {
|
|
1169
1112
|
const live = sharedConfig.context && sharedConfig.context.liveHoles;
|
|
1170
1113
|
if (!live) return render();
|
|
@@ -1175,25 +1118,96 @@ function suppressedFill(render) {
|
|
|
1175
1118
|
live.suppressed--;
|
|
1176
1119
|
}
|
|
1177
1120
|
}
|
|
1121
|
+
let parked = null;
|
|
1122
|
+
let parkedIds = 0;
|
|
1123
|
+
const PARKED = /<!--sc-n:(\d+)-->/;
|
|
1124
|
+
function park(render) {
|
|
1125
|
+
if (!parked) return render();
|
|
1126
|
+
const id = ++parkedIds;
|
|
1127
|
+
parked.set(id, {
|
|
1128
|
+
render,
|
|
1129
|
+
out: undefined
|
|
1130
|
+
});
|
|
1131
|
+
return {
|
|
1132
|
+
t: `<!--sc-n:${id}-->`
|
|
1133
|
+
};
|
|
1134
|
+
}
|
|
1135
|
+
const runParked = (entry, owner) => entry.out || (entry.out = entry.render(owner));
|
|
1136
|
+
function placeParked(node, nested, owner) {
|
|
1137
|
+
const out = expandParked(node, nested, owner);
|
|
1138
|
+
for (const entry of nested.values()) runParked(entry, owner);
|
|
1139
|
+
return out;
|
|
1140
|
+
}
|
|
1141
|
+
function expandParked(node, nested, owner) {
|
|
1142
|
+
if (Array.isArray(node)) {
|
|
1143
|
+
const out = node.map(n => expandParked(n, nested, owner));
|
|
1144
|
+
out.$slot = node.$slot;
|
|
1145
|
+
return out;
|
|
1146
|
+
}
|
|
1147
|
+
if (!node || node.t === undefined) return node;
|
|
1148
|
+
if (!node.h) return splitParked(node.t, nested, owner) || node;
|
|
1149
|
+
const out = [];
|
|
1150
|
+
node.t.forEach((t, i) => {
|
|
1151
|
+
out.push(splitParked(t, nested, owner) || {
|
|
1152
|
+
t
|
|
1153
|
+
});
|
|
1154
|
+
if (i < node.h.length) out.push({
|
|
1155
|
+
t: ["", ""],
|
|
1156
|
+
h: [node.h[i]],
|
|
1157
|
+
p: [node.p[i]]
|
|
1158
|
+
});
|
|
1159
|
+
});
|
|
1160
|
+
return out;
|
|
1161
|
+
}
|
|
1162
|
+
function splitParked(t, nested, owner) {
|
|
1163
|
+
const parts = typeof t === "string" ? t.split(PARKED) : [t];
|
|
1164
|
+
return parts.length > 1 ? parts.map((part, i) => i & 1 ? runParked(nested.get(+part), owner) : {
|
|
1165
|
+
t: part
|
|
1166
|
+
}) : undefined;
|
|
1167
|
+
}
|
|
1178
1168
|
function createDocumentSlotProps(clientProps, frameId) {
|
|
1179
1169
|
const counts = Object.create(null);
|
|
1170
|
+
let depsBatch = null;
|
|
1171
|
+
let depsN = 0;
|
|
1172
|
+
let wideSent = 0;
|
|
1173
|
+
const depsContext = sharedConfig.context;
|
|
1174
|
+
const noteDeps = (occurrence, reads, untracked) => {
|
|
1175
|
+
if (!depsContext || !depsContext.serialize || !depsContext.edges) return;
|
|
1176
|
+
const own = `sc-${frameId}-${occurrence}-`;
|
|
1177
|
+
const batch = () => {
|
|
1178
|
+
if (depsBatch) return depsBatch;
|
|
1179
|
+
queueMicrotask(() => {
|
|
1180
|
+
const b = {};
|
|
1181
|
+
for (const sid in depsBatch) b[sid] = packOccurrences(depsBatch[sid]);
|
|
1182
|
+
depsBatch = null;
|
|
1183
|
+
const wide = depsContext.edgeWide?.s || null;
|
|
1184
|
+
if (wide && wide.size > wideSent) {
|
|
1185
|
+
b["*"] = [...wide].slice(wideSent).join(" ");
|
|
1186
|
+
wideSent = wide.size;
|
|
1187
|
+
}
|
|
1188
|
+
if (depsN === 0 || Object.keys(b).length) depsContext.serialize(`sc:deps:${frameId}:${depsN++}`, b);
|
|
1189
|
+
});
|
|
1190
|
+
return depsBatch = Object.create(null);
|
|
1191
|
+
};
|
|
1192
|
+
const b = batch();
|
|
1193
|
+
if (reads) for (const sid of reads) if (!sid.startsWith(own)) (b[sid] ||= []).push(occurrence);
|
|
1194
|
+
if (untracked) (b["!"] ||= []).push(occurrence);
|
|
1195
|
+
};
|
|
1180
1196
|
const getters = new Map();
|
|
1181
1197
|
const repeats = new Map();
|
|
1182
|
-
const range = (occurrence, content) => {
|
|
1198
|
+
const range = (occurrence, content, tail) => {
|
|
1183
1199
|
const r = [{
|
|
1184
1200
|
t: `<!--slot:${occurrence}:start-->`
|
|
1185
|
-
}, content, {
|
|
1201
|
+
}, content, tail, {
|
|
1186
1202
|
t: `<!--slot:${occurrence}:end-->`
|
|
1187
1203
|
}];
|
|
1188
1204
|
r.$slot = true;
|
|
1189
|
-
r
|
|
1190
|
-
const face = slotFace(r, content);
|
|
1191
|
-
r.$face = face;
|
|
1192
|
-
return slotProxy(r, occurrence, face, face === SLOT_FACE_DATA ? content : undefined, undefined, documentNeeds);
|
|
1205
|
+
return r;
|
|
1193
1206
|
};
|
|
1194
1207
|
const zoneOwner = getOwner ? getOwner() : null;
|
|
1195
|
-
const scoped = (occurrence, render) => {
|
|
1208
|
+
const scoped = (occurrence, render, owner) => {
|
|
1196
1209
|
const id = `sc-${frameId}-${occurrence}-`;
|
|
1210
|
+
if (owner) return runWithOwner(owner, () => runWithHydrationScope(id, render));
|
|
1197
1211
|
const run = () => Hydration ? Hydration({
|
|
1198
1212
|
id,
|
|
1199
1213
|
get children() {
|
|
@@ -1213,18 +1227,13 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1213
1227
|
if (!fn) {
|
|
1214
1228
|
fn = (...callArgs) => {
|
|
1215
1229
|
if (callArgs.length === 0 || callArgs[0] === undefined) {
|
|
1216
|
-
|
|
1217
|
-
const repeat = repeats.get(rk);
|
|
1218
|
-
if (repeat) return repeat;
|
|
1219
|
-
const out = suppressedFill(() => scoped(prop, () => {
|
|
1230
|
+
return park(owner => suppressedFill(() => scoped(prop, () => {
|
|
1220
1231
|
const value = clientProps[prop];
|
|
1221
1232
|
return range(prop, typeof value === "function" ? value() : value);
|
|
1222
|
-
}));
|
|
1223
|
-
if (out.$face === SLOT_FACE_DATA) repeats.set(rk, out);
|
|
1224
|
-
return out;
|
|
1233
|
+
}, owner)));
|
|
1225
1234
|
}
|
|
1226
1235
|
const raw = callArgs[0];
|
|
1227
|
-
const rk =
|
|
1236
|
+
const rk = keyedId(prop, raw);
|
|
1228
1237
|
const repeat = rk !== undefined && repeats.get(rk);
|
|
1229
1238
|
if (repeat) return repeat;
|
|
1230
1239
|
const occurrence = occurrenceId(prop, raw, counts);
|
|
@@ -1232,10 +1241,10 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1232
1241
|
if (typeof slot !== "function") return range(occurrence, undefined);
|
|
1233
1242
|
const context = sharedConfig.context;
|
|
1234
1243
|
const recordKey = `sc:slot:${frameId}:${occurrence}`;
|
|
1244
|
+
const deferred = !!parked;
|
|
1235
1245
|
let settleRecord;
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
}
|
|
1246
|
+
const declare = () => context && context.async && context.serialize(recordKey, new Promise(resolve => settleRecord = resolve));
|
|
1247
|
+
deferred || declare();
|
|
1239
1248
|
try {
|
|
1240
1249
|
const resolved = {};
|
|
1241
1250
|
const liveArgs = sharedConfig.context && sharedConfig.context.live && sharedConfig.context.live.args;
|
|
@@ -1243,6 +1252,7 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1243
1252
|
const evals = {};
|
|
1244
1253
|
const states = {};
|
|
1245
1254
|
const minted = {};
|
|
1255
|
+
const nestedOf = {};
|
|
1246
1256
|
for (const key of Object.keys(raw)) {
|
|
1247
1257
|
if (key === "$key") continue;
|
|
1248
1258
|
const desc = Object.getOwnPropertyDescriptor(raw, key);
|
|
@@ -1261,6 +1271,8 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1261
1271
|
if (evaluate) {
|
|
1262
1272
|
evals[key] = evaluate;
|
|
1263
1273
|
const stampBefore = scopeStamp();
|
|
1274
|
+
const outer = parked;
|
|
1275
|
+
const nested = nestedOf[key] = parked = new Map();
|
|
1264
1276
|
try {
|
|
1265
1277
|
value = evaluate();
|
|
1266
1278
|
states[key] = {
|
|
@@ -1268,6 +1280,9 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1268
1280
|
last: value
|
|
1269
1281
|
};
|
|
1270
1282
|
} catch (err) {
|
|
1283
|
+
parked = outer;
|
|
1284
|
+
for (const entry of nested.values()) runParked(entry);
|
|
1285
|
+
nested.clear();
|
|
1271
1286
|
const blocked = ssrHandleError && ssrHandleError(err);
|
|
1272
1287
|
if (!blocked) throw err;
|
|
1273
1288
|
const state = states[key] = {
|
|
@@ -1280,6 +1295,7 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1280
1295
|
if (liveArgs) liveArgs.commit();
|
|
1281
1296
|
});
|
|
1282
1297
|
}
|
|
1298
|
+
parked = outer;
|
|
1283
1299
|
if (scopeStamp() !== stampBefore) minted[key] = true;
|
|
1284
1300
|
}
|
|
1285
1301
|
vals[key] = value;
|
|
@@ -1296,6 +1312,7 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1296
1312
|
key,
|
|
1297
1313
|
childId,
|
|
1298
1314
|
value,
|
|
1315
|
+
nested: nestedOf[key],
|
|
1299
1316
|
used: false,
|
|
1300
1317
|
locked: false
|
|
1301
1318
|
};
|
|
@@ -1306,7 +1323,7 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1306
1323
|
region.used = true;
|
|
1307
1324
|
return [{
|
|
1308
1325
|
t: frameElementOpen(childId)
|
|
1309
|
-
}, value, {
|
|
1326
|
+
}, region.nested && region.nested.size ? placeParked(value, region.nested, getOwner()) : value, {
|
|
1310
1327
|
t: FRAME_ELEMENT_CLOSE
|
|
1311
1328
|
}];
|
|
1312
1329
|
};
|
|
@@ -1327,49 +1344,67 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1327
1344
|
configurable: true
|
|
1328
1345
|
});
|
|
1329
1346
|
} else {
|
|
1330
|
-
resolved[key] = vals[key] =
|
|
1347
|
+
resolved[key] = vals[key] = noteTraces(value, documentNeeds);
|
|
1331
1348
|
}
|
|
1332
1349
|
}
|
|
1333
|
-
const
|
|
1334
|
-
const
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
for (const
|
|
1338
|
-
|
|
1339
|
-
const region = regions.find(r => r.key === key);
|
|
1340
|
-
if (region) {
|
|
1341
|
-
args[key] = {
|
|
1342
|
-
$frame: region.childId
|
|
1343
|
-
};
|
|
1344
|
-
continue;
|
|
1345
|
-
}
|
|
1346
|
-
if (!isContainerTraced(value) && isServerContent(value)) continue;
|
|
1347
|
-
args[key] = argBorderForm(value, key, occurrence, documentNeeds);
|
|
1348
|
-
}
|
|
1349
|
-
settleRecord ? settleRecord({
|
|
1350
|
-
...args
|
|
1351
|
-
}) : context.serialize(recordKey, {
|
|
1352
|
-
...args
|
|
1353
|
-
});
|
|
1354
|
-
for (const region of unused) {
|
|
1350
|
+
for (const key in nestedOf) if (!regions.some(r => r.key === key)) for (const entry of nestedOf[key].values()) runParked(entry);
|
|
1351
|
+
const flip = () => {
|
|
1352
|
+
if (flip.done || !context) return;
|
|
1353
|
+
flip.done = true;
|
|
1354
|
+
for (const region of regions) {
|
|
1355
|
+
if (region.used) continue;
|
|
1355
1356
|
region.locked = true;
|
|
1356
|
-
context.serialize(`sc:region:${region.childId}`, resolveRegionHtml(context, region.value));
|
|
1357
|
+
context.serialize(`sc:region:${region.childId}`, resolveRegionHtml(context, region.nested && region.nested.size ? placeParked(region.value, region.nested) : region.value));
|
|
1357
1358
|
}
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1359
|
+
};
|
|
1360
|
+
flip.$lhSkip = true;
|
|
1361
|
+
const finish = owner => {
|
|
1362
|
+
if (deferred) declare();
|
|
1363
|
+
try {
|
|
1364
|
+
const tracked = trackFillReads(() => suppressedFill(() => scoped(occurrence, () => range(occurrence, slot(resolved), flip), owner)));
|
|
1365
|
+
const out = tracked.result;
|
|
1366
|
+
noteDeps(occurrence, tracked.reads, tracked.untracked || hasAsyncHoles(out));
|
|
1367
|
+
if (context) {
|
|
1368
|
+
const args = {};
|
|
1369
|
+
for (const key of Object.keys(vals)) {
|
|
1370
|
+
const value = vals[key];
|
|
1371
|
+
const region = regions.find(r => r.key === key);
|
|
1372
|
+
if (region) {
|
|
1373
|
+
args[key] = {
|
|
1374
|
+
$frame: region.childId
|
|
1375
|
+
};
|
|
1376
|
+
continue;
|
|
1377
|
+
}
|
|
1378
|
+
if (!isContainerTraced(value) && isServerContent(value)) continue;
|
|
1379
|
+
args[key] = argBorderForm(value, documentNeeds);
|
|
1380
|
+
}
|
|
1381
|
+
settleRecord ? settleRecord({
|
|
1382
|
+
...args
|
|
1383
|
+
}) : context.serialize(recordKey, {
|
|
1384
|
+
...args
|
|
1368
1385
|
});
|
|
1386
|
+
if (liveArgs) {
|
|
1387
|
+
for (const key of Object.keys(evals)) {
|
|
1388
|
+
if (regions.some(r => r.key === key)) continue;
|
|
1389
|
+
if (minted[key]) continue;
|
|
1390
|
+
const ledgerKey = `${frameId}:${occurrence}:${key}`;
|
|
1391
|
+
openArgBinding(liveArgs, ledgerKey, occurrence, key, evals[key], states[key], value => {
|
|
1392
|
+
args[key] = argBorderForm(value, documentNeeds);
|
|
1393
|
+
liveArgs.slot(frameId, occurrence, {
|
|
1394
|
+
...args
|
|
1395
|
+
});
|
|
1396
|
+
});
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1369
1399
|
}
|
|
1400
|
+
return out;
|
|
1401
|
+
} catch (error) {
|
|
1402
|
+
settleRecord && settleRecord(undefined);
|
|
1403
|
+
throw error;
|
|
1370
1404
|
}
|
|
1371
|
-
}
|
|
1372
|
-
|
|
1405
|
+
};
|
|
1406
|
+
const out = park(finish);
|
|
1407
|
+
if (rk !== undefined && rk === occurrence) repeats.has(rk) || repeats.set(rk, out);
|
|
1373
1408
|
return out;
|
|
1374
1409
|
} catch (error) {
|
|
1375
1410
|
settleRecord && settleRecord(undefined);
|
|
@@ -1385,9 +1420,40 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
1385
1420
|
}
|
|
1386
1421
|
const FRAME_TAG = "solid-frame";
|
|
1387
1422
|
const FRAME_ID_ATTR = "data-fid";
|
|
1388
|
-
|
|
1423
|
+
const FRAME_ARGS_ATTR = "data-fa";
|
|
1424
|
+
function frameElementOpen(id, args) {
|
|
1389
1425
|
const escaped = sharedConfig.context ? sharedConfig.context.escape(String(id), true) : String(id);
|
|
1390
|
-
return `<${FRAME_TAG} ${FRAME_ID_ATTR}="${escaped}" style="display:contents">`;
|
|
1426
|
+
return `<${FRAME_TAG} ${FRAME_ID_ATTR}="${escaped}"${args ? ` ${FRAME_ARGS_ATTR}="${args}"` : ""} style="display:contents">`;
|
|
1427
|
+
}
|
|
1428
|
+
const DOCUMENT_SITES = Symbol();
|
|
1429
|
+
function contextSites(ctx) {
|
|
1430
|
+
if (ctx[DOCUMENT_SITES]) return ctx[DOCUMENT_SITES];
|
|
1431
|
+
const proto = Object.getPrototypeOf(ctx);
|
|
1432
|
+
if (proto && proto[DOCUMENT_SITES]) return ctx[DOCUMENT_SITES] = proto[DOCUMENT_SITES];
|
|
1433
|
+
if (proto && typeof proto.escape === "function") return ctx[DOCUMENT_SITES] = contextSites(proto);
|
|
1434
|
+
return ctx[DOCUMENT_SITES] = {
|
|
1435
|
+
byOwner: new Map(),
|
|
1436
|
+
counts: Object.create(null)
|
|
1437
|
+
};
|
|
1438
|
+
}
|
|
1439
|
+
function mintSiteId(sites, fnId) {
|
|
1440
|
+
const n = sites.counts[fnId] || 0;
|
|
1441
|
+
sites.counts[fnId] = n + 1;
|
|
1442
|
+
return n === 0 ? fnId : fnId + "~" + (n + 1);
|
|
1443
|
+
}
|
|
1444
|
+
function documentSiteId(fnId) {
|
|
1445
|
+
const ctx = sharedConfig.context;
|
|
1446
|
+
if (!ctx) return fnId;
|
|
1447
|
+
const sites = contextSites(ctx);
|
|
1448
|
+
const owner = getOwner ? getOwner() : null;
|
|
1449
|
+
if (!owner) return mintSiteId(sites, fnId);
|
|
1450
|
+
let byFn = sites.byOwner.get(owner);
|
|
1451
|
+
if (!byFn) sites.byOwner.set(owner, byFn = new Map());
|
|
1452
|
+
const prev = byFn.get(fnId);
|
|
1453
|
+
if (prev) return prev;
|
|
1454
|
+
const siteId = mintSiteId(sites, fnId);
|
|
1455
|
+
byFn.set(fnId, siteId);
|
|
1456
|
+
return siteId;
|
|
1391
1457
|
}
|
|
1392
1458
|
const FRAME_ELEMENT_CLOSE = `</${FRAME_TAG}>`;
|
|
1393
1459
|
function documentNeeds(name) {
|
|
@@ -1409,6 +1475,7 @@ function armDocumentLiveHoles(ctx) {
|
|
|
1409
1475
|
if (live.holes) {
|
|
1410
1476
|
ctx.commit = live.commit;
|
|
1411
1477
|
ctx.commitEpoch = live.commitEpoch;
|
|
1478
|
+
ctx.unsettled = live.unsettled;
|
|
1412
1479
|
}
|
|
1413
1480
|
return;
|
|
1414
1481
|
}
|
|
@@ -1417,6 +1484,7 @@ function armDocumentLiveHoles(ctx) {
|
|
|
1417
1484
|
if (live) live.holes = null;
|
|
1418
1485
|
return;
|
|
1419
1486
|
}
|
|
1487
|
+
let unsettled = false;
|
|
1420
1488
|
const bindings = new Map();
|
|
1421
1489
|
let epoch = 0;
|
|
1422
1490
|
let sweepScheduled = false;
|
|
@@ -1424,7 +1492,7 @@ function armDocumentLiveHoles(ctx) {
|
|
|
1424
1492
|
let swept = null;
|
|
1425
1493
|
const sweep = () => {
|
|
1426
1494
|
epoch++;
|
|
1427
|
-
const
|
|
1495
|
+
const r = swept = {};
|
|
1428
1496
|
try {
|
|
1429
1497
|
for (const b of [...bindings.values()]) {
|
|
1430
1498
|
try {
|
|
@@ -1435,12 +1503,8 @@ function armDocumentLiveHoles(ctx) {
|
|
|
1435
1503
|
} finally {
|
|
1436
1504
|
swept = null;
|
|
1437
1505
|
}
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
const pushOps = ops => {
|
|
1441
|
-
if (ops.length === 1) push(ops[0]);else if (ops.length) push({
|
|
1442
|
-
type: "ops",
|
|
1443
|
-
ops
|
|
1506
|
+
for (const _ in r) return push({
|
|
1507
|
+
r
|
|
1444
1508
|
});
|
|
1445
1509
|
};
|
|
1446
1510
|
const scheduleSweep = () => {
|
|
@@ -1455,51 +1519,62 @@ function armDocumentLiveHoles(ctx) {
|
|
|
1455
1519
|
ctx.serialize("sc:live", new ReadableStream({
|
|
1456
1520
|
start(c) {
|
|
1457
1521
|
channel = c;
|
|
1522
|
+
},
|
|
1523
|
+
cancel() {
|
|
1524
|
+
closed = true;
|
|
1458
1525
|
}
|
|
1459
1526
|
}));
|
|
1460
|
-
const push =
|
|
1461
|
-
if (!closed) channel.enqueue(
|
|
1527
|
+
const push = batch => {
|
|
1528
|
+
if (!closed) channel.enqueue(batch);
|
|
1462
1529
|
};
|
|
1530
|
+
const write = r => swept ? Object.assign(swept, r) : push({
|
|
1531
|
+
r
|
|
1532
|
+
});
|
|
1463
1533
|
ctx.liveHoles = live.holes = createLiveHoles({
|
|
1464
1534
|
openBinding(key, b) {
|
|
1535
|
+
documentNeeds("wire");
|
|
1465
1536
|
bindings.set(key, b);
|
|
1466
1537
|
},
|
|
1467
1538
|
closeBinding(key) {
|
|
1468
1539
|
bindings.delete(key);
|
|
1469
1540
|
},
|
|
1470
|
-
hole(key,
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1541
|
+
hole(key, value) {
|
|
1542
|
+
write({
|
|
1543
|
+
["hole:" + key]: {
|
|
1544
|
+
kind: "html",
|
|
1545
|
+
value,
|
|
1546
|
+
digest: textDigest(value)
|
|
1547
|
+
}
|
|
1548
|
+
});
|
|
1478
1549
|
},
|
|
1479
|
-
attr(key,
|
|
1480
|
-
const
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
digest: textDigest(attrs)
|
|
1550
|
+
attr(key, value, removed) {
|
|
1551
|
+
const record = {
|
|
1552
|
+
kind: "attrs",
|
|
1553
|
+
value,
|
|
1554
|
+
digest: textDigest(value)
|
|
1485
1555
|
};
|
|
1486
|
-
if (removed && removed.length)
|
|
1487
|
-
|
|
1556
|
+
if (removed && removed.length) record.removed = removed;
|
|
1557
|
+
write({
|
|
1558
|
+
["attr:" + key]: record
|
|
1559
|
+
});
|
|
1488
1560
|
},
|
|
1489
1561
|
error(key, error) {
|
|
1490
1562
|
push({
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1563
|
+
r: {
|
|
1564
|
+
[`hole:${key}:error`]: error
|
|
1565
|
+
}
|
|
1494
1566
|
});
|
|
1495
1567
|
},
|
|
1496
1568
|
commit: scheduleSweep,
|
|
1497
1569
|
get epoch() {
|
|
1498
1570
|
return epoch;
|
|
1499
1571
|
}
|
|
1500
|
-
}, true);
|
|
1572
|
+
}, true, () => !unsettled, ctx._errorScope);
|
|
1501
1573
|
ctx.commit = live.commit = scheduleSweep;
|
|
1502
1574
|
ctx.commitEpoch = live.commitEpoch = () => epoch;
|
|
1575
|
+
ctx.unsettled = live.unsettled = () => {
|
|
1576
|
+
unsettled = true;
|
|
1577
|
+
};
|
|
1503
1578
|
live.args = {
|
|
1504
1579
|
openBinding(key, b) {
|
|
1505
1580
|
bindings.set(key, b);
|
|
@@ -1509,19 +1584,23 @@ function armDocumentLiveHoles(ctx) {
|
|
|
1509
1584
|
},
|
|
1510
1585
|
slot(fid, occurrence, args) {
|
|
1511
1586
|
push({
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1587
|
+
r: {
|
|
1588
|
+
[`slot:${occurrence}`]: {
|
|
1589
|
+
kind: "slot",
|
|
1590
|
+
args
|
|
1591
|
+
}
|
|
1592
|
+
},
|
|
1593
|
+
fid
|
|
1516
1594
|
});
|
|
1517
1595
|
},
|
|
1518
1596
|
commit: scheduleSweep
|
|
1519
1597
|
};
|
|
1520
1598
|
live.error = (fid, error) => {
|
|
1521
1599
|
push({
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1600
|
+
r: {
|
|
1601
|
+
":error": error
|
|
1602
|
+
},
|
|
1603
|
+
fid
|
|
1525
1604
|
});
|
|
1526
1605
|
};
|
|
1527
1606
|
live.end = () => {
|
|
@@ -1538,31 +1617,34 @@ function frameTransformDirectResult(value, {
|
|
|
1538
1617
|
}) {
|
|
1539
1618
|
if (typeof value !== "function") return value;
|
|
1540
1619
|
const component = value;
|
|
1541
|
-
const
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1620
|
+
const address = frameAddress(id, args);
|
|
1621
|
+
const wrapped = props => {
|
|
1622
|
+
const siteId = documentSiteId(id);
|
|
1623
|
+
return [{
|
|
1624
|
+
t: frameElementOpen(siteId, address.slice(id.length + 1))
|
|
1625
|
+
},
|
|
1626
|
+
serverOwned(() => {
|
|
1627
|
+
const page = sharedConfig.context;
|
|
1628
|
+
armDocumentLiveHoles(page);
|
|
1629
|
+
if (tierUrls && page && page.live && !page.live.tierUrls) page.live.tierUrls = tierUrls;
|
|
1630
|
+
const ctx = Object.create(page);
|
|
1631
|
+
ctx.frameId = siteId;
|
|
1632
|
+
sharedConfig.context = ctx;
|
|
1633
|
+
try {
|
|
1634
|
+
const slotProps = createDocumentSlotProps(props, siteId);
|
|
1635
|
+
const live = !!wrapped[LIVE_SOURCE];
|
|
1636
|
+
if (live) documentNeeds("wire");
|
|
1637
|
+
return serverComponentScope(() => component(slotProps), live);
|
|
1638
|
+
} finally {
|
|
1639
|
+
sharedConfig.context = page;
|
|
1640
|
+
}
|
|
1641
|
+
}), {
|
|
1642
|
+
t: FRAME_ELEMENT_CLOSE
|
|
1643
|
+
}];
|
|
1644
|
+
};
|
|
1563
1645
|
wrapped[SERVER_COMPONENT] = id;
|
|
1564
1646
|
wrapped[SERVER_COMPONENT_SOURCE] = component;
|
|
1565
|
-
wrapped[SERVER_COMPONENT_ADDRESS] =
|
|
1647
|
+
wrapped[SERVER_COMPONENT_ADDRESS] = address;
|
|
1566
1648
|
return wrapped;
|
|
1567
1649
|
}
|
|
1568
1650
|
function resolveRegionHtml(ctx, node) {
|
|
@@ -1665,6 +1747,15 @@ function createSlotProps(sink, frame) {
|
|
|
1665
1747
|
const counts = Object.create(null);
|
|
1666
1748
|
const getters = new Map();
|
|
1667
1749
|
const repeats = new Map();
|
|
1750
|
+
let pass = null;
|
|
1751
|
+
let passRepeats = null;
|
|
1752
|
+
const recs = new Map();
|
|
1753
|
+
const forget = occurrence => {
|
|
1754
|
+
const rec = recs.get(occurrence);
|
|
1755
|
+
if (!rec) return;
|
|
1756
|
+
recs.delete(occurrence);
|
|
1757
|
+
for (const key in rec.vals) sink.closeBinding(`${occurrence}:${key}`);
|
|
1758
|
+
};
|
|
1668
1759
|
const needs = sink.needs || (() => {});
|
|
1669
1760
|
return new Proxy(Object.create(null), {
|
|
1670
1761
|
has() {
|
|
@@ -1677,25 +1768,38 @@ function createSlotProps(sink, frame) {
|
|
|
1677
1768
|
if (!fn) {
|
|
1678
1769
|
fn = (...callArgs) => {
|
|
1679
1770
|
if (callArgs.length === 0 || callArgs[0] === undefined) {
|
|
1680
|
-
return
|
|
1771
|
+
return slotRange(prop);
|
|
1681
1772
|
}
|
|
1682
|
-
const rk = repeatKey(prop, callArgs[0]);
|
|
1683
|
-
const repeat = rk !== undefined && repeats.get(rk);
|
|
1684
|
-
if (repeat) return repeat;
|
|
1685
1773
|
const live = sharedConfig.context && sharedConfig.context.liveHoles;
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1774
|
+
const sweeping = !!live && live.sweeping;
|
|
1775
|
+
let rmap = repeats;
|
|
1776
|
+
if (sweeping) {
|
|
1777
|
+
if (pass !== live.visit) passRepeats = new Map();
|
|
1778
|
+
pass = live.visit;
|
|
1779
|
+
rmap = passRepeats;
|
|
1780
|
+
}
|
|
1781
|
+
const rk = keyedId(prop, callArgs[0]);
|
|
1782
|
+
const repeat = rk !== undefined && rmap.get(rk);
|
|
1783
|
+
if (repeat) return repeat;
|
|
1784
|
+
if (sweeping && !live.scope) {
|
|
1785
|
+
live.gateHit = true;
|
|
1786
|
+
return {
|
|
1787
|
+
t: "",
|
|
1788
|
+
$slot: true
|
|
1789
|
+
};
|
|
1695
1790
|
}
|
|
1696
1791
|
const raw = callArgs[0];
|
|
1697
|
-
|
|
1792
|
+
let occurrence = keyedId(prop, raw);
|
|
1793
|
+
if (occurrence === undefined) {
|
|
1794
|
+
const positional = sweeping ? undefined : occurrenceId(prop, raw, counts);
|
|
1795
|
+
occurrence = live ? live.slotId(prop, positional) : positional;
|
|
1796
|
+
}
|
|
1797
|
+
if (sweeping && live.dry) return slotRange(occurrence);
|
|
1798
|
+
const prev = recs.get(occurrence);
|
|
1799
|
+
let changed = !prev;
|
|
1800
|
+
const digest = live && live.scope ? argDigest : noDigest;
|
|
1698
1801
|
const args = {};
|
|
1802
|
+
const vals = {};
|
|
1699
1803
|
const opened = [];
|
|
1700
1804
|
for (const key of Object.keys(raw)) {
|
|
1701
1805
|
if (key === "$key") continue;
|
|
@@ -1711,6 +1815,7 @@ function createSlotProps(sink, frame) {
|
|
|
1711
1815
|
let evaluate = null;
|
|
1712
1816
|
let value;
|
|
1713
1817
|
let state = null;
|
|
1818
|
+
let pending = false;
|
|
1714
1819
|
const stampBefore = scopeStamp();
|
|
1715
1820
|
try {
|
|
1716
1821
|
if (desc.get) {
|
|
@@ -1732,6 +1837,7 @@ function createSlotProps(sink, frame) {
|
|
|
1732
1837
|
settled: false,
|
|
1733
1838
|
last: undefined
|
|
1734
1839
|
};
|
|
1840
|
+
pending = true;
|
|
1735
1841
|
const pendingState = state;
|
|
1736
1842
|
value = retryArgUntilSettled(evaluate, blocked, key, occurrence, v => {
|
|
1737
1843
|
pendingState.settled = true;
|
|
@@ -1743,6 +1849,7 @@ function createSlotProps(sink, frame) {
|
|
|
1743
1849
|
const t = typeof value;
|
|
1744
1850
|
if (value == null || t === "string" || t === "number" || t === "boolean") {
|
|
1745
1851
|
args[key] = value;
|
|
1852
|
+
vals[key] = digest(value);
|
|
1746
1853
|
if (evaluate) state = {
|
|
1747
1854
|
settled: true,
|
|
1748
1855
|
last: value
|
|
@@ -1752,21 +1859,27 @@ function createSlotProps(sink, frame) {
|
|
|
1752
1859
|
if (resolved.h.length) {
|
|
1753
1860
|
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.");
|
|
1754
1861
|
}
|
|
1755
|
-
|
|
1862
|
+
vals[key] = "<" + resolved.t[0];
|
|
1863
|
+
if (!prev || prev.vals[key] !== vals[key]) sink.region(childId, resolved.t[0]);
|
|
1756
1864
|
args[key] = {
|
|
1757
1865
|
$frame: childId
|
|
1758
1866
|
};
|
|
1759
1867
|
} else {
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1868
|
+
vals[key] = pending ? PENDING_ARG : digest(value);
|
|
1869
|
+
if (prev && prev.vals[key] === vals[key]) args[key] = prev.args[key];else {
|
|
1870
|
+
const ref = prev ? `arg:${occurrence}:${key}@${sink.nextArgRef(`${occurrence}:${key}`)}` : `arg:${occurrence}:${key}`;
|
|
1871
|
+
if (prev) sink.mintRef(ref);
|
|
1872
|
+
ctx.serialize(ref, argBorderForm(value, needs));
|
|
1873
|
+
args[key] = {
|
|
1874
|
+
$ref: ref
|
|
1875
|
+
};
|
|
1876
|
+
}
|
|
1765
1877
|
if (evaluate && !state) state = {
|
|
1766
1878
|
settled: true,
|
|
1767
1879
|
last: value
|
|
1768
1880
|
};
|
|
1769
1881
|
}
|
|
1882
|
+
if (prev && prev.vals[key] !== vals[key]) changed = true;
|
|
1770
1883
|
if (evaluate && state && !mintedEval) opened.push({
|
|
1771
1884
|
key,
|
|
1772
1885
|
evaluate,
|
|
@@ -1776,9 +1889,18 @@ function createSlotProps(sink, frame) {
|
|
|
1776
1889
|
ctx.registerFragment = origRegister;
|
|
1777
1890
|
}
|
|
1778
1891
|
}
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1892
|
+
if (prev) for (const key in prev.vals) if (!(key in vals)) changed = true;
|
|
1893
|
+
const rec = changed ? {
|
|
1894
|
+
args,
|
|
1895
|
+
vals
|
|
1896
|
+
} : prev;
|
|
1897
|
+
if (changed) {
|
|
1898
|
+
recs.set(occurrence, rec);
|
|
1899
|
+
sink.slot(occurrence, {
|
|
1900
|
+
...args
|
|
1901
|
+
});
|
|
1902
|
+
}
|
|
1903
|
+
if (live && live.visit) live.seen(occurrence, () => recs.get(occurrence) === rec && forget(occurrence));
|
|
1782
1904
|
const ctx = sharedConfig.context;
|
|
1783
1905
|
for (const b of opened) {
|
|
1784
1906
|
const key = b.key;
|
|
@@ -1786,23 +1908,23 @@ function createSlotProps(sink, frame) {
|
|
|
1786
1908
|
openArgBinding(sink, ledgerKey, occurrence, key, b.evaluate, b.state, value => {
|
|
1787
1909
|
const t = typeof value;
|
|
1788
1910
|
if (value == null || t === "string" || t === "number" || t === "boolean") {
|
|
1789
|
-
args[key] = value;
|
|
1911
|
+
rec.args[key] = value;
|
|
1790
1912
|
} else {
|
|
1791
1913
|
const ref = `arg:${occurrence}:${key}@${sink.nextArgRef(ledgerKey)}`;
|
|
1792
1914
|
sink.mintRef(ref);
|
|
1793
|
-
ctx.serialize(ref, argBorderForm(value,
|
|
1794
|
-
args[key] = {
|
|
1915
|
+
ctx.serialize(ref, argBorderForm(value, needs));
|
|
1916
|
+
rec.args[key] = {
|
|
1795
1917
|
$ref: ref
|
|
1796
1918
|
};
|
|
1797
1919
|
}
|
|
1920
|
+
rec.vals[key] = digest(value);
|
|
1798
1921
|
sink.slot(occurrence, {
|
|
1799
|
-
...args
|
|
1922
|
+
...rec.args
|
|
1800
1923
|
});
|
|
1801
1924
|
});
|
|
1802
1925
|
}
|
|
1803
|
-
const
|
|
1804
|
-
|
|
1805
|
-
if (keyed) repeats.set(rk, out);
|
|
1926
|
+
const out = slotRange(occurrence);
|
|
1927
|
+
if (rk !== undefined && rk === occurrence) rmap.set(rk, out);
|
|
1806
1928
|
return out;
|
|
1807
1929
|
};
|
|
1808
1930
|
fn.$lhSkip = true;
|
|
@@ -1848,6 +1970,7 @@ function serverComponentResponse(component, options = {}, init = {}) {
|
|
|
1848
1970
|
});
|
|
1849
1971
|
let closed = false;
|
|
1850
1972
|
let stopLive = null;
|
|
1973
|
+
let failed = false;
|
|
1851
1974
|
const body = new ReadableStream({
|
|
1852
1975
|
start(controller) {
|
|
1853
1976
|
const end = () => {
|
|
@@ -1866,10 +1989,11 @@ function serverComponentResponse(component, options = {}, init = {}) {
|
|
|
1866
1989
|
teardown.abort();
|
|
1867
1990
|
});
|
|
1868
1991
|
stream.pipe({
|
|
1869
|
-
write(
|
|
1992
|
+
write(message) {
|
|
1993
|
+
if (message.r && ":error" in message.r) failed = true;
|
|
1870
1994
|
if (closed) return;
|
|
1871
1995
|
try {
|
|
1872
|
-
controller.enqueue(frame(JSON.stringify(
|
|
1996
|
+
controller.enqueue(frame(JSON.stringify(message)));
|
|
1873
1997
|
} catch (_) {
|
|
1874
1998
|
closed = true;
|
|
1875
1999
|
}
|
|
@@ -1889,6 +2013,10 @@ function serverComponentResponse(component, options = {}, init = {}) {
|
|
|
1889
2013
|
});
|
|
1890
2014
|
}
|
|
1891
2015
|
});
|
|
2016
|
+
if (failed) {
|
|
2017
|
+
headers.set("Cache-Control", "no-store");
|
|
2018
|
+
for (const name of [...headers.keys()]) if (name === "surrogate-control" || name.endsWith("cdn-cache-control")) headers.delete(name);
|
|
2019
|
+
}
|
|
1892
2020
|
return new Response(body, {
|
|
1893
2021
|
status: init.status || 200,
|
|
1894
2022
|
headers
|
|
@@ -2023,10 +2151,10 @@ function frameFlightResponse({
|
|
|
2023
2151
|
let closed = false;
|
|
2024
2152
|
const body = new ReadableStream({
|
|
2025
2153
|
async start(controller) {
|
|
2026
|
-
const write =
|
|
2154
|
+
const write = message => {
|
|
2027
2155
|
if (closed) return;
|
|
2028
2156
|
try {
|
|
2029
|
-
controller.enqueue(createChunk(JSON.stringify(
|
|
2157
|
+
controller.enqueue(createChunk(JSON.stringify(message)));
|
|
2030
2158
|
} catch (_) {
|
|
2031
2159
|
closed = true;
|
|
2032
2160
|
}
|
|
@@ -2105,4 +2233,4 @@ function asyncArg(value) {
|
|
|
2105
2233
|
return value;
|
|
2106
2234
|
}
|
|
2107
2235
|
|
|
2108
|
-
export { FRAME_HAVE_BUDGET, FRAME_HAVE_HEADER, FRAME_STREAM_HEADER, FRAME_TIERS_HEADER, SERVER_COMPONENT_BOOTSTRAP, ServerComponentPlugin, asyncArg,
|
|
2236
|
+
export { FRAME_HAVE_BUDGET, FRAME_HAVE_HEADER, FRAME_STREAM_HEADER, FRAME_TIERS_HEADER, SERVER_COMPONENT_BOOTSTRAP, ServerComponentPlugin, asyncArg, frameTransformDirectResult, frameTransformFlightResult, frameTransformResult, isFrameStreamResponse };
|