@solidjs/web 2.0.0-rc.8 → 2.0.0-rc.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/server.dev.js +626 -125
- package/dist/server.js +433 -95
- package/dist/server.observe.js +3980 -0
- package/dist/web.dev.js +208 -60
- package/dist/web.js +175 -58
- package/dist/web.observe.js +175 -58
- package/frames/dist/client.dev.js +103 -4
- package/frames/dist/client.js +5 -2
- package/frames/dist/client.observe.js +2123 -0
- package/frames/dist/server.dev.js +521 -79
- package/frames/dist/server.js +352 -52
- package/frames/dist/server.observe.js +4946 -0
- package/frames/package.json +12 -0
- package/package.json +87 -3
- package/server-functions/dist/client.dev.js +1102 -0
- package/server-functions/dist/client.js +74 -69
- package/server-functions/dist/client.observe.js +1102 -0
- package/server-functions/dist/server.dev.js +402 -31
- package/server-functions/dist/server.js +339 -30
- package/server-functions/dist/server.observe.js +2726 -0
- package/server-functions/package.json +12 -0
- package/types/client.d.ts +22 -1
- package/types/diagnostics.d.ts +24 -0
- package/types/frames/frame-transport.d.ts +1 -1
- package/types/index.d.ts +25 -15
- package/types/index.server.d.ts +35 -8
- package/types/jsx.d.ts +15 -4
- package/types/observe.d.ts +294 -0
- package/types/response.d.ts +18 -0
- package/types/server-functions/client.d.ts +32 -22
- package/types/server-functions/server.d.ts +28 -37
- package/types/server-functions/shared.d.ts +39 -9
- package/types/server-mock.d.ts +26 -4
- package/types/server-observe.d.ts +39 -0
- package/types/server.d.ts +104 -5
- package/types/trace.d.ts +79 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { reportServerError, ssrHandleError, ssrSanitizeError, inServerComponentScope, creationStamp, runInServerComponentScope, getProjectionTrace } from 'solid-js/internal';
|
|
2
|
+
import { OBSERVE, DEV, getOwner, sharedConfig, createRoot, runWithOwner, NoHydration, createMemo, Hydration, createOwner } from 'solid-js';
|
|
2
3
|
import { Feature, createStream, toCrossJSONStream, Serializer, getCrossReferenceHeader } from 'seroval';
|
|
3
4
|
import { AbortSignalPlugin, CustomEventPlugin, DOMExceptionPlugin, EventPlugin, FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin } from 'seroval-plugins/web';
|
|
4
5
|
|
|
@@ -101,6 +102,167 @@ const ContainerTracePlugin = {
|
|
|
101
102
|
|
|
102
103
|
const COMPOSED_BODY_FRAMING = /*#__PURE__*/new Set(["content-length", "content-encoding", "transfer-encoding"]);
|
|
103
104
|
|
|
105
|
+
const PROVIDER = Symbol.for("solid-js/observe/server/provider");
|
|
106
|
+
function currentProvider() {
|
|
107
|
+
if (OBSERVE === undefined) return undefined;
|
|
108
|
+
const slot = OBSERVE.server.trace;
|
|
109
|
+
return slot && slot[PROVIDER];
|
|
110
|
+
}
|
|
111
|
+
const TRACEPARENT = /^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})(-.*)?$/;
|
|
112
|
+
const ZERO_TRACE = "00000000000000000000000000000000";
|
|
113
|
+
const ZERO_SPAN = "0000000000000000";
|
|
114
|
+
function parseTraceparent(value) {
|
|
115
|
+
if (!value) return undefined;
|
|
116
|
+
const m = TRACEPARENT.exec(value.trim());
|
|
117
|
+
if (!m) return undefined;
|
|
118
|
+
const [, version, traceId, parentId, flags, rest] = m;
|
|
119
|
+
if (version === "ff") return undefined;
|
|
120
|
+
if (version === "00" && rest !== undefined) return undefined;
|
|
121
|
+
if (traceId === ZERO_TRACE || parentId === ZERO_SPAN) return undefined;
|
|
122
|
+
return {
|
|
123
|
+
traceId,
|
|
124
|
+
parentId,
|
|
125
|
+
sampled: (parseInt(flags, 16) & 1) === 1
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function randomHex(bytes) {
|
|
129
|
+
const buffer = new Uint8Array(bytes);
|
|
130
|
+
crypto.getRandomValues(buffer);
|
|
131
|
+
let out = "";
|
|
132
|
+
for (let i = 0; i < buffer.length; i++) out += (buffer[i] < 16 ? "0" : "") + buffer[i].toString(16);
|
|
133
|
+
return out;
|
|
134
|
+
}
|
|
135
|
+
function randomTraceId() {
|
|
136
|
+
let id = randomHex(16);
|
|
137
|
+
while (id === ZERO_TRACE) id = randomHex(16);
|
|
138
|
+
return id;
|
|
139
|
+
}
|
|
140
|
+
function randomSpanId() {
|
|
141
|
+
let id = randomHex(8);
|
|
142
|
+
while (id === ZERO_SPAN) id = randomHex(8);
|
|
143
|
+
return id;
|
|
144
|
+
}
|
|
145
|
+
function formatTraceparent(context) {
|
|
146
|
+
return `00-${context.traceId}-${context.spanId}-${context.sampled === true ? "01" : "00"}`;
|
|
147
|
+
}
|
|
148
|
+
const RECORDS_KEY = Symbol.for("@solidjs/web/trace/records");
|
|
149
|
+
function records$1() {
|
|
150
|
+
const g = globalThis;
|
|
151
|
+
return g[RECORDS_KEY] || (g[RECORDS_KEY] = new WeakMap());
|
|
152
|
+
}
|
|
153
|
+
function traceFor(key, request) {
|
|
154
|
+
const store = records$1();
|
|
155
|
+
let record = store.get(key);
|
|
156
|
+
if (record) return record;
|
|
157
|
+
const headers = request ? request.headers : undefined;
|
|
158
|
+
const incoming = headers ? parseTraceparent(headers.get("traceparent")) : undefined;
|
|
159
|
+
const context = {
|
|
160
|
+
traceId: incoming ? incoming.traceId : randomTraceId(),
|
|
161
|
+
spanId: randomSpanId(),
|
|
162
|
+
entries: {}
|
|
163
|
+
};
|
|
164
|
+
if (incoming) {
|
|
165
|
+
context.parentId = incoming.parentId;
|
|
166
|
+
context.sampled = incoming.sampled;
|
|
167
|
+
}
|
|
168
|
+
if (headers) {
|
|
169
|
+
const state = headers.get("tracestate");
|
|
170
|
+
if (state) context.state = state;
|
|
171
|
+
const baggage = headers.get("baggage");
|
|
172
|
+
if (baggage) context.baggage = baggage;
|
|
173
|
+
}
|
|
174
|
+
let answered = false;
|
|
175
|
+
let providedEntries;
|
|
176
|
+
{
|
|
177
|
+
const provider = currentProvider();
|
|
178
|
+
if (provider) {
|
|
179
|
+
let answer;
|
|
180
|
+
try {
|
|
181
|
+
answer = provider(request);
|
|
182
|
+
} catch (error) {
|
|
183
|
+
console.error(error);
|
|
184
|
+
}
|
|
185
|
+
if (answer !== undefined && answer !== null) {
|
|
186
|
+
answered = true;
|
|
187
|
+
if (answer.traceId !== undefined) context.traceId = answer.traceId;
|
|
188
|
+
if (answer.spanId !== undefined) context.spanId = answer.spanId;
|
|
189
|
+
if (answer.parentId !== undefined) context.parentId = answer.parentId;
|
|
190
|
+
if (answer.sampled !== undefined) context.sampled = answer.sampled;
|
|
191
|
+
if (answer.state !== undefined) context.state = answer.state;
|
|
192
|
+
if (answer.baggage !== undefined) context.baggage = answer.baggage;
|
|
193
|
+
providedEntries = answer.entries;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
context.entries.traceparent = formatTraceparent(context);
|
|
198
|
+
if (providedEntries) Object.assign(context.entries, providedEntries);
|
|
199
|
+
record = {
|
|
200
|
+
context,
|
|
201
|
+
emit: incoming !== undefined && incoming.sampled || answered
|
|
202
|
+
};
|
|
203
|
+
store.set(key, record);
|
|
204
|
+
return record;
|
|
205
|
+
}
|
|
206
|
+
const TOKEN = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
|
|
207
|
+
function splitServerTiming(value) {
|
|
208
|
+
const entries = [];
|
|
209
|
+
let start = 0;
|
|
210
|
+
let quoted = false;
|
|
211
|
+
for (let i = 0; i < value.length; i++) {
|
|
212
|
+
const c = value[i];
|
|
213
|
+
if (quoted) {
|
|
214
|
+
if (c === "\\") i++;else if (c === '"') quoted = false;
|
|
215
|
+
} else if (c === '"') quoted = true;else if (c === ",") {
|
|
216
|
+
entries.push(value.slice(start, i));
|
|
217
|
+
start = i + 1;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
entries.push(value.slice(start));
|
|
221
|
+
return entries;
|
|
222
|
+
}
|
|
223
|
+
function metricName(entry) {
|
|
224
|
+
return entry.split(";")[0].trim().toLowerCase();
|
|
225
|
+
}
|
|
226
|
+
function namesOnServerTiming(headers) {
|
|
227
|
+
const names = new Set();
|
|
228
|
+
const existing = headers.get("server-timing");
|
|
229
|
+
if (existing) {
|
|
230
|
+
for (const entry of splitServerTiming(existing)) {
|
|
231
|
+
const name = metricName(entry);
|
|
232
|
+
if (name) names.add(name);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return names;
|
|
236
|
+
}
|
|
237
|
+
function quoteDesc(value) {
|
|
238
|
+
return value.replace(/[\x00-\x1f\x7f]/g, "").replace(/[\\"]/g, m => "\\" + m);
|
|
239
|
+
}
|
|
240
|
+
function appendTraceServerTiming(headers, record) {
|
|
241
|
+
if (!record.emit) return;
|
|
242
|
+
const entries = record.context.entries;
|
|
243
|
+
let present;
|
|
244
|
+
for (const name in entries) {
|
|
245
|
+
if (!TOKEN.test(name)) continue;
|
|
246
|
+
if (!present) present = namesOnServerTiming(headers);
|
|
247
|
+
if (present.has(name.toLowerCase())) continue;
|
|
248
|
+
headers.append("Server-Timing", `${name};desc="${quoteDesc(entries[name])}"`);
|
|
249
|
+
present.add(name.toLowerCase());
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
function escapeAttr(value) {
|
|
253
|
+
return value.replace(/[&"<>]/g, c => c === "&" ? "&" : c === '"' ? """ : c === "<" ? "<" : ">");
|
|
254
|
+
}
|
|
255
|
+
function traceMetaMarkup(record) {
|
|
256
|
+
if (!record.emit) return "";
|
|
257
|
+
let markup = "";
|
|
258
|
+
const entries = record.context.entries;
|
|
259
|
+
for (const name in entries) {
|
|
260
|
+
if (!TOKEN.test(name)) continue;
|
|
261
|
+
markup += `<meta name="${name}" content="${escapeAttr(entries[name])}">`;
|
|
262
|
+
}
|
|
263
|
+
return markup;
|
|
264
|
+
}
|
|
265
|
+
|
|
104
266
|
setContainerTraceStreamMint(iterable => {
|
|
105
267
|
const stream = createStream();
|
|
106
268
|
(async () => {
|
|
@@ -402,6 +564,22 @@ function serializeStream(value, codecOptions) {
|
|
|
402
564
|
});
|
|
403
565
|
}
|
|
404
566
|
|
|
567
|
+
function emitFinding(finding, subject = getOwner()) {
|
|
568
|
+
if (OBSERVE === undefined) return;
|
|
569
|
+
const entry = OBSERVE.diagnostics.emit(finding, subject);
|
|
570
|
+
if (DEV !== undefined) DEV.report(entry);
|
|
571
|
+
}
|
|
572
|
+
function recordFinding(finding, subject = getOwner()) {
|
|
573
|
+
if (OBSERVE !== undefined) OBSERVE.diagnostics.emit(finding, subject);
|
|
574
|
+
}
|
|
575
|
+
function devCheck(finding, subject) {
|
|
576
|
+
emitFinding(finding, subject);
|
|
577
|
+
}
|
|
578
|
+
function errorText(error) {
|
|
579
|
+
if (error instanceof Error) return error.message ? `${error.name}: ${error.message}` : error.name;
|
|
580
|
+
return String(error);
|
|
581
|
+
}
|
|
582
|
+
|
|
405
583
|
const HEAD_ELIGIBLE_TAGS = new Set(["title", "meta", "link", "style", "script", "base"]);
|
|
406
584
|
const HEAD_ATTR_NAME = /^[a-zA-Z_][a-zA-Z0-9_:.-]*$/;
|
|
407
585
|
const RESOURCE_LINK_RELS = new Set(["preload", "modulepreload", "prefetch", "preconnect", "dns-prefetch", "stylesheet"]);
|
|
@@ -485,7 +663,16 @@ function resolveHead(groups) {
|
|
|
485
663
|
}
|
|
486
664
|
for (const [identity, tags] of byIdentity) {
|
|
487
665
|
if (identity === "title") {
|
|
488
|
-
if (tags.length > 1)
|
|
666
|
+
if (tags.length > 1) devCheck({
|
|
667
|
+
code: "HEAD_TAG_INVALID",
|
|
668
|
+
kind: "head",
|
|
669
|
+
severity: "warn",
|
|
670
|
+
message: "[HEAD_TAG_INVALID] Multiple <title> tags in one head group; the last one wins.",
|
|
671
|
+
data: {
|
|
672
|
+
reason: "duplicate-title",
|
|
673
|
+
detail: tags.length
|
|
674
|
+
}
|
|
675
|
+
});
|
|
489
676
|
winners.set(identity, {
|
|
490
677
|
seq: group.seq,
|
|
491
678
|
tags: [tags[tags.length - 1]]
|
|
@@ -564,10 +751,10 @@ function resolveAssets(moduleUrl, manifest) {
|
|
|
564
751
|
href: bad,
|
|
565
752
|
...rest
|
|
566
753
|
} = link;
|
|
567
|
-
if (bad !== undefined)
|
|
754
|
+
if (bad !== undefined) preloadInvalid("href", "Preload href must be a non-empty string; dropping it.", bad);
|
|
568
755
|
preloads.push(rest);
|
|
569
756
|
}
|
|
570
|
-
if (srcset && hasRelativeCandidate(srcset))
|
|
757
|
+
if (srcset && hasRelativeCandidate(srcset)) preloadInvalid("imagesrcset", "imagesrcset candidates are not joined with the manifest base — they resolve " + "against the document URL, so a relative candidate points somewhere else " + "than the joined href; the integration should emit resolved URLs.", srcset);
|
|
571
758
|
}
|
|
572
759
|
}
|
|
573
760
|
if (e.imports) for (let i = 0; i < e.imports.length; i++) walk(e.imports[i]);
|
|
@@ -704,13 +891,53 @@ function isSetAttr(value) {
|
|
|
704
891
|
return value != null && value !== false && value !== "";
|
|
705
892
|
}
|
|
706
893
|
const PRELOAD_LINK_ATTRIBUTES = ["type", "crossorigin", "integrity", "referrerpolicy", "fetchpriority", "media", "imagesrcset", "imagesizes"];
|
|
894
|
+
function preloadInvalid(field, message, value) {
|
|
895
|
+
devCheck({
|
|
896
|
+
code: "PRELOAD_DESCRIPTOR_INVALID",
|
|
897
|
+
kind: "head",
|
|
898
|
+
severity: "warn",
|
|
899
|
+
message: `[PRELOAD_DESCRIPTOR_INVALID] ${message}`,
|
|
900
|
+
data: value === undefined ? {
|
|
901
|
+
field
|
|
902
|
+
} : {
|
|
903
|
+
field,
|
|
904
|
+
value
|
|
905
|
+
}
|
|
906
|
+
});
|
|
907
|
+
}
|
|
908
|
+
function unrecognizedInsert(node) {
|
|
909
|
+
devCheck({
|
|
910
|
+
code: "UNRECOGNIZED_INSERT_VALUE",
|
|
911
|
+
kind: "render",
|
|
912
|
+
severity: "warn",
|
|
913
|
+
message: `[UNRECOGNIZED_INSERT_VALUE] Unrecognized value. Skipped inserting (${typeof node}).`,
|
|
914
|
+
data: {
|
|
915
|
+
type: typeof node,
|
|
916
|
+
value: node
|
|
917
|
+
}
|
|
918
|
+
});
|
|
919
|
+
}
|
|
920
|
+
function headTagInvalid(reason, message, detail) {
|
|
921
|
+
devCheck({
|
|
922
|
+
code: "HEAD_TAG_INVALID",
|
|
923
|
+
kind: "head",
|
|
924
|
+
severity: "warn",
|
|
925
|
+
message: `[HEAD_TAG_INVALID] ${message}`,
|
|
926
|
+
data: detail === undefined ? {
|
|
927
|
+
reason
|
|
928
|
+
} : {
|
|
929
|
+
reason,
|
|
930
|
+
detail
|
|
931
|
+
}
|
|
932
|
+
});
|
|
933
|
+
}
|
|
707
934
|
function registerPreloadLink(tracking, headRegistry, link, nonce) {
|
|
708
935
|
if (!link || typeof link !== "object") {
|
|
709
|
-
|
|
936
|
+
preloadInvalid("descriptor", 'registerAsset("preload") requires a descriptor object.', link);
|
|
710
937
|
return null;
|
|
711
938
|
}
|
|
712
939
|
if (typeof link.as !== "string") {
|
|
713
|
-
|
|
940
|
+
preloadInvalid("as", 'registerAsset("preload") requires an as destination.');
|
|
714
941
|
return null;
|
|
715
942
|
}
|
|
716
943
|
const as = asciiLowerCase(link.as);
|
|
@@ -726,11 +953,11 @@ function registerPreloadLink(tracking, headRegistry, link, nonce) {
|
|
|
726
953
|
case "track":
|
|
727
954
|
break;
|
|
728
955
|
default:
|
|
729
|
-
|
|
956
|
+
preloadInvalid("as", `registerAsset("preload") received an unsupported as destination "${link.as}".`, link.as);
|
|
730
957
|
return null;
|
|
731
958
|
}
|
|
732
959
|
const responsive = as === "image";
|
|
733
|
-
if (!responsive && (isSetAttr(link.imagesrcset) || isSetAttr(link.imagesizes)))
|
|
960
|
+
if (!responsive && (isSetAttr(link.imagesrcset) || isSetAttr(link.imagesizes))) preloadInvalid(isSetAttr(link.imagesrcset) ? "imagesrcset" : "imagesizes", 'registerAsset("preload") only supports imagesrcset and imagesizes with as="image".');
|
|
734
961
|
let srcset = null;
|
|
735
962
|
let sizes = null;
|
|
736
963
|
if (responsive) {
|
|
@@ -738,19 +965,19 @@ function registerPreloadLink(tracking, headRegistry, link, nonce) {
|
|
|
738
965
|
const value = link[name];
|
|
739
966
|
if (!isSetAttr(value)) continue;
|
|
740
967
|
if (typeof value !== "string") {
|
|
741
|
-
|
|
968
|
+
preloadInvalid(name, `registerAsset("preload") expects a string ${name}.`, value);
|
|
742
969
|
continue;
|
|
743
970
|
}
|
|
744
971
|
if (name === "imagesrcset") srcset = value;else sizes = value;
|
|
745
972
|
}
|
|
746
973
|
}
|
|
747
974
|
const href = typeof link.href === "string" && link.href ? link.href : null;
|
|
748
|
-
if (!href && link.href != null && link.href !== false)
|
|
975
|
+
if (!href && link.href != null && link.href !== false) preloadInvalid("href", "Preload href must be a non-empty string; dropping it.", link.href);
|
|
749
976
|
if (!href && !srcset) {
|
|
750
|
-
|
|
977
|
+
preloadInvalid("href", 'registerAsset("preload") requires a non-empty string href or imagesrcset.');
|
|
751
978
|
return null;
|
|
752
979
|
}
|
|
753
|
-
if (srcset && !sizes && hasWidthDescriptor(srcset))
|
|
980
|
+
if (srcset && !sizes && hasWidthDescriptor(srcset)) preloadInvalid("imagesizes", "imagesrcset uses a width descriptor, so imagesizes is required; without it the " + "source size defaults to 100vw and the preload may not match the image.", srcset);
|
|
754
981
|
const props = {
|
|
755
982
|
rel: "preload"
|
|
756
983
|
};
|
|
@@ -769,7 +996,7 @@ function registerPreloadLink(tracking, headRegistry, link, nonce) {
|
|
|
769
996
|
}
|
|
770
997
|
const identity = resourceIdentity("link", props);
|
|
771
998
|
if (headRegistry.resources.has(identity)) return null;
|
|
772
|
-
if (props.crossorigin == null && (as === "font" || as === "fetch"))
|
|
999
|
+
if (props.crossorigin == null && (as === "font" || as === "fetch")) preloadInvalid("crossorigin", `registerAsset("preload") with as="${as}" has no crossorigin and may not match the eventual request.`);
|
|
773
1000
|
const attrs = headAttrRecord(props);
|
|
774
1001
|
const nonceValue = destination && nonce && nonce[destination];
|
|
775
1002
|
if (typeof nonceValue === "string" && nonceValue) attrs.nonce = nonceValue;
|
|
@@ -813,7 +1040,7 @@ function registerHeadTags(registry, context, tracking, emitResource, nonce, tags
|
|
|
813
1040
|
for (let i = 0; i < tags.length; i++) {
|
|
814
1041
|
const desc = tags[i];
|
|
815
1042
|
if (!desc || !HEAD_ELIGIBLE_TAGS.has(desc.tag)) {
|
|
816
|
-
|
|
1043
|
+
headTagInvalid("non-head-tag", `useHead: ignoring non-head tag <${desc && desc.tag}>`, desc);
|
|
817
1044
|
continue;
|
|
818
1045
|
}
|
|
819
1046
|
const cls = classifyHeadTag(desc);
|
|
@@ -865,7 +1092,7 @@ function headShellReady(registry, block) {
|
|
|
865
1092
|
} : undefined);
|
|
866
1093
|
} catch (err) {
|
|
867
1094
|
if (pends(err)) continue;
|
|
868
|
-
|
|
1095
|
+
headTagInvalid("props-error", `useHead: error evaluating resource tag props: ${errorText(err)}`, err);
|
|
869
1096
|
parked.splice(i, 1);
|
|
870
1097
|
continue;
|
|
871
1098
|
}
|
|
@@ -906,7 +1133,7 @@ function emitHeadResource(registry, context, tracking, emitResource, nonce, desc
|
|
|
906
1133
|
});
|
|
907
1134
|
return;
|
|
908
1135
|
}
|
|
909
|
-
|
|
1136
|
+
headTagInvalid("props-error", `useHead: error evaluating resource tag props: ${errorText(err)}`, err);
|
|
910
1137
|
return;
|
|
911
1138
|
}
|
|
912
1139
|
const identity = resourceIdentity(desc.tag, props);
|
|
@@ -968,7 +1195,7 @@ function commitHeadBoundary(registry, boundary, isPendingFragment) {
|
|
|
968
1195
|
try {
|
|
969
1196
|
resolved = reg.list();
|
|
970
1197
|
} catch (err) {
|
|
971
|
-
|
|
1198
|
+
headTagInvalid("group-error", `useHead: error evaluating head group membership: ${errorText(err)}`, err);
|
|
972
1199
|
continue;
|
|
973
1200
|
}
|
|
974
1201
|
if (!Array.isArray(resolved)) resolved = [resolved];
|
|
@@ -976,7 +1203,7 @@ function commitHeadBoundary(registry, boundary, isPendingFragment) {
|
|
|
976
1203
|
for (let j = 0; j < resolved.length; j++) {
|
|
977
1204
|
const desc = resolved[j];
|
|
978
1205
|
if (!desc || !HEAD_ELIGIBLE_TAGS.has(desc.tag)) {
|
|
979
|
-
|
|
1206
|
+
headTagInvalid("non-head-tag", `useHead: ignoring non-head tag <${desc && desc.tag}>`, desc);
|
|
980
1207
|
continue;
|
|
981
1208
|
}
|
|
982
1209
|
const cls = classifyHeadTag(desc);
|
|
@@ -1002,12 +1229,12 @@ function commitHeadBoundary(registry, boundary, isPendingFragment) {
|
|
|
1002
1229
|
} : undefined);
|
|
1003
1230
|
key = evalHeadValue(desc.key);
|
|
1004
1231
|
} catch (err) {
|
|
1005
|
-
|
|
1232
|
+
headTagInvalid("props-error", `useHead: error evaluating tag props: ${errorText(err)}`, err);
|
|
1006
1233
|
continue;
|
|
1007
1234
|
}
|
|
1008
1235
|
const identity = replaceableIdentity(desc.tag, props, key, "u:" + registry.uniq++);
|
|
1009
1236
|
if ((identity === "base" || identity === "charset") && registry.shellFlushed) {
|
|
1010
|
-
|
|
1237
|
+
headTagInvalid("after-shell-flush", `useHead: <${desc.tag}> (${identity}) registered after shell flush is ignored`, identity);
|
|
1011
1238
|
continue;
|
|
1012
1239
|
}
|
|
1013
1240
|
tags.push({
|
|
@@ -1041,7 +1268,7 @@ function headGroupSignature(winner) {
|
|
|
1041
1268
|
}
|
|
1042
1269
|
return sig;
|
|
1043
1270
|
}
|
|
1044
|
-
function renderShellHead(registry, nonce, isPendingFragment, noScripts) {
|
|
1271
|
+
function renderShellHead(registry, nonce, isPendingFragment, noScripts, traceMetas = "") {
|
|
1045
1272
|
commitHeadBoundary(registry, "", isPendingFragment);
|
|
1046
1273
|
registry.shellFlushed = true;
|
|
1047
1274
|
const winners = resolveHead(registry.committed);
|
|
@@ -1067,7 +1294,7 @@ function renderShellHead(registry, nonce, isPendingFragment, noScripts) {
|
|
|
1067
1294
|
}
|
|
1068
1295
|
return {
|
|
1069
1296
|
prelude,
|
|
1070
|
-
html: registry.eagerHtml + links + metas + others + scripts,
|
|
1297
|
+
html: registry.eagerHtml + links + metas + traceMetas + others + scripts,
|
|
1071
1298
|
title,
|
|
1072
1299
|
noScripts
|
|
1073
1300
|
};
|
|
@@ -1097,7 +1324,7 @@ function flushHeadFragment(registry, boundary, nonce) {
|
|
|
1097
1324
|
for (const name in t.props) {
|
|
1098
1325
|
if (name === "children" || name === "ref" || name.slice(0, 2) === "on") continue;
|
|
1099
1326
|
if (!HEAD_ATTR_NAME.test(name)) {
|
|
1100
|
-
|
|
1327
|
+
headTagInvalid("invalid-attribute", `useHead: ignoring invalid attribute name "${name}"`, name);
|
|
1101
1328
|
continue;
|
|
1102
1329
|
}
|
|
1103
1330
|
const v = t.props[name];
|
|
@@ -1175,7 +1402,7 @@ function renderHeadAttrHtml(props) {
|
|
|
1175
1402
|
for (const name in props) {
|
|
1176
1403
|
if (name === "children" || name === "ref" || name.slice(0, 2) === "on") continue;
|
|
1177
1404
|
if (!HEAD_ATTR_NAME.test(name)) {
|
|
1178
|
-
|
|
1405
|
+
headTagInvalid("invalid-attribute", `useHead: ignoring invalid attribute name "${name}"`, name);
|
|
1179
1406
|
continue;
|
|
1180
1407
|
}
|
|
1181
1408
|
const v = props[name];
|
|
@@ -1220,8 +1447,19 @@ function renderToStream(code, options = {}) {
|
|
|
1220
1447
|
const requestEvent = peekRequestEvent();
|
|
1221
1448
|
let dispose;
|
|
1222
1449
|
let dead = false;
|
|
1223
|
-
const abandon =
|
|
1450
|
+
const abandon = disconnect => {
|
|
1224
1451
|
if (dead) return;
|
|
1452
|
+
if (disconnect) emitFinding({
|
|
1453
|
+
code: "SSR_STREAM_ABANDONED",
|
|
1454
|
+
kind: "ssr",
|
|
1455
|
+
severity: "warn",
|
|
1456
|
+
message: `[SSR_STREAM_ABANDONED] The response stream was abandoned mid-render (${disconnect}) ` + `with ${registry.size} fragment(s) still pending; the render was torn down.`,
|
|
1457
|
+
data: {
|
|
1458
|
+
reason: disconnect,
|
|
1459
|
+
shellFlushed: firstFlushed,
|
|
1460
|
+
pendingFragments: registry.size
|
|
1461
|
+
}
|
|
1462
|
+
}, null);
|
|
1225
1463
|
dead = true;
|
|
1226
1464
|
completed = true;
|
|
1227
1465
|
buffer = {
|
|
@@ -1237,11 +1475,26 @@ function renderToStream(code, options = {}) {
|
|
|
1237
1475
|
}
|
|
1238
1476
|
};
|
|
1239
1477
|
const failRender = err => {
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1478
|
+
reportServerError(err, {
|
|
1479
|
+
kind: "render",
|
|
1480
|
+
handling: "failed"
|
|
1481
|
+
}, null);
|
|
1482
|
+
if (!options.onError && ambientServerErrorHook() === undefined) console.error(err);
|
|
1243
1483
|
abandon();
|
|
1244
1484
|
};
|
|
1485
|
+
const failRootRender = err => {
|
|
1486
|
+
emitFinding({
|
|
1487
|
+
code: "SSR_RENDER_ERROR_CONTAINED",
|
|
1488
|
+
kind: "ssr",
|
|
1489
|
+
severity: "error",
|
|
1490
|
+
message: `[SSR_RENDER_ERROR_CONTAINED] Render error outside any boundary — the request failed: ` + errorText(err),
|
|
1491
|
+
data: {
|
|
1492
|
+
handling: "failed",
|
|
1493
|
+
error: err
|
|
1494
|
+
}
|
|
1495
|
+
}, null);
|
|
1496
|
+
failRender(err);
|
|
1497
|
+
};
|
|
1245
1498
|
const coalesceWrites = (writeRaw, endRaw) => {
|
|
1246
1499
|
let buf = "";
|
|
1247
1500
|
let scheduled = false;
|
|
@@ -1274,7 +1527,7 @@ function renderToStream(code, options = {}) {
|
|
|
1274
1527
|
try {
|
|
1275
1528
|
w.write(payload);
|
|
1276
1529
|
} catch (_) {
|
|
1277
|
-
abandon();
|
|
1530
|
+
abandon("sink");
|
|
1278
1531
|
}
|
|
1279
1532
|
},
|
|
1280
1533
|
end() {
|
|
@@ -1282,7 +1535,7 @@ function renderToStream(code, options = {}) {
|
|
|
1282
1535
|
try {
|
|
1283
1536
|
w.end();
|
|
1284
1537
|
} catch (_) {
|
|
1285
|
-
abandon();
|
|
1538
|
+
abandon("sink");
|
|
1286
1539
|
}
|
|
1287
1540
|
}
|
|
1288
1541
|
});
|
|
@@ -1379,7 +1632,7 @@ function renderToStream(code, options = {}) {
|
|
|
1379
1632
|
plugins: options.plugins,
|
|
1380
1633
|
onData: payload => sink.data(payload),
|
|
1381
1634
|
onDone,
|
|
1382
|
-
onError: options.onError
|
|
1635
|
+
onError: serializerErrorHook(options.onError)
|
|
1383
1636
|
});
|
|
1384
1637
|
let rootAssetsSerialized = false;
|
|
1385
1638
|
const serializeRootAssets = () => {
|
|
@@ -1404,6 +1657,34 @@ function renderToStream(code, options = {}) {
|
|
|
1404
1657
|
};
|
|
1405
1658
|
const registry = new Map();
|
|
1406
1659
|
const pendingSerialized = new Map();
|
|
1660
|
+
const guardedChannels = new WeakMap();
|
|
1661
|
+
const verdictNow = error => {
|
|
1662
|
+
throw ssrSanitizeError(error, null);
|
|
1663
|
+
};
|
|
1664
|
+
const guardChannel = p => {
|
|
1665
|
+
if (!p || typeof p !== "object" || "__SEROVAL_STREAM__" in p) return p;
|
|
1666
|
+
const thenable = typeof p.then === "function";
|
|
1667
|
+
const iterable = !thenable && typeof p[Symbol.asyncIterator] === "function";
|
|
1668
|
+
if (!thenable && !iterable) return p;
|
|
1669
|
+
let guarded = guardedChannels.get(p);
|
|
1670
|
+
if (guarded === undefined) {
|
|
1671
|
+
guarded = thenable ? p.then(undefined, verdictNow) : {
|
|
1672
|
+
[Symbol.asyncIterator]() {
|
|
1673
|
+
const iterator = p[Symbol.asyncIterator]();
|
|
1674
|
+
return {
|
|
1675
|
+
next: value => iterator.next(value).then(undefined, verdictNow),
|
|
1676
|
+
return: value => iterator.return ? iterator.return(value) : Promise.resolve({
|
|
1677
|
+
done: true,
|
|
1678
|
+
value
|
|
1679
|
+
}),
|
|
1680
|
+
throw: error => iterator.throw ? iterator.throw(error) : Promise.reject(error)
|
|
1681
|
+
};
|
|
1682
|
+
}
|
|
1683
|
+
};
|
|
1684
|
+
guardedChannels.set(p, guarded);
|
|
1685
|
+
}
|
|
1686
|
+
return guarded;
|
|
1687
|
+
};
|
|
1407
1688
|
const trackSerialized = (id, p) => {
|
|
1408
1689
|
let settle;
|
|
1409
1690
|
const raced = Promise.race([p, new Promise(r => settle = r)]);
|
|
@@ -1412,19 +1693,35 @@ function renderToStream(code, options = {}) {
|
|
|
1412
1693
|
p.then(drop, drop);
|
|
1413
1694
|
return raced;
|
|
1414
1695
|
};
|
|
1415
|
-
const abandonSubtree = key => {
|
|
1696
|
+
const abandonSubtree = (key, error) => {
|
|
1697
|
+
let fragments = 0;
|
|
1698
|
+
let serialized = 0;
|
|
1416
1699
|
for (const [k, entry] of registry) {
|
|
1417
1700
|
if (k.length > key.length && k.startsWith(key)) {
|
|
1418
1701
|
registry.delete(k);
|
|
1419
1702
|
entry.resolve();
|
|
1703
|
+
fragments++;
|
|
1420
1704
|
}
|
|
1421
1705
|
}
|
|
1422
1706
|
for (const [id, settle] of pendingSerialized) {
|
|
1423
1707
|
if (id.startsWith(key)) {
|
|
1424
1708
|
pendingSerialized.delete(id);
|
|
1425
1709
|
settle();
|
|
1710
|
+
serialized++;
|
|
1426
1711
|
}
|
|
1427
1712
|
}
|
|
1713
|
+
if ((fragments || serialized)) emitFinding({
|
|
1714
|
+
code: "SSR_SUBTREE_ABANDONED",
|
|
1715
|
+
kind: "ssr",
|
|
1716
|
+
severity: "warn",
|
|
1717
|
+
message: `[SSR_SUBTREE_ABANDONED] Fragment '${key}' failed with ${fragments} nested fragment(s) and ` + `${serialized} serialized value(s) still pending; the subtree was discarded and the client ` + `renders it from scratch.`,
|
|
1718
|
+
data: {
|
|
1719
|
+
fragment: key,
|
|
1720
|
+
fragments,
|
|
1721
|
+
serialized,
|
|
1722
|
+
error
|
|
1723
|
+
}
|
|
1724
|
+
}, null);
|
|
1428
1725
|
};
|
|
1429
1726
|
const writeTasks = () => {
|
|
1430
1727
|
if (tasks.length && !completed && firstFlushed) {
|
|
@@ -1545,6 +1842,7 @@ function renderToStream(code, options = {}) {
|
|
|
1545
1842
|
},
|
|
1546
1843
|
serialize(id, p, deferStream) {
|
|
1547
1844
|
if (sharedConfig.context.noHydrate) return;
|
|
1845
|
+
p = guardChannel(p);
|
|
1548
1846
|
if (p && typeof p === "object" && typeof p.then === "function") {
|
|
1549
1847
|
if (!firstFlushed && deferStream) {
|
|
1550
1848
|
blockingPromises.add(p);
|
|
@@ -1587,7 +1885,7 @@ function renderToStream(code, options = {}) {
|
|
|
1587
1885
|
const p = new Promise((r, rej) => (resolve = r, reject = rej));
|
|
1588
1886
|
registry.set(key, {
|
|
1589
1887
|
resolve: err => queue(() => queue(() => {
|
|
1590
|
-
err ? reject(err) : resolve(true);
|
|
1888
|
+
err ? reject(ssrSanitizeError(err, null)) : resolve(true);
|
|
1591
1889
|
queue(flushEnd);
|
|
1592
1890
|
}))
|
|
1593
1891
|
});
|
|
@@ -1597,8 +1895,8 @@ function renderToStream(code, options = {}) {
|
|
|
1597
1895
|
if (registry.has(key)) {
|
|
1598
1896
|
const item = registry.get(key);
|
|
1599
1897
|
registry.delete(key);
|
|
1600
|
-
if (error) abandonSubtree(key);
|
|
1601
|
-
if (item.children) {
|
|
1898
|
+
if (error) abandonSubtree(key, error);
|
|
1899
|
+
if (item.children && !error) {
|
|
1602
1900
|
for (const k in item.children) {
|
|
1603
1901
|
value = replacePlaceholder(value, k, item.children[k]);
|
|
1604
1902
|
}
|
|
@@ -1628,7 +1926,7 @@ function renderToStream(code, options = {}) {
|
|
|
1628
1926
|
sink.fragment(key, resolveSSRSelectValues(value !== undefined ? value : " "), {
|
|
1629
1927
|
styles,
|
|
1630
1928
|
revealGroup,
|
|
1631
|
-
error
|
|
1929
|
+
error: error ? ssrSanitizeError(error, null) : error
|
|
1632
1930
|
});
|
|
1633
1931
|
item.resolve(error);
|
|
1634
1932
|
}
|
|
@@ -1654,9 +1952,15 @@ function renderToStream(code, options = {}) {
|
|
|
1654
1952
|
};
|
|
1655
1953
|
applyAssetTracking(context, tracking, manifest, noScripts);
|
|
1656
1954
|
context.failRender = failRender;
|
|
1955
|
+
context.errorPolicy = options.onError;
|
|
1956
|
+
context.flushed = () => firstFlushed;
|
|
1957
|
+
context.trace = requestEvent ? traceForEvent(requestEvent) : traceFor(context, undefined);
|
|
1657
1958
|
registerEntryAssets(manifest);
|
|
1658
1959
|
let html = createRoot(d => {
|
|
1659
|
-
dispose =
|
|
1960
|
+
dispose = () => {
|
|
1961
|
+
context.trace = undefined;
|
|
1962
|
+
d();
|
|
1963
|
+
};
|
|
1660
1964
|
const res = resolveSSRNode(escape(code()));
|
|
1661
1965
|
if (!res.h.length) return res.t[0];
|
|
1662
1966
|
rootHoles = [];
|
|
@@ -1719,7 +2023,7 @@ function renderToStream(code, options = {}) {
|
|
|
1719
2023
|
}
|
|
1720
2024
|
serializeRootAssets();
|
|
1721
2025
|
flushStubBatch();
|
|
1722
|
-
const head = renderShellHead(headRegistry, nonce, k => registry.has(k), noScripts);
|
|
2026
|
+
const head = renderShellHead(headRegistry, nonce, k => registry.has(k), noScripts, traceMetaMarkup(context.trace));
|
|
1723
2027
|
sink.shell(resolveSSRSelectValues(html), {
|
|
1724
2028
|
preloads: tracking.emittedAssets,
|
|
1725
2029
|
preloadLinks: tracking.preloadLinks,
|
|
@@ -1774,7 +2078,7 @@ function renderToStream(code, options = {}) {
|
|
|
1774
2078
|
try {
|
|
1775
2079
|
doShell();
|
|
1776
2080
|
} catch (err) {
|
|
1777
|
-
|
|
2081
|
+
failRootRender(err);
|
|
1778
2082
|
return resolve();
|
|
1779
2083
|
}
|
|
1780
2084
|
if (!shellCompleted) return flush();
|
|
@@ -1784,7 +2088,7 @@ function renderToStream(code, options = {}) {
|
|
|
1784
2088
|
let ended = false;
|
|
1785
2089
|
const failed = () => {
|
|
1786
2090
|
if (!ended) {
|
|
1787
|
-
abandon();
|
|
2091
|
+
abandon("consumer");
|
|
1788
2092
|
resolve();
|
|
1789
2093
|
}
|
|
1790
2094
|
};
|
|
@@ -1815,7 +2119,9 @@ function renderToStream(code, options = {}) {
|
|
|
1815
2119
|
return {
|
|
1816
2120
|
then(onFulfilled, onRejected) {
|
|
1817
2121
|
const freezeHead = () => {
|
|
1818
|
-
if (requestEvent && requestEvent.response) commitResponseStub(requestEvent.response
|
|
2122
|
+
if (requestEvent && requestEvent.response) commitResponseStub(requestEvent.response, {
|
|
2123
|
+
event: requestEvent
|
|
2124
|
+
});
|
|
1819
2125
|
};
|
|
1820
2126
|
const p = new Promise(resolve => {
|
|
1821
2127
|
function complete() {
|
|
@@ -1836,7 +2142,7 @@ function renderToStream(code, options = {}) {
|
|
|
1836
2142
|
try {
|
|
1837
2143
|
if (blockingPromises.size !== lastBlockingSize || !resolveRootHoles() || blockingPromises.size !== lastBlockingSize || !headShellReady(headRegistry, p => blockingPromises.add(p))) return flush();
|
|
1838
2144
|
} catch (err) {
|
|
1839
|
-
|
|
2145
|
+
failRootRender(err);
|
|
1840
2146
|
return resolve(tmp);
|
|
1841
2147
|
}
|
|
1842
2148
|
queue(flushEnd);
|
|
@@ -1856,7 +2162,7 @@ function renderToStream(code, options = {}) {
|
|
|
1856
2162
|
try {
|
|
1857
2163
|
doShell();
|
|
1858
2164
|
} catch (err) {
|
|
1859
|
-
|
|
2165
|
+
failRootRender(err);
|
|
1860
2166
|
try {
|
|
1861
2167
|
w.end();
|
|
1862
2168
|
} catch (_) {}
|
|
@@ -1975,6 +2281,10 @@ function ssrGroupSlot(fn, idx) {
|
|
|
1975
2281
|
}
|
|
1976
2282
|
};
|
|
1977
2283
|
}
|
|
2284
|
+
function wireErrorMessage(err) {
|
|
2285
|
+
const wire = ssrSanitizeError(err, null);
|
|
2286
|
+
return String(wire && wire.message || wire);
|
|
2287
|
+
}
|
|
1978
2288
|
const holePositionCache = new WeakMap();
|
|
1979
2289
|
function holeContentPositions(t) {
|
|
1980
2290
|
let cached = holePositionCache.get(t);
|
|
@@ -2131,7 +2441,7 @@ function createLiveHoles(sink, scoped) {
|
|
|
2131
2441
|
} catch (err) {
|
|
2132
2442
|
b.closed = true;
|
|
2133
2443
|
sink.closeBinding(b.key);
|
|
2134
|
-
sink.error(b.key,
|
|
2444
|
+
sink.error(b.key, wireErrorMessage(err));
|
|
2135
2445
|
return;
|
|
2136
2446
|
} finally {
|
|
2137
2447
|
engine.sweeping = prevSweeping;
|
|
@@ -2276,7 +2586,7 @@ function createLiveHoles(sink, scoped) {
|
|
|
2276
2586
|
if (ssrHandleError(err, true)) return;
|
|
2277
2587
|
b.closed = true;
|
|
2278
2588
|
sink.closeBinding(b.key);
|
|
2279
|
-
sink.error("lha:" + cap.id,
|
|
2589
|
+
sink.error("lha:" + cap.id, wireErrorMessage(err));
|
|
2280
2590
|
return;
|
|
2281
2591
|
} finally {
|
|
2282
2592
|
engine.sweeping = prevSweeping;
|
|
@@ -2804,23 +3114,26 @@ function replacePlaceholder(html, key, value) {
|
|
|
2804
3114
|
const last = html.indexOf(close, first + marker.length);
|
|
2805
3115
|
return html.slice(0, first) + value + html.slice(last + close.length);
|
|
2806
3116
|
}
|
|
2807
|
-
|
|
3117
|
+
let ssrTextTail = false;
|
|
3118
|
+
function tryResolveString(node, nested) {
|
|
3119
|
+
if (!nested) ssrTextTail = false;
|
|
2808
3120
|
const t = typeof node;
|
|
2809
|
-
if (t === "string")
|
|
2810
|
-
|
|
3121
|
+
if (t === "string" || t === "number") {
|
|
3122
|
+
const s = ssrTextTail ? "<!--!$-->" + node : "" + node;
|
|
3123
|
+
ssrTextTail = true;
|
|
3124
|
+
return s;
|
|
3125
|
+
}
|
|
2811
3126
|
if (node == null || t === "boolean") return "";
|
|
2812
3127
|
if (t === "object") {
|
|
2813
3128
|
if (Array.isArray(node)) {
|
|
2814
3129
|
const joined = tryJoinPlainSSRArray(node);
|
|
2815
|
-
if (joined !== undefined)
|
|
3130
|
+
if (joined !== undefined) {
|
|
3131
|
+
ssrTextTail = false;
|
|
3132
|
+
return joined;
|
|
3133
|
+
}
|
|
2816
3134
|
let s = "";
|
|
2817
|
-
let prevNonObj = false;
|
|
2818
3135
|
for (let i = 0, len = node.length; i < len; i++) {
|
|
2819
|
-
const
|
|
2820
|
-
const itemNonObj = item !== null && typeof item !== "object";
|
|
2821
|
-
if (prevNonObj && itemNonObj) s += "<!--!$-->";
|
|
2822
|
-
prevNonObj = itemNonObj;
|
|
2823
|
-
const r = tryResolveString(item);
|
|
3136
|
+
const r = tryResolveString(node[i], true);
|
|
2824
3137
|
if (typeof r !== "string") return {
|
|
2825
3138
|
bail: node
|
|
2826
3139
|
};
|
|
@@ -2832,9 +3145,10 @@ function tryResolveString(node) {
|
|
|
2832
3145
|
merge: node
|
|
2833
3146
|
};
|
|
2834
3147
|
if (node.t === undefined) {
|
|
2835
|
-
|
|
3148
|
+
unrecognizedInsert(node);
|
|
2836
3149
|
return "";
|
|
2837
3150
|
}
|
|
3151
|
+
ssrTextTail = false;
|
|
2838
3152
|
return Array.isArray(node.t) ? node.t[0] : node.t;
|
|
2839
3153
|
}
|
|
2840
3154
|
if (t === "function") {
|
|
@@ -2842,9 +3156,11 @@ function tryResolveString(node) {
|
|
|
2842
3156
|
try {
|
|
2843
3157
|
v = node();
|
|
2844
3158
|
} catch (err) {
|
|
2845
|
-
|
|
3159
|
+
const wrap = buildAsyncWrap(err, node);
|
|
3160
|
+
if (wrap) ssrTextTail = true;
|
|
3161
|
+
return wrap || "";
|
|
2846
3162
|
}
|
|
2847
|
-
return tryResolveString(v);
|
|
3163
|
+
return tryResolveString(v, true);
|
|
2848
3164
|
}
|
|
2849
3165
|
return "";
|
|
2850
3166
|
}
|
|
@@ -2852,21 +3168,19 @@ function resolveSSRNode(node, result = {
|
|
|
2852
3168
|
t: [""],
|
|
2853
3169
|
h: [],
|
|
2854
3170
|
p: []
|
|
2855
|
-
}, top) {
|
|
3171
|
+
}, top, nested) {
|
|
3172
|
+
if (!nested) ssrTextTail = false;
|
|
2856
3173
|
const t = typeof node;
|
|
2857
3174
|
if (t === "string" || t === "number") {
|
|
2858
|
-
result.t[result.t.length - 1] += node;
|
|
3175
|
+
result.t[result.t.length - 1] += ssrTextTail ? "<!--!$-->" + node : node;
|
|
3176
|
+
ssrTextTail = true;
|
|
2859
3177
|
} else if (node == null || t === "boolean") ; else if (Array.isArray(node)) {
|
|
2860
3178
|
const slotLive = node.$slot && sharedConfig.context && sharedConfig.context.liveHoles;
|
|
2861
3179
|
if (slotLive) slotLive.suppressed++;
|
|
2862
3180
|
try {
|
|
2863
|
-
let prevNonObj = false;
|
|
2864
3181
|
for (let i = 0, len = node.length; i < len; i++) {
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
if (!top && prevNonObj && itemNonObj) result.t[result.t.length - 1] += `<!--!$-->`;
|
|
2868
|
-
prevNonObj = itemNonObj;
|
|
2869
|
-
resolveSSRNode(item, result);
|
|
3182
|
+
if (top) ssrTextTail = false;
|
|
3183
|
+
resolveSSRNode(node[i], result, false, true);
|
|
2870
3184
|
}
|
|
2871
3185
|
} finally {
|
|
2872
3186
|
if (slotLive) slotLive.suppressed--;
|
|
@@ -2879,23 +3193,30 @@ function resolveSSRNode(node, result = {
|
|
|
2879
3193
|
result.h.push(...node.h);
|
|
2880
3194
|
result.p.push(...node.p);
|
|
2881
3195
|
}
|
|
3196
|
+
ssrTextTail = false;
|
|
2882
3197
|
} else if (node.t !== undefined) {
|
|
2883
3198
|
result.t[result.t.length - 1] += node.t;
|
|
2884
|
-
|
|
3199
|
+
ssrTextTail = false;
|
|
3200
|
+
} else unrecognizedInsert(node);
|
|
2885
3201
|
} else if (t === "function") {
|
|
2886
3202
|
const live = sharedConfig.context && sharedConfig.context.liveHoles;
|
|
2887
3203
|
let liveNode = null;
|
|
2888
3204
|
if (live && (liveNode = live.content(node)) !== null) {
|
|
2889
|
-
if (typeof liveNode === "string")
|
|
3205
|
+
if (typeof liveNode === "string") {
|
|
3206
|
+
result.t[result.t.length - 1] += ssrTextTail ? "<!--!$-->" + liveNode : liveNode;
|
|
3207
|
+
ssrTextTail = true;
|
|
3208
|
+
} else resolveSSRNode(liveNode, result, false, true);
|
|
2890
3209
|
} else {
|
|
2891
3210
|
try {
|
|
2892
|
-
resolveSSRNode(node(), result);
|
|
3211
|
+
resolveSSRNode(node(), result, false, true);
|
|
2893
3212
|
} catch (err) {
|
|
2894
3213
|
const wrap = buildAsyncWrap(err, node);
|
|
2895
3214
|
if (wrap) {
|
|
3215
|
+
if (ssrTextTail) result.t[result.t.length - 1] += "<!--!$-->";
|
|
2896
3216
|
result.h.push(wrap.fn);
|
|
2897
3217
|
result.p.push(wrap.p);
|
|
2898
3218
|
result.t.push("");
|
|
3219
|
+
ssrTextTail = true;
|
|
2899
3220
|
}
|
|
2900
3221
|
}
|
|
2901
3222
|
}
|
|
@@ -2908,20 +3229,58 @@ function resolveSSRSync(node) {
|
|
|
2908
3229
|
throw new Error("This value cannot be rendered synchronously. Are you missing a boundary?");
|
|
2909
3230
|
}
|
|
2910
3231
|
const RequestContext = Symbol.for("solid.RequestContext");
|
|
3232
|
+
const ServerErrors = Symbol.for("solid-js/server/errors");
|
|
3233
|
+
function serializerErrorHook(hook) {
|
|
3234
|
+
return hook === undefined ? undefined : err => {
|
|
3235
|
+
reportServerError(err, {
|
|
3236
|
+
kind: "render",
|
|
3237
|
+
handling: "serialize"
|
|
3238
|
+
}, null);
|
|
3239
|
+
};
|
|
3240
|
+
}
|
|
3241
|
+
function ambientServerErrorHook() {
|
|
3242
|
+
const slot = globalThis[ServerErrors];
|
|
3243
|
+
return slot === undefined ? undefined : slot.hook;
|
|
3244
|
+
}
|
|
2911
3245
|
function peekRequestEvent() {
|
|
2912
3246
|
const store = globalThis[RequestContext];
|
|
2913
3247
|
return store ? store.getStore() : undefined;
|
|
2914
3248
|
}
|
|
3249
|
+
function traceForEvent(event) {
|
|
3250
|
+
return traceFor(event.request || event, event.request);
|
|
3251
|
+
}
|
|
3252
|
+
function traceForStub(stub, event) {
|
|
3253
|
+
if (!event) {
|
|
3254
|
+
event = peekRequestEvent();
|
|
3255
|
+
if (!event || event.response !== stub) return undefined;
|
|
3256
|
+
}
|
|
3257
|
+
return traceForEvent(event);
|
|
3258
|
+
}
|
|
2915
3259
|
function reportLostHeaderWrite(method, name) {
|
|
2916
|
-
const message = `Response header write dropped: headers.${method}(${JSON.stringify(String(name))}) ` + "ran after the response head was sent. Write headers before the shell flushes " + "(or before the handler returns).";
|
|
3260
|
+
const message = `[LATE_HEADER_WRITE] Response header write dropped: headers.${method}(${JSON.stringify(String(name))}) ` + "ran after the response head was sent. Write headers before the shell flushes " + "(or before the handler returns).";
|
|
3261
|
+
recordFinding({
|
|
3262
|
+
code: "LATE_HEADER_WRITE",
|
|
3263
|
+
kind: "head",
|
|
3264
|
+
severity: "error",
|
|
3265
|
+
message,
|
|
3266
|
+
data: {
|
|
3267
|
+
method,
|
|
3268
|
+
name: String(name)
|
|
3269
|
+
}
|
|
3270
|
+
});
|
|
2917
3271
|
throw new Error(message);
|
|
2918
3272
|
}
|
|
2919
3273
|
function commitResponseStub(stub, {
|
|
2920
|
-
allowLateLocation = false
|
|
3274
|
+
allowLateLocation = false,
|
|
3275
|
+
event
|
|
2921
3276
|
} = {}) {
|
|
2922
3277
|
if (!stub || stub.committed) return stub;
|
|
2923
|
-
stub.committed = true;
|
|
2924
3278
|
const headers = stub.headers;
|
|
3279
|
+
if (headers && typeof headers.append === "function") {
|
|
3280
|
+
const trace = traceForStub(stub, event);
|
|
3281
|
+
if (trace) appendTraceServerTiming(headers, trace);
|
|
3282
|
+
}
|
|
3283
|
+
stub.committed = true;
|
|
2925
3284
|
if (!headers || typeof headers.set !== "function") return stub;
|
|
2926
3285
|
for (const method of ["set", "append", "delete"]) {
|
|
2927
3286
|
const original = headers[method].bind(headers);
|
|
@@ -2937,6 +3296,62 @@ function commitResponseStub(stub, {
|
|
|
2937
3296
|
/*#__PURE__*/new Set([ERROR_HEADER, BODY_FORMAT_HEADER, SINGLE_FLIGHT_HEADER, REVALIDATE_HEADER, REDIRECT_HEADER, "Location",
|
|
2938
3297
|
...COMPOSED_BODY_FRAMING].map(header => header.toLowerCase()));
|
|
2939
3298
|
|
|
3299
|
+
const RECORDS = Symbol.for("@solidjs/signals/observe/records");
|
|
3300
|
+
function records() {
|
|
3301
|
+
return globalThis[RECORDS];
|
|
3302
|
+
}
|
|
3303
|
+
function frameCensus(event, type, own) {
|
|
3304
|
+
event.chunks++;
|
|
3305
|
+
switch (type) {
|
|
3306
|
+
case "html":
|
|
3307
|
+
if (!own) event.regions++;else if (event.shellMs === undefined) event.shellMs = performance.now() - event.at;
|
|
3308
|
+
break;
|
|
3309
|
+
case "fragment":
|
|
3310
|
+
event.fragments++;
|
|
3311
|
+
break;
|
|
3312
|
+
case "slot":
|
|
3313
|
+
event.slots++;
|
|
3314
|
+
break;
|
|
3315
|
+
case "error":
|
|
3316
|
+
event.errors++;
|
|
3317
|
+
break;
|
|
3318
|
+
}
|
|
3319
|
+
}
|
|
3320
|
+
|
|
3321
|
+
function observeFrame(frame) {
|
|
3322
|
+
const channel = records();
|
|
3323
|
+
if (channel === undefined || !channel.observed("frame")) return undefined;
|
|
3324
|
+
const event = {
|
|
3325
|
+
side: "server",
|
|
3326
|
+
id: frame.id,
|
|
3327
|
+
version: frame.version,
|
|
3328
|
+
at: performance.now(),
|
|
3329
|
+
durationMs: 0,
|
|
3330
|
+
outcome: "complete",
|
|
3331
|
+
chunks: 0,
|
|
3332
|
+
fragments: 0,
|
|
3333
|
+
slots: 0,
|
|
3334
|
+
regions: 0,
|
|
3335
|
+
errors: 0
|
|
3336
|
+
};
|
|
3337
|
+
let settled = false;
|
|
3338
|
+
return {
|
|
3339
|
+
chunk(chunk) {
|
|
3340
|
+
if (chunk.type === "complete") return;
|
|
3341
|
+
frameCensus(event, chunk.type, chunk.id === frame.id);
|
|
3342
|
+
},
|
|
3343
|
+
settle(outcome, error) {
|
|
3344
|
+
if (settled) return;
|
|
3345
|
+
settled = true;
|
|
3346
|
+
event.durationMs = performance.now() - event.at;
|
|
3347
|
+
event.outcome = outcome;
|
|
3348
|
+
const live = {};
|
|
3349
|
+
if (outcome === "error") live.error = error;
|
|
3350
|
+
channel.emit("frame", event, live);
|
|
3351
|
+
}
|
|
3352
|
+
};
|
|
3353
|
+
}
|
|
3354
|
+
|
|
2940
3355
|
function scopeDeferredResult(value, scope) {
|
|
2941
3356
|
const bound = bindDeferredBody(value, scope);
|
|
2942
3357
|
if (bound !== value || value === null || typeof value !== "object") return bound;
|
|
@@ -3128,7 +3543,7 @@ function guardFailures(value, state) {
|
|
|
3128
3543
|
try {
|
|
3129
3544
|
top.accessorValue = descriptor.get.call(top.value);
|
|
3130
3545
|
} catch (error) {
|
|
3131
|
-
throw
|
|
3546
|
+
throw wireServerFunctionError(error, "channel");
|
|
3132
3547
|
}
|
|
3133
3548
|
top.accessorRead = i;
|
|
3134
3549
|
}
|
|
@@ -3238,7 +3653,7 @@ function enterGuard(value, state) {
|
|
|
3238
3653
|
} = await guardOperation(state, () => reader.read());
|
|
3239
3654
|
done ? controller.close() : controller.enqueue(guardOperation(state, () => guardFailures(chunk, state)));
|
|
3240
3655
|
} catch (error) {
|
|
3241
|
-
controller.error(guardOperation(state, () =>
|
|
3656
|
+
controller.error(guardOperation(state, () => wireServerFunctionError(error, "channel")));
|
|
3242
3657
|
}
|
|
3243
3658
|
},
|
|
3244
3659
|
cancel(reason) {
|
|
@@ -3252,7 +3667,7 @@ function enterGuard(value, state) {
|
|
|
3252
3667
|
}
|
|
3253
3668
|
if (typeof value.then === "function") {
|
|
3254
3669
|
const guardedPromise = Promise.resolve(value).then(resolved => guardOperation(state, () => guardFailures(resolved, state)), error => {
|
|
3255
|
-
throw guardOperation(state, () =>
|
|
3670
|
+
throw guardOperation(state, () => wireServerFunctionError(error, "channel"));
|
|
3256
3671
|
});
|
|
3257
3672
|
guardedPromise.catch(() => {});
|
|
3258
3673
|
state.seen.set(value, guardedPromise);
|
|
@@ -3287,7 +3702,7 @@ function enterGuard(value, state) {
|
|
|
3287
3702
|
value: guardOperation(state, () => guardFailures(step.value, state))
|
|
3288
3703
|
};
|
|
3289
3704
|
}, error => {
|
|
3290
|
-
throw guardOperation(state, () =>
|
|
3705
|
+
throw guardOperation(state, () => wireServerFunctionError(error, "channel"));
|
|
3291
3706
|
});
|
|
3292
3707
|
return {
|
|
3293
3708
|
next: () => finished || !gate || gate.wantsMore() ? step() : gate.awaitDemand().then(step),
|
|
@@ -3349,6 +3764,26 @@ function keepGuarded(value, next, changed, state) {
|
|
|
3349
3764
|
state.seen.set(value, value);
|
|
3350
3765
|
return value;
|
|
3351
3766
|
}
|
|
3767
|
+
const REQUEST_ERROR_HOOKS = new WeakMap();
|
|
3768
|
+
function siteFor(handling, event, direct) {
|
|
3769
|
+
const invocation = event ? INVOCATIONS.get(event) : undefined;
|
|
3770
|
+
const site = {
|
|
3771
|
+
kind: "server-function",
|
|
3772
|
+
handling,
|
|
3773
|
+
direct
|
|
3774
|
+
};
|
|
3775
|
+
if (invocation) site.functionId = invocation.id;
|
|
3776
|
+
if (event) site.event = event;
|
|
3777
|
+
return site;
|
|
3778
|
+
}
|
|
3779
|
+
function wireServerFunctionError(value, handling, event = currentEvent()) {
|
|
3780
|
+
const report = reportServerError(value, siteFor(handling, event, false), null, event ? REQUEST_ERROR_HOOKS.get(event) : undefined);
|
|
3781
|
+
return report.mapped ? report.value : sanitizeServerError(value);
|
|
3782
|
+
}
|
|
3783
|
+
function currentEvent() {
|
|
3784
|
+
const store = globalThis[RequestContext];
|
|
3785
|
+
return store ? store.getStore() : undefined;
|
|
3786
|
+
}
|
|
3352
3787
|
function sanitizeServerError(value) {
|
|
3353
3788
|
return value;
|
|
3354
3789
|
}
|
|
@@ -3734,9 +4169,13 @@ function frameStream(makeCode, options) {
|
|
|
3734
4169
|
version
|
|
3735
4170
|
};
|
|
3736
4171
|
function stream(w) {
|
|
3737
|
-
const
|
|
4172
|
+
const observation = observeFrame(frame);
|
|
4173
|
+
const emit = observation ? chunk => {
|
|
4174
|
+
observation.chunk(chunk);
|
|
4175
|
+
w.write(chunk);
|
|
4176
|
+
} : chunk => w.write(chunk);
|
|
3738
4177
|
const sink = createFrameSink(emit, frame);
|
|
3739
|
-
|
|
4178
|
+
w.write({
|
|
3740
4179
|
type: "start",
|
|
3741
4180
|
id,
|
|
3742
4181
|
version
|
|
@@ -3751,12 +4190,15 @@ function frameStream(makeCode, options) {
|
|
|
3751
4190
|
write() {},
|
|
3752
4191
|
end() {
|
|
3753
4192
|
sink.end();
|
|
4193
|
+
observation && observation.settle("complete");
|
|
3754
4194
|
w.end && w.end();
|
|
3755
4195
|
}
|
|
3756
4196
|
});
|
|
3757
4197
|
} catch (err) {
|
|
3758
|
-
|
|
4198
|
+
const wire = ssrSanitizeError(err, null);
|
|
4199
|
+
sink.error("", wire instanceof Error ? wire.message : String(wire));
|
|
3759
4200
|
sink.end();
|
|
4201
|
+
observation && observation.settle("error", err);
|
|
3760
4202
|
w.end && w.end();
|
|
3761
4203
|
}
|
|
3762
4204
|
}
|