@solidjs/web 2.0.0-rc.7 → 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 +638 -124
- package/dist/server.js +445 -94
- package/dist/{server.dev.cjs → server.observe.js} +602 -416
- package/dist/web.dev.js +229 -49
- package/dist/web.js +194 -46
- package/dist/{web.cjs → web.observe.js} +290 -275
- package/frames/dist/client.dev.js +103 -4
- package/frames/dist/client.js +5 -2
- package/frames/dist/{client.dev.cjs → client.observe.js} +139 -79
- package/frames/dist/server.dev.js +540 -79
- package/frames/dist/server.js +371 -52
- package/frames/dist/{server.cjs → server.observe.js} +544 -140
- package/frames/package.json +15 -21
- package/package.json +145 -294
- package/serialization/decode/package.json +3 -9
- package/serialization/package.json +3 -9
- package/serialization/types/serializer-decode.d.ts +49 -2
- package/server-functions/dist/{client.cjs → client.dev.js} +140 -107
- package/server-functions/dist/client.js +74 -69
- package/server-functions/dist/client.observe.js +1102 -0
- package/server-functions/dist/server.dev.js +430 -41
- package/server-functions/dist/server.js +367 -40
- package/server-functions/dist/{server.cjs → server.observe.js} +430 -85
- package/server-functions/package.json +15 -21
- package/server-functions/rich-args/package.json +3 -9
- package/storage/package.json +3 -9
- package/types/client.d.ts +39 -1
- package/types/diagnostics.d.ts +24 -0
- package/types/frames/frame-transport.d.ts +1 -1
- package/types/frames/serializer-decode.d.ts +49 -2
- 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/serializer-decode.d.ts +49 -2
- package/types/server-functions/client.d.ts +32 -22
- package/types/server-functions/server.d.ts +55 -41
- 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 +105 -6
- package/types/trace.d.ts +79 -0
- package/dist/server.cjs +0 -3708
- package/dist/web.dev.cjs +0 -2285
- package/frames/dist/client.cjs +0 -2043
- package/frames/dist/server.dev.cjs +0 -4584
- package/serialization/dist/decode.cjs +0 -155
- package/serialization/dist/serialization.cjs +0 -275
- package/serialization/types-cjs/index.d.cts +0 -101
- package/serialization/types-cjs/package.json +0 -3
- package/serialization/types-cjs/serializer-decode.d.cts +0 -172
- package/serialization/types-cjs/serializer.d.cts +0 -101
- package/server-functions/dist/rich-args.cjs +0 -11
- package/server-functions/dist/server.dev.cjs +0 -2409
- package/storage/dist/storage.cjs +0 -12
- package/storage/types-cjs/index.d.cts +0 -28
- package/storage/types-cjs/package.json +0 -3
- package/types-cjs/client.d.cts +0 -197
- package/types-cjs/constants.d.cts +0 -20
- package/types-cjs/cookies.d.cts +0 -41
- package/types-cjs/frames/client.d.cts +0 -36
- package/types-cjs/frames/frame-client.d.cts +0 -370
- package/types-cjs/frames/frame-container-plugin.d.cts +0 -71
- package/types-cjs/frames/frame-sink.d.cts +0 -92
- package/types-cjs/frames/frame-transport.d.cts +0 -189
- package/types-cjs/frames/serializer-decode.d.cts +0 -172
- package/types-cjs/frames/serializer.d.cts +0 -101
- package/types-cjs/frames/server.d.cts +0 -52
- package/types-cjs/head.d.cts +0 -19
- package/types-cjs/index.d.cts +0 -191
- package/types-cjs/index.server.d.cts +0 -147
- package/types-cjs/jsx-properties.d.cts +0 -93
- package/types-cjs/jsx.d.cts +0 -4146
- package/types-cjs/package.json +0 -3
- package/types-cjs/reconcile.d.cts +0 -1
- package/types-cjs/render.d.cts +0 -6
- package/types-cjs/response.d.cts +0 -81
- package/types-cjs/serializer-decode.d.cts +0 -172
- package/types-cjs/serializer.d.cts +0 -101
- package/types-cjs/server-functions/client.d.cts +0 -184
- package/types-cjs/server-functions/flash.d.cts +0 -36
- package/types-cjs/server-functions/registry.d.cts +0 -100
- package/types-cjs/server-functions/rich-args.d.cts +0 -1
- package/types-cjs/server-functions/server.d.cts +0 -546
- package/types-cjs/server-functions/shared.d.cts +0 -283
- package/types-cjs/server-mock.d.cts +0 -337
- package/types-cjs/server.d.cts +0 -408
package/dist/server.dev.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { createRenderEffect, getOwner, createMemo,
|
|
2
|
-
export { Errored, For, Hydration, Loading, Match, NoHydration, Repeat, Reveal, Show, Switch, createComponent, getOwner, merge as mergeProps,
|
|
1
|
+
import { createRenderEffect, getOwner, createMemo, OBSERVE, DEV, sharedConfig, createRoot, $PROXY, runWithOwner, createComponent, omit, getNextChildId, untrack, NotReadyError, onCleanup } from 'solid-js';
|
|
2
|
+
export { Errored, For, Hydration, Loading, Match, NoHydration, Repeat, Reveal, Show, Switch, createComponent, getOwner, merge as mergeProps, sharedConfig, untrack } from 'solid-js';
|
|
3
|
+
import { inServerComponentScope, sourceOwners, viewOf, sourceKeys, SOURCE_PLAIN, sourceGet, reportServerError, ssrHandleError, creationStamp, ssrSanitizeError, SOURCE_PROXY, getProjectionTrace } from 'solid-js/internal';
|
|
4
|
+
export { ssrScope as scope } from 'solid-js/internal';
|
|
3
5
|
import { Feature, createStream, Serializer, getCrossReferenceHeader } from 'seroval';
|
|
4
6
|
import { AbortSignalPlugin, CustomEventPlugin, DOMExceptionPlugin, EventPlugin, FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin } from 'seroval-plugins/web';
|
|
5
7
|
|
|
@@ -88,6 +90,177 @@ function memo(fn) {
|
|
|
88
90
|
return createMemo(() => fn(), syncOptions);
|
|
89
91
|
}
|
|
90
92
|
|
|
93
|
+
const PROVIDER = Symbol.for("solid-js/observe/server/provider");
|
|
94
|
+
function currentProvider() {
|
|
95
|
+
if (OBSERVE === undefined) return undefined;
|
|
96
|
+
const slot = OBSERVE.server.trace;
|
|
97
|
+
return slot && slot[PROVIDER];
|
|
98
|
+
}
|
|
99
|
+
const TRACEPARENT = /^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})(-.*)?$/;
|
|
100
|
+
const ZERO_TRACE = "00000000000000000000000000000000";
|
|
101
|
+
const ZERO_SPAN = "0000000000000000";
|
|
102
|
+
function parseTraceparent(value) {
|
|
103
|
+
if (!value) return undefined;
|
|
104
|
+
const m = TRACEPARENT.exec(value.trim());
|
|
105
|
+
if (!m) return undefined;
|
|
106
|
+
const [, version, traceId, parentId, flags, rest] = m;
|
|
107
|
+
if (version === "ff") return undefined;
|
|
108
|
+
if (version === "00" && rest !== undefined) return undefined;
|
|
109
|
+
if (traceId === ZERO_TRACE || parentId === ZERO_SPAN) return undefined;
|
|
110
|
+
return {
|
|
111
|
+
traceId,
|
|
112
|
+
parentId,
|
|
113
|
+
sampled: (parseInt(flags, 16) & 1) === 1
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function randomHex(bytes) {
|
|
117
|
+
const buffer = new Uint8Array(bytes);
|
|
118
|
+
crypto.getRandomValues(buffer);
|
|
119
|
+
let out = "";
|
|
120
|
+
for (let i = 0; i < buffer.length; i++) out += (buffer[i] < 16 ? "0" : "") + buffer[i].toString(16);
|
|
121
|
+
return out;
|
|
122
|
+
}
|
|
123
|
+
function randomTraceId() {
|
|
124
|
+
let id = randomHex(16);
|
|
125
|
+
while (id === ZERO_TRACE) id = randomHex(16);
|
|
126
|
+
return id;
|
|
127
|
+
}
|
|
128
|
+
function randomSpanId() {
|
|
129
|
+
let id = randomHex(8);
|
|
130
|
+
while (id === ZERO_SPAN) id = randomHex(8);
|
|
131
|
+
return id;
|
|
132
|
+
}
|
|
133
|
+
function formatTraceparent(context) {
|
|
134
|
+
return `00-${context.traceId}-${context.spanId}-${context.sampled === true ? "01" : "00"}`;
|
|
135
|
+
}
|
|
136
|
+
const RECORDS_KEY = Symbol.for("@solidjs/web/trace/records");
|
|
137
|
+
function records() {
|
|
138
|
+
const g = globalThis;
|
|
139
|
+
return g[RECORDS_KEY] || (g[RECORDS_KEY] = new WeakMap());
|
|
140
|
+
}
|
|
141
|
+
function traceFor(key, request) {
|
|
142
|
+
const store = records();
|
|
143
|
+
let record = store.get(key);
|
|
144
|
+
if (record) return record;
|
|
145
|
+
const headers = request ? request.headers : undefined;
|
|
146
|
+
const incoming = headers ? parseTraceparent(headers.get("traceparent")) : undefined;
|
|
147
|
+
const context = {
|
|
148
|
+
traceId: incoming ? incoming.traceId : randomTraceId(),
|
|
149
|
+
spanId: randomSpanId(),
|
|
150
|
+
entries: {}
|
|
151
|
+
};
|
|
152
|
+
if (incoming) {
|
|
153
|
+
context.parentId = incoming.parentId;
|
|
154
|
+
context.sampled = incoming.sampled;
|
|
155
|
+
}
|
|
156
|
+
if (headers) {
|
|
157
|
+
const state = headers.get("tracestate");
|
|
158
|
+
if (state) context.state = state;
|
|
159
|
+
const baggage = headers.get("baggage");
|
|
160
|
+
if (baggage) context.baggage = baggage;
|
|
161
|
+
}
|
|
162
|
+
let answered = false;
|
|
163
|
+
let providedEntries;
|
|
164
|
+
{
|
|
165
|
+
const provider = currentProvider();
|
|
166
|
+
if (provider) {
|
|
167
|
+
let answer;
|
|
168
|
+
try {
|
|
169
|
+
answer = provider(request);
|
|
170
|
+
} catch (error) {
|
|
171
|
+
console.error(error);
|
|
172
|
+
}
|
|
173
|
+
if (answer !== undefined && answer !== null) {
|
|
174
|
+
answered = true;
|
|
175
|
+
if (answer.traceId !== undefined) context.traceId = answer.traceId;
|
|
176
|
+
if (answer.spanId !== undefined) context.spanId = answer.spanId;
|
|
177
|
+
if (answer.parentId !== undefined) context.parentId = answer.parentId;
|
|
178
|
+
if (answer.sampled !== undefined) context.sampled = answer.sampled;
|
|
179
|
+
if (answer.state !== undefined) context.state = answer.state;
|
|
180
|
+
if (answer.baggage !== undefined) context.baggage = answer.baggage;
|
|
181
|
+
providedEntries = answer.entries;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
context.entries.traceparent = formatTraceparent(context);
|
|
186
|
+
if (providedEntries) Object.assign(context.entries, providedEntries);
|
|
187
|
+
record = {
|
|
188
|
+
context,
|
|
189
|
+
emit: incoming !== undefined && incoming.sampled || answered
|
|
190
|
+
};
|
|
191
|
+
store.set(key, record);
|
|
192
|
+
return record;
|
|
193
|
+
}
|
|
194
|
+
const TOKEN = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
|
|
195
|
+
function splitServerTiming(value) {
|
|
196
|
+
const entries = [];
|
|
197
|
+
let start = 0;
|
|
198
|
+
let quoted = false;
|
|
199
|
+
for (let i = 0; i < value.length; i++) {
|
|
200
|
+
const c = value[i];
|
|
201
|
+
if (quoted) {
|
|
202
|
+
if (c === "\\") i++;else if (c === '"') quoted = false;
|
|
203
|
+
} else if (c === '"') quoted = true;else if (c === ",") {
|
|
204
|
+
entries.push(value.slice(start, i));
|
|
205
|
+
start = i + 1;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
entries.push(value.slice(start));
|
|
209
|
+
return entries;
|
|
210
|
+
}
|
|
211
|
+
function metricName(entry) {
|
|
212
|
+
return entry.split(";")[0].trim().toLowerCase();
|
|
213
|
+
}
|
|
214
|
+
function namesOnServerTiming(headers) {
|
|
215
|
+
const names = new Set();
|
|
216
|
+
const existing = headers.get("server-timing");
|
|
217
|
+
if (existing) {
|
|
218
|
+
for (const entry of splitServerTiming(existing)) {
|
|
219
|
+
const name = metricName(entry);
|
|
220
|
+
if (name) names.add(name);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return names;
|
|
224
|
+
}
|
|
225
|
+
function quoteDesc(value) {
|
|
226
|
+
return value.replace(/[\x00-\x1f\x7f]/g, "").replace(/[\\"]/g, m => "\\" + m);
|
|
227
|
+
}
|
|
228
|
+
function appendTraceServerTiming(headers, record) {
|
|
229
|
+
if (!record.emit) return;
|
|
230
|
+
const entries = record.context.entries;
|
|
231
|
+
let present;
|
|
232
|
+
for (const name in entries) {
|
|
233
|
+
if (!TOKEN.test(name)) continue;
|
|
234
|
+
if (!present) present = namesOnServerTiming(headers);
|
|
235
|
+
if (present.has(name.toLowerCase())) continue;
|
|
236
|
+
headers.append("Server-Timing", `${name};desc="${quoteDesc(entries[name])}"`);
|
|
237
|
+
present.add(name.toLowerCase());
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
function mergeServerTiming(target, value) {
|
|
241
|
+
const present = namesOnServerTiming(target);
|
|
242
|
+
for (const entry of splitServerTiming(value)) {
|
|
243
|
+
const trimmed = entry.trim();
|
|
244
|
+
const name = metricName(trimmed);
|
|
245
|
+
if (!name || present.has(name)) continue;
|
|
246
|
+
target.append("Server-Timing", trimmed);
|
|
247
|
+
present.add(name);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
function escapeAttr(value) {
|
|
251
|
+
return value.replace(/[&"<>]/g, c => c === "&" ? "&" : c === '"' ? """ : c === "<" ? "<" : ">");
|
|
252
|
+
}
|
|
253
|
+
function traceMetaMarkup(record) {
|
|
254
|
+
if (!record.emit) return "";
|
|
255
|
+
let markup = "";
|
|
256
|
+
const entries = record.context.entries;
|
|
257
|
+
for (const name in entries) {
|
|
258
|
+
if (!TOKEN.test(name)) continue;
|
|
259
|
+
markup += `<meta name="${name}" content="${escapeAttr(entries[name])}">`;
|
|
260
|
+
}
|
|
261
|
+
return markup;
|
|
262
|
+
}
|
|
263
|
+
|
|
91
264
|
const STATE = Symbol.for("solid.container-trace-state");
|
|
92
265
|
const state = globalThis[STATE] || (globalThis[STATE] = {
|
|
93
266
|
materialized: new WeakMap(),
|
|
@@ -234,6 +407,7 @@ function isSafeError(value) {
|
|
|
234
407
|
return !!(value && (typeof value === "object" || typeof value === "function") && value[SAFE_ERROR]);
|
|
235
408
|
}
|
|
236
409
|
const REVALIDATE_HEADER = "X-Revalidate";
|
|
410
|
+
const REVALIDATE_ALL = "*";
|
|
237
411
|
const RESPONSE_HEADER_VALUE_LIMIT = 4096;
|
|
238
412
|
function initWithRevalidate(init = {}) {
|
|
239
413
|
const resolved = typeof init === "number" ? {
|
|
@@ -256,7 +430,11 @@ function initWithRevalidate(init = {}) {
|
|
|
256
430
|
headers = new Headers(responseInit.headers);
|
|
257
431
|
}
|
|
258
432
|
if (revalidate !== undefined) {
|
|
259
|
-
const
|
|
433
|
+
const list = Array.isArray(revalidate) ? revalidate : [revalidate];
|
|
434
|
+
if (list.length > 1 && list.includes(REVALIDATE_ALL)) {
|
|
435
|
+
throw new TypeError(`revalidate names "${REVALIDATE_ALL}" alongside other keys; "${REVALIDATE_ALL}" already ` + `means every entry and stands alone — pass revalidate: "${REVALIDATE_ALL}" or the named keys.`);
|
|
436
|
+
}
|
|
437
|
+
const keys = list.join(",");
|
|
260
438
|
if (keys.length > RESPONSE_HEADER_VALUE_LIMIT) {
|
|
261
439
|
throw new TypeError(`revalidate names ${keys.length} characters of cache keys; past ` + `${RESPONSE_HEADER_VALUE_LIMIT} the ${REVALIDATE_HEADER} header would overflow ` + `receivers (an 8 KiB proxy buffer holds the whole header block) and the response ` + `dies at the socket after the mutation committed. Split the invalidation across ` + `calls or use coarser keys — a dropped key would be a silently stale cache, so ` + `the runtime refuses rather than trims.`);
|
|
262
440
|
}
|
|
@@ -404,6 +582,22 @@ const BODY_FORMAT_HEADER = "X-Server-Function-Format";
|
|
|
404
582
|
const REDIRECT_HEADER = "X-Server-Function-Redirect";
|
|
405
583
|
const SINGLE_FLIGHT_HEADER = "X-Single-Flight";
|
|
406
584
|
|
|
585
|
+
function emitFinding(finding, subject = getOwner()) {
|
|
586
|
+
if (OBSERVE === undefined) return;
|
|
587
|
+
const entry = OBSERVE.diagnostics.emit(finding, subject);
|
|
588
|
+
if (DEV !== undefined) DEV.report(entry);
|
|
589
|
+
}
|
|
590
|
+
function recordFinding(finding, subject = getOwner()) {
|
|
591
|
+
if (OBSERVE !== undefined) OBSERVE.diagnostics.emit(finding, subject);
|
|
592
|
+
}
|
|
593
|
+
function devCheck(finding, subject) {
|
|
594
|
+
emitFinding(finding, subject);
|
|
595
|
+
}
|
|
596
|
+
function errorText(error) {
|
|
597
|
+
if (error instanceof Error) return error.message ? `${error.name}: ${error.message}` : error.name;
|
|
598
|
+
return String(error);
|
|
599
|
+
}
|
|
600
|
+
|
|
407
601
|
const HEAD_ELIGIBLE_TAGS = new Set(["title", "meta", "link", "style", "script", "base"]);
|
|
408
602
|
const HEAD_ATTR_NAME = /^[a-zA-Z_][a-zA-Z0-9_:.-]*$/;
|
|
409
603
|
const RESOURCE_LINK_RELS = new Set(["preload", "modulepreload", "prefetch", "preconnect", "dns-prefetch", "stylesheet"]);
|
|
@@ -487,7 +681,16 @@ function resolveHead(groups) {
|
|
|
487
681
|
}
|
|
488
682
|
for (const [identity, tags] of byIdentity) {
|
|
489
683
|
if (identity === "title") {
|
|
490
|
-
if (tags.length > 1)
|
|
684
|
+
if (tags.length > 1) devCheck({
|
|
685
|
+
code: "HEAD_TAG_INVALID",
|
|
686
|
+
kind: "head",
|
|
687
|
+
severity: "warn",
|
|
688
|
+
message: "[HEAD_TAG_INVALID] Multiple <title> tags in one head group; the last one wins.",
|
|
689
|
+
data: {
|
|
690
|
+
reason: "duplicate-title",
|
|
691
|
+
detail: tags.length
|
|
692
|
+
}
|
|
693
|
+
});
|
|
491
694
|
winners.set(identity, {
|
|
492
695
|
seq: group.seq,
|
|
493
696
|
tags: [tags[tags.length - 1]]
|
|
@@ -566,10 +769,10 @@ function resolveAssets(moduleUrl, manifest) {
|
|
|
566
769
|
href: bad,
|
|
567
770
|
...rest
|
|
568
771
|
} = link;
|
|
569
|
-
if (bad !== undefined)
|
|
772
|
+
if (bad !== undefined) preloadInvalid("href", "Preload href must be a non-empty string; dropping it.", bad);
|
|
570
773
|
preloads.push(rest);
|
|
571
774
|
}
|
|
572
|
-
if (srcset && hasRelativeCandidate(srcset))
|
|
775
|
+
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);
|
|
573
776
|
}
|
|
574
777
|
}
|
|
575
778
|
if (e.imports) for (let i = 0; i < e.imports.length; i++) walk(e.imports[i]);
|
|
@@ -706,13 +909,53 @@ function isSetAttr(value) {
|
|
|
706
909
|
return value != null && value !== false && value !== "";
|
|
707
910
|
}
|
|
708
911
|
const PRELOAD_LINK_ATTRIBUTES = ["type", "crossorigin", "integrity", "referrerpolicy", "fetchpriority", "media", "imagesrcset", "imagesizes"];
|
|
912
|
+
function preloadInvalid(field, message, value) {
|
|
913
|
+
devCheck({
|
|
914
|
+
code: "PRELOAD_DESCRIPTOR_INVALID",
|
|
915
|
+
kind: "head",
|
|
916
|
+
severity: "warn",
|
|
917
|
+
message: `[PRELOAD_DESCRIPTOR_INVALID] ${message}`,
|
|
918
|
+
data: value === undefined ? {
|
|
919
|
+
field
|
|
920
|
+
} : {
|
|
921
|
+
field,
|
|
922
|
+
value
|
|
923
|
+
}
|
|
924
|
+
});
|
|
925
|
+
}
|
|
926
|
+
function unrecognizedInsert(node) {
|
|
927
|
+
devCheck({
|
|
928
|
+
code: "UNRECOGNIZED_INSERT_VALUE",
|
|
929
|
+
kind: "render",
|
|
930
|
+
severity: "warn",
|
|
931
|
+
message: `[UNRECOGNIZED_INSERT_VALUE] Unrecognized value. Skipped inserting (${typeof node}).`,
|
|
932
|
+
data: {
|
|
933
|
+
type: typeof node,
|
|
934
|
+
value: node
|
|
935
|
+
}
|
|
936
|
+
});
|
|
937
|
+
}
|
|
938
|
+
function headTagInvalid(reason, message, detail) {
|
|
939
|
+
devCheck({
|
|
940
|
+
code: "HEAD_TAG_INVALID",
|
|
941
|
+
kind: "head",
|
|
942
|
+
severity: "warn",
|
|
943
|
+
message: `[HEAD_TAG_INVALID] ${message}`,
|
|
944
|
+
data: detail === undefined ? {
|
|
945
|
+
reason
|
|
946
|
+
} : {
|
|
947
|
+
reason,
|
|
948
|
+
detail
|
|
949
|
+
}
|
|
950
|
+
});
|
|
951
|
+
}
|
|
709
952
|
function registerPreloadLink(tracking, headRegistry, link, nonce) {
|
|
710
953
|
if (!link || typeof link !== "object") {
|
|
711
|
-
|
|
954
|
+
preloadInvalid("descriptor", 'registerAsset("preload") requires a descriptor object.', link);
|
|
712
955
|
return null;
|
|
713
956
|
}
|
|
714
957
|
if (typeof link.as !== "string") {
|
|
715
|
-
|
|
958
|
+
preloadInvalid("as", 'registerAsset("preload") requires an as destination.');
|
|
716
959
|
return null;
|
|
717
960
|
}
|
|
718
961
|
const as = asciiLowerCase(link.as);
|
|
@@ -728,11 +971,11 @@ function registerPreloadLink(tracking, headRegistry, link, nonce) {
|
|
|
728
971
|
case "track":
|
|
729
972
|
break;
|
|
730
973
|
default:
|
|
731
|
-
|
|
974
|
+
preloadInvalid("as", `registerAsset("preload") received an unsupported as destination "${link.as}".`, link.as);
|
|
732
975
|
return null;
|
|
733
976
|
}
|
|
734
977
|
const responsive = as === "image";
|
|
735
|
-
if (!responsive && (isSetAttr(link.imagesrcset) || isSetAttr(link.imagesizes)))
|
|
978
|
+
if (!responsive && (isSetAttr(link.imagesrcset) || isSetAttr(link.imagesizes))) preloadInvalid(isSetAttr(link.imagesrcset) ? "imagesrcset" : "imagesizes", 'registerAsset("preload") only supports imagesrcset and imagesizes with as="image".');
|
|
736
979
|
let srcset = null;
|
|
737
980
|
let sizes = null;
|
|
738
981
|
if (responsive) {
|
|
@@ -740,19 +983,19 @@ function registerPreloadLink(tracking, headRegistry, link, nonce) {
|
|
|
740
983
|
const value = link[name];
|
|
741
984
|
if (!isSetAttr(value)) continue;
|
|
742
985
|
if (typeof value !== "string") {
|
|
743
|
-
|
|
986
|
+
preloadInvalid(name, `registerAsset("preload") expects a string ${name}.`, value);
|
|
744
987
|
continue;
|
|
745
988
|
}
|
|
746
989
|
if (name === "imagesrcset") srcset = value;else sizes = value;
|
|
747
990
|
}
|
|
748
991
|
}
|
|
749
992
|
const href = typeof link.href === "string" && link.href ? link.href : null;
|
|
750
|
-
if (!href && link.href != null && link.href !== false)
|
|
993
|
+
if (!href && link.href != null && link.href !== false) preloadInvalid("href", "Preload href must be a non-empty string; dropping it.", link.href);
|
|
751
994
|
if (!href && !srcset) {
|
|
752
|
-
|
|
995
|
+
preloadInvalid("href", 'registerAsset("preload") requires a non-empty string href or imagesrcset.');
|
|
753
996
|
return null;
|
|
754
997
|
}
|
|
755
|
-
if (srcset && !sizes && hasWidthDescriptor(srcset))
|
|
998
|
+
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);
|
|
756
999
|
const props = {
|
|
757
1000
|
rel: "preload"
|
|
758
1001
|
};
|
|
@@ -771,7 +1014,7 @@ function registerPreloadLink(tracking, headRegistry, link, nonce) {
|
|
|
771
1014
|
}
|
|
772
1015
|
const identity = resourceIdentity("link", props);
|
|
773
1016
|
if (headRegistry.resources.has(identity)) return null;
|
|
774
|
-
if (props.crossorigin == null && (as === "font" || as === "fetch"))
|
|
1017
|
+
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.`);
|
|
775
1018
|
const attrs = headAttrRecord(props);
|
|
776
1019
|
const nonceValue = destination && nonce && nonce[destination];
|
|
777
1020
|
if (typeof nonceValue === "string" && nonceValue) attrs.nonce = nonceValue;
|
|
@@ -815,7 +1058,7 @@ function registerHeadTags(registry, context, tracking, emitResource, nonce, tags
|
|
|
815
1058
|
for (let i = 0; i < tags.length; i++) {
|
|
816
1059
|
const desc = tags[i];
|
|
817
1060
|
if (!desc || !HEAD_ELIGIBLE_TAGS.has(desc.tag)) {
|
|
818
|
-
|
|
1061
|
+
headTagInvalid("non-head-tag", `useHead: ignoring non-head tag <${desc && desc.tag}>`, desc);
|
|
819
1062
|
continue;
|
|
820
1063
|
}
|
|
821
1064
|
const cls = classifyHeadTag(desc);
|
|
@@ -867,7 +1110,7 @@ function headShellReady(registry, block) {
|
|
|
867
1110
|
} : undefined);
|
|
868
1111
|
} catch (err) {
|
|
869
1112
|
if (pends(err)) continue;
|
|
870
|
-
|
|
1113
|
+
headTagInvalid("props-error", `useHead: error evaluating resource tag props: ${errorText(err)}`, err);
|
|
871
1114
|
parked.splice(i, 1);
|
|
872
1115
|
continue;
|
|
873
1116
|
}
|
|
@@ -908,7 +1151,7 @@ function emitHeadResource(registry, context, tracking, emitResource, nonce, desc
|
|
|
908
1151
|
});
|
|
909
1152
|
return;
|
|
910
1153
|
}
|
|
911
|
-
|
|
1154
|
+
headTagInvalid("props-error", `useHead: error evaluating resource tag props: ${errorText(err)}`, err);
|
|
912
1155
|
return;
|
|
913
1156
|
}
|
|
914
1157
|
const identity = resourceIdentity(desc.tag, props);
|
|
@@ -970,7 +1213,7 @@ function commitHeadBoundary(registry, boundary, isPendingFragment) {
|
|
|
970
1213
|
try {
|
|
971
1214
|
resolved = reg.list();
|
|
972
1215
|
} catch (err) {
|
|
973
|
-
|
|
1216
|
+
headTagInvalid("group-error", `useHead: error evaluating head group membership: ${errorText(err)}`, err);
|
|
974
1217
|
continue;
|
|
975
1218
|
}
|
|
976
1219
|
if (!Array.isArray(resolved)) resolved = [resolved];
|
|
@@ -978,7 +1221,7 @@ function commitHeadBoundary(registry, boundary, isPendingFragment) {
|
|
|
978
1221
|
for (let j = 0; j < resolved.length; j++) {
|
|
979
1222
|
const desc = resolved[j];
|
|
980
1223
|
if (!desc || !HEAD_ELIGIBLE_TAGS.has(desc.tag)) {
|
|
981
|
-
|
|
1224
|
+
headTagInvalid("non-head-tag", `useHead: ignoring non-head tag <${desc && desc.tag}>`, desc);
|
|
982
1225
|
continue;
|
|
983
1226
|
}
|
|
984
1227
|
const cls = classifyHeadTag(desc);
|
|
@@ -1004,12 +1247,12 @@ function commitHeadBoundary(registry, boundary, isPendingFragment) {
|
|
|
1004
1247
|
} : undefined);
|
|
1005
1248
|
key = evalHeadValue(desc.key);
|
|
1006
1249
|
} catch (err) {
|
|
1007
|
-
|
|
1250
|
+
headTagInvalid("props-error", `useHead: error evaluating tag props: ${errorText(err)}`, err);
|
|
1008
1251
|
continue;
|
|
1009
1252
|
}
|
|
1010
1253
|
const identity = replaceableIdentity(desc.tag, props, key, "u:" + registry.uniq++);
|
|
1011
1254
|
if ((identity === "base" || identity === "charset") && registry.shellFlushed) {
|
|
1012
|
-
|
|
1255
|
+
headTagInvalid("after-shell-flush", `useHead: <${desc.tag}> (${identity}) registered after shell flush is ignored`, identity);
|
|
1013
1256
|
continue;
|
|
1014
1257
|
}
|
|
1015
1258
|
tags.push({
|
|
@@ -1043,7 +1286,7 @@ function headGroupSignature(winner) {
|
|
|
1043
1286
|
}
|
|
1044
1287
|
return sig;
|
|
1045
1288
|
}
|
|
1046
|
-
function renderShellHead(registry, nonce, isPendingFragment, noScripts) {
|
|
1289
|
+
function renderShellHead(registry, nonce, isPendingFragment, noScripts, traceMetas = "") {
|
|
1047
1290
|
commitHeadBoundary(registry, "", isPendingFragment);
|
|
1048
1291
|
registry.shellFlushed = true;
|
|
1049
1292
|
const winners = resolveHead(registry.committed);
|
|
@@ -1069,7 +1312,7 @@ function renderShellHead(registry, nonce, isPendingFragment, noScripts) {
|
|
|
1069
1312
|
}
|
|
1070
1313
|
return {
|
|
1071
1314
|
prelude,
|
|
1072
|
-
html: registry.eagerHtml + links + metas + others + scripts,
|
|
1315
|
+
html: registry.eagerHtml + links + metas + traceMetas + others + scripts,
|
|
1073
1316
|
title,
|
|
1074
1317
|
noScripts
|
|
1075
1318
|
};
|
|
@@ -1099,7 +1342,7 @@ function flushHeadFragment(registry, boundary, nonce) {
|
|
|
1099
1342
|
for (const name in t.props) {
|
|
1100
1343
|
if (name === "children" || name === "ref" || name.slice(0, 2) === "on") continue;
|
|
1101
1344
|
if (!HEAD_ATTR_NAME.test(name)) {
|
|
1102
|
-
|
|
1345
|
+
headTagInvalid("invalid-attribute", `useHead: ignoring invalid attribute name "${name}"`, name);
|
|
1103
1346
|
continue;
|
|
1104
1347
|
}
|
|
1105
1348
|
const v = t.props[name];
|
|
@@ -1189,7 +1432,7 @@ function renderHeadAttrHtml(props) {
|
|
|
1189
1432
|
for (const name in props) {
|
|
1190
1433
|
if (name === "children" || name === "ref" || name.slice(0, 2) === "on") continue;
|
|
1191
1434
|
if (!HEAD_ATTR_NAME.test(name)) {
|
|
1192
|
-
|
|
1435
|
+
headTagInvalid("invalid-attribute", `useHead: ignoring invalid attribute name "${name}"`, name);
|
|
1193
1436
|
continue;
|
|
1194
1437
|
}
|
|
1195
1438
|
const v = props[name];
|
|
@@ -1222,7 +1465,7 @@ function renderHeadTagMarkup(tag, props, identity, nonce) {
|
|
|
1222
1465
|
function useHead(tags) {
|
|
1223
1466
|
const ctx = sharedConfig.context;
|
|
1224
1467
|
if (!ctx || !ctx.registerHeadTags) {
|
|
1225
|
-
|
|
1468
|
+
headTagInvalid("outside-render", "useHead() called outside of a server render; registration ignored.");
|
|
1226
1469
|
return;
|
|
1227
1470
|
}
|
|
1228
1471
|
ctx.registerHeadTags(tags);
|
|
@@ -1249,7 +1492,7 @@ function renderToString(code, options = {}) {
|
|
|
1249
1492
|
}
|
|
1250
1493
|
scripts += script + ";";
|
|
1251
1494
|
},
|
|
1252
|
-
onError: options.onError
|
|
1495
|
+
onError: serializerErrorHook(options.onError)
|
|
1253
1496
|
});
|
|
1254
1497
|
const tracking = createAssetTracking();
|
|
1255
1498
|
const headRegistry = createHeadRegistry();
|
|
@@ -1258,6 +1501,7 @@ function renderToString(code, options = {}) {
|
|
|
1258
1501
|
escape: escape,
|
|
1259
1502
|
resolve: resolveSSRNode,
|
|
1260
1503
|
ssr: ssr,
|
|
1504
|
+
errorPolicy: options.onError,
|
|
1261
1505
|
registerHeadTags(tags) {
|
|
1262
1506
|
registerHeadTags(headRegistry, sharedConfig.context, tracking, null, nonce, tags);
|
|
1263
1507
|
},
|
|
@@ -1290,17 +1534,32 @@ function renderToString(code, options = {}) {
|
|
|
1290
1534
|
};
|
|
1291
1535
|
applyAssetTracking(sharedConfig.context, tracking, manifest, noScripts);
|
|
1292
1536
|
registerEntryAssets(manifest);
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1537
|
+
const context = sharedConfig.context;
|
|
1538
|
+
const requestEvent = peekRequestEvent();
|
|
1539
|
+
context.trace = requestEvent ? traceForEvent(requestEvent) : traceFor(context, undefined);
|
|
1540
|
+
let dispose;
|
|
1541
|
+
try {
|
|
1542
|
+
const html = createRoot(d => {
|
|
1543
|
+
dispose = d;
|
|
1544
|
+
return resolveSSRSync(escape(code()));
|
|
1545
|
+
}, {
|
|
1546
|
+
id: renderId
|
|
1547
|
+
});
|
|
1548
|
+
serializeFragmentAssets("", tracking.boundaryModules, sharedConfig.context, renderId);
|
|
1549
|
+
sharedConfig.context.noHydrate = true;
|
|
1550
|
+
serializer.close();
|
|
1551
|
+
const head = renderShellHead(headRegistry, nonce, null, noScripts, traceMetaMarkup(context.trace));
|
|
1552
|
+
const document = assembleDocument(resolveSSRSelectValues(html), tracking.emittedAssets, tracking.preloadLinks, tracking.inlineStyles, scripts.length ? scripts : "", nonce, head, onHead);
|
|
1553
|
+
if (requestEvent && requestEvent.response) {
|
|
1554
|
+
commitResponseStub(requestEvent.response, {
|
|
1555
|
+
event: requestEvent
|
|
1556
|
+
});
|
|
1557
|
+
}
|
|
1558
|
+
return document;
|
|
1559
|
+
} finally {
|
|
1560
|
+
context.trace = undefined;
|
|
1561
|
+
if (dispose) dispose();
|
|
1562
|
+
}
|
|
1304
1563
|
}
|
|
1305
1564
|
function renderToStream(code, options = {}) {
|
|
1306
1565
|
let {
|
|
@@ -1315,8 +1574,19 @@ function renderToStream(code, options = {}) {
|
|
|
1315
1574
|
const requestEvent = peekRequestEvent();
|
|
1316
1575
|
let dispose;
|
|
1317
1576
|
let dead = false;
|
|
1318
|
-
const abandon =
|
|
1577
|
+
const abandon = disconnect => {
|
|
1319
1578
|
if (dead) return;
|
|
1579
|
+
if (disconnect) emitFinding({
|
|
1580
|
+
code: "SSR_STREAM_ABANDONED",
|
|
1581
|
+
kind: "ssr",
|
|
1582
|
+
severity: "warn",
|
|
1583
|
+
message: `[SSR_STREAM_ABANDONED] The response stream was abandoned mid-render (${disconnect}) ` + `with ${registry.size} fragment(s) still pending; the render was torn down.`,
|
|
1584
|
+
data: {
|
|
1585
|
+
reason: disconnect,
|
|
1586
|
+
shellFlushed: firstFlushed,
|
|
1587
|
+
pendingFragments: registry.size
|
|
1588
|
+
}
|
|
1589
|
+
}, null);
|
|
1320
1590
|
dead = true;
|
|
1321
1591
|
completed = true;
|
|
1322
1592
|
buffer = {
|
|
@@ -1332,11 +1602,26 @@ function renderToStream(code, options = {}) {
|
|
|
1332
1602
|
}
|
|
1333
1603
|
};
|
|
1334
1604
|
const failRender = err => {
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1605
|
+
reportServerError(err, {
|
|
1606
|
+
kind: "render",
|
|
1607
|
+
handling: "failed"
|
|
1608
|
+
}, null);
|
|
1609
|
+
if (!options.onError && ambientServerErrorHook() === undefined) console.error(err);
|
|
1338
1610
|
abandon();
|
|
1339
1611
|
};
|
|
1612
|
+
const failRootRender = err => {
|
|
1613
|
+
emitFinding({
|
|
1614
|
+
code: "SSR_RENDER_ERROR_CONTAINED",
|
|
1615
|
+
kind: "ssr",
|
|
1616
|
+
severity: "error",
|
|
1617
|
+
message: `[SSR_RENDER_ERROR_CONTAINED] Render error outside any boundary — the request failed: ` + errorText(err),
|
|
1618
|
+
data: {
|
|
1619
|
+
handling: "failed",
|
|
1620
|
+
error: err
|
|
1621
|
+
}
|
|
1622
|
+
}, null);
|
|
1623
|
+
failRender(err);
|
|
1624
|
+
};
|
|
1340
1625
|
const coalesceWrites = (writeRaw, endRaw) => {
|
|
1341
1626
|
let buf = "";
|
|
1342
1627
|
let scheduled = false;
|
|
@@ -1369,7 +1654,7 @@ function renderToStream(code, options = {}) {
|
|
|
1369
1654
|
try {
|
|
1370
1655
|
w.write(payload);
|
|
1371
1656
|
} catch (_) {
|
|
1372
|
-
abandon();
|
|
1657
|
+
abandon("sink");
|
|
1373
1658
|
}
|
|
1374
1659
|
},
|
|
1375
1660
|
end() {
|
|
@@ -1377,7 +1662,7 @@ function renderToStream(code, options = {}) {
|
|
|
1377
1662
|
try {
|
|
1378
1663
|
w.end();
|
|
1379
1664
|
} catch (_) {
|
|
1380
|
-
abandon();
|
|
1665
|
+
abandon("sink");
|
|
1381
1666
|
}
|
|
1382
1667
|
}
|
|
1383
1668
|
});
|
|
@@ -1474,7 +1759,7 @@ function renderToStream(code, options = {}) {
|
|
|
1474
1759
|
plugins: options.plugins,
|
|
1475
1760
|
onData: payload => sink.data(payload),
|
|
1476
1761
|
onDone,
|
|
1477
|
-
onError: options.onError
|
|
1762
|
+
onError: serializerErrorHook(options.onError)
|
|
1478
1763
|
});
|
|
1479
1764
|
let rootAssetsSerialized = false;
|
|
1480
1765
|
const serializeRootAssets = () => {
|
|
@@ -1499,6 +1784,34 @@ function renderToStream(code, options = {}) {
|
|
|
1499
1784
|
};
|
|
1500
1785
|
const registry = new Map();
|
|
1501
1786
|
const pendingSerialized = new Map();
|
|
1787
|
+
const guardedChannels = new WeakMap();
|
|
1788
|
+
const verdictNow = error => {
|
|
1789
|
+
throw ssrSanitizeError(error, null);
|
|
1790
|
+
};
|
|
1791
|
+
const guardChannel = p => {
|
|
1792
|
+
if (!p || typeof p !== "object" || "__SEROVAL_STREAM__" in p) return p;
|
|
1793
|
+
const thenable = typeof p.then === "function";
|
|
1794
|
+
const iterable = !thenable && typeof p[Symbol.asyncIterator] === "function";
|
|
1795
|
+
if (!thenable && !iterable) return p;
|
|
1796
|
+
let guarded = guardedChannels.get(p);
|
|
1797
|
+
if (guarded === undefined) {
|
|
1798
|
+
guarded = thenable ? p.then(undefined, verdictNow) : {
|
|
1799
|
+
[Symbol.asyncIterator]() {
|
|
1800
|
+
const iterator = p[Symbol.asyncIterator]();
|
|
1801
|
+
return {
|
|
1802
|
+
next: value => iterator.next(value).then(undefined, verdictNow),
|
|
1803
|
+
return: value => iterator.return ? iterator.return(value) : Promise.resolve({
|
|
1804
|
+
done: true,
|
|
1805
|
+
value
|
|
1806
|
+
}),
|
|
1807
|
+
throw: error => iterator.throw ? iterator.throw(error) : Promise.reject(error)
|
|
1808
|
+
};
|
|
1809
|
+
}
|
|
1810
|
+
};
|
|
1811
|
+
guardedChannels.set(p, guarded);
|
|
1812
|
+
}
|
|
1813
|
+
return guarded;
|
|
1814
|
+
};
|
|
1502
1815
|
const trackSerialized = (id, p) => {
|
|
1503
1816
|
let settle;
|
|
1504
1817
|
const raced = Promise.race([p, new Promise(r => settle = r)]);
|
|
@@ -1507,19 +1820,35 @@ function renderToStream(code, options = {}) {
|
|
|
1507
1820
|
p.then(drop, drop);
|
|
1508
1821
|
return raced;
|
|
1509
1822
|
};
|
|
1510
|
-
const abandonSubtree = key => {
|
|
1823
|
+
const abandonSubtree = (key, error) => {
|
|
1824
|
+
let fragments = 0;
|
|
1825
|
+
let serialized = 0;
|
|
1511
1826
|
for (const [k, entry] of registry) {
|
|
1512
1827
|
if (k.length > key.length && k.startsWith(key)) {
|
|
1513
1828
|
registry.delete(k);
|
|
1514
1829
|
entry.resolve();
|
|
1830
|
+
fragments++;
|
|
1515
1831
|
}
|
|
1516
1832
|
}
|
|
1517
1833
|
for (const [id, settle] of pendingSerialized) {
|
|
1518
1834
|
if (id.startsWith(key)) {
|
|
1519
1835
|
pendingSerialized.delete(id);
|
|
1520
1836
|
settle();
|
|
1837
|
+
serialized++;
|
|
1521
1838
|
}
|
|
1522
1839
|
}
|
|
1840
|
+
if ((fragments || serialized)) emitFinding({
|
|
1841
|
+
code: "SSR_SUBTREE_ABANDONED",
|
|
1842
|
+
kind: "ssr",
|
|
1843
|
+
severity: "warn",
|
|
1844
|
+
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.`,
|
|
1845
|
+
data: {
|
|
1846
|
+
fragment: key,
|
|
1847
|
+
fragments,
|
|
1848
|
+
serialized,
|
|
1849
|
+
error
|
|
1850
|
+
}
|
|
1851
|
+
}, null);
|
|
1523
1852
|
};
|
|
1524
1853
|
const writeTasks = () => {
|
|
1525
1854
|
if (tasks.length && !completed && firstFlushed) {
|
|
@@ -1640,6 +1969,7 @@ function renderToStream(code, options = {}) {
|
|
|
1640
1969
|
},
|
|
1641
1970
|
serialize(id, p, deferStream) {
|
|
1642
1971
|
if (sharedConfig.context.noHydrate) return;
|
|
1972
|
+
p = guardChannel(p);
|
|
1643
1973
|
if (p && typeof p === "object" && typeof p.then === "function") {
|
|
1644
1974
|
if (!firstFlushed && deferStream) {
|
|
1645
1975
|
blockingPromises.add(p);
|
|
@@ -1682,7 +2012,7 @@ function renderToStream(code, options = {}) {
|
|
|
1682
2012
|
const p = new Promise((r, rej) => (resolve = r, reject = rej));
|
|
1683
2013
|
registry.set(key, {
|
|
1684
2014
|
resolve: err => queue(() => queue(() => {
|
|
1685
|
-
err ? reject(err) : resolve(true);
|
|
2015
|
+
err ? reject(ssrSanitizeError(err, null)) : resolve(true);
|
|
1686
2016
|
queue(flushEnd);
|
|
1687
2017
|
}))
|
|
1688
2018
|
});
|
|
@@ -1692,8 +2022,8 @@ function renderToStream(code, options = {}) {
|
|
|
1692
2022
|
if (registry.has(key)) {
|
|
1693
2023
|
const item = registry.get(key);
|
|
1694
2024
|
registry.delete(key);
|
|
1695
|
-
if (error) abandonSubtree(key);
|
|
1696
|
-
if (item.children) {
|
|
2025
|
+
if (error) abandonSubtree(key, error);
|
|
2026
|
+
if (item.children && !error) {
|
|
1697
2027
|
for (const k in item.children) {
|
|
1698
2028
|
value = replacePlaceholder(value, k, item.children[k]);
|
|
1699
2029
|
}
|
|
@@ -1723,7 +2053,7 @@ function renderToStream(code, options = {}) {
|
|
|
1723
2053
|
sink.fragment(key, resolveSSRSelectValues(value !== undefined ? value : " "), {
|
|
1724
2054
|
styles,
|
|
1725
2055
|
revealGroup,
|
|
1726
|
-
error
|
|
2056
|
+
error: error ? ssrSanitizeError(error, null) : error
|
|
1727
2057
|
});
|
|
1728
2058
|
item.resolve(error);
|
|
1729
2059
|
}
|
|
@@ -1749,9 +2079,15 @@ function renderToStream(code, options = {}) {
|
|
|
1749
2079
|
};
|
|
1750
2080
|
applyAssetTracking(context, tracking, manifest, noScripts);
|
|
1751
2081
|
context.failRender = failRender;
|
|
2082
|
+
context.errorPolicy = options.onError;
|
|
2083
|
+
context.flushed = () => firstFlushed;
|
|
2084
|
+
context.trace = requestEvent ? traceForEvent(requestEvent) : traceFor(context, undefined);
|
|
1752
2085
|
registerEntryAssets(manifest);
|
|
1753
2086
|
let html = createRoot(d => {
|
|
1754
|
-
dispose =
|
|
2087
|
+
dispose = () => {
|
|
2088
|
+
context.trace = undefined;
|
|
2089
|
+
d();
|
|
2090
|
+
};
|
|
1755
2091
|
const res = resolveSSRNode(escape(code()));
|
|
1756
2092
|
if (!res.h.length) return res.t[0];
|
|
1757
2093
|
rootHoles = [];
|
|
@@ -1814,7 +2150,7 @@ function renderToStream(code, options = {}) {
|
|
|
1814
2150
|
}
|
|
1815
2151
|
serializeRootAssets();
|
|
1816
2152
|
flushStubBatch();
|
|
1817
|
-
const head = renderShellHead(headRegistry, nonce, k => registry.has(k), noScripts);
|
|
2153
|
+
const head = renderShellHead(headRegistry, nonce, k => registry.has(k), noScripts, traceMetaMarkup(context.trace));
|
|
1818
2154
|
sink.shell(resolveSSRSelectValues(html), {
|
|
1819
2155
|
preloads: tracking.emittedAssets,
|
|
1820
2156
|
preloadLinks: tracking.preloadLinks,
|
|
@@ -1869,7 +2205,7 @@ function renderToStream(code, options = {}) {
|
|
|
1869
2205
|
try {
|
|
1870
2206
|
doShell();
|
|
1871
2207
|
} catch (err) {
|
|
1872
|
-
|
|
2208
|
+
failRootRender(err);
|
|
1873
2209
|
return resolve();
|
|
1874
2210
|
}
|
|
1875
2211
|
if (!shellCompleted) return flush();
|
|
@@ -1879,7 +2215,7 @@ function renderToStream(code, options = {}) {
|
|
|
1879
2215
|
let ended = false;
|
|
1880
2216
|
const failed = () => {
|
|
1881
2217
|
if (!ended) {
|
|
1882
|
-
abandon();
|
|
2218
|
+
abandon("consumer");
|
|
1883
2219
|
resolve();
|
|
1884
2220
|
}
|
|
1885
2221
|
};
|
|
@@ -1910,7 +2246,9 @@ function renderToStream(code, options = {}) {
|
|
|
1910
2246
|
return {
|
|
1911
2247
|
then(onFulfilled, onRejected) {
|
|
1912
2248
|
const freezeHead = () => {
|
|
1913
|
-
if (requestEvent && requestEvent.response) commitResponseStub(requestEvent.response
|
|
2249
|
+
if (requestEvent && requestEvent.response) commitResponseStub(requestEvent.response, {
|
|
2250
|
+
event: requestEvent
|
|
2251
|
+
});
|
|
1914
2252
|
};
|
|
1915
2253
|
const p = new Promise(resolve => {
|
|
1916
2254
|
function complete() {
|
|
@@ -1931,7 +2269,7 @@ function renderToStream(code, options = {}) {
|
|
|
1931
2269
|
try {
|
|
1932
2270
|
if (blockingPromises.size !== lastBlockingSize || !resolveRootHoles() || blockingPromises.size !== lastBlockingSize || !headShellReady(headRegistry, p => blockingPromises.add(p))) return flush();
|
|
1933
2271
|
} catch (err) {
|
|
1934
|
-
|
|
2272
|
+
failRootRender(err);
|
|
1935
2273
|
return resolve(tmp);
|
|
1936
2274
|
}
|
|
1937
2275
|
queue(flushEnd);
|
|
@@ -1951,7 +2289,7 @@ function renderToStream(code, options = {}) {
|
|
|
1951
2289
|
try {
|
|
1952
2290
|
doShell();
|
|
1953
2291
|
} catch (err) {
|
|
1954
|
-
|
|
2292
|
+
failRootRender(err);
|
|
1955
2293
|
try {
|
|
1956
2294
|
w.end();
|
|
1957
2295
|
} catch (_) {}
|
|
@@ -2081,6 +2419,10 @@ function ssrGroupSlot(fn, idx) {
|
|
|
2081
2419
|
}
|
|
2082
2420
|
};
|
|
2083
2421
|
}
|
|
2422
|
+
function wireErrorMessage(err) {
|
|
2423
|
+
const wire = ssrSanitizeError(err, null);
|
|
2424
|
+
return String(wire && wire.message || wire);
|
|
2425
|
+
}
|
|
2084
2426
|
const holePositionCache = new WeakMap();
|
|
2085
2427
|
function holeContentPositions(t) {
|
|
2086
2428
|
let cached = holePositionCache.get(t);
|
|
@@ -2237,7 +2579,7 @@ function createLiveHoles(sink, scoped) {
|
|
|
2237
2579
|
} catch (err) {
|
|
2238
2580
|
b.closed = true;
|
|
2239
2581
|
sink.closeBinding(b.key);
|
|
2240
|
-
sink.error(b.key,
|
|
2582
|
+
sink.error(b.key, wireErrorMessage(err));
|
|
2241
2583
|
return;
|
|
2242
2584
|
} finally {
|
|
2243
2585
|
engine.sweeping = prevSweeping;
|
|
@@ -2382,7 +2724,7 @@ function createLiveHoles(sink, scoped) {
|
|
|
2382
2724
|
if (ssrHandleError(err, true)) return;
|
|
2383
2725
|
b.closed = true;
|
|
2384
2726
|
sink.closeBinding(b.key);
|
|
2385
|
-
sink.error("lha:" + cap.id,
|
|
2727
|
+
sink.error("lha:" + cap.id, wireErrorMessage(err));
|
|
2386
2728
|
return;
|
|
2387
2729
|
} finally {
|
|
2388
2730
|
engine.sweeping = prevSweeping;
|
|
@@ -2674,45 +3016,107 @@ function ssrStyle(value) {
|
|
|
2674
3016
|
function ssrStyleProperty(name, value) {
|
|
2675
3017
|
return value != null ? name + value : "";
|
|
2676
3018
|
}
|
|
2677
|
-
function ssrElement(tag, props, children, needsId) {
|
|
3019
|
+
function ssrElement(tag, props, children, needsId, skip) {
|
|
2678
3020
|
const hk = needsId ? ssrHydrationKey() : "";
|
|
2679
3021
|
if (typeof props === "function") props = props();
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
let
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
if (
|
|
2689
|
-
continue;
|
|
3022
|
+
let sources = null;
|
|
3023
|
+
let kind = SOURCE_PLAIN;
|
|
3024
|
+
let viewKeys = null;
|
|
3025
|
+
let owners = null;
|
|
3026
|
+
if (Array.isArray(props)) {
|
|
3027
|
+
let i = 0;
|
|
3028
|
+
for (; i < props.length; i++) {
|
|
3029
|
+
const s = props[i];
|
|
3030
|
+
if (s == null || typeof s === "function" || $PROXY in s) break;
|
|
2690
3031
|
}
|
|
2691
|
-
if (
|
|
2692
|
-
|
|
2693
|
-
|
|
3032
|
+
if (i === props.length) sources = props;else {
|
|
3033
|
+
viewKeys = [];
|
|
3034
|
+
owners = [];
|
|
3035
|
+
for (let i = 0; i < props.length; i++) {
|
|
3036
|
+
let s = props[i];
|
|
3037
|
+
if (typeof s === "function") s = s();
|
|
3038
|
+
if (s != null) sourceOwners(s, viewKeys, owners);
|
|
3039
|
+
}
|
|
2694
3040
|
}
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
3041
|
+
} else if (props == null) {
|
|
3042
|
+
props = {};
|
|
3043
|
+
} else if ($PROXY in props) {
|
|
3044
|
+
if (viewOf(props) !== undefined) {
|
|
3045
|
+
viewKeys = [];
|
|
3046
|
+
owners = [];
|
|
3047
|
+
sourceOwners(props, viewKeys, owners);
|
|
3048
|
+
} else kind = SOURCE_PROXY;
|
|
3049
|
+
}
|
|
3050
|
+
const skipChildren = VOID_ELEMENTS.test(tag);
|
|
3051
|
+
let result = `<${tag}${hk}`;
|
|
3052
|
+
const last = sources === null ? 0 : sources.length - 1;
|
|
3053
|
+
let keysOf = null;
|
|
3054
|
+
if (sources !== null) {
|
|
3055
|
+
keysOf = new Array(last + 1);
|
|
3056
|
+
for (let s = 0; s <= last; s++) keysOf[s] = Object.keys(sources[s]);
|
|
3057
|
+
}
|
|
3058
|
+
for (let s = 0; s <= last; s++) {
|
|
3059
|
+
const keys = owners !== null ? viewKeys : keysOf !== null ? keysOf[s] : sourceKeys(props, kind);
|
|
3060
|
+
if (sources !== null) props = sources[s];
|
|
3061
|
+
nextKey: for (let i = 0; i < keys.length; i++) {
|
|
3062
|
+
const prop = keys[i];
|
|
3063
|
+
if (typeof prop !== "string" || skip !== undefined && skip(prop)) continue;
|
|
3064
|
+
if (owners !== null) props = owners[i];
|
|
3065
|
+
for (let j = s + 1; j <= last; j++) {
|
|
3066
|
+
if (keysOf[j].includes(prop)) continue nextKey;
|
|
3067
|
+
}
|
|
3068
|
+
if (tag === "textarea" && (prop === "value" || prop === "defaultValue")) {
|
|
3069
|
+
const value = sourceGet(props, kind, prop);
|
|
3070
|
+
if (value !== null) children = escape(value);
|
|
3071
|
+
continue;
|
|
3072
|
+
}
|
|
3073
|
+
if (ChildProperties.has(prop)) {
|
|
3074
|
+
if (children === undefined && !skipChildren) children = tag === "script" || tag === "style" || prop === "innerHTML" ? sourceGet(props, kind, prop) : escape(sourceGet(props, kind, prop));
|
|
3075
|
+
continue;
|
|
3076
|
+
}
|
|
3077
|
+
const value = sourceGet(props, kind, prop);
|
|
3078
|
+
if (value == undefined || prop === "ref" || prop.slice(0, 2) === "on" || prop.slice(0, 5) === "prop:") {
|
|
3079
|
+
if (typeof value === "function" && value[CLAIM_PROP] !== undefined && (prop === "ref" || prop.slice(0, 2) === "on")) {
|
|
3080
|
+
devCheck({
|
|
3081
|
+
code: "BEHAVIOR_CLAIM_DROPPED",
|
|
3082
|
+
kind: "ssr",
|
|
3083
|
+
severity: "warn",
|
|
3084
|
+
message: `[BEHAVIOR_CLAIM_DROPPED] A spread on a server-rendered <${tag}> carries \`${prop}\` from client props — ` + `spreads don't participate in behavior claims, so this drops. ` + `Write the position out: \`${prop}={props.${String(value[CLAIM_PROP])}}\`.`,
|
|
3085
|
+
data: {
|
|
3086
|
+
reason: "spread",
|
|
3087
|
+
tag,
|
|
3088
|
+
position: prop,
|
|
3089
|
+
prop: String(value[CLAIM_PROP])
|
|
3090
|
+
}
|
|
3091
|
+
});
|
|
3092
|
+
}
|
|
3093
|
+
continue;
|
|
3094
|
+
} else if (prop === "style") {
|
|
3095
|
+
result += ` style="${ssrStyle(value)}"`;
|
|
3096
|
+
} else if (prop === "class") {
|
|
3097
|
+
result += ` class="${ssrClassName(value)}"`;
|
|
3098
|
+
} else if (typeof value === "boolean") {
|
|
3099
|
+
if (!value) continue;
|
|
3100
|
+
result += ` ${escape(prop)}`;
|
|
3101
|
+
} else {
|
|
3102
|
+
result += value === "" ? ` ${escape(prop)}` : ` ${escape(prop)}="${escape(value, true)}"`;
|
|
2702
3103
|
}
|
|
2703
|
-
continue;
|
|
2704
|
-
} else if (typeof value === "boolean") {
|
|
2705
|
-
if (!value) continue;
|
|
2706
|
-
result += escape(prop);
|
|
2707
|
-
} else {
|
|
2708
|
-
result += value === "" ? escape(prop) : `${escape(prop)}="${escape(value, true)}"`;
|
|
2709
3104
|
}
|
|
2710
|
-
if (i !== keys.length - 1) result += " ";
|
|
2711
3105
|
}
|
|
2712
3106
|
if (skipChildren) return {
|
|
2713
|
-
t: result + "/>"
|
|
3107
|
+
t: result + " />"
|
|
2714
3108
|
};
|
|
2715
3109
|
if (typeof children === "function") children = children();
|
|
3110
|
+
const ct = typeof children;
|
|
3111
|
+
if (ct === "string" || ct === "number") return {
|
|
3112
|
+
t: result + ">" + children + "</" + tag + ">"
|
|
3113
|
+
};
|
|
3114
|
+
if (children == null || ct === "boolean") return {
|
|
3115
|
+
t: result + "></" + tag + ">"
|
|
3116
|
+
};
|
|
3117
|
+
if (ct === "object" && !children.h && typeof children.t === "string") return {
|
|
3118
|
+
t: result + ">" + children.t + "</" + tag + ">"
|
|
3119
|
+
};
|
|
2716
3120
|
return ssr([result + ">", `</${tag}>`], resolveSSRNode(children, undefined, true));
|
|
2717
3121
|
}
|
|
2718
3122
|
function ssrAttribute(key, value) {
|
|
@@ -2742,7 +3146,17 @@ function ssrClaim(map) {
|
|
|
2742
3146
|
const prop = typeof fn === "function" && fn[CLAIM_PROP] || undefined;
|
|
2743
3147
|
if (prop === undefined) {
|
|
2744
3148
|
{
|
|
2745
|
-
|
|
3149
|
+
devCheck({
|
|
3150
|
+
code: "BEHAVIOR_CLAIM_DROPPED",
|
|
3151
|
+
kind: "ssr",
|
|
3152
|
+
severity: "warn",
|
|
3153
|
+
message: `[BEHAVIOR_CLAIM_DROPPED] A \`${pos}\` position on a server-rendered element received a server-local ` + `${typeof fn} — this handler can never run. Pass the function through the ` + `server component's props from the client (compose on the client before ` + `passing), or bind a mutation to \`action=\`.`,
|
|
3154
|
+
data: {
|
|
3155
|
+
reason: "server-local",
|
|
3156
|
+
position: pos,
|
|
3157
|
+
received: typeof fn
|
|
3158
|
+
}
|
|
3159
|
+
});
|
|
2746
3160
|
}
|
|
2747
3161
|
continue;
|
|
2748
3162
|
}
|
|
@@ -2862,10 +3276,13 @@ function escape(s, attr) {
|
|
|
2862
3276
|
if (!attr && Array.isArray(s)) {
|
|
2863
3277
|
const joined = tryJoinPlainSSRArray(s);
|
|
2864
3278
|
if (joined !== undefined) return joined;
|
|
3279
|
+
const src = s;
|
|
2865
3280
|
s = s.slice();
|
|
2866
3281
|
for (let i = 0; i < s.length; i++) s[i] = escape(s[i]);
|
|
3282
|
+
if (src.$slot) s.$slot = true;
|
|
2867
3283
|
return s;
|
|
2868
3284
|
}
|
|
3285
|
+
if (!attr && t === "function") return escapeLate(s);
|
|
2869
3286
|
if (attr) {
|
|
2870
3287
|
if (s == null || t === "boolean" || t === "number") return s;
|
|
2871
3288
|
return escape(String(s), attr);
|
|
@@ -2876,6 +3293,15 @@ function escape(s, attr) {
|
|
|
2876
3293
|
if (i < 0) return s;
|
|
2877
3294
|
return escapeSlow(s, attr, i);
|
|
2878
3295
|
}
|
|
3296
|
+
function escapeLate(fn) {
|
|
3297
|
+
if (fn.$esc) return fn;
|
|
3298
|
+
const w = () => escape(fn());
|
|
3299
|
+
w.$esc = true;
|
|
3300
|
+
if (fn.$lhSkip) w.$lhSkip = true;
|
|
3301
|
+
if (fn.$lhSuppress) w.$lhSuppress = true;
|
|
3302
|
+
if (fn.$lhBinding) w.$lhBinding = fn.$lhBinding;
|
|
3303
|
+
return w;
|
|
3304
|
+
}
|
|
2879
3305
|
const ESCAPE_CONTENT = /[&<]/;
|
|
2880
3306
|
const ESCAPE_ATTR = /[&"<]/;
|
|
2881
3307
|
function escapeSlow(s, attr, start) {
|
|
@@ -3139,23 +3565,26 @@ function flattenClassList(list, result) {
|
|
|
3139
3565
|
else if (typeof item !== "boolean" && (item || item === 0)) result[item] = true;
|
|
3140
3566
|
}
|
|
3141
3567
|
}
|
|
3142
|
-
|
|
3568
|
+
let ssrTextTail = false;
|
|
3569
|
+
function tryResolveString(node, nested) {
|
|
3570
|
+
if (!nested) ssrTextTail = false;
|
|
3143
3571
|
const t = typeof node;
|
|
3144
|
-
if (t === "string")
|
|
3145
|
-
|
|
3572
|
+
if (t === "string" || t === "number") {
|
|
3573
|
+
const s = ssrTextTail ? "<!--!$-->" + node : "" + node;
|
|
3574
|
+
ssrTextTail = true;
|
|
3575
|
+
return s;
|
|
3576
|
+
}
|
|
3146
3577
|
if (node == null || t === "boolean") return "";
|
|
3147
3578
|
if (t === "object") {
|
|
3148
3579
|
if (Array.isArray(node)) {
|
|
3149
3580
|
const joined = tryJoinPlainSSRArray(node);
|
|
3150
|
-
if (joined !== undefined)
|
|
3581
|
+
if (joined !== undefined) {
|
|
3582
|
+
ssrTextTail = false;
|
|
3583
|
+
return joined;
|
|
3584
|
+
}
|
|
3151
3585
|
let s = "";
|
|
3152
|
-
let prevNonObj = false;
|
|
3153
3586
|
for (let i = 0, len = node.length; i < len; i++) {
|
|
3154
|
-
const
|
|
3155
|
-
const itemNonObj = item !== null && typeof item !== "object";
|
|
3156
|
-
if (prevNonObj && itemNonObj) s += "<!--!$-->";
|
|
3157
|
-
prevNonObj = itemNonObj;
|
|
3158
|
-
const r = tryResolveString(item);
|
|
3587
|
+
const r = tryResolveString(node[i], true);
|
|
3159
3588
|
if (typeof r !== "string") return {
|
|
3160
3589
|
bail: node
|
|
3161
3590
|
};
|
|
@@ -3167,9 +3596,10 @@ function tryResolveString(node) {
|
|
|
3167
3596
|
merge: node
|
|
3168
3597
|
};
|
|
3169
3598
|
if (node.t === undefined) {
|
|
3170
|
-
|
|
3599
|
+
unrecognizedInsert(node);
|
|
3171
3600
|
return "";
|
|
3172
3601
|
}
|
|
3602
|
+
ssrTextTail = false;
|
|
3173
3603
|
return Array.isArray(node.t) ? node.t[0] : node.t;
|
|
3174
3604
|
}
|
|
3175
3605
|
if (t === "function") {
|
|
@@ -3177,9 +3607,11 @@ function tryResolveString(node) {
|
|
|
3177
3607
|
try {
|
|
3178
3608
|
v = node();
|
|
3179
3609
|
} catch (err) {
|
|
3180
|
-
|
|
3610
|
+
const wrap = buildAsyncWrap(err, node);
|
|
3611
|
+
if (wrap) ssrTextTail = true;
|
|
3612
|
+
return wrap || "";
|
|
3181
3613
|
}
|
|
3182
|
-
return tryResolveString(v);
|
|
3614
|
+
return tryResolveString(v, true);
|
|
3183
3615
|
}
|
|
3184
3616
|
return "";
|
|
3185
3617
|
}
|
|
@@ -3187,21 +3619,19 @@ function resolveSSRNode(node, result = {
|
|
|
3187
3619
|
t: [""],
|
|
3188
3620
|
h: [],
|
|
3189
3621
|
p: []
|
|
3190
|
-
}, top) {
|
|
3622
|
+
}, top, nested) {
|
|
3623
|
+
if (!nested) ssrTextTail = false;
|
|
3191
3624
|
const t = typeof node;
|
|
3192
3625
|
if (t === "string" || t === "number") {
|
|
3193
|
-
result.t[result.t.length - 1] += node;
|
|
3626
|
+
result.t[result.t.length - 1] += ssrTextTail ? "<!--!$-->" + node : node;
|
|
3627
|
+
ssrTextTail = true;
|
|
3194
3628
|
} else if (node == null || t === "boolean") ; else if (Array.isArray(node)) {
|
|
3195
3629
|
const slotLive = node.$slot && sharedConfig.context && sharedConfig.context.liveHoles;
|
|
3196
3630
|
if (slotLive) slotLive.suppressed++;
|
|
3197
3631
|
try {
|
|
3198
|
-
let prevNonObj = false;
|
|
3199
3632
|
for (let i = 0, len = node.length; i < len; i++) {
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
if (!top && prevNonObj && itemNonObj) result.t[result.t.length - 1] += `<!--!$-->`;
|
|
3203
|
-
prevNonObj = itemNonObj;
|
|
3204
|
-
resolveSSRNode(item, result);
|
|
3633
|
+
if (top) ssrTextTail = false;
|
|
3634
|
+
resolveSSRNode(node[i], result, false, true);
|
|
3205
3635
|
}
|
|
3206
3636
|
} finally {
|
|
3207
3637
|
if (slotLive) slotLive.suppressed--;
|
|
@@ -3214,23 +3644,30 @@ function resolveSSRNode(node, result = {
|
|
|
3214
3644
|
result.h.push(...node.h);
|
|
3215
3645
|
result.p.push(...node.p);
|
|
3216
3646
|
}
|
|
3647
|
+
ssrTextTail = false;
|
|
3217
3648
|
} else if (node.t !== undefined) {
|
|
3218
3649
|
result.t[result.t.length - 1] += node.t;
|
|
3219
|
-
|
|
3650
|
+
ssrTextTail = false;
|
|
3651
|
+
} else unrecognizedInsert(node);
|
|
3220
3652
|
} else if (t === "function") {
|
|
3221
3653
|
const live = sharedConfig.context && sharedConfig.context.liveHoles;
|
|
3222
3654
|
let liveNode = null;
|
|
3223
3655
|
if (live && (liveNode = live.content(node)) !== null) {
|
|
3224
|
-
if (typeof liveNode === "string")
|
|
3656
|
+
if (typeof liveNode === "string") {
|
|
3657
|
+
result.t[result.t.length - 1] += ssrTextTail ? "<!--!$-->" + liveNode : liveNode;
|
|
3658
|
+
ssrTextTail = true;
|
|
3659
|
+
} else resolveSSRNode(liveNode, result, false, true);
|
|
3225
3660
|
} else {
|
|
3226
3661
|
try {
|
|
3227
|
-
resolveSSRNode(node(), result);
|
|
3662
|
+
resolveSSRNode(node(), result, false, true);
|
|
3228
3663
|
} catch (err) {
|
|
3229
3664
|
const wrap = buildAsyncWrap(err, node);
|
|
3230
3665
|
if (wrap) {
|
|
3666
|
+
if (ssrTextTail) result.t[result.t.length - 1] += "<!--!$-->";
|
|
3231
3667
|
result.h.push(wrap.fn);
|
|
3232
3668
|
result.p.push(wrap.p);
|
|
3233
3669
|
result.t.push("");
|
|
3670
|
+
ssrTextTail = true;
|
|
3234
3671
|
}
|
|
3235
3672
|
}
|
|
3236
3673
|
}
|
|
@@ -3243,6 +3680,26 @@ function resolveSSRSync(node) {
|
|
|
3243
3680
|
throw new Error("This value cannot be rendered synchronously. Are you missing a boundary?");
|
|
3244
3681
|
}
|
|
3245
3682
|
const RequestContext = Symbol.for("solid.RequestContext");
|
|
3683
|
+
const ServerErrors = Symbol.for("solid-js/server/errors");
|
|
3684
|
+
function serializerErrorHook(hook) {
|
|
3685
|
+
return hook === undefined ? undefined : err => {
|
|
3686
|
+
reportServerError(err, {
|
|
3687
|
+
kind: "render",
|
|
3688
|
+
handling: "serialize"
|
|
3689
|
+
}, null);
|
|
3690
|
+
};
|
|
3691
|
+
}
|
|
3692
|
+
function ambientServerErrorHook() {
|
|
3693
|
+
const slot = globalThis[ServerErrors];
|
|
3694
|
+
return slot === undefined ? undefined : slot.hook;
|
|
3695
|
+
}
|
|
3696
|
+
function configureServerErrors(config) {
|
|
3697
|
+
const g = globalThis;
|
|
3698
|
+
if (config && config.onError !== undefined && typeof config.onError !== "function") {
|
|
3699
|
+
throw new TypeError(`Invalid onError: expected a function, received ${typeof config.onError}.`);
|
|
3700
|
+
}
|
|
3701
|
+
(g[ServerErrors] ||= {}).hook = config ? config.onError : undefined;
|
|
3702
|
+
}
|
|
3246
3703
|
function getRequestEvent() {
|
|
3247
3704
|
return globalThis[RequestContext] ? globalThis[RequestContext].getStore() || sharedConfig.context && sharedConfig.context.event || console.warn("RequestEvent is missing. This is most likely due to accessing `getRequestEvent` non-managed async scope in a partially polyfilled environment. Try moving it above all `await` calls.") : undefined;
|
|
3248
3705
|
}
|
|
@@ -3250,6 +3707,22 @@ function peekRequestEvent() {
|
|
|
3250
3707
|
const store = globalThis[RequestContext];
|
|
3251
3708
|
return store ? store.getStore() : undefined;
|
|
3252
3709
|
}
|
|
3710
|
+
function traceForEvent(event) {
|
|
3711
|
+
return traceFor(event.request || event, event.request);
|
|
3712
|
+
}
|
|
3713
|
+
function getTraceContext() {
|
|
3714
|
+
const event = peekRequestEvent();
|
|
3715
|
+
if (event) return traceForEvent(event).context;
|
|
3716
|
+
const ctx = sharedConfig.context;
|
|
3717
|
+
return ctx && ctx.trace ? ctx.trace.context : undefined;
|
|
3718
|
+
}
|
|
3719
|
+
function traceForStub(stub, event) {
|
|
3720
|
+
if (!event) {
|
|
3721
|
+
event = peekRequestEvent();
|
|
3722
|
+
if (!event || event.response !== stub) return undefined;
|
|
3723
|
+
}
|
|
3724
|
+
return traceForEvent(event);
|
|
3725
|
+
}
|
|
3253
3726
|
function createResponseStub() {
|
|
3254
3727
|
return {
|
|
3255
3728
|
status: undefined,
|
|
@@ -3267,15 +3740,30 @@ function createRequestEvent(request, init) {
|
|
|
3267
3740
|
};
|
|
3268
3741
|
}
|
|
3269
3742
|
function reportLostHeaderWrite(method, name) {
|
|
3270
|
-
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).";
|
|
3743
|
+
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).";
|
|
3744
|
+
recordFinding({
|
|
3745
|
+
code: "LATE_HEADER_WRITE",
|
|
3746
|
+
kind: "head",
|
|
3747
|
+
severity: "error",
|
|
3748
|
+
message,
|
|
3749
|
+
data: {
|
|
3750
|
+
method,
|
|
3751
|
+
name: String(name)
|
|
3752
|
+
}
|
|
3753
|
+
});
|
|
3271
3754
|
throw new Error(message);
|
|
3272
3755
|
}
|
|
3273
3756
|
function commitResponseStub(stub, {
|
|
3274
|
-
allowLateLocation = false
|
|
3757
|
+
allowLateLocation = false,
|
|
3758
|
+
event
|
|
3275
3759
|
} = {}) {
|
|
3276
3760
|
if (!stub || stub.committed) return stub;
|
|
3277
|
-
stub.committed = true;
|
|
3278
3761
|
const headers = stub.headers;
|
|
3762
|
+
if (headers && typeof headers.append === "function") {
|
|
3763
|
+
const trace = traceForStub(stub, event);
|
|
3764
|
+
if (trace) appendTraceServerTiming(headers, trace);
|
|
3765
|
+
}
|
|
3766
|
+
stub.committed = true;
|
|
3279
3767
|
if (!headers || typeof headers.set !== "function") return stub;
|
|
3280
3768
|
for (const method of ["set", "append", "delete"]) {
|
|
3281
3769
|
const original = headers[method].bind(headers);
|
|
@@ -3296,7 +3784,7 @@ function getExpectedRedirectStatus(response) {
|
|
|
3296
3784
|
function mergeStubHeaders(target, stub) {
|
|
3297
3785
|
if (!stub) return target;
|
|
3298
3786
|
stub.headers.forEach((value, key) => {
|
|
3299
|
-
if (key !== "set-cookie") target.set(key, value);
|
|
3787
|
+
if (key === "server-timing") mergeServerTiming(target, value);else if (key !== "set-cookie") target.set(key, value);
|
|
3300
3788
|
});
|
|
3301
3789
|
const setCookies = stub.headers.getSetCookie ? stub.headers.getSetCookie() : [];
|
|
3302
3790
|
for (const cookie of setCookies) target.append("set-cookie", cookie);
|
|
@@ -3320,19 +3808,35 @@ function fillsStubGap(key, headers, response) {
|
|
|
3320
3808
|
}
|
|
3321
3809
|
function commitEventResponse(response, event = getRequestEvent()) {
|
|
3322
3810
|
const stub = event && event.response;
|
|
3323
|
-
if (!stub || !stub.headers || stub.committed)
|
|
3811
|
+
if (!stub || !stub.headers || stub.committed) {
|
|
3812
|
+
if (!event || stub) return response;
|
|
3813
|
+
const trace = traceForEvent(event);
|
|
3814
|
+
if (!trace.emit) return response;
|
|
3815
|
+
const headers = copyInitHeaders(response.headers);
|
|
3816
|
+
appendTraceServerTiming(headers, trace);
|
|
3817
|
+
return new Response(response.body, {
|
|
3818
|
+
status: response.status,
|
|
3819
|
+
statusText: response.statusText,
|
|
3820
|
+
headers
|
|
3821
|
+
});
|
|
3822
|
+
}
|
|
3324
3823
|
const cookies = stub.headers.getSetCookie ? stub.headers.getSetCookie() : [];
|
|
3325
|
-
commitResponseStub(stub
|
|
3824
|
+
commitResponseStub(stub, {
|
|
3825
|
+
event
|
|
3826
|
+
});
|
|
3326
3827
|
let hasGaps = false;
|
|
3327
3828
|
stub.headers.forEach((value, key) => {
|
|
3328
3829
|
if (fillsStubGap(key, response.headers, response)) hasGaps = true;
|
|
3329
3830
|
});
|
|
3330
|
-
|
|
3831
|
+
const timing = stub.headers.get("server-timing");
|
|
3832
|
+
const mergesTiming = timing !== null && response.headers.has("server-timing");
|
|
3833
|
+
if (!cookies.length && !hasGaps && !mergesTiming) return response;
|
|
3331
3834
|
const headers = copyInitHeaders(response.headers);
|
|
3332
3835
|
for (const cookie of cookies) headers.append("Set-Cookie", cookie);
|
|
3333
3836
|
stub.headers.forEach((value, key) => {
|
|
3334
3837
|
if (fillsStubGap(key, headers, response)) headers.set(key, value);
|
|
3335
3838
|
});
|
|
3839
|
+
if (mergesTiming) mergeServerTiming(headers, timing);
|
|
3336
3840
|
return new Response(response.body, {
|
|
3337
3841
|
status: response.status,
|
|
3338
3842
|
statusText: response.statusText,
|
|
@@ -3358,7 +3862,9 @@ function createSSRResponse(result, event, options = {}) {
|
|
|
3358
3862
|
} = options;
|
|
3359
3863
|
const nonce = normalizeNonce(options.nonce);
|
|
3360
3864
|
if (typeof result === "string") {
|
|
3361
|
-
if (stub) commitResponseStub(stub
|
|
3865
|
+
if (stub) commitResponseStub(stub, {
|
|
3866
|
+
event
|
|
3867
|
+
});
|
|
3362
3868
|
const head = deriveHead(stub, responseInit);
|
|
3363
3869
|
if (stub && stub.headers.get("Location")) {
|
|
3364
3870
|
return new Response(null, {
|
|
@@ -3393,7 +3899,8 @@ function createSSRResponse(result, event, options = {}) {
|
|
|
3393
3899
|
if (!flushed) {
|
|
3394
3900
|
flushed = true;
|
|
3395
3901
|
if (stub) commitResponseStub(stub, {
|
|
3396
|
-
allowLateLocation: true
|
|
3902
|
+
allowLateLocation: true,
|
|
3903
|
+
event
|
|
3397
3904
|
});
|
|
3398
3905
|
const head = deriveHead(stub, responseInit);
|
|
3399
3906
|
if (stub && stub.headers.get("Location")) {
|
|
@@ -3467,6 +3974,13 @@ setContainerTraceResolver(getProjectionTrace);
|
|
|
3467
3974
|
const isServer = true;
|
|
3468
3975
|
const isDev = true;
|
|
3469
3976
|
function dynamic(source, options) {
|
|
3977
|
+
if (options?.static) {
|
|
3978
|
+
const component = untrack(source);
|
|
3979
|
+
if (component && typeof component.then === "function") throw new Error("dynamic(): a static source must resolve synchronously, not to a promise");
|
|
3980
|
+
if (typeof component === "function") return props => component(props);
|
|
3981
|
+
if (typeof component === "string") return props => ssrElement(component, props, undefined, true);
|
|
3982
|
+
return () => undefined;
|
|
3983
|
+
}
|
|
3470
3984
|
const cached = createMemo(source, {
|
|
3471
3985
|
serialize: false
|
|
3472
3986
|
});
|
|
@@ -3624,4 +4138,4 @@ function httpHeader(name, value, options) {
|
|
|
3624
4138
|
}
|
|
3625
4139
|
}
|
|
3626
4140
|
|
|
3627
|
-
export { CLAIMS_DOCUMENT, CLAIMS_STREAM, CLAIM_PROP, ChildProperties, DOMElements, DOMWithState, DelegatedEvents, Dynamic, HREF, HydrationScript, MathMLElements, NULL_BODY_STATUSES, Namespaces, Portal, RESPONSE_HEADER_VALUE_LIMIT, REVALIDATE_HEADER, RawTextElements, RequestContext, ResponseEnvelope, SAFE_ERROR, SVGElements, VoidElements, notSup as acquireAsset, notSup as addEvent, applyRef, notSup as assign, claimElement, claimElementTree, notSup as className, clearFlashCookie, clientOnly, commitEventResponse, commitResponseStub, composeMiddleware, createLiveHoles, createRequestEvent, createResponseStub, createSSRResponse, notSup as delegateEvents, dynamic, notSup as dynamicProperty, effect, escape, generateHydrationScript, notSup as getDelegatedRoot, getExpectedRedirectStatus, getHydrationKey, notSup as getNextElement, notSup as getNextMarker, notSup as getNextMatch, getRequestEvent, getServerFunctionMetadata, getServerFunctionRPC, hasFlashCookie, httpHeader, httpStatus, notSup as hydrate, notSup as insert, isDev, isHref, isResponseEnvelope, isSafeError, isServer, isServerFunction, markSafeError, memo, parseCookieHeader, redirect, notSup as ref, notSup as registerDelegatedContainer, notSup as registerDelegatedRoot, registerElementClaim, reload, notSup as render, renderToStream, renderToString, resolveSSRNode, resolveSSRSelectValues, respond, notSup as runHydrationEvents, scriptNonce, serializeCookie, notSup as setAttribute, notSup as setAttributeNS, notSup as setProperty, notSup as setStyleProperty, notSup as spread, ssr, ssrAttribute, ssrClaim, ssrClassName, ssrElement, ssrGroup, ssrHydrationKey, ssrSelectValues, ssrStyle, ssrStyleProperty, notSup as style, styleNonce, notSup as template, notSup as unregisterDelegatedContainer, notSup as unregisterDelegatedRoot, useHead };
|
|
4141
|
+
export { CLAIMS_DOCUMENT, CLAIMS_STREAM, CLAIM_PROP, ChildProperties, DOMElements, DOMWithState, DelegatedEvents, Dynamic, HREF, HydrationScript, MathMLElements, NULL_BODY_STATUSES, Namespaces, Portal, RESPONSE_HEADER_VALUE_LIMIT, REVALIDATE_ALL, REVALIDATE_HEADER, RawTextElements, RequestContext, ResponseEnvelope, SAFE_ERROR, SVGElements, VoidElements, notSup as acquireAsset, notSup as addEvent, applyRef, notSup as assign, claimElement, claimElementTree, notSup as className, clearFlashCookie, clientOnly, commitEventResponse, commitResponseStub, composeMiddleware, configureServerErrors, createLiveHoles, createRequestEvent, createResponseStub, createSSRResponse, notSup as delegateEvents, dynamic, notSup as dynamicProperty, effect, escape, generateHydrationScript, notSup as getDelegatedRoot, getExpectedRedirectStatus, getHydrationKey, notSup as getNextElement, notSup as getNextMarker, notSup as getNextMatch, getRequestEvent, getServerFunctionMetadata, getServerFunctionRPC, getTraceContext, hasFlashCookie, httpHeader, httpStatus, notSup as hydrate, notSup as insert, isDev, isHref, isResponseEnvelope, isSafeError, isServer, isServerFunction, markSafeError, memo, parseCookieHeader, notSup as readShallow, redirect, notSup as ref, notSup as registerDelegatedContainer, notSup as registerDelegatedRoot, registerElementClaim, reload, notSup as render, renderToStream, renderToString, resolveSSRNode, resolveSSRSelectValues, respond, notSup as runHydrationEvents, scriptNonce, serializeCookie, notSup as setAttribute, notSup as setAttributeNS, notSup as setProperty, notSup as setStyleProperty, notSup as spread, ssr, ssrAttribute, ssrClaim, ssrClassName, ssrElement, ssrGroup, ssrHydrationKey, ssrSelectValues, ssrStyle, ssrStyleProperty, notSup as style, styleNonce, notSup as template, notSup as unregisterDelegatedContainer, notSup as unregisterDelegatedRoot, useHead };
|