@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
package/dist/server.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { createRenderEffect, createMemo, sharedConfig, createRoot,
|
|
2
|
-
export { Errored, For, Hydration, Loading, Match, NoHydration, Repeat, Reveal, Show, Switch, createComponent, getOwner, merge as mergeProps,
|
|
1
|
+
import { createRenderEffect, createMemo, sharedConfig, createRoot, $PROXY, getOwner, 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
|
|
|
@@ -77,6 +79,148 @@ function memo(fn) {
|
|
|
77
79
|
return createMemo(() => fn(), syncOptions);
|
|
78
80
|
}
|
|
79
81
|
|
|
82
|
+
const TRACEPARENT = /^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})(-.*)?$/;
|
|
83
|
+
const ZERO_TRACE = "00000000000000000000000000000000";
|
|
84
|
+
const ZERO_SPAN = "0000000000000000";
|
|
85
|
+
function parseTraceparent(value) {
|
|
86
|
+
if (!value) return undefined;
|
|
87
|
+
const m = TRACEPARENT.exec(value.trim());
|
|
88
|
+
if (!m) return undefined;
|
|
89
|
+
const [, version, traceId, parentId, flags, rest] = m;
|
|
90
|
+
if (version === "ff") return undefined;
|
|
91
|
+
if (version === "00" && rest !== undefined) return undefined;
|
|
92
|
+
if (traceId === ZERO_TRACE || parentId === ZERO_SPAN) return undefined;
|
|
93
|
+
return {
|
|
94
|
+
traceId,
|
|
95
|
+
parentId,
|
|
96
|
+
sampled: (parseInt(flags, 16) & 1) === 1
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function randomHex(bytes) {
|
|
100
|
+
const buffer = new Uint8Array(bytes);
|
|
101
|
+
crypto.getRandomValues(buffer);
|
|
102
|
+
let out = "";
|
|
103
|
+
for (let i = 0; i < buffer.length; i++) out += (buffer[i] < 16 ? "0" : "") + buffer[i].toString(16);
|
|
104
|
+
return out;
|
|
105
|
+
}
|
|
106
|
+
function randomTraceId() {
|
|
107
|
+
let id = randomHex(16);
|
|
108
|
+
while (id === ZERO_TRACE) id = randomHex(16);
|
|
109
|
+
return id;
|
|
110
|
+
}
|
|
111
|
+
function randomSpanId() {
|
|
112
|
+
let id = randomHex(8);
|
|
113
|
+
while (id === ZERO_SPAN) id = randomHex(8);
|
|
114
|
+
return id;
|
|
115
|
+
}
|
|
116
|
+
function formatTraceparent(context) {
|
|
117
|
+
return `00-${context.traceId}-${context.spanId}-${context.sampled === true ? "01" : "00"}`;
|
|
118
|
+
}
|
|
119
|
+
const RECORDS_KEY = Symbol.for("@solidjs/web/trace/records");
|
|
120
|
+
function records() {
|
|
121
|
+
const g = globalThis;
|
|
122
|
+
return g[RECORDS_KEY] || (g[RECORDS_KEY] = new WeakMap());
|
|
123
|
+
}
|
|
124
|
+
function traceFor(key, request) {
|
|
125
|
+
const store = records();
|
|
126
|
+
let record = store.get(key);
|
|
127
|
+
if (record) return record;
|
|
128
|
+
const headers = request ? request.headers : undefined;
|
|
129
|
+
const incoming = headers ? parseTraceparent(headers.get("traceparent")) : undefined;
|
|
130
|
+
const context = {
|
|
131
|
+
traceId: incoming ? incoming.traceId : randomTraceId(),
|
|
132
|
+
spanId: randomSpanId(),
|
|
133
|
+
entries: {}
|
|
134
|
+
};
|
|
135
|
+
if (incoming) {
|
|
136
|
+
context.parentId = incoming.parentId;
|
|
137
|
+
context.sampled = incoming.sampled;
|
|
138
|
+
}
|
|
139
|
+
if (headers) {
|
|
140
|
+
const state = headers.get("tracestate");
|
|
141
|
+
if (state) context.state = state;
|
|
142
|
+
const baggage = headers.get("baggage");
|
|
143
|
+
if (baggage) context.baggage = baggage;
|
|
144
|
+
}
|
|
145
|
+
let answered = false;
|
|
146
|
+
context.entries.traceparent = formatTraceparent(context);
|
|
147
|
+
record = {
|
|
148
|
+
context,
|
|
149
|
+
emit: incoming !== undefined && incoming.sampled || answered
|
|
150
|
+
};
|
|
151
|
+
store.set(key, record);
|
|
152
|
+
return record;
|
|
153
|
+
}
|
|
154
|
+
const TOKEN = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
|
|
155
|
+
function splitServerTiming(value) {
|
|
156
|
+
const entries = [];
|
|
157
|
+
let start = 0;
|
|
158
|
+
let quoted = false;
|
|
159
|
+
for (let i = 0; i < value.length; i++) {
|
|
160
|
+
const c = value[i];
|
|
161
|
+
if (quoted) {
|
|
162
|
+
if (c === "\\") i++;else if (c === '"') quoted = false;
|
|
163
|
+
} else if (c === '"') quoted = true;else if (c === ",") {
|
|
164
|
+
entries.push(value.slice(start, i));
|
|
165
|
+
start = i + 1;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
entries.push(value.slice(start));
|
|
169
|
+
return entries;
|
|
170
|
+
}
|
|
171
|
+
function metricName(entry) {
|
|
172
|
+
return entry.split(";")[0].trim().toLowerCase();
|
|
173
|
+
}
|
|
174
|
+
function namesOnServerTiming(headers) {
|
|
175
|
+
const names = new Set();
|
|
176
|
+
const existing = headers.get("server-timing");
|
|
177
|
+
if (existing) {
|
|
178
|
+
for (const entry of splitServerTiming(existing)) {
|
|
179
|
+
const name = metricName(entry);
|
|
180
|
+
if (name) names.add(name);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return names;
|
|
184
|
+
}
|
|
185
|
+
function quoteDesc(value) {
|
|
186
|
+
return value.replace(/[\x00-\x1f\x7f]/g, "").replace(/[\\"]/g, m => "\\" + m);
|
|
187
|
+
}
|
|
188
|
+
function appendTraceServerTiming(headers, record) {
|
|
189
|
+
if (!record.emit) return;
|
|
190
|
+
const entries = record.context.entries;
|
|
191
|
+
let present;
|
|
192
|
+
for (const name in entries) {
|
|
193
|
+
if (!TOKEN.test(name)) continue;
|
|
194
|
+
if (!present) present = namesOnServerTiming(headers);
|
|
195
|
+
if (present.has(name.toLowerCase())) continue;
|
|
196
|
+
headers.append("Server-Timing", `${name};desc="${quoteDesc(entries[name])}"`);
|
|
197
|
+
present.add(name.toLowerCase());
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
function mergeServerTiming(target, value) {
|
|
201
|
+
const present = namesOnServerTiming(target);
|
|
202
|
+
for (const entry of splitServerTiming(value)) {
|
|
203
|
+
const trimmed = entry.trim();
|
|
204
|
+
const name = metricName(trimmed);
|
|
205
|
+
if (!name || present.has(name)) continue;
|
|
206
|
+
target.append("Server-Timing", trimmed);
|
|
207
|
+
present.add(name);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
function escapeAttr(value) {
|
|
211
|
+
return value.replace(/[&"<>]/g, c => c === "&" ? "&" : c === '"' ? """ : c === "<" ? "<" : ">");
|
|
212
|
+
}
|
|
213
|
+
function traceMetaMarkup(record) {
|
|
214
|
+
if (!record.emit) return "";
|
|
215
|
+
let markup = "";
|
|
216
|
+
const entries = record.context.entries;
|
|
217
|
+
for (const name in entries) {
|
|
218
|
+
if (!TOKEN.test(name)) continue;
|
|
219
|
+
markup += `<meta name="${name}" content="${escapeAttr(entries[name])}">`;
|
|
220
|
+
}
|
|
221
|
+
return markup;
|
|
222
|
+
}
|
|
223
|
+
|
|
80
224
|
const STATE = Symbol.for("solid.container-trace-state");
|
|
81
225
|
const state = globalThis[STATE] || (globalThis[STATE] = {
|
|
82
226
|
materialized: new WeakMap(),
|
|
@@ -223,6 +367,7 @@ function isSafeError(value) {
|
|
|
223
367
|
return !!(value && (typeof value === "object" || typeof value === "function") && value[SAFE_ERROR]);
|
|
224
368
|
}
|
|
225
369
|
const REVALIDATE_HEADER = "X-Revalidate";
|
|
370
|
+
const REVALIDATE_ALL = "*";
|
|
226
371
|
const RESPONSE_HEADER_VALUE_LIMIT = 4096;
|
|
227
372
|
function initWithRevalidate(init = {}) {
|
|
228
373
|
const resolved = typeof init === "number" ? {
|
|
@@ -245,7 +390,11 @@ function initWithRevalidate(init = {}) {
|
|
|
245
390
|
headers = new Headers(responseInit.headers);
|
|
246
391
|
}
|
|
247
392
|
if (revalidate !== undefined) {
|
|
248
|
-
const
|
|
393
|
+
const list = Array.isArray(revalidate) ? revalidate : [revalidate];
|
|
394
|
+
if (list.length > 1 && list.includes(REVALIDATE_ALL)) {
|
|
395
|
+
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.`);
|
|
396
|
+
}
|
|
397
|
+
const keys = list.join(",");
|
|
249
398
|
if (keys.length > RESPONSE_HEADER_VALUE_LIMIT) {
|
|
250
399
|
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.`);
|
|
251
400
|
}
|
|
@@ -967,7 +1116,7 @@ function headGroupSignature(winner) {
|
|
|
967
1116
|
}
|
|
968
1117
|
return sig;
|
|
969
1118
|
}
|
|
970
|
-
function renderShellHead(registry, nonce, isPendingFragment, noScripts) {
|
|
1119
|
+
function renderShellHead(registry, nonce, isPendingFragment, noScripts, traceMetas = "") {
|
|
971
1120
|
commitHeadBoundary(registry, "", isPendingFragment);
|
|
972
1121
|
registry.shellFlushed = true;
|
|
973
1122
|
const winners = resolveHead(registry.committed);
|
|
@@ -993,7 +1142,7 @@ function renderShellHead(registry, nonce, isPendingFragment, noScripts) {
|
|
|
993
1142
|
}
|
|
994
1143
|
return {
|
|
995
1144
|
prelude,
|
|
996
|
-
html: registry.eagerHtml + links + metas + others + scripts,
|
|
1145
|
+
html: registry.eagerHtml + links + metas + traceMetas + others + scripts,
|
|
997
1146
|
title,
|
|
998
1147
|
noScripts
|
|
999
1148
|
};
|
|
@@ -1170,7 +1319,7 @@ function renderToString(code, options = {}) {
|
|
|
1170
1319
|
}
|
|
1171
1320
|
scripts += script + ";";
|
|
1172
1321
|
},
|
|
1173
|
-
onError: options.onError
|
|
1322
|
+
onError: serializerErrorHook(options.onError)
|
|
1174
1323
|
});
|
|
1175
1324
|
const tracking = createAssetTracking();
|
|
1176
1325
|
const headRegistry = createHeadRegistry();
|
|
@@ -1179,6 +1328,7 @@ function renderToString(code, options = {}) {
|
|
|
1179
1328
|
escape: escape,
|
|
1180
1329
|
resolve: resolveSSRNode,
|
|
1181
1330
|
ssr: ssr,
|
|
1331
|
+
errorPolicy: options.onError,
|
|
1182
1332
|
registerHeadTags(tags) {
|
|
1183
1333
|
registerHeadTags(headRegistry, sharedConfig.context, tracking, null, nonce, tags);
|
|
1184
1334
|
},
|
|
@@ -1211,17 +1361,32 @@ function renderToString(code, options = {}) {
|
|
|
1211
1361
|
};
|
|
1212
1362
|
applyAssetTracking(sharedConfig.context, tracking, manifest, noScripts);
|
|
1213
1363
|
registerEntryAssets(manifest);
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1364
|
+
const context = sharedConfig.context;
|
|
1365
|
+
const requestEvent = peekRequestEvent();
|
|
1366
|
+
context.trace = requestEvent ? traceForEvent(requestEvent) : traceFor(context, undefined);
|
|
1367
|
+
let dispose;
|
|
1368
|
+
try {
|
|
1369
|
+
const html = createRoot(d => {
|
|
1370
|
+
dispose = d;
|
|
1371
|
+
return resolveSSRSync(escape(code()));
|
|
1372
|
+
}, {
|
|
1373
|
+
id: renderId
|
|
1374
|
+
});
|
|
1375
|
+
serializeFragmentAssets("", tracking.boundaryModules, sharedConfig.context, renderId);
|
|
1376
|
+
sharedConfig.context.noHydrate = true;
|
|
1377
|
+
serializer.close();
|
|
1378
|
+
const head = renderShellHead(headRegistry, nonce, null, noScripts, traceMetaMarkup(context.trace));
|
|
1379
|
+
const document = assembleDocument(resolveSSRSelectValues(html), tracking.emittedAssets, tracking.preloadLinks, tracking.inlineStyles, scripts.length ? scripts : "", nonce, head, onHead);
|
|
1380
|
+
if (requestEvent && requestEvent.response) {
|
|
1381
|
+
commitResponseStub(requestEvent.response, {
|
|
1382
|
+
event: requestEvent
|
|
1383
|
+
});
|
|
1384
|
+
}
|
|
1385
|
+
return document;
|
|
1386
|
+
} finally {
|
|
1387
|
+
context.trace = undefined;
|
|
1388
|
+
if (dispose) dispose();
|
|
1389
|
+
}
|
|
1225
1390
|
}
|
|
1226
1391
|
function renderToStream(code, options = {}) {
|
|
1227
1392
|
let {
|
|
@@ -1236,7 +1401,7 @@ function renderToStream(code, options = {}) {
|
|
|
1236
1401
|
const requestEvent = peekRequestEvent();
|
|
1237
1402
|
let dispose;
|
|
1238
1403
|
let dead = false;
|
|
1239
|
-
const abandon =
|
|
1404
|
+
const abandon = disconnect => {
|
|
1240
1405
|
if (dead) return;
|
|
1241
1406
|
dead = true;
|
|
1242
1407
|
completed = true;
|
|
@@ -1253,11 +1418,16 @@ function renderToStream(code, options = {}) {
|
|
|
1253
1418
|
}
|
|
1254
1419
|
};
|
|
1255
1420
|
const failRender = err => {
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1421
|
+
reportServerError(err, {
|
|
1422
|
+
kind: "render",
|
|
1423
|
+
handling: "failed"
|
|
1424
|
+
}, null);
|
|
1425
|
+
if (!options.onError && ambientServerErrorHook() === undefined) console.error(err);
|
|
1259
1426
|
abandon();
|
|
1260
1427
|
};
|
|
1428
|
+
const failRootRender = err => {
|
|
1429
|
+
failRender(err);
|
|
1430
|
+
};
|
|
1261
1431
|
const coalesceWrites = (writeRaw, endRaw) => {
|
|
1262
1432
|
let buf = "";
|
|
1263
1433
|
let scheduled = false;
|
|
@@ -1395,7 +1565,7 @@ function renderToStream(code, options = {}) {
|
|
|
1395
1565
|
plugins: options.plugins,
|
|
1396
1566
|
onData: payload => sink.data(payload),
|
|
1397
1567
|
onDone,
|
|
1398
|
-
onError: options.onError
|
|
1568
|
+
onError: serializerErrorHook(options.onError)
|
|
1399
1569
|
});
|
|
1400
1570
|
let rootAssetsSerialized = false;
|
|
1401
1571
|
const serializeRootAssets = () => {
|
|
@@ -1420,6 +1590,34 @@ function renderToStream(code, options = {}) {
|
|
|
1420
1590
|
};
|
|
1421
1591
|
const registry = new Map();
|
|
1422
1592
|
const pendingSerialized = new Map();
|
|
1593
|
+
const guardedChannels = new WeakMap();
|
|
1594
|
+
const verdictNow = error => {
|
|
1595
|
+
throw ssrSanitizeError(error, null);
|
|
1596
|
+
};
|
|
1597
|
+
const guardChannel = p => {
|
|
1598
|
+
if (!p || typeof p !== "object" || "__SEROVAL_STREAM__" in p) return p;
|
|
1599
|
+
const thenable = typeof p.then === "function";
|
|
1600
|
+
const iterable = !thenable && typeof p[Symbol.asyncIterator] === "function";
|
|
1601
|
+
if (!thenable && !iterable) return p;
|
|
1602
|
+
let guarded = guardedChannels.get(p);
|
|
1603
|
+
if (guarded === undefined) {
|
|
1604
|
+
guarded = thenable ? p.then(undefined, verdictNow) : {
|
|
1605
|
+
[Symbol.asyncIterator]() {
|
|
1606
|
+
const iterator = p[Symbol.asyncIterator]();
|
|
1607
|
+
return {
|
|
1608
|
+
next: value => iterator.next(value).then(undefined, verdictNow),
|
|
1609
|
+
return: value => iterator.return ? iterator.return(value) : Promise.resolve({
|
|
1610
|
+
done: true,
|
|
1611
|
+
value
|
|
1612
|
+
}),
|
|
1613
|
+
throw: error => iterator.throw ? iterator.throw(error) : Promise.reject(error)
|
|
1614
|
+
};
|
|
1615
|
+
}
|
|
1616
|
+
};
|
|
1617
|
+
guardedChannels.set(p, guarded);
|
|
1618
|
+
}
|
|
1619
|
+
return guarded;
|
|
1620
|
+
};
|
|
1423
1621
|
const trackSerialized = (id, p) => {
|
|
1424
1622
|
let settle;
|
|
1425
1623
|
const raced = Promise.race([p, new Promise(r => settle = r)]);
|
|
@@ -1428,7 +1626,7 @@ function renderToStream(code, options = {}) {
|
|
|
1428
1626
|
p.then(drop, drop);
|
|
1429
1627
|
return raced;
|
|
1430
1628
|
};
|
|
1431
|
-
const abandonSubtree = key => {
|
|
1629
|
+
const abandonSubtree = (key, error) => {
|
|
1432
1630
|
for (const [k, entry] of registry) {
|
|
1433
1631
|
if (k.length > key.length && k.startsWith(key)) {
|
|
1434
1632
|
registry.delete(k);
|
|
@@ -1561,6 +1759,7 @@ function renderToStream(code, options = {}) {
|
|
|
1561
1759
|
},
|
|
1562
1760
|
serialize(id, p, deferStream) {
|
|
1563
1761
|
if (sharedConfig.context.noHydrate) return;
|
|
1762
|
+
p = guardChannel(p);
|
|
1564
1763
|
if (p && typeof p === "object" && typeof p.then === "function") {
|
|
1565
1764
|
if (!firstFlushed && deferStream) {
|
|
1566
1765
|
blockingPromises.add(p);
|
|
@@ -1603,7 +1802,7 @@ function renderToStream(code, options = {}) {
|
|
|
1603
1802
|
const p = new Promise((r, rej) => (resolve = r, reject = rej));
|
|
1604
1803
|
registry.set(key, {
|
|
1605
1804
|
resolve: err => queue(() => queue(() => {
|
|
1606
|
-
err ? reject(err) : resolve(true);
|
|
1805
|
+
err ? reject(ssrSanitizeError(err, null)) : resolve(true);
|
|
1607
1806
|
queue(flushEnd);
|
|
1608
1807
|
}))
|
|
1609
1808
|
});
|
|
@@ -1614,7 +1813,7 @@ function renderToStream(code, options = {}) {
|
|
|
1614
1813
|
const item = registry.get(key);
|
|
1615
1814
|
registry.delete(key);
|
|
1616
1815
|
if (error) abandonSubtree(key);
|
|
1617
|
-
if (item.children) {
|
|
1816
|
+
if (item.children && !error) {
|
|
1618
1817
|
for (const k in item.children) {
|
|
1619
1818
|
value = replacePlaceholder(value, k, item.children[k]);
|
|
1620
1819
|
}
|
|
@@ -1644,7 +1843,7 @@ function renderToStream(code, options = {}) {
|
|
|
1644
1843
|
sink.fragment(key, resolveSSRSelectValues(value !== undefined ? value : " "), {
|
|
1645
1844
|
styles,
|
|
1646
1845
|
revealGroup,
|
|
1647
|
-
error
|
|
1846
|
+
error: error ? ssrSanitizeError(error, null) : error
|
|
1648
1847
|
});
|
|
1649
1848
|
item.resolve(error);
|
|
1650
1849
|
}
|
|
@@ -1670,9 +1869,15 @@ function renderToStream(code, options = {}) {
|
|
|
1670
1869
|
};
|
|
1671
1870
|
applyAssetTracking(context, tracking, manifest, noScripts);
|
|
1672
1871
|
context.failRender = failRender;
|
|
1872
|
+
context.errorPolicy = options.onError;
|
|
1873
|
+
context.flushed = () => firstFlushed;
|
|
1874
|
+
context.trace = requestEvent ? traceForEvent(requestEvent) : traceFor(context, undefined);
|
|
1673
1875
|
registerEntryAssets(manifest);
|
|
1674
1876
|
let html = createRoot(d => {
|
|
1675
|
-
dispose =
|
|
1877
|
+
dispose = () => {
|
|
1878
|
+
context.trace = undefined;
|
|
1879
|
+
d();
|
|
1880
|
+
};
|
|
1676
1881
|
const res = resolveSSRNode(escape(code()));
|
|
1677
1882
|
if (!res.h.length) return res.t[0];
|
|
1678
1883
|
rootHoles = [];
|
|
@@ -1735,7 +1940,7 @@ function renderToStream(code, options = {}) {
|
|
|
1735
1940
|
}
|
|
1736
1941
|
serializeRootAssets();
|
|
1737
1942
|
flushStubBatch();
|
|
1738
|
-
const head = renderShellHead(headRegistry, nonce, k => registry.has(k), noScripts);
|
|
1943
|
+
const head = renderShellHead(headRegistry, nonce, k => registry.has(k), noScripts, traceMetaMarkup(context.trace));
|
|
1739
1944
|
sink.shell(resolveSSRSelectValues(html), {
|
|
1740
1945
|
preloads: tracking.emittedAssets,
|
|
1741
1946
|
preloadLinks: tracking.preloadLinks,
|
|
@@ -1790,7 +1995,7 @@ function renderToStream(code, options = {}) {
|
|
|
1790
1995
|
try {
|
|
1791
1996
|
doShell();
|
|
1792
1997
|
} catch (err) {
|
|
1793
|
-
|
|
1998
|
+
failRootRender(err);
|
|
1794
1999
|
return resolve();
|
|
1795
2000
|
}
|
|
1796
2001
|
if (!shellCompleted) return flush();
|
|
@@ -1831,7 +2036,9 @@ function renderToStream(code, options = {}) {
|
|
|
1831
2036
|
return {
|
|
1832
2037
|
then(onFulfilled, onRejected) {
|
|
1833
2038
|
const freezeHead = () => {
|
|
1834
|
-
if (requestEvent && requestEvent.response) commitResponseStub(requestEvent.response
|
|
2039
|
+
if (requestEvent && requestEvent.response) commitResponseStub(requestEvent.response, {
|
|
2040
|
+
event: requestEvent
|
|
2041
|
+
});
|
|
1835
2042
|
};
|
|
1836
2043
|
const p = new Promise(resolve => {
|
|
1837
2044
|
function complete() {
|
|
@@ -1852,7 +2059,7 @@ function renderToStream(code, options = {}) {
|
|
|
1852
2059
|
try {
|
|
1853
2060
|
if (blockingPromises.size !== lastBlockingSize || !resolveRootHoles() || blockingPromises.size !== lastBlockingSize || !headShellReady(headRegistry, p => blockingPromises.add(p))) return flush();
|
|
1854
2061
|
} catch (err) {
|
|
1855
|
-
|
|
2062
|
+
failRootRender(err);
|
|
1856
2063
|
return resolve(tmp);
|
|
1857
2064
|
}
|
|
1858
2065
|
queue(flushEnd);
|
|
@@ -1872,7 +2079,7 @@ function renderToStream(code, options = {}) {
|
|
|
1872
2079
|
try {
|
|
1873
2080
|
doShell();
|
|
1874
2081
|
} catch (err) {
|
|
1875
|
-
|
|
2082
|
+
failRootRender(err);
|
|
1876
2083
|
try {
|
|
1877
2084
|
w.end();
|
|
1878
2085
|
} catch (_) {}
|
|
@@ -2002,6 +2209,10 @@ function ssrGroupSlot(fn, idx) {
|
|
|
2002
2209
|
}
|
|
2003
2210
|
};
|
|
2004
2211
|
}
|
|
2212
|
+
function wireErrorMessage(err) {
|
|
2213
|
+
const wire = ssrSanitizeError(err, null);
|
|
2214
|
+
return String(wire && wire.message || wire);
|
|
2215
|
+
}
|
|
2005
2216
|
const holePositionCache = new WeakMap();
|
|
2006
2217
|
function holeContentPositions(t) {
|
|
2007
2218
|
let cached = holePositionCache.get(t);
|
|
@@ -2158,7 +2369,7 @@ function createLiveHoles(sink, scoped) {
|
|
|
2158
2369
|
} catch (err) {
|
|
2159
2370
|
b.closed = true;
|
|
2160
2371
|
sink.closeBinding(b.key);
|
|
2161
|
-
sink.error(b.key,
|
|
2372
|
+
sink.error(b.key, wireErrorMessage(err));
|
|
2162
2373
|
return;
|
|
2163
2374
|
} finally {
|
|
2164
2375
|
engine.sweeping = prevSweeping;
|
|
@@ -2303,7 +2514,7 @@ function createLiveHoles(sink, scoped) {
|
|
|
2303
2514
|
if (ssrHandleError(err, true)) return;
|
|
2304
2515
|
b.closed = true;
|
|
2305
2516
|
sink.closeBinding(b.key);
|
|
2306
|
-
sink.error("lha:" + cap.id,
|
|
2517
|
+
sink.error("lha:" + cap.id, wireErrorMessage(err));
|
|
2307
2518
|
return;
|
|
2308
2519
|
} finally {
|
|
2309
2520
|
engine.sweeping = prevSweeping;
|
|
@@ -2595,43 +2806,93 @@ function ssrStyle(value) {
|
|
|
2595
2806
|
function ssrStyleProperty(name, value) {
|
|
2596
2807
|
return value != null ? name + value : "";
|
|
2597
2808
|
}
|
|
2598
|
-
function ssrElement(tag, props, children, needsId) {
|
|
2809
|
+
function ssrElement(tag, props, children, needsId, skip) {
|
|
2599
2810
|
const hk = needsId ? ssrHydrationKey() : "";
|
|
2600
2811
|
if (typeof props === "function") props = props();
|
|
2601
|
-
|
|
2812
|
+
let sources = null;
|
|
2813
|
+
let kind = SOURCE_PLAIN;
|
|
2814
|
+
let viewKeys = null;
|
|
2815
|
+
let owners = null;
|
|
2816
|
+
if (Array.isArray(props)) {
|
|
2817
|
+
let i = 0;
|
|
2818
|
+
for (; i < props.length; i++) {
|
|
2819
|
+
const s = props[i];
|
|
2820
|
+
if (s == null || typeof s === "function" || $PROXY in s) break;
|
|
2821
|
+
}
|
|
2822
|
+
if (i === props.length) sources = props;else {
|
|
2823
|
+
viewKeys = [];
|
|
2824
|
+
owners = [];
|
|
2825
|
+
for (let i = 0; i < props.length; i++) {
|
|
2826
|
+
let s = props[i];
|
|
2827
|
+
if (typeof s === "function") s = s();
|
|
2828
|
+
if (s != null) sourceOwners(s, viewKeys, owners);
|
|
2829
|
+
}
|
|
2830
|
+
}
|
|
2831
|
+
} else if (props == null) {
|
|
2832
|
+
props = {};
|
|
2833
|
+
} else if ($PROXY in props) {
|
|
2834
|
+
if (viewOf(props) !== undefined) {
|
|
2835
|
+
viewKeys = [];
|
|
2836
|
+
owners = [];
|
|
2837
|
+
sourceOwners(props, viewKeys, owners);
|
|
2838
|
+
} else kind = SOURCE_PROXY;
|
|
2839
|
+
}
|
|
2602
2840
|
const skipChildren = VOID_ELEMENTS.test(tag);
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
if (
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2841
|
+
let result = `<${tag}${hk}`;
|
|
2842
|
+
const last = sources === null ? 0 : sources.length - 1;
|
|
2843
|
+
let keysOf = null;
|
|
2844
|
+
if (sources !== null) {
|
|
2845
|
+
keysOf = new Array(last + 1);
|
|
2846
|
+
for (let s = 0; s <= last; s++) keysOf[s] = Object.keys(sources[s]);
|
|
2847
|
+
}
|
|
2848
|
+
for (let s = 0; s <= last; s++) {
|
|
2849
|
+
const keys = owners !== null ? viewKeys : keysOf !== null ? keysOf[s] : sourceKeys(props, kind);
|
|
2850
|
+
if (sources !== null) props = sources[s];
|
|
2851
|
+
nextKey: for (let i = 0; i < keys.length; i++) {
|
|
2852
|
+
const prop = keys[i];
|
|
2853
|
+
if (typeof prop !== "string" || skip !== undefined && skip(prop)) continue;
|
|
2854
|
+
if (owners !== null) props = owners[i];
|
|
2855
|
+
for (let j = s + 1; j <= last; j++) {
|
|
2856
|
+
if (keysOf[j].includes(prop)) continue nextKey;
|
|
2857
|
+
}
|
|
2858
|
+
if (tag === "textarea" && (prop === "value" || prop === "defaultValue")) {
|
|
2859
|
+
const value = sourceGet(props, kind, prop);
|
|
2860
|
+
if (value !== null) children = escape(value);
|
|
2861
|
+
continue;
|
|
2862
|
+
}
|
|
2863
|
+
if (ChildProperties.has(prop)) {
|
|
2864
|
+
if (children === undefined && !skipChildren) children = tag === "script" || tag === "style" || prop === "innerHTML" ? sourceGet(props, kind, prop) : escape(sourceGet(props, kind, prop));
|
|
2865
|
+
continue;
|
|
2866
|
+
}
|
|
2867
|
+
const value = sourceGet(props, kind, prop);
|
|
2868
|
+
if (value == undefined || prop === "ref" || prop.slice(0, 2) === "on" || prop.slice(0, 5) === "prop:") {
|
|
2869
|
+
continue;
|
|
2870
|
+
} else if (prop === "style") {
|
|
2871
|
+
result += ` style="${ssrStyle(value)}"`;
|
|
2872
|
+
} else if (prop === "class") {
|
|
2873
|
+
result += ` class="${ssrClassName(value)}"`;
|
|
2874
|
+
} else if (typeof value === "boolean") {
|
|
2875
|
+
if (!value) continue;
|
|
2876
|
+
result += ` ${escape(prop)}`;
|
|
2877
|
+
} else {
|
|
2878
|
+
result += value === "" ? ` ${escape(prop)}` : ` ${escape(prop)}="${escape(value, true)}"`;
|
|
2879
|
+
}
|
|
2628
2880
|
}
|
|
2629
|
-
if (i !== keys.length - 1) result += " ";
|
|
2630
2881
|
}
|
|
2631
2882
|
if (skipChildren) return {
|
|
2632
|
-
t: result + "/>"
|
|
2883
|
+
t: result + " />"
|
|
2633
2884
|
};
|
|
2634
2885
|
if (typeof children === "function") children = children();
|
|
2886
|
+
const ct = typeof children;
|
|
2887
|
+
if (ct === "string" || ct === "number") return {
|
|
2888
|
+
t: result + ">" + children + "</" + tag + ">"
|
|
2889
|
+
};
|
|
2890
|
+
if (children == null || ct === "boolean") return {
|
|
2891
|
+
t: result + "></" + tag + ">"
|
|
2892
|
+
};
|
|
2893
|
+
if (ct === "object" && !children.h && typeof children.t === "string") return {
|
|
2894
|
+
t: result + ">" + children.t + "</" + tag + ">"
|
|
2895
|
+
};
|
|
2635
2896
|
return ssr([result + ">", `</${tag}>`], resolveSSRNode(children, undefined, true));
|
|
2636
2897
|
}
|
|
2637
2898
|
function ssrAttribute(key, value) {
|
|
@@ -3067,23 +3328,26 @@ function flattenClassList(list, result) {
|
|
|
3067
3328
|
else if (typeof item !== "boolean" && (item || item === 0)) result[item] = true;
|
|
3068
3329
|
}
|
|
3069
3330
|
}
|
|
3070
|
-
|
|
3331
|
+
let ssrTextTail = false;
|
|
3332
|
+
function tryResolveString(node, nested) {
|
|
3333
|
+
if (!nested) ssrTextTail = false;
|
|
3071
3334
|
const t = typeof node;
|
|
3072
|
-
if (t === "string")
|
|
3073
|
-
|
|
3335
|
+
if (t === "string" || t === "number") {
|
|
3336
|
+
const s = ssrTextTail ? "<!--!$-->" + node : "" + node;
|
|
3337
|
+
ssrTextTail = true;
|
|
3338
|
+
return s;
|
|
3339
|
+
}
|
|
3074
3340
|
if (node == null || t === "boolean") return "";
|
|
3075
3341
|
if (t === "object") {
|
|
3076
3342
|
if (Array.isArray(node)) {
|
|
3077
3343
|
const joined = tryJoinPlainSSRArray(node);
|
|
3078
|
-
if (joined !== undefined)
|
|
3344
|
+
if (joined !== undefined) {
|
|
3345
|
+
ssrTextTail = false;
|
|
3346
|
+
return joined;
|
|
3347
|
+
}
|
|
3079
3348
|
let s = "";
|
|
3080
|
-
let prevNonObj = false;
|
|
3081
3349
|
for (let i = 0, len = node.length; i < len; i++) {
|
|
3082
|
-
const
|
|
3083
|
-
const itemNonObj = item !== null && typeof item !== "object";
|
|
3084
|
-
if (prevNonObj && itemNonObj) s += "<!--!$-->";
|
|
3085
|
-
prevNonObj = itemNonObj;
|
|
3086
|
-
const r = tryResolveString(item);
|
|
3350
|
+
const r = tryResolveString(node[i], true);
|
|
3087
3351
|
if (typeof r !== "string") return {
|
|
3088
3352
|
bail: node
|
|
3089
3353
|
};
|
|
@@ -3097,6 +3361,7 @@ function tryResolveString(node) {
|
|
|
3097
3361
|
if (node.t === undefined) {
|
|
3098
3362
|
return "";
|
|
3099
3363
|
}
|
|
3364
|
+
ssrTextTail = false;
|
|
3100
3365
|
return Array.isArray(node.t) ? node.t[0] : node.t;
|
|
3101
3366
|
}
|
|
3102
3367
|
if (t === "function") {
|
|
@@ -3104,9 +3369,11 @@ function tryResolveString(node) {
|
|
|
3104
3369
|
try {
|
|
3105
3370
|
v = node();
|
|
3106
3371
|
} catch (err) {
|
|
3107
|
-
|
|
3372
|
+
const wrap = buildAsyncWrap(err, node);
|
|
3373
|
+
if (wrap) ssrTextTail = true;
|
|
3374
|
+
return wrap || "";
|
|
3108
3375
|
}
|
|
3109
|
-
return tryResolveString(v);
|
|
3376
|
+
return tryResolveString(v, true);
|
|
3110
3377
|
}
|
|
3111
3378
|
return "";
|
|
3112
3379
|
}
|
|
@@ -3114,21 +3381,19 @@ function resolveSSRNode(node, result = {
|
|
|
3114
3381
|
t: [""],
|
|
3115
3382
|
h: [],
|
|
3116
3383
|
p: []
|
|
3117
|
-
}, top) {
|
|
3384
|
+
}, top, nested) {
|
|
3385
|
+
if (!nested) ssrTextTail = false;
|
|
3118
3386
|
const t = typeof node;
|
|
3119
3387
|
if (t === "string" || t === "number") {
|
|
3120
|
-
result.t[result.t.length - 1] += node;
|
|
3388
|
+
result.t[result.t.length - 1] += ssrTextTail ? "<!--!$-->" + node : node;
|
|
3389
|
+
ssrTextTail = true;
|
|
3121
3390
|
} else if (node == null || t === "boolean") ; else if (Array.isArray(node)) {
|
|
3122
3391
|
const slotLive = node.$slot && sharedConfig.context && sharedConfig.context.liveHoles;
|
|
3123
3392
|
if (slotLive) slotLive.suppressed++;
|
|
3124
3393
|
try {
|
|
3125
|
-
let prevNonObj = false;
|
|
3126
3394
|
for (let i = 0, len = node.length; i < len; i++) {
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
if (!top && prevNonObj && itemNonObj) result.t[result.t.length - 1] += `<!--!$-->`;
|
|
3130
|
-
prevNonObj = itemNonObj;
|
|
3131
|
-
resolveSSRNode(item, result);
|
|
3395
|
+
if (top) ssrTextTail = false;
|
|
3396
|
+
resolveSSRNode(node[i], result, false, true);
|
|
3132
3397
|
}
|
|
3133
3398
|
} finally {
|
|
3134
3399
|
if (slotLive) slotLive.suppressed--;
|
|
@@ -3141,23 +3406,30 @@ function resolveSSRNode(node, result = {
|
|
|
3141
3406
|
result.h.push(...node.h);
|
|
3142
3407
|
result.p.push(...node.p);
|
|
3143
3408
|
}
|
|
3409
|
+
ssrTextTail = false;
|
|
3144
3410
|
} else if (node.t !== undefined) {
|
|
3145
3411
|
result.t[result.t.length - 1] += node.t;
|
|
3412
|
+
ssrTextTail = false;
|
|
3146
3413
|
} else ;
|
|
3147
3414
|
} else if (t === "function") {
|
|
3148
3415
|
const live = sharedConfig.context && sharedConfig.context.liveHoles;
|
|
3149
3416
|
let liveNode = null;
|
|
3150
3417
|
if (live && (liveNode = live.content(node)) !== null) {
|
|
3151
|
-
if (typeof liveNode === "string")
|
|
3418
|
+
if (typeof liveNode === "string") {
|
|
3419
|
+
result.t[result.t.length - 1] += ssrTextTail ? "<!--!$-->" + liveNode : liveNode;
|
|
3420
|
+
ssrTextTail = true;
|
|
3421
|
+
} else resolveSSRNode(liveNode, result, false, true);
|
|
3152
3422
|
} else {
|
|
3153
3423
|
try {
|
|
3154
|
-
resolveSSRNode(node(), result);
|
|
3424
|
+
resolveSSRNode(node(), result, false, true);
|
|
3155
3425
|
} catch (err) {
|
|
3156
3426
|
const wrap = buildAsyncWrap(err, node);
|
|
3157
3427
|
if (wrap) {
|
|
3428
|
+
if (ssrTextTail) result.t[result.t.length - 1] += "<!--!$-->";
|
|
3158
3429
|
result.h.push(wrap.fn);
|
|
3159
3430
|
result.p.push(wrap.p);
|
|
3160
3431
|
result.t.push("");
|
|
3432
|
+
ssrTextTail = true;
|
|
3161
3433
|
}
|
|
3162
3434
|
}
|
|
3163
3435
|
}
|
|
@@ -3170,6 +3442,26 @@ function resolveSSRSync(node) {
|
|
|
3170
3442
|
throw new Error("This value cannot be rendered synchronously. Are you missing a boundary?");
|
|
3171
3443
|
}
|
|
3172
3444
|
const RequestContext = Symbol.for("solid.RequestContext");
|
|
3445
|
+
const ServerErrors = Symbol.for("solid-js/server/errors");
|
|
3446
|
+
function serializerErrorHook(hook) {
|
|
3447
|
+
return hook === undefined ? undefined : err => {
|
|
3448
|
+
reportServerError(err, {
|
|
3449
|
+
kind: "render",
|
|
3450
|
+
handling: "serialize"
|
|
3451
|
+
}, null);
|
|
3452
|
+
};
|
|
3453
|
+
}
|
|
3454
|
+
function ambientServerErrorHook() {
|
|
3455
|
+
const slot = globalThis[ServerErrors];
|
|
3456
|
+
return slot === undefined ? undefined : slot.hook;
|
|
3457
|
+
}
|
|
3458
|
+
function configureServerErrors(config) {
|
|
3459
|
+
const g = globalThis;
|
|
3460
|
+
if (config && config.onError !== undefined && typeof config.onError !== "function") {
|
|
3461
|
+
throw new TypeError(`Invalid onError: expected a function, received ${typeof config.onError}.`);
|
|
3462
|
+
}
|
|
3463
|
+
(g[ServerErrors] ||= {}).hook = config ? config.onError : undefined;
|
|
3464
|
+
}
|
|
3173
3465
|
function getRequestEvent() {
|
|
3174
3466
|
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;
|
|
3175
3467
|
}
|
|
@@ -3177,6 +3469,22 @@ function peekRequestEvent() {
|
|
|
3177
3469
|
const store = globalThis[RequestContext];
|
|
3178
3470
|
return store ? store.getStore() : undefined;
|
|
3179
3471
|
}
|
|
3472
|
+
function traceForEvent(event) {
|
|
3473
|
+
return traceFor(event.request || event, event.request);
|
|
3474
|
+
}
|
|
3475
|
+
function getTraceContext() {
|
|
3476
|
+
const event = peekRequestEvent();
|
|
3477
|
+
if (event) return traceForEvent(event).context;
|
|
3478
|
+
const ctx = sharedConfig.context;
|
|
3479
|
+
return ctx && ctx.trace ? ctx.trace.context : undefined;
|
|
3480
|
+
}
|
|
3481
|
+
function traceForStub(stub, event) {
|
|
3482
|
+
if (!event) {
|
|
3483
|
+
event = peekRequestEvent();
|
|
3484
|
+
if (!event || event.response !== stub) return undefined;
|
|
3485
|
+
}
|
|
3486
|
+
return traceForEvent(event);
|
|
3487
|
+
}
|
|
3180
3488
|
function createResponseStub() {
|
|
3181
3489
|
return {
|
|
3182
3490
|
status: undefined,
|
|
@@ -3194,15 +3502,20 @@ function createRequestEvent(request, init) {
|
|
|
3194
3502
|
};
|
|
3195
3503
|
}
|
|
3196
3504
|
function reportLostHeaderWrite(method, name) {
|
|
3197
|
-
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).";
|
|
3505
|
+
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).";
|
|
3198
3506
|
console.error(message);
|
|
3199
3507
|
}
|
|
3200
3508
|
function commitResponseStub(stub, {
|
|
3201
|
-
allowLateLocation = false
|
|
3509
|
+
allowLateLocation = false,
|
|
3510
|
+
event
|
|
3202
3511
|
} = {}) {
|
|
3203
3512
|
if (!stub || stub.committed) return stub;
|
|
3204
|
-
stub.committed = true;
|
|
3205
3513
|
const headers = stub.headers;
|
|
3514
|
+
if (headers && typeof headers.append === "function") {
|
|
3515
|
+
const trace = traceForStub(stub, event);
|
|
3516
|
+
if (trace) appendTraceServerTiming(headers, trace);
|
|
3517
|
+
}
|
|
3518
|
+
stub.committed = true;
|
|
3206
3519
|
if (!headers || typeof headers.set !== "function") return stub;
|
|
3207
3520
|
for (const method of ["set", "append", "delete"]) {
|
|
3208
3521
|
const original = headers[method].bind(headers);
|
|
@@ -3223,7 +3536,7 @@ function getExpectedRedirectStatus(response) {
|
|
|
3223
3536
|
function mergeStubHeaders(target, stub) {
|
|
3224
3537
|
if (!stub) return target;
|
|
3225
3538
|
stub.headers.forEach((value, key) => {
|
|
3226
|
-
if (key !== "set-cookie") target.set(key, value);
|
|
3539
|
+
if (key === "server-timing") mergeServerTiming(target, value);else if (key !== "set-cookie") target.set(key, value);
|
|
3227
3540
|
});
|
|
3228
3541
|
const setCookies = stub.headers.getSetCookie ? stub.headers.getSetCookie() : [];
|
|
3229
3542
|
for (const cookie of setCookies) target.append("set-cookie", cookie);
|
|
@@ -3247,19 +3560,35 @@ function fillsStubGap(key, headers, response) {
|
|
|
3247
3560
|
}
|
|
3248
3561
|
function commitEventResponse(response, event = getRequestEvent()) {
|
|
3249
3562
|
const stub = event && event.response;
|
|
3250
|
-
if (!stub || !stub.headers || stub.committed)
|
|
3563
|
+
if (!stub || !stub.headers || stub.committed) {
|
|
3564
|
+
if (!event || stub) return response;
|
|
3565
|
+
const trace = traceForEvent(event);
|
|
3566
|
+
if (!trace.emit) return response;
|
|
3567
|
+
const headers = copyInitHeaders(response.headers);
|
|
3568
|
+
appendTraceServerTiming(headers, trace);
|
|
3569
|
+
return new Response(response.body, {
|
|
3570
|
+
status: response.status,
|
|
3571
|
+
statusText: response.statusText,
|
|
3572
|
+
headers
|
|
3573
|
+
});
|
|
3574
|
+
}
|
|
3251
3575
|
const cookies = stub.headers.getSetCookie ? stub.headers.getSetCookie() : [];
|
|
3252
|
-
commitResponseStub(stub
|
|
3576
|
+
commitResponseStub(stub, {
|
|
3577
|
+
event
|
|
3578
|
+
});
|
|
3253
3579
|
let hasGaps = false;
|
|
3254
3580
|
stub.headers.forEach((value, key) => {
|
|
3255
3581
|
if (fillsStubGap(key, response.headers, response)) hasGaps = true;
|
|
3256
3582
|
});
|
|
3257
|
-
|
|
3583
|
+
const timing = stub.headers.get("server-timing");
|
|
3584
|
+
const mergesTiming = timing !== null && response.headers.has("server-timing");
|
|
3585
|
+
if (!cookies.length && !hasGaps && !mergesTiming) return response;
|
|
3258
3586
|
const headers = copyInitHeaders(response.headers);
|
|
3259
3587
|
for (const cookie of cookies) headers.append("Set-Cookie", cookie);
|
|
3260
3588
|
stub.headers.forEach((value, key) => {
|
|
3261
3589
|
if (fillsStubGap(key, headers, response)) headers.set(key, value);
|
|
3262
3590
|
});
|
|
3591
|
+
if (mergesTiming) mergeServerTiming(headers, timing);
|
|
3263
3592
|
return new Response(response.body, {
|
|
3264
3593
|
status: response.status,
|
|
3265
3594
|
statusText: response.statusText,
|
|
@@ -3285,7 +3614,9 @@ function createSSRResponse(result, event, options = {}) {
|
|
|
3285
3614
|
} = options;
|
|
3286
3615
|
const nonce = normalizeNonce(options.nonce);
|
|
3287
3616
|
if (typeof result === "string") {
|
|
3288
|
-
if (stub) commitResponseStub(stub
|
|
3617
|
+
if (stub) commitResponseStub(stub, {
|
|
3618
|
+
event
|
|
3619
|
+
});
|
|
3289
3620
|
const head = deriveHead(stub, responseInit);
|
|
3290
3621
|
if (stub && stub.headers.get("Location")) {
|
|
3291
3622
|
return new Response(null, {
|
|
@@ -3320,7 +3651,8 @@ function createSSRResponse(result, event, options = {}) {
|
|
|
3320
3651
|
if (!flushed) {
|
|
3321
3652
|
flushed = true;
|
|
3322
3653
|
if (stub) commitResponseStub(stub, {
|
|
3323
|
-
allowLateLocation: true
|
|
3654
|
+
allowLateLocation: true,
|
|
3655
|
+
event
|
|
3324
3656
|
});
|
|
3325
3657
|
const head = deriveHead(stub, responseInit);
|
|
3326
3658
|
if (stub && stub.headers.get("Location")) {
|
|
@@ -3394,6 +3726,12 @@ setContainerTraceResolver(getProjectionTrace);
|
|
|
3394
3726
|
const isServer = true;
|
|
3395
3727
|
const isDev = false;
|
|
3396
3728
|
function dynamic(source, options) {
|
|
3729
|
+
if (options?.static) {
|
|
3730
|
+
const component = untrack(source);
|
|
3731
|
+
if (typeof component === "function") return props => component(props);
|
|
3732
|
+
if (typeof component === "string") return props => ssrElement(component, props, undefined, true);
|
|
3733
|
+
return () => undefined;
|
|
3734
|
+
}
|
|
3397
3735
|
const cached = createMemo(source, {
|
|
3398
3736
|
serialize: false
|
|
3399
3737
|
});
|
|
@@ -3551,4 +3889,4 @@ function httpHeader(name, value, options) {
|
|
|
3551
3889
|
}
|
|
3552
3890
|
}
|
|
3553
3891
|
|
|
3554
|
-
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, 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 };
|
|
3892
|
+
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 };
|