@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
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var web = require('seroval-plugins/web');
|
|
1
|
+
import { reportServerError, ssrHandleError, ssrSanitizeError, inServerComponentScope, creationStamp, runInServerComponentScope, getProjectionTrace } from 'solid-js/internal';
|
|
2
|
+
import { OBSERVE, getOwner, sharedConfig, createRoot, runWithOwner, NoHydration, createMemo, Hydration, createOwner } from 'solid-js';
|
|
3
|
+
import { Feature, createStream, toCrossJSONStream, Serializer, getCrossReferenceHeader } from 'seroval';
|
|
4
|
+
import { AbortSignalPlugin, CustomEventPlugin, DOMExceptionPlugin, EventPlugin, FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin } from 'seroval-plugins/web';
|
|
6
5
|
|
|
7
6
|
const STATE = Symbol.for("solid.container-trace-state");
|
|
8
7
|
const state = globalThis[STATE] || (globalThis[STATE] = {
|
|
@@ -103,8 +102,169 @@ const ContainerTracePlugin = {
|
|
|
103
102
|
|
|
104
103
|
const COMPOSED_BODY_FRAMING = /*#__PURE__*/new Set(["content-length", "content-encoding", "transfer-encoding"]);
|
|
105
104
|
|
|
105
|
+
const PROVIDER = Symbol.for("solid-js/observe/server/provider");
|
|
106
|
+
function currentProvider() {
|
|
107
|
+
if (OBSERVE === undefined) return undefined;
|
|
108
|
+
const slot = OBSERVE.server.trace;
|
|
109
|
+
return slot && slot[PROVIDER];
|
|
110
|
+
}
|
|
111
|
+
const TRACEPARENT = /^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})(-.*)?$/;
|
|
112
|
+
const ZERO_TRACE = "00000000000000000000000000000000";
|
|
113
|
+
const ZERO_SPAN = "0000000000000000";
|
|
114
|
+
function parseTraceparent(value) {
|
|
115
|
+
if (!value) return undefined;
|
|
116
|
+
const m = TRACEPARENT.exec(value.trim());
|
|
117
|
+
if (!m) return undefined;
|
|
118
|
+
const [, version, traceId, parentId, flags, rest] = m;
|
|
119
|
+
if (version === "ff") return undefined;
|
|
120
|
+
if (version === "00" && rest !== undefined) return undefined;
|
|
121
|
+
if (traceId === ZERO_TRACE || parentId === ZERO_SPAN) return undefined;
|
|
122
|
+
return {
|
|
123
|
+
traceId,
|
|
124
|
+
parentId,
|
|
125
|
+
sampled: (parseInt(flags, 16) & 1) === 1
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function randomHex(bytes) {
|
|
129
|
+
const buffer = new Uint8Array(bytes);
|
|
130
|
+
crypto.getRandomValues(buffer);
|
|
131
|
+
let out = "";
|
|
132
|
+
for (let i = 0; i < buffer.length; i++) out += (buffer[i] < 16 ? "0" : "") + buffer[i].toString(16);
|
|
133
|
+
return out;
|
|
134
|
+
}
|
|
135
|
+
function randomTraceId() {
|
|
136
|
+
let id = randomHex(16);
|
|
137
|
+
while (id === ZERO_TRACE) id = randomHex(16);
|
|
138
|
+
return id;
|
|
139
|
+
}
|
|
140
|
+
function randomSpanId() {
|
|
141
|
+
let id = randomHex(8);
|
|
142
|
+
while (id === ZERO_SPAN) id = randomHex(8);
|
|
143
|
+
return id;
|
|
144
|
+
}
|
|
145
|
+
function formatTraceparent(context) {
|
|
146
|
+
return `00-${context.traceId}-${context.spanId}-${context.sampled === true ? "01" : "00"}`;
|
|
147
|
+
}
|
|
148
|
+
const RECORDS_KEY = Symbol.for("@solidjs/web/trace/records");
|
|
149
|
+
function records$1() {
|
|
150
|
+
const g = globalThis;
|
|
151
|
+
return g[RECORDS_KEY] || (g[RECORDS_KEY] = new WeakMap());
|
|
152
|
+
}
|
|
153
|
+
function traceFor(key, request) {
|
|
154
|
+
const store = records$1();
|
|
155
|
+
let record = store.get(key);
|
|
156
|
+
if (record) return record;
|
|
157
|
+
const headers = request ? request.headers : undefined;
|
|
158
|
+
const incoming = headers ? parseTraceparent(headers.get("traceparent")) : undefined;
|
|
159
|
+
const context = {
|
|
160
|
+
traceId: incoming ? incoming.traceId : randomTraceId(),
|
|
161
|
+
spanId: randomSpanId(),
|
|
162
|
+
entries: {}
|
|
163
|
+
};
|
|
164
|
+
if (incoming) {
|
|
165
|
+
context.parentId = incoming.parentId;
|
|
166
|
+
context.sampled = incoming.sampled;
|
|
167
|
+
}
|
|
168
|
+
if (headers) {
|
|
169
|
+
const state = headers.get("tracestate");
|
|
170
|
+
if (state) context.state = state;
|
|
171
|
+
const baggage = headers.get("baggage");
|
|
172
|
+
if (baggage) context.baggage = baggage;
|
|
173
|
+
}
|
|
174
|
+
let answered = false;
|
|
175
|
+
let providedEntries;
|
|
176
|
+
{
|
|
177
|
+
const provider = currentProvider();
|
|
178
|
+
if (provider) {
|
|
179
|
+
let answer;
|
|
180
|
+
try {
|
|
181
|
+
answer = provider(request);
|
|
182
|
+
} catch (error) {
|
|
183
|
+
console.error(error);
|
|
184
|
+
}
|
|
185
|
+
if (answer !== undefined && answer !== null) {
|
|
186
|
+
answered = true;
|
|
187
|
+
if (answer.traceId !== undefined) context.traceId = answer.traceId;
|
|
188
|
+
if (answer.spanId !== undefined) context.spanId = answer.spanId;
|
|
189
|
+
if (answer.parentId !== undefined) context.parentId = answer.parentId;
|
|
190
|
+
if (answer.sampled !== undefined) context.sampled = answer.sampled;
|
|
191
|
+
if (answer.state !== undefined) context.state = answer.state;
|
|
192
|
+
if (answer.baggage !== undefined) context.baggage = answer.baggage;
|
|
193
|
+
providedEntries = answer.entries;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
context.entries.traceparent = formatTraceparent(context);
|
|
198
|
+
if (providedEntries) Object.assign(context.entries, providedEntries);
|
|
199
|
+
record = {
|
|
200
|
+
context,
|
|
201
|
+
emit: incoming !== undefined && incoming.sampled || answered
|
|
202
|
+
};
|
|
203
|
+
store.set(key, record);
|
|
204
|
+
return record;
|
|
205
|
+
}
|
|
206
|
+
const TOKEN = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
|
|
207
|
+
function splitServerTiming(value) {
|
|
208
|
+
const entries = [];
|
|
209
|
+
let start = 0;
|
|
210
|
+
let quoted = false;
|
|
211
|
+
for (let i = 0; i < value.length; i++) {
|
|
212
|
+
const c = value[i];
|
|
213
|
+
if (quoted) {
|
|
214
|
+
if (c === "\\") i++;else if (c === '"') quoted = false;
|
|
215
|
+
} else if (c === '"') quoted = true;else if (c === ",") {
|
|
216
|
+
entries.push(value.slice(start, i));
|
|
217
|
+
start = i + 1;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
entries.push(value.slice(start));
|
|
221
|
+
return entries;
|
|
222
|
+
}
|
|
223
|
+
function metricName(entry) {
|
|
224
|
+
return entry.split(";")[0].trim().toLowerCase();
|
|
225
|
+
}
|
|
226
|
+
function namesOnServerTiming(headers) {
|
|
227
|
+
const names = new Set();
|
|
228
|
+
const existing = headers.get("server-timing");
|
|
229
|
+
if (existing) {
|
|
230
|
+
for (const entry of splitServerTiming(existing)) {
|
|
231
|
+
const name = metricName(entry);
|
|
232
|
+
if (name) names.add(name);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return names;
|
|
236
|
+
}
|
|
237
|
+
function quoteDesc(value) {
|
|
238
|
+
return value.replace(/[\x00-\x1f\x7f]/g, "").replace(/[\\"]/g, m => "\\" + m);
|
|
239
|
+
}
|
|
240
|
+
function appendTraceServerTiming(headers, record) {
|
|
241
|
+
if (!record.emit) return;
|
|
242
|
+
const entries = record.context.entries;
|
|
243
|
+
let present;
|
|
244
|
+
for (const name in entries) {
|
|
245
|
+
if (!TOKEN.test(name)) continue;
|
|
246
|
+
if (!present) present = namesOnServerTiming(headers);
|
|
247
|
+
if (present.has(name.toLowerCase())) continue;
|
|
248
|
+
headers.append("Server-Timing", `${name};desc="${quoteDesc(entries[name])}"`);
|
|
249
|
+
present.add(name.toLowerCase());
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
function escapeAttr(value) {
|
|
253
|
+
return value.replace(/[&"<>]/g, c => c === "&" ? "&" : c === '"' ? """ : c === "<" ? "<" : ">");
|
|
254
|
+
}
|
|
255
|
+
function traceMetaMarkup(record) {
|
|
256
|
+
if (!record.emit) return "";
|
|
257
|
+
let markup = "";
|
|
258
|
+
const entries = record.context.entries;
|
|
259
|
+
for (const name in entries) {
|
|
260
|
+
if (!TOKEN.test(name)) continue;
|
|
261
|
+
markup += `<meta name="${name}" content="${escapeAttr(entries[name])}">`;
|
|
262
|
+
}
|
|
263
|
+
return markup;
|
|
264
|
+
}
|
|
265
|
+
|
|
106
266
|
setContainerTraceStreamMint(iterable => {
|
|
107
|
-
const stream =
|
|
267
|
+
const stream = createStream();
|
|
108
268
|
(async () => {
|
|
109
269
|
try {
|
|
110
270
|
for await (const value of iterable) stream.next(value);
|
|
@@ -115,14 +275,14 @@ setContainerTraceStreamMint(iterable => {
|
|
|
115
275
|
})();
|
|
116
276
|
return stream;
|
|
117
277
|
});
|
|
118
|
-
const DEFAULT_WEB_PLUGINS = Object.freeze([
|
|
119
|
-
|
|
120
|
-
|
|
278
|
+
const DEFAULT_WEB_PLUGINS = Object.freeze([AbortSignalPlugin,
|
|
279
|
+
CustomEventPlugin, DOMExceptionPlugin, EventPlugin,
|
|
280
|
+
FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin,
|
|
121
281
|
ContainerTracePlugin]);
|
|
122
282
|
function resolveSerializerPlugins(customPlugins) {
|
|
123
283
|
return customPlugins ? [...customPlugins, ...DEFAULT_WEB_PLUGINS] : [...DEFAULT_WEB_PLUGINS];
|
|
124
284
|
}
|
|
125
|
-
const JSON_CODEC_DISABLED_FEATURES =
|
|
285
|
+
const JSON_CODEC_DISABLED_FEATURES = Feature.RegExp;
|
|
126
286
|
const JSON_CODEC_DEPTH_LIMIT = 64;
|
|
127
287
|
function resolveCodecOptions({
|
|
128
288
|
plugins,
|
|
@@ -138,11 +298,11 @@ function resolveCodecOptions({
|
|
|
138
298
|
};
|
|
139
299
|
}
|
|
140
300
|
|
|
141
|
-
const DEFAULT_DISABLED_FEATURES =
|
|
142
|
-
const serializeOnlyDisabledFeatures = serializeErrorStacks => (serializeErrorStacks === undefined ? process.env.NODE_ENV === "development" : serializeErrorStacks) ? 0 :
|
|
301
|
+
const DEFAULT_DISABLED_FEATURES = Feature.AggregateError | Feature.BigIntTypedArray;
|
|
302
|
+
const serializeOnlyDisabledFeatures = serializeErrorStacks => (serializeErrorStacks === undefined ? process.env.NODE_ENV === "development" : serializeErrorStacks) ? 0 : Feature.ErrorPrototypeStack;
|
|
143
303
|
const HYDRATION_GLOBAL = "_$HY.r";
|
|
144
304
|
function createSerializer(options) {
|
|
145
|
-
return new
|
|
305
|
+
return new Serializer({
|
|
146
306
|
...options,
|
|
147
307
|
plugins: resolveSerializerPlugins(options.plugins),
|
|
148
308
|
disabledFeatures: (options.disabledFeatures === undefined ? DEFAULT_DISABLED_FEATURES : options.disabledFeatures) | serializeOnlyDisabledFeatures(options.serializeErrorStacks)
|
|
@@ -165,7 +325,7 @@ function createHydrationSerializer({
|
|
|
165
325
|
});
|
|
166
326
|
}
|
|
167
327
|
function getLocalHeaderScript(id) {
|
|
168
|
-
return
|
|
328
|
+
return getCrossReferenceHeader(id) + ";";
|
|
169
329
|
}
|
|
170
330
|
function createJSONSerializer({
|
|
171
331
|
onData,
|
|
@@ -199,7 +359,7 @@ function createJSONSerializer({
|
|
|
199
359
|
pendingWrites++;
|
|
200
360
|
let settled = false;
|
|
201
361
|
let cancel = null;
|
|
202
|
-
const stream =
|
|
362
|
+
const stream = toCrossJSONStream(value, {
|
|
203
363
|
refs,
|
|
204
364
|
plugins: resolved.plugins,
|
|
205
365
|
disabledFeatures: resolved.disabledFeatures | serializeOnlyDisabledFeatures(resolved.serializeErrorStacks),
|
|
@@ -408,6 +568,18 @@ function serializeStream(value, codecOptions) {
|
|
|
408
568
|
});
|
|
409
569
|
}
|
|
410
570
|
|
|
571
|
+
function emitFinding(finding, subject = getOwner()) {
|
|
572
|
+
if (OBSERVE === undefined) return;
|
|
573
|
+
OBSERVE.diagnostics.emit(finding, subject);
|
|
574
|
+
}
|
|
575
|
+
function recordFinding(finding, subject = getOwner()) {
|
|
576
|
+
if (OBSERVE !== undefined) OBSERVE.diagnostics.emit(finding, subject);
|
|
577
|
+
}
|
|
578
|
+
function errorText(error) {
|
|
579
|
+
if (error instanceof Error) return error.message ? `${error.name}: ${error.message}` : error.name;
|
|
580
|
+
return String(error);
|
|
581
|
+
}
|
|
582
|
+
|
|
411
583
|
const HEAD_ELIGIBLE_TAGS = new Set(["title", "meta", "link", "style", "script", "base"]);
|
|
412
584
|
const HEAD_ATTR_NAME = /^[a-zA-Z_][a-zA-Z0-9_:.-]*$/;
|
|
413
585
|
const RESOURCE_LINK_RELS = new Set(["preload", "modulepreload", "prefetch", "preconnect", "dns-prefetch", "stylesheet"]);
|
|
@@ -559,7 +731,7 @@ function resolveAssets(moduleUrl, manifest) {
|
|
|
559
731
|
}
|
|
560
732
|
function registerEntryAssets(manifest) {
|
|
561
733
|
if (!manifest || typeof manifest === "function" || typeof manifest.resolve === "function") return;
|
|
562
|
-
const ctx =
|
|
734
|
+
const ctx = sharedConfig.context;
|
|
563
735
|
if (!ctx?.registerAsset) return;
|
|
564
736
|
for (const key in manifest) {
|
|
565
737
|
if (manifest[key].isEntry) {
|
|
@@ -776,7 +948,7 @@ function registerHeadTags(registry, context, tracking, emitResource, nonce, tags
|
|
|
776
948
|
return;
|
|
777
949
|
}
|
|
778
950
|
if (!Array.isArray(tags)) tags = [tags];
|
|
779
|
-
const probe =
|
|
951
|
+
const probe = sharedConfig.context && sharedConfig.context._loadingPhase;
|
|
780
952
|
let replaceable = null;
|
|
781
953
|
for (let i = 0; i < tags.length; i++) {
|
|
782
954
|
const desc = tags[i];
|
|
@@ -791,7 +963,7 @@ function registerHeadTags(registry, context, tracking, emitResource, nonce, tags
|
|
|
791
963
|
} : undefined);
|
|
792
964
|
evalHeadValue(desc.key);
|
|
793
965
|
} catch (err) {
|
|
794
|
-
if (
|
|
966
|
+
if (ssrHandleError(err)) throw err;
|
|
795
967
|
}
|
|
796
968
|
}
|
|
797
969
|
if (cls.resource) {
|
|
@@ -813,7 +985,7 @@ function registerHeadTags(registry, context, tracking, emitResource, nonce, tags
|
|
|
813
985
|
function headShellReady(registry, block) {
|
|
814
986
|
let ready = true;
|
|
815
987
|
const pends = err => {
|
|
816
|
-
const source =
|
|
988
|
+
const source = ssrHandleError(err, true);
|
|
817
989
|
if (!source) return false;
|
|
818
990
|
block(source);
|
|
819
991
|
ready = false;
|
|
@@ -862,9 +1034,9 @@ function emitHeadResource(registry, context, tracking, emitResource, nonce, desc
|
|
|
862
1034
|
rel
|
|
863
1035
|
} : undefined);
|
|
864
1036
|
} catch (err) {
|
|
865
|
-
const loadingPhase =
|
|
866
|
-
if (loadingPhase &&
|
|
867
|
-
if (!loadingPhase && !context._currentBoundaryId && !registry.shellFlushed && typeof context.block === "function" &&
|
|
1037
|
+
const loadingPhase = sharedConfig.context && sharedConfig.context._loadingPhase;
|
|
1038
|
+
if (loadingPhase && ssrHandleError(err)) throw err;
|
|
1039
|
+
if (!loadingPhase && !context._currentBoundaryId && !registry.shellFlushed && typeof context.block === "function" && ssrHandleError(err, true)) {
|
|
868
1040
|
registry.parkedResources.push({
|
|
869
1041
|
desc,
|
|
870
1042
|
rel,
|
|
@@ -1002,7 +1174,7 @@ function headGroupSignature(winner) {
|
|
|
1002
1174
|
}
|
|
1003
1175
|
return sig;
|
|
1004
1176
|
}
|
|
1005
|
-
function renderShellHead(registry, nonce, isPendingFragment, noScripts) {
|
|
1177
|
+
function renderShellHead(registry, nonce, isPendingFragment, noScripts, traceMetas = "") {
|
|
1006
1178
|
commitHeadBoundary(registry, "", isPendingFragment);
|
|
1007
1179
|
registry.shellFlushed = true;
|
|
1008
1180
|
const winners = resolveHead(registry.committed);
|
|
@@ -1028,7 +1200,7 @@ function renderShellHead(registry, nonce, isPendingFragment, noScripts) {
|
|
|
1028
1200
|
}
|
|
1029
1201
|
return {
|
|
1030
1202
|
prelude,
|
|
1031
|
-
html: registry.eagerHtml + links + metas + others + scripts,
|
|
1203
|
+
html: registry.eagerHtml + links + metas + traceMetas + others + scripts,
|
|
1032
1204
|
title,
|
|
1033
1205
|
noScripts
|
|
1034
1206
|
};
|
|
@@ -1179,8 +1351,19 @@ function renderToStream(code, options = {}) {
|
|
|
1179
1351
|
const requestEvent = peekRequestEvent();
|
|
1180
1352
|
let dispose;
|
|
1181
1353
|
let dead = false;
|
|
1182
|
-
const abandon =
|
|
1354
|
+
const abandon = disconnect => {
|
|
1183
1355
|
if (dead) return;
|
|
1356
|
+
if (disconnect) emitFinding({
|
|
1357
|
+
code: "SSR_STREAM_ABANDONED",
|
|
1358
|
+
kind: "ssr",
|
|
1359
|
+
severity: "warn",
|
|
1360
|
+
message: `[SSR_STREAM_ABANDONED] The response stream was abandoned mid-render (${disconnect}) ` + `with ${registry.size} fragment(s) still pending; the render was torn down.`,
|
|
1361
|
+
data: {
|
|
1362
|
+
reason: disconnect,
|
|
1363
|
+
shellFlushed: firstFlushed,
|
|
1364
|
+
pendingFragments: registry.size
|
|
1365
|
+
}
|
|
1366
|
+
}, null);
|
|
1184
1367
|
dead = true;
|
|
1185
1368
|
completed = true;
|
|
1186
1369
|
buffer = {
|
|
@@ -1196,11 +1379,26 @@ function renderToStream(code, options = {}) {
|
|
|
1196
1379
|
}
|
|
1197
1380
|
};
|
|
1198
1381
|
const failRender = err => {
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1382
|
+
reportServerError(err, {
|
|
1383
|
+
kind: "render",
|
|
1384
|
+
handling: "failed"
|
|
1385
|
+
}, null);
|
|
1386
|
+
if (!options.onError && ambientServerErrorHook() === undefined) console.error(err);
|
|
1202
1387
|
abandon();
|
|
1203
1388
|
};
|
|
1389
|
+
const failRootRender = err => {
|
|
1390
|
+
emitFinding({
|
|
1391
|
+
code: "SSR_RENDER_ERROR_CONTAINED",
|
|
1392
|
+
kind: "ssr",
|
|
1393
|
+
severity: "error",
|
|
1394
|
+
message: `[SSR_RENDER_ERROR_CONTAINED] Render error outside any boundary — the request failed: ` + errorText(err),
|
|
1395
|
+
data: {
|
|
1396
|
+
handling: "failed",
|
|
1397
|
+
error: err
|
|
1398
|
+
}
|
|
1399
|
+
}, null);
|
|
1400
|
+
failRender(err);
|
|
1401
|
+
};
|
|
1204
1402
|
const coalesceWrites = (writeRaw, endRaw) => {
|
|
1205
1403
|
let buf = "";
|
|
1206
1404
|
let scheduled = false;
|
|
@@ -1233,7 +1431,7 @@ function renderToStream(code, options = {}) {
|
|
|
1233
1431
|
try {
|
|
1234
1432
|
w.write(payload);
|
|
1235
1433
|
} catch (_) {
|
|
1236
|
-
abandon();
|
|
1434
|
+
abandon("sink");
|
|
1237
1435
|
}
|
|
1238
1436
|
},
|
|
1239
1437
|
end() {
|
|
@@ -1241,7 +1439,7 @@ function renderToStream(code, options = {}) {
|
|
|
1241
1439
|
try {
|
|
1242
1440
|
w.end();
|
|
1243
1441
|
} catch (_) {
|
|
1244
|
-
abandon();
|
|
1442
|
+
abandon("sink");
|
|
1245
1443
|
}
|
|
1246
1444
|
}
|
|
1247
1445
|
});
|
|
@@ -1338,7 +1536,7 @@ function renderToStream(code, options = {}) {
|
|
|
1338
1536
|
plugins: options.plugins,
|
|
1339
1537
|
onData: payload => sink.data(payload),
|
|
1340
1538
|
onDone,
|
|
1341
|
-
onError: options.onError
|
|
1539
|
+
onError: serializerErrorHook(options.onError)
|
|
1342
1540
|
});
|
|
1343
1541
|
let rootAssetsSerialized = false;
|
|
1344
1542
|
const serializeRootAssets = () => {
|
|
@@ -1363,6 +1561,34 @@ function renderToStream(code, options = {}) {
|
|
|
1363
1561
|
};
|
|
1364
1562
|
const registry = new Map();
|
|
1365
1563
|
const pendingSerialized = new Map();
|
|
1564
|
+
const guardedChannels = new WeakMap();
|
|
1565
|
+
const verdictNow = error => {
|
|
1566
|
+
throw ssrSanitizeError(error, null);
|
|
1567
|
+
};
|
|
1568
|
+
const guardChannel = p => {
|
|
1569
|
+
if (!p || typeof p !== "object" || "__SEROVAL_STREAM__" in p) return p;
|
|
1570
|
+
const thenable = typeof p.then === "function";
|
|
1571
|
+
const iterable = !thenable && typeof p[Symbol.asyncIterator] === "function";
|
|
1572
|
+
if (!thenable && !iterable) return p;
|
|
1573
|
+
let guarded = guardedChannels.get(p);
|
|
1574
|
+
if (guarded === undefined) {
|
|
1575
|
+
guarded = thenable ? p.then(undefined, verdictNow) : {
|
|
1576
|
+
[Symbol.asyncIterator]() {
|
|
1577
|
+
const iterator = p[Symbol.asyncIterator]();
|
|
1578
|
+
return {
|
|
1579
|
+
next: value => iterator.next(value).then(undefined, verdictNow),
|
|
1580
|
+
return: value => iterator.return ? iterator.return(value) : Promise.resolve({
|
|
1581
|
+
done: true,
|
|
1582
|
+
value
|
|
1583
|
+
}),
|
|
1584
|
+
throw: error => iterator.throw ? iterator.throw(error) : Promise.reject(error)
|
|
1585
|
+
};
|
|
1586
|
+
}
|
|
1587
|
+
};
|
|
1588
|
+
guardedChannels.set(p, guarded);
|
|
1589
|
+
}
|
|
1590
|
+
return guarded;
|
|
1591
|
+
};
|
|
1366
1592
|
const trackSerialized = (id, p) => {
|
|
1367
1593
|
let settle;
|
|
1368
1594
|
const raced = Promise.race([p, new Promise(r => settle = r)]);
|
|
@@ -1371,19 +1597,35 @@ function renderToStream(code, options = {}) {
|
|
|
1371
1597
|
p.then(drop, drop);
|
|
1372
1598
|
return raced;
|
|
1373
1599
|
};
|
|
1374
|
-
const abandonSubtree = key => {
|
|
1600
|
+
const abandonSubtree = (key, error) => {
|
|
1601
|
+
let fragments = 0;
|
|
1602
|
+
let serialized = 0;
|
|
1375
1603
|
for (const [k, entry] of registry) {
|
|
1376
1604
|
if (k.length > key.length && k.startsWith(key)) {
|
|
1377
1605
|
registry.delete(k);
|
|
1378
1606
|
entry.resolve();
|
|
1607
|
+
fragments++;
|
|
1379
1608
|
}
|
|
1380
1609
|
}
|
|
1381
1610
|
for (const [id, settle] of pendingSerialized) {
|
|
1382
1611
|
if (id.startsWith(key)) {
|
|
1383
1612
|
pendingSerialized.delete(id);
|
|
1384
1613
|
settle();
|
|
1614
|
+
serialized++;
|
|
1385
1615
|
}
|
|
1386
1616
|
}
|
|
1617
|
+
if ((fragments || serialized)) emitFinding({
|
|
1618
|
+
code: "SSR_SUBTREE_ABANDONED",
|
|
1619
|
+
kind: "ssr",
|
|
1620
|
+
severity: "warn",
|
|
1621
|
+
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.`,
|
|
1622
|
+
data: {
|
|
1623
|
+
fragment: key,
|
|
1624
|
+
fragments,
|
|
1625
|
+
serialized,
|
|
1626
|
+
error
|
|
1627
|
+
}
|
|
1628
|
+
}, null);
|
|
1387
1629
|
};
|
|
1388
1630
|
const writeTasks = () => {
|
|
1389
1631
|
if (tasks.length && !completed && firstFlushed) {
|
|
@@ -1439,7 +1681,7 @@ function renderToStream(code, options = {}) {
|
|
|
1439
1681
|
emitTask(`${!headScriptFlushed ? HEAD_SCRIPT : ""}(_$HY.hp=_$HY.hp||{})[${JSON.stringify(key)}]=${payload}`);
|
|
1440
1682
|
headScriptFlushed = true;
|
|
1441
1683
|
};
|
|
1442
|
-
|
|
1684
|
+
sharedConfig.context = context = {
|
|
1443
1685
|
async: true,
|
|
1444
1686
|
nonce: options.nonce,
|
|
1445
1687
|
live: {},
|
|
@@ -1503,7 +1745,8 @@ function renderToStream(code, options = {}) {
|
|
|
1503
1745
|
html = html.slice(0, first) + resolveSSRSync(escape(payloadFn())) + html.slice(last + placeholder.length + 1);
|
|
1504
1746
|
},
|
|
1505
1747
|
serialize(id, p, deferStream) {
|
|
1506
|
-
if (
|
|
1748
|
+
if (sharedConfig.context.noHydrate) return;
|
|
1749
|
+
p = guardChannel(p);
|
|
1507
1750
|
if (p && typeof p === "object" && typeof p.then === "function") {
|
|
1508
1751
|
if (!firstFlushed && deferStream) {
|
|
1509
1752
|
blockingPromises.add(p);
|
|
@@ -1546,7 +1789,7 @@ function renderToStream(code, options = {}) {
|
|
|
1546
1789
|
const p = new Promise((r, rej) => (resolve = r, reject = rej));
|
|
1547
1790
|
registry.set(key, {
|
|
1548
1791
|
resolve: err => queue(() => queue(() => {
|
|
1549
|
-
err ? reject(err) : resolve(true);
|
|
1792
|
+
err ? reject(ssrSanitizeError(err, null)) : resolve(true);
|
|
1550
1793
|
queue(flushEnd);
|
|
1551
1794
|
}))
|
|
1552
1795
|
});
|
|
@@ -1556,8 +1799,8 @@ function renderToStream(code, options = {}) {
|
|
|
1556
1799
|
if (registry.has(key)) {
|
|
1557
1800
|
const item = registry.get(key);
|
|
1558
1801
|
registry.delete(key);
|
|
1559
|
-
if (error) abandonSubtree(key);
|
|
1560
|
-
if (item.children) {
|
|
1802
|
+
if (error) abandonSubtree(key, error);
|
|
1803
|
+
if (item.children && !error) {
|
|
1561
1804
|
for (const k in item.children) {
|
|
1562
1805
|
value = replacePlaceholder(value, k, item.children[k]);
|
|
1563
1806
|
}
|
|
@@ -1587,7 +1830,7 @@ function renderToStream(code, options = {}) {
|
|
|
1587
1830
|
sink.fragment(key, resolveSSRSelectValues(value !== undefined ? value : " "), {
|
|
1588
1831
|
styles,
|
|
1589
1832
|
revealGroup,
|
|
1590
|
-
error
|
|
1833
|
+
error: error ? ssrSanitizeError(error, null) : error
|
|
1591
1834
|
});
|
|
1592
1835
|
item.resolve(error);
|
|
1593
1836
|
}
|
|
@@ -1613,9 +1856,15 @@ function renderToStream(code, options = {}) {
|
|
|
1613
1856
|
};
|
|
1614
1857
|
applyAssetTracking(context, tracking, manifest, noScripts);
|
|
1615
1858
|
context.failRender = failRender;
|
|
1859
|
+
context.errorPolicy = options.onError;
|
|
1860
|
+
context.flushed = () => firstFlushed;
|
|
1861
|
+
context.trace = requestEvent ? traceForEvent(requestEvent) : traceFor(context, undefined);
|
|
1616
1862
|
registerEntryAssets(manifest);
|
|
1617
|
-
let html =
|
|
1618
|
-
dispose =
|
|
1863
|
+
let html = createRoot(d => {
|
|
1864
|
+
dispose = () => {
|
|
1865
|
+
context.trace = undefined;
|
|
1866
|
+
d();
|
|
1867
|
+
};
|
|
1619
1868
|
const res = resolveSSRNode(escape(code()));
|
|
1620
1869
|
if (!res.h.length) return res.t[0];
|
|
1621
1870
|
rootHoles = [];
|
|
@@ -1667,7 +1916,7 @@ function renderToStream(code, options = {}) {
|
|
|
1667
1916
|
}
|
|
1668
1917
|
function doShell() {
|
|
1669
1918
|
if (shellCompleted) return;
|
|
1670
|
-
|
|
1919
|
+
sharedConfig.context = context;
|
|
1671
1920
|
if (blockingPromises.size !== lastBlockingSize) return;
|
|
1672
1921
|
if (!resolveRootHoles()) return;
|
|
1673
1922
|
if (blockingPromises.size !== lastBlockingSize) return;
|
|
@@ -1678,7 +1927,7 @@ function renderToStream(code, options = {}) {
|
|
|
1678
1927
|
}
|
|
1679
1928
|
serializeRootAssets();
|
|
1680
1929
|
flushStubBatch();
|
|
1681
|
-
const head = renderShellHead(headRegistry, nonce, k => registry.has(k), noScripts);
|
|
1930
|
+
const head = renderShellHead(headRegistry, nonce, k => registry.has(k), noScripts, traceMetaMarkup(context.trace));
|
|
1682
1931
|
sink.shell(resolveSSRSelectValues(html), {
|
|
1683
1932
|
preloads: tracking.emittedAssets,
|
|
1684
1933
|
preloadLinks: tracking.preloadLinks,
|
|
@@ -1733,7 +1982,7 @@ function renderToStream(code, options = {}) {
|
|
|
1733
1982
|
try {
|
|
1734
1983
|
doShell();
|
|
1735
1984
|
} catch (err) {
|
|
1736
|
-
|
|
1985
|
+
failRootRender(err);
|
|
1737
1986
|
return resolve();
|
|
1738
1987
|
}
|
|
1739
1988
|
if (!shellCompleted) return flush();
|
|
@@ -1743,7 +1992,7 @@ function renderToStream(code, options = {}) {
|
|
|
1743
1992
|
let ended = false;
|
|
1744
1993
|
const failed = () => {
|
|
1745
1994
|
if (!ended) {
|
|
1746
|
-
abandon();
|
|
1995
|
+
abandon("consumer");
|
|
1747
1996
|
resolve();
|
|
1748
1997
|
}
|
|
1749
1998
|
};
|
|
@@ -1774,7 +2023,9 @@ function renderToStream(code, options = {}) {
|
|
|
1774
2023
|
return {
|
|
1775
2024
|
then(onFulfilled, onRejected) {
|
|
1776
2025
|
const freezeHead = () => {
|
|
1777
|
-
if (requestEvent && requestEvent.response) commitResponseStub(requestEvent.response
|
|
2026
|
+
if (requestEvent && requestEvent.response) commitResponseStub(requestEvent.response, {
|
|
2027
|
+
event: requestEvent
|
|
2028
|
+
});
|
|
1778
2029
|
};
|
|
1779
2030
|
const p = new Promise(resolve => {
|
|
1780
2031
|
function complete() {
|
|
@@ -1795,7 +2046,7 @@ function renderToStream(code, options = {}) {
|
|
|
1795
2046
|
try {
|
|
1796
2047
|
if (blockingPromises.size !== lastBlockingSize || !resolveRootHoles() || blockingPromises.size !== lastBlockingSize || !headShellReady(headRegistry, p => blockingPromises.add(p))) return flush();
|
|
1797
2048
|
} catch (err) {
|
|
1798
|
-
|
|
2049
|
+
failRootRender(err);
|
|
1799
2050
|
return resolve(tmp);
|
|
1800
2051
|
}
|
|
1801
2052
|
queue(flushEnd);
|
|
@@ -1815,7 +2066,7 @@ function renderToStream(code, options = {}) {
|
|
|
1815
2066
|
try {
|
|
1816
2067
|
doShell();
|
|
1817
2068
|
} catch (err) {
|
|
1818
|
-
|
|
2069
|
+
failRootRender(err);
|
|
1819
2070
|
try {
|
|
1820
2071
|
w.end();
|
|
1821
2072
|
} catch (_) {}
|
|
@@ -1852,14 +2103,14 @@ function renderToStream(code, options = {}) {
|
|
|
1852
2103
|
};
|
|
1853
2104
|
}
|
|
1854
2105
|
function buildAsyncWrap(err, node) {
|
|
1855
|
-
const p =
|
|
2106
|
+
const p = ssrHandleError(err);
|
|
1856
2107
|
if (!p) return null;
|
|
1857
2108
|
if (node.$rw) return {
|
|
1858
2109
|
fn: node,
|
|
1859
2110
|
p
|
|
1860
2111
|
};
|
|
1861
|
-
const owner =
|
|
1862
|
-
const live =
|
|
2112
|
+
const owner = getOwner();
|
|
2113
|
+
const live = sharedConfig.context && sharedConfig.context.liveHoles;
|
|
1863
2114
|
const suppress = node.$lhSuppress || live && (live.suppressed || live.sweeping);
|
|
1864
2115
|
if (!owner) {
|
|
1865
2116
|
if (suppress) node.$lhSuppress = true;
|
|
@@ -1868,7 +2119,7 @@ function buildAsyncWrap(err, node) {
|
|
|
1868
2119
|
p
|
|
1869
2120
|
};
|
|
1870
2121
|
}
|
|
1871
|
-
const fn = () =>
|
|
2122
|
+
const fn = () => runWithOwner(owner, node);
|
|
1872
2123
|
fn.$rw = true;
|
|
1873
2124
|
if (suppress) fn.$lhSuppress = true;
|
|
1874
2125
|
if (node.$lhSkip) fn.$lhSkip = true;
|
|
@@ -1934,6 +2185,10 @@ function ssrGroupSlot(fn, idx) {
|
|
|
1934
2185
|
}
|
|
1935
2186
|
};
|
|
1936
2187
|
}
|
|
2188
|
+
function wireErrorMessage(err) {
|
|
2189
|
+
const wire = ssrSanitizeError(err, null);
|
|
2190
|
+
return String(wire && wire.message || wire);
|
|
2191
|
+
}
|
|
1937
2192
|
const holePositionCache = new WeakMap();
|
|
1938
2193
|
function holeContentPositions(t) {
|
|
1939
2194
|
let cached = holePositionCache.get(t);
|
|
@@ -1995,16 +2250,16 @@ function holeContentPositions(t) {
|
|
|
1995
2250
|
}
|
|
1996
2251
|
function createLiveHoles(sink, scoped) {
|
|
1997
2252
|
let nextId = 0;
|
|
1998
|
-
const stamp = typeof
|
|
1999
|
-
const inScope = scoped && typeof
|
|
2253
|
+
const stamp = typeof creationStamp === "function" ? creationStamp : () => 0;
|
|
2254
|
+
const inScope = scoped && typeof inServerComponentScope === "function" ? inServerComponentScope : null;
|
|
2000
2255
|
const stripMarkers = html => html.replace(/<!--lh:\/?\d+-->/g, "");
|
|
2001
2256
|
const swept = (owner, ctx, fn) => {
|
|
2002
|
-
const prev =
|
|
2003
|
-
|
|
2257
|
+
const prev = sharedConfig.context;
|
|
2258
|
+
sharedConfig.context = ctx;
|
|
2004
2259
|
try {
|
|
2005
|
-
return owner ?
|
|
2260
|
+
return owner ? runWithOwner(owner, fn) : fn();
|
|
2006
2261
|
} finally {
|
|
2007
|
-
|
|
2262
|
+
sharedConfig.context = prev;
|
|
2008
2263
|
}
|
|
2009
2264
|
};
|
|
2010
2265
|
function resolveHoleValue(hole) {
|
|
@@ -2071,8 +2326,8 @@ function createLiveHoles(sink, scoped) {
|
|
|
2071
2326
|
if (inScope && !inScope()) return null;
|
|
2072
2327
|
const recordsBefore = engine.recordStamp;
|
|
2073
2328
|
const ownersBefore = stamp();
|
|
2074
|
-
const owner =
|
|
2075
|
-
const holeCtx =
|
|
2329
|
+
const owner = getOwner();
|
|
2330
|
+
const holeCtx = sharedConfig.context;
|
|
2076
2331
|
const b = {
|
|
2077
2332
|
key: null,
|
|
2078
2333
|
children: [],
|
|
@@ -2090,7 +2345,7 @@ function createLiveHoles(sink, scoped) {
|
|
|
2090
2345
|
} catch (err) {
|
|
2091
2346
|
b.closed = true;
|
|
2092
2347
|
sink.closeBinding(b.key);
|
|
2093
|
-
sink.error(b.key,
|
|
2348
|
+
sink.error(b.key, wireErrorMessage(err));
|
|
2094
2349
|
return;
|
|
2095
2350
|
} finally {
|
|
2096
2351
|
engine.sweeping = prevSweeping;
|
|
@@ -2193,8 +2448,8 @@ function createLiveHoles(sink, scoped) {
|
|
|
2193
2448
|
return !inScope || inScope();
|
|
2194
2449
|
},
|
|
2195
2450
|
attr(cap) {
|
|
2196
|
-
const owner =
|
|
2197
|
-
const holeCtx =
|
|
2451
|
+
const owner = getOwner();
|
|
2452
|
+
const holeCtx = sharedConfig.context;
|
|
2198
2453
|
const b = {
|
|
2199
2454
|
key: "lha:" + cap.id,
|
|
2200
2455
|
children: [],
|
|
@@ -2232,10 +2487,10 @@ function createLiveHoles(sink, scoped) {
|
|
|
2232
2487
|
};
|
|
2233
2488
|
swept(owner, holeCtx, run);
|
|
2234
2489
|
} catch (err) {
|
|
2235
|
-
if (
|
|
2490
|
+
if (ssrHandleError(err, true)) return;
|
|
2236
2491
|
b.closed = true;
|
|
2237
2492
|
sink.closeBinding(b.key);
|
|
2238
|
-
sink.error("lha:" + cap.id,
|
|
2493
|
+
sink.error("lha:" + cap.id, wireErrorMessage(err));
|
|
2239
2494
|
return;
|
|
2240
2495
|
} finally {
|
|
2241
2496
|
engine.sweeping = prevSweeping;
|
|
@@ -2275,7 +2530,7 @@ function ssr(t) {
|
|
|
2275
2530
|
let lastGroup = null;
|
|
2276
2531
|
let lastGroupVal = null;
|
|
2277
2532
|
let lastGroupIdx = 0;
|
|
2278
|
-
const live =
|
|
2533
|
+
const live = sharedConfig.context && sharedConfig.context.liveHoles;
|
|
2279
2534
|
const hp = live ? holeContentPositions(t) : null;
|
|
2280
2535
|
let lastOpen = null;
|
|
2281
2536
|
let cap = null;
|
|
@@ -2502,10 +2757,13 @@ function escape(s, attr) {
|
|
|
2502
2757
|
if (!attr && Array.isArray(s)) {
|
|
2503
2758
|
const joined = tryJoinPlainSSRArray(s);
|
|
2504
2759
|
if (joined !== undefined) return joined;
|
|
2760
|
+
const src = s;
|
|
2505
2761
|
s = s.slice();
|
|
2506
2762
|
for (let i = 0; i < s.length; i++) s[i] = escape(s[i]);
|
|
2763
|
+
if (src.$slot) s.$slot = true;
|
|
2507
2764
|
return s;
|
|
2508
2765
|
}
|
|
2766
|
+
if (!attr && t === "function") return escapeLate(s);
|
|
2509
2767
|
if (attr) {
|
|
2510
2768
|
if (s == null || t === "boolean" || t === "number") return s;
|
|
2511
2769
|
return escape(String(s), attr);
|
|
@@ -2516,6 +2774,15 @@ function escape(s, attr) {
|
|
|
2516
2774
|
if (i < 0) return s;
|
|
2517
2775
|
return escapeSlow(s, attr, i);
|
|
2518
2776
|
}
|
|
2777
|
+
function escapeLate(fn) {
|
|
2778
|
+
if (fn.$esc) return fn;
|
|
2779
|
+
const w = () => escape(fn());
|
|
2780
|
+
w.$esc = true;
|
|
2781
|
+
if (fn.$lhSkip) w.$lhSkip = true;
|
|
2782
|
+
if (fn.$lhSuppress) w.$lhSuppress = true;
|
|
2783
|
+
if (fn.$lhBinding) w.$lhBinding = fn.$lhBinding;
|
|
2784
|
+
return w;
|
|
2785
|
+
}
|
|
2519
2786
|
const ESCAPE_CONTENT = /[&<]/;
|
|
2520
2787
|
const ESCAPE_ATTR = /[&"<]/;
|
|
2521
2788
|
function escapeSlow(s, attr, start) {
|
|
@@ -2751,23 +3018,26 @@ function replacePlaceholder(html, key, value) {
|
|
|
2751
3018
|
const last = html.indexOf(close, first + marker.length);
|
|
2752
3019
|
return html.slice(0, first) + value + html.slice(last + close.length);
|
|
2753
3020
|
}
|
|
2754
|
-
|
|
3021
|
+
let ssrTextTail = false;
|
|
3022
|
+
function tryResolveString(node, nested) {
|
|
3023
|
+
if (!nested) ssrTextTail = false;
|
|
2755
3024
|
const t = typeof node;
|
|
2756
|
-
if (t === "string")
|
|
2757
|
-
|
|
3025
|
+
if (t === "string" || t === "number") {
|
|
3026
|
+
const s = ssrTextTail ? "<!--!$-->" + node : "" + node;
|
|
3027
|
+
ssrTextTail = true;
|
|
3028
|
+
return s;
|
|
3029
|
+
}
|
|
2758
3030
|
if (node == null || t === "boolean") return "";
|
|
2759
3031
|
if (t === "object") {
|
|
2760
3032
|
if (Array.isArray(node)) {
|
|
2761
3033
|
const joined = tryJoinPlainSSRArray(node);
|
|
2762
|
-
if (joined !== undefined)
|
|
3034
|
+
if (joined !== undefined) {
|
|
3035
|
+
ssrTextTail = false;
|
|
3036
|
+
return joined;
|
|
3037
|
+
}
|
|
2763
3038
|
let s = "";
|
|
2764
|
-
let prevNonObj = false;
|
|
2765
3039
|
for (let i = 0, len = node.length; i < len; i++) {
|
|
2766
|
-
const
|
|
2767
|
-
const itemNonObj = item !== null && typeof item !== "object";
|
|
2768
|
-
if (prevNonObj && itemNonObj) s += "<!--!$-->";
|
|
2769
|
-
prevNonObj = itemNonObj;
|
|
2770
|
-
const r = tryResolveString(item);
|
|
3040
|
+
const r = tryResolveString(node[i], true);
|
|
2771
3041
|
if (typeof r !== "string") return {
|
|
2772
3042
|
bail: node
|
|
2773
3043
|
};
|
|
@@ -2781,6 +3051,7 @@ function tryResolveString(node) {
|
|
|
2781
3051
|
if (node.t === undefined) {
|
|
2782
3052
|
return "";
|
|
2783
3053
|
}
|
|
3054
|
+
ssrTextTail = false;
|
|
2784
3055
|
return Array.isArray(node.t) ? node.t[0] : node.t;
|
|
2785
3056
|
}
|
|
2786
3057
|
if (t === "function") {
|
|
@@ -2788,9 +3059,11 @@ function tryResolveString(node) {
|
|
|
2788
3059
|
try {
|
|
2789
3060
|
v = node();
|
|
2790
3061
|
} catch (err) {
|
|
2791
|
-
|
|
3062
|
+
const wrap = buildAsyncWrap(err, node);
|
|
3063
|
+
if (wrap) ssrTextTail = true;
|
|
3064
|
+
return wrap || "";
|
|
2792
3065
|
}
|
|
2793
|
-
return tryResolveString(v);
|
|
3066
|
+
return tryResolveString(v, true);
|
|
2794
3067
|
}
|
|
2795
3068
|
return "";
|
|
2796
3069
|
}
|
|
@@ -2798,21 +3071,19 @@ function resolveSSRNode(node, result = {
|
|
|
2798
3071
|
t: [""],
|
|
2799
3072
|
h: [],
|
|
2800
3073
|
p: []
|
|
2801
|
-
}, top) {
|
|
3074
|
+
}, top, nested) {
|
|
3075
|
+
if (!nested) ssrTextTail = false;
|
|
2802
3076
|
const t = typeof node;
|
|
2803
3077
|
if (t === "string" || t === "number") {
|
|
2804
|
-
result.t[result.t.length - 1] += node;
|
|
3078
|
+
result.t[result.t.length - 1] += ssrTextTail ? "<!--!$-->" + node : node;
|
|
3079
|
+
ssrTextTail = true;
|
|
2805
3080
|
} else if (node == null || t === "boolean") ; else if (Array.isArray(node)) {
|
|
2806
|
-
const slotLive = node.$slot &&
|
|
3081
|
+
const slotLive = node.$slot && sharedConfig.context && sharedConfig.context.liveHoles;
|
|
2807
3082
|
if (slotLive) slotLive.suppressed++;
|
|
2808
3083
|
try {
|
|
2809
|
-
let prevNonObj = false;
|
|
2810
3084
|
for (let i = 0, len = node.length; i < len; i++) {
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
if (!top && prevNonObj && itemNonObj) result.t[result.t.length - 1] += `<!--!$-->`;
|
|
2814
|
-
prevNonObj = itemNonObj;
|
|
2815
|
-
resolveSSRNode(item, result);
|
|
3085
|
+
if (top) ssrTextTail = false;
|
|
3086
|
+
resolveSSRNode(node[i], result, false, true);
|
|
2816
3087
|
}
|
|
2817
3088
|
} finally {
|
|
2818
3089
|
if (slotLive) slotLive.suppressed--;
|
|
@@ -2825,23 +3096,30 @@ function resolveSSRNode(node, result = {
|
|
|
2825
3096
|
result.h.push(...node.h);
|
|
2826
3097
|
result.p.push(...node.p);
|
|
2827
3098
|
}
|
|
3099
|
+
ssrTextTail = false;
|
|
2828
3100
|
} else if (node.t !== undefined) {
|
|
2829
3101
|
result.t[result.t.length - 1] += node.t;
|
|
3102
|
+
ssrTextTail = false;
|
|
2830
3103
|
} else ;
|
|
2831
3104
|
} else if (t === "function") {
|
|
2832
|
-
const live =
|
|
3105
|
+
const live = sharedConfig.context && sharedConfig.context.liveHoles;
|
|
2833
3106
|
let liveNode = null;
|
|
2834
3107
|
if (live && (liveNode = live.content(node)) !== null) {
|
|
2835
|
-
if (typeof liveNode === "string")
|
|
3108
|
+
if (typeof liveNode === "string") {
|
|
3109
|
+
result.t[result.t.length - 1] += ssrTextTail ? "<!--!$-->" + liveNode : liveNode;
|
|
3110
|
+
ssrTextTail = true;
|
|
3111
|
+
} else resolveSSRNode(liveNode, result, false, true);
|
|
2836
3112
|
} else {
|
|
2837
3113
|
try {
|
|
2838
|
-
resolveSSRNode(node(), result);
|
|
3114
|
+
resolveSSRNode(node(), result, false, true);
|
|
2839
3115
|
} catch (err) {
|
|
2840
3116
|
const wrap = buildAsyncWrap(err, node);
|
|
2841
3117
|
if (wrap) {
|
|
3118
|
+
if (ssrTextTail) result.t[result.t.length - 1] += "<!--!$-->";
|
|
2842
3119
|
result.h.push(wrap.fn);
|
|
2843
3120
|
result.p.push(wrap.p);
|
|
2844
3121
|
result.t.push("");
|
|
3122
|
+
ssrTextTail = true;
|
|
2845
3123
|
}
|
|
2846
3124
|
}
|
|
2847
3125
|
}
|
|
@@ -2854,20 +3132,58 @@ function resolveSSRSync(node) {
|
|
|
2854
3132
|
throw new Error("This value cannot be rendered synchronously. Are you missing a boundary?");
|
|
2855
3133
|
}
|
|
2856
3134
|
const RequestContext = Symbol.for("solid.RequestContext");
|
|
3135
|
+
const ServerErrors = Symbol.for("solid-js/server/errors");
|
|
3136
|
+
function serializerErrorHook(hook) {
|
|
3137
|
+
return hook === undefined ? undefined : err => {
|
|
3138
|
+
reportServerError(err, {
|
|
3139
|
+
kind: "render",
|
|
3140
|
+
handling: "serialize"
|
|
3141
|
+
}, null);
|
|
3142
|
+
};
|
|
3143
|
+
}
|
|
3144
|
+
function ambientServerErrorHook() {
|
|
3145
|
+
const slot = globalThis[ServerErrors];
|
|
3146
|
+
return slot === undefined ? undefined : slot.hook;
|
|
3147
|
+
}
|
|
2857
3148
|
function peekRequestEvent() {
|
|
2858
3149
|
const store = globalThis[RequestContext];
|
|
2859
3150
|
return store ? store.getStore() : undefined;
|
|
2860
3151
|
}
|
|
3152
|
+
function traceForEvent(event) {
|
|
3153
|
+
return traceFor(event.request || event, event.request);
|
|
3154
|
+
}
|
|
3155
|
+
function traceForStub(stub, event) {
|
|
3156
|
+
if (!event) {
|
|
3157
|
+
event = peekRequestEvent();
|
|
3158
|
+
if (!event || event.response !== stub) return undefined;
|
|
3159
|
+
}
|
|
3160
|
+
return traceForEvent(event);
|
|
3161
|
+
}
|
|
2861
3162
|
function reportLostHeaderWrite(method, name) {
|
|
2862
|
-
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).";
|
|
3163
|
+
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).";
|
|
3164
|
+
recordFinding({
|
|
3165
|
+
code: "LATE_HEADER_WRITE",
|
|
3166
|
+
kind: "head",
|
|
3167
|
+
severity: "error",
|
|
3168
|
+
message,
|
|
3169
|
+
data: {
|
|
3170
|
+
method,
|
|
3171
|
+
name: String(name)
|
|
3172
|
+
}
|
|
3173
|
+
});
|
|
2863
3174
|
console.error(message);
|
|
2864
3175
|
}
|
|
2865
3176
|
function commitResponseStub(stub, {
|
|
2866
|
-
allowLateLocation = false
|
|
3177
|
+
allowLateLocation = false,
|
|
3178
|
+
event
|
|
2867
3179
|
} = {}) {
|
|
2868
3180
|
if (!stub || stub.committed) return stub;
|
|
2869
|
-
stub.committed = true;
|
|
2870
3181
|
const headers = stub.headers;
|
|
3182
|
+
if (headers && typeof headers.append === "function") {
|
|
3183
|
+
const trace = traceForStub(stub, event);
|
|
3184
|
+
if (trace) appendTraceServerTiming(headers, trace);
|
|
3185
|
+
}
|
|
3186
|
+
stub.committed = true;
|
|
2871
3187
|
if (!headers || typeof headers.set !== "function") return stub;
|
|
2872
3188
|
for (const method of ["set", "append", "delete"]) {
|
|
2873
3189
|
const original = headers[method].bind(headers);
|
|
@@ -2883,6 +3199,62 @@ function commitResponseStub(stub, {
|
|
|
2883
3199
|
/*#__PURE__*/new Set([ERROR_HEADER, BODY_FORMAT_HEADER, SINGLE_FLIGHT_HEADER, REVALIDATE_HEADER, REDIRECT_HEADER, "Location",
|
|
2884
3200
|
...COMPOSED_BODY_FRAMING].map(header => header.toLowerCase()));
|
|
2885
3201
|
|
|
3202
|
+
const RECORDS = Symbol.for("@solidjs/signals/observe/records");
|
|
3203
|
+
function records() {
|
|
3204
|
+
return globalThis[RECORDS];
|
|
3205
|
+
}
|
|
3206
|
+
function frameCensus(event, type, own) {
|
|
3207
|
+
event.chunks++;
|
|
3208
|
+
switch (type) {
|
|
3209
|
+
case "html":
|
|
3210
|
+
if (!own) event.regions++;else if (event.shellMs === undefined) event.shellMs = performance.now() - event.at;
|
|
3211
|
+
break;
|
|
3212
|
+
case "fragment":
|
|
3213
|
+
event.fragments++;
|
|
3214
|
+
break;
|
|
3215
|
+
case "slot":
|
|
3216
|
+
event.slots++;
|
|
3217
|
+
break;
|
|
3218
|
+
case "error":
|
|
3219
|
+
event.errors++;
|
|
3220
|
+
break;
|
|
3221
|
+
}
|
|
3222
|
+
}
|
|
3223
|
+
|
|
3224
|
+
function observeFrame(frame) {
|
|
3225
|
+
const channel = records();
|
|
3226
|
+
if (channel === undefined || !channel.observed("frame")) return undefined;
|
|
3227
|
+
const event = {
|
|
3228
|
+
side: "server",
|
|
3229
|
+
id: frame.id,
|
|
3230
|
+
version: frame.version,
|
|
3231
|
+
at: performance.now(),
|
|
3232
|
+
durationMs: 0,
|
|
3233
|
+
outcome: "complete",
|
|
3234
|
+
chunks: 0,
|
|
3235
|
+
fragments: 0,
|
|
3236
|
+
slots: 0,
|
|
3237
|
+
regions: 0,
|
|
3238
|
+
errors: 0
|
|
3239
|
+
};
|
|
3240
|
+
let settled = false;
|
|
3241
|
+
return {
|
|
3242
|
+
chunk(chunk) {
|
|
3243
|
+
if (chunk.type === "complete") return;
|
|
3244
|
+
frameCensus(event, chunk.type, chunk.id === frame.id);
|
|
3245
|
+
},
|
|
3246
|
+
settle(outcome, error) {
|
|
3247
|
+
if (settled) return;
|
|
3248
|
+
settled = true;
|
|
3249
|
+
event.durationMs = performance.now() - event.at;
|
|
3250
|
+
event.outcome = outcome;
|
|
3251
|
+
const live = {};
|
|
3252
|
+
if (outcome === "error") live.error = error;
|
|
3253
|
+
channel.emit("frame", event, live);
|
|
3254
|
+
}
|
|
3255
|
+
};
|
|
3256
|
+
}
|
|
3257
|
+
|
|
2886
3258
|
function scopeDeferredResult(value, scope) {
|
|
2887
3259
|
const bound = bindDeferredBody(value, scope);
|
|
2888
3260
|
if (bound !== value || value === null || typeof value !== "object") return bound;
|
|
@@ -3037,6 +3409,13 @@ function bindDeferredBody(value, scope) {
|
|
|
3037
3409
|
}
|
|
3038
3410
|
return value;
|
|
3039
3411
|
}
|
|
3412
|
+
function processState(key, create) {
|
|
3413
|
+
const slot = Symbol.for(key);
|
|
3414
|
+
return globalThis[slot] || (globalThis[slot] = create());
|
|
3415
|
+
}
|
|
3416
|
+
processState("solid.ServerFunctionRegistrations", () => new Map());
|
|
3417
|
+
processState("solid.ServerFunctionMethods", () => new Map());
|
|
3418
|
+
processState("solid.ServerFunctionReferenceBindings", () => new WeakMap());
|
|
3040
3419
|
const INVOCATIONS = new WeakMap();
|
|
3041
3420
|
function getEventServerFunctionInvocation(event) {
|
|
3042
3421
|
return event && INVOCATIONS.get(event);
|
|
@@ -3067,7 +3446,7 @@ function guardFailures(value, state) {
|
|
|
3067
3446
|
try {
|
|
3068
3447
|
top.accessorValue = descriptor.get.call(top.value);
|
|
3069
3448
|
} catch (error) {
|
|
3070
|
-
throw
|
|
3449
|
+
throw wireServerFunctionError(error, "channel");
|
|
3071
3450
|
}
|
|
3072
3451
|
top.accessorRead = i;
|
|
3073
3452
|
}
|
|
@@ -3177,7 +3556,7 @@ function enterGuard(value, state) {
|
|
|
3177
3556
|
} = await guardOperation(state, () => reader.read());
|
|
3178
3557
|
done ? controller.close() : controller.enqueue(guardOperation(state, () => guardFailures(chunk, state)));
|
|
3179
3558
|
} catch (error) {
|
|
3180
|
-
controller.error(guardOperation(state, () =>
|
|
3559
|
+
controller.error(guardOperation(state, () => wireServerFunctionError(error, "channel")));
|
|
3181
3560
|
}
|
|
3182
3561
|
},
|
|
3183
3562
|
cancel(reason) {
|
|
@@ -3191,7 +3570,7 @@ function enterGuard(value, state) {
|
|
|
3191
3570
|
}
|
|
3192
3571
|
if (typeof value.then === "function") {
|
|
3193
3572
|
const guardedPromise = Promise.resolve(value).then(resolved => guardOperation(state, () => guardFailures(resolved, state)), error => {
|
|
3194
|
-
throw guardOperation(state, () =>
|
|
3573
|
+
throw guardOperation(state, () => wireServerFunctionError(error, "channel"));
|
|
3195
3574
|
});
|
|
3196
3575
|
guardedPromise.catch(() => {});
|
|
3197
3576
|
state.seen.set(value, guardedPromise);
|
|
@@ -3226,7 +3605,7 @@ function enterGuard(value, state) {
|
|
|
3226
3605
|
value: guardOperation(state, () => guardFailures(step.value, state))
|
|
3227
3606
|
};
|
|
3228
3607
|
}, error => {
|
|
3229
|
-
throw guardOperation(state, () =>
|
|
3608
|
+
throw guardOperation(state, () => wireServerFunctionError(error, "channel"));
|
|
3230
3609
|
});
|
|
3231
3610
|
return {
|
|
3232
3611
|
next: () => finished || !gate || gate.wantsMore() ? step() : gate.awaitDemand().then(step),
|
|
@@ -3289,8 +3668,37 @@ function keepGuarded(value, next, changed, state) {
|
|
|
3289
3668
|
return value;
|
|
3290
3669
|
}
|
|
3291
3670
|
const GENERIC_SERVER_ERROR_MESSAGE = "Internal Server Error";
|
|
3671
|
+
const REQUEST_ERROR_HOOKS = new WeakMap();
|
|
3672
|
+
function siteFor(handling, event, direct) {
|
|
3673
|
+
const invocation = event ? INVOCATIONS.get(event) : undefined;
|
|
3674
|
+
const site = {
|
|
3675
|
+
kind: "server-function",
|
|
3676
|
+
handling,
|
|
3677
|
+
direct
|
|
3678
|
+
};
|
|
3679
|
+
if (invocation) site.functionId = invocation.id;
|
|
3680
|
+
if (event) site.event = event;
|
|
3681
|
+
return site;
|
|
3682
|
+
}
|
|
3683
|
+
function wireServerFunctionError(value, handling, event = currentEvent()) {
|
|
3684
|
+
const report = reportServerError(value, siteFor(handling, event, false), null, event ? REQUEST_ERROR_HOOKS.get(event) : undefined);
|
|
3685
|
+
return report.mapped ? report.value : sanitizeServerError(value);
|
|
3686
|
+
}
|
|
3687
|
+
function currentEvent() {
|
|
3688
|
+
const store = globalThis[RequestContext];
|
|
3689
|
+
return store ? store.getStore() : undefined;
|
|
3690
|
+
}
|
|
3292
3691
|
function sanitizeServerError(value) {
|
|
3293
3692
|
if (isSafeError(value)) return value;
|
|
3693
|
+
emitFinding({
|
|
3694
|
+
code: "SERVER_FN_ERROR_SANITIZED",
|
|
3695
|
+
kind: "ssr",
|
|
3696
|
+
severity: "error",
|
|
3697
|
+
message: `[SERVER_FN_ERROR_SANITIZED] Server function error replaced with a generic Error before serialization: ${errorText(value)}`,
|
|
3698
|
+
data: {
|
|
3699
|
+
error: value
|
|
3700
|
+
}
|
|
3701
|
+
}, null);
|
|
3294
3702
|
return new Error(GENERIC_SERVER_ERROR_MESSAGE);
|
|
3295
3703
|
}
|
|
3296
3704
|
function nativePromise(value) {
|
|
@@ -3351,22 +3759,22 @@ function flightCodec(codec) {
|
|
|
3351
3759
|
};
|
|
3352
3760
|
}
|
|
3353
3761
|
|
|
3354
|
-
const runWithHydrationScope = (id, fn) =>
|
|
3762
|
+
const runWithHydrationScope = (id, fn) => runWithOwner(createOwner({
|
|
3355
3763
|
id
|
|
3356
3764
|
}), fn);
|
|
3357
|
-
const ssrAsyncValue = value =>
|
|
3765
|
+
const ssrAsyncValue = value => createMemo(() => value, {
|
|
3358
3766
|
serialize: false
|
|
3359
3767
|
});
|
|
3360
|
-
const scopeStamp = typeof
|
|
3768
|
+
const scopeStamp = typeof creationStamp === "function" ? creationStamp : () => 0;
|
|
3361
3769
|
function serverOwned(render) {
|
|
3362
|
-
return
|
|
3770
|
+
return NoHydration ? NoHydration({
|
|
3363
3771
|
get children() {
|
|
3364
3772
|
return render();
|
|
3365
3773
|
}
|
|
3366
3774
|
}) : render();
|
|
3367
3775
|
}
|
|
3368
3776
|
function serverComponentScope(render) {
|
|
3369
|
-
return
|
|
3777
|
+
return runInServerComponentScope ? runInServerComponentScope(render) : render();
|
|
3370
3778
|
}
|
|
3371
3779
|
function wirePreload(entry) {
|
|
3372
3780
|
return entry.href ? {
|
|
@@ -3654,7 +4062,7 @@ function renderServerComponent(component, options = {}) {
|
|
|
3654
4062
|
return frameStream((sink, frame) => {
|
|
3655
4063
|
const props = createSlotProps(sink, frame);
|
|
3656
4064
|
return () => {
|
|
3657
|
-
const ctx =
|
|
4065
|
+
const ctx = sharedConfig.context;
|
|
3658
4066
|
if (ctx) {
|
|
3659
4067
|
ctx.commit = sink.commit;
|
|
3660
4068
|
ctx.commitEpoch = () => sink.epoch;
|
|
@@ -3675,9 +4083,13 @@ function frameStream(makeCode, options) {
|
|
|
3675
4083
|
version
|
|
3676
4084
|
};
|
|
3677
4085
|
function stream(w) {
|
|
3678
|
-
const
|
|
4086
|
+
const observation = observeFrame(frame);
|
|
4087
|
+
const emit = observation ? chunk => {
|
|
4088
|
+
observation.chunk(chunk);
|
|
4089
|
+
w.write(chunk);
|
|
4090
|
+
} : chunk => w.write(chunk);
|
|
3679
4091
|
const sink = createFrameSink(emit, frame);
|
|
3680
|
-
|
|
4092
|
+
w.write({
|
|
3681
4093
|
type: "start",
|
|
3682
4094
|
id,
|
|
3683
4095
|
version
|
|
@@ -3692,12 +4104,15 @@ function frameStream(makeCode, options) {
|
|
|
3692
4104
|
write() {},
|
|
3693
4105
|
end() {
|
|
3694
4106
|
sink.end();
|
|
4107
|
+
observation && observation.settle("complete");
|
|
3695
4108
|
w.end && w.end();
|
|
3696
4109
|
}
|
|
3697
4110
|
});
|
|
3698
4111
|
} catch (err) {
|
|
3699
|
-
|
|
4112
|
+
const wire = ssrSanitizeError(err, null);
|
|
4113
|
+
sink.error("", wire instanceof Error ? wire.message : String(wire));
|
|
3700
4114
|
sink.end();
|
|
4115
|
+
observation && observation.settle("error", err);
|
|
3701
4116
|
w.end && w.end();
|
|
3702
4117
|
}
|
|
3703
4118
|
}
|
|
@@ -3770,7 +4185,7 @@ function tapFirstYield(iterable) {
|
|
|
3770
4185
|
};
|
|
3771
4186
|
}
|
|
3772
4187
|
function suppressedFill(render) {
|
|
3773
|
-
const live =
|
|
4188
|
+
const live = sharedConfig.context && sharedConfig.context.liveHoles;
|
|
3774
4189
|
if (!live) return render();
|
|
3775
4190
|
live.suppressed++;
|
|
3776
4191
|
try {
|
|
@@ -3791,16 +4206,16 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
3791
4206
|
r.$slot = true;
|
|
3792
4207
|
return r;
|
|
3793
4208
|
};
|
|
3794
|
-
const zoneOwner =
|
|
4209
|
+
const zoneOwner = getOwner ? getOwner() : null;
|
|
3795
4210
|
const scoped = (occurrence, render) => {
|
|
3796
4211
|
const id = `sc-${frameId}-${occurrence}-`;
|
|
3797
|
-
const run = () =>
|
|
4212
|
+
const run = () => Hydration ? Hydration({
|
|
3798
4213
|
id,
|
|
3799
4214
|
get children() {
|
|
3800
4215
|
return render();
|
|
3801
4216
|
}
|
|
3802
4217
|
}) : runWithHydrationScope(id, render);
|
|
3803
|
-
return zoneOwner ?
|
|
4218
|
+
return zoneOwner ? runWithOwner(zoneOwner, run) : run();
|
|
3804
4219
|
};
|
|
3805
4220
|
return new Proxy(Object.create(null), {
|
|
3806
4221
|
has() {
|
|
@@ -3823,7 +4238,7 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
3823
4238
|
const slot = clientProps[prop];
|
|
3824
4239
|
if (typeof slot !== "function") return range(occurrence, undefined);
|
|
3825
4240
|
const resolved = {};
|
|
3826
|
-
const liveArgs =
|
|
4241
|
+
const liveArgs = sharedConfig.context && sharedConfig.context.live && sharedConfig.context.live.args;
|
|
3827
4242
|
const vals = {};
|
|
3828
4243
|
const evals = {};
|
|
3829
4244
|
const states = {};
|
|
@@ -3853,7 +4268,7 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
3853
4268
|
last: value
|
|
3854
4269
|
};
|
|
3855
4270
|
} catch (err) {
|
|
3856
|
-
const blocked =
|
|
4271
|
+
const blocked = ssrHandleError && ssrHandleError(err);
|
|
3857
4272
|
if (!blocked) throw err;
|
|
3858
4273
|
const state = states[key] = {
|
|
3859
4274
|
settled: false,
|
|
@@ -3915,7 +4330,7 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
3915
4330
|
}
|
|
3916
4331
|
const out = suppressedFill(() => scoped(occurrence, () => range(occurrence, slot(resolved))));
|
|
3917
4332
|
const unused = regions.filter(r => !r.used);
|
|
3918
|
-
if (
|
|
4333
|
+
if (sharedConfig.context) {
|
|
3919
4334
|
const args = {};
|
|
3920
4335
|
for (const key of Object.keys(vals)) {
|
|
3921
4336
|
const value = vals[key];
|
|
@@ -3929,12 +4344,12 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
3929
4344
|
if (!isContainerTraced(value) && isServerContent(value)) continue;
|
|
3930
4345
|
args[key] = envelopeContainerTraces(value);
|
|
3931
4346
|
}
|
|
3932
|
-
|
|
4347
|
+
sharedConfig.context.serialize(`sc:slot:${frameId}:${occurrence}`, {
|
|
3933
4348
|
...args
|
|
3934
4349
|
});
|
|
3935
4350
|
for (const region of unused) {
|
|
3936
4351
|
region.locked = true;
|
|
3937
|
-
|
|
4352
|
+
sharedConfig.context.serialize(`sc:region:${region.childId}`, resolveRegionHtml(sharedConfig.context, region.value));
|
|
3938
4353
|
}
|
|
3939
4354
|
if (liveArgs) {
|
|
3940
4355
|
for (const key of Object.keys(evals)) {
|
|
@@ -3963,7 +4378,7 @@ function createDocumentSlotProps(clientProps, frameId) {
|
|
|
3963
4378
|
const FRAME_TAG = "solid-frame";
|
|
3964
4379
|
const FRAME_ID_ATTR = "data-fid";
|
|
3965
4380
|
function frameElementOpen(id) {
|
|
3966
|
-
const escaped =
|
|
4381
|
+
const escaped = sharedConfig.context ? sharedConfig.context.escape(String(id), true) : String(id);
|
|
3967
4382
|
return `<${FRAME_TAG} ${FRAME_ID_ATTR}="${escaped}" style="display:contents">`;
|
|
3968
4383
|
}
|
|
3969
4384
|
const FRAME_ELEMENT_CLOSE = `</${FRAME_TAG}>`;
|
|
@@ -4084,8 +4499,8 @@ function frameTransformDirectResult(value, {
|
|
|
4084
4499
|
t: frameElementOpen(id)
|
|
4085
4500
|
},
|
|
4086
4501
|
serverOwned(() => {
|
|
4087
|
-
armDocumentLiveHoles(
|
|
4088
|
-
|
|
4502
|
+
armDocumentLiveHoles(sharedConfig.context);
|
|
4503
|
+
sharedConfig.context.claims = CLAIMS_DOCUMENT;
|
|
4089
4504
|
const slotProps = createDocumentSlotProps(props, id);
|
|
4090
4505
|
return serverComponentScope(() => component(slotProps));
|
|
4091
4506
|
}), {
|
|
@@ -4130,11 +4545,11 @@ function contentArgError(key, occurrence) {
|
|
|
4130
4545
|
return new Error("Async slot arg resolved to JSX (arg '" + key + "' of " + occurrence + "). Async args must resolve to serializable values; render async content through a boundary instead.");
|
|
4131
4546
|
}
|
|
4132
4547
|
function retryArgUntilSettled(evaluate, blocked, key, occurrence, onSettle) {
|
|
4133
|
-
const owner =
|
|
4548
|
+
const owner = getOwner();
|
|
4134
4549
|
return new Promise((resolve, reject) => {
|
|
4135
4550
|
const retry = () => {
|
|
4136
4551
|
try {
|
|
4137
|
-
const value = owner ?
|
|
4552
|
+
const value = owner ? runWithOwner(owner, evaluate) : evaluate();
|
|
4138
4553
|
if (isServerContent(value)) {
|
|
4139
4554
|
reject(contentArgError(key, occurrence));
|
|
4140
4555
|
return;
|
|
@@ -4142,7 +4557,7 @@ function retryArgUntilSettled(evaluate, blocked, key, occurrence, onSettle) {
|
|
|
4142
4557
|
if (onSettle) onSettle(value);
|
|
4143
4558
|
resolve(value);
|
|
4144
4559
|
} catch (err) {
|
|
4145
|
-
const next =
|
|
4560
|
+
const next = ssrHandleError && ssrHandleError(err);
|
|
4146
4561
|
if (next) next.then(retry, retry);else reject(err);
|
|
4147
4562
|
}
|
|
4148
4563
|
};
|
|
@@ -4150,16 +4565,16 @@ function retryArgUntilSettled(evaluate, blocked, key, occurrence, onSettle) {
|
|
|
4150
4565
|
});
|
|
4151
4566
|
}
|
|
4152
4567
|
function openArgBinding(sink, ledgerKey, occurrence, key, evaluate, state, emit) {
|
|
4153
|
-
const owner =
|
|
4568
|
+
const owner = getOwner();
|
|
4154
4569
|
sink.openBinding(ledgerKey, {
|
|
4155
4570
|
sweep() {
|
|
4156
4571
|
if (!state.settled) return;
|
|
4157
4572
|
let value;
|
|
4158
4573
|
const stampBefore = scopeStamp();
|
|
4159
4574
|
try {
|
|
4160
|
-
value = owner ?
|
|
4575
|
+
value = owner ? runWithOwner(owner, evaluate) : evaluate();
|
|
4161
4576
|
} catch (err) {
|
|
4162
|
-
const blocked =
|
|
4577
|
+
const blocked = ssrHandleError && ssrHandleError(err);
|
|
4163
4578
|
if (!blocked) {
|
|
4164
4579
|
sink.closeBinding(ledgerKey);
|
|
4165
4580
|
emit(Promise.reject(err instanceof Error ? err : new Error(String(err))));
|
|
@@ -4208,7 +4623,7 @@ function createSlotProps(sink, frame) {
|
|
|
4208
4623
|
if (callArgs.length === 0 || callArgs[0] === undefined) {
|
|
4209
4624
|
return slotRange(prop);
|
|
4210
4625
|
}
|
|
4211
|
-
const live =
|
|
4626
|
+
const live = sharedConfig.context && sharedConfig.context.liveHoles;
|
|
4212
4627
|
if (live) {
|
|
4213
4628
|
if (live.sweeping) {
|
|
4214
4629
|
live.gateHit = true;
|
|
@@ -4226,7 +4641,7 @@ function createSlotProps(sink, frame) {
|
|
|
4226
4641
|
for (const key of Object.keys(raw)) {
|
|
4227
4642
|
if (key === "$key") continue;
|
|
4228
4643
|
const childId = `${frame.id}.${occurrence}.${key}`;
|
|
4229
|
-
const ctx =
|
|
4644
|
+
const ctx = sharedConfig.context;
|
|
4230
4645
|
const origRegister = ctx.registerFragment;
|
|
4231
4646
|
ctx.registerFragment = (fragKey, fragOptions) => {
|
|
4232
4647
|
sink.tagRegion(fragKey, childId);
|
|
@@ -4252,7 +4667,7 @@ function createSlotProps(sink, frame) {
|
|
|
4252
4667
|
}
|
|
4253
4668
|
}
|
|
4254
4669
|
} catch (err) {
|
|
4255
|
-
const blocked =
|
|
4670
|
+
const blocked = ssrHandleError && ssrHandleError(err);
|
|
4256
4671
|
if (!blocked) throw err;
|
|
4257
4672
|
state = {
|
|
4258
4673
|
settled: false,
|
|
@@ -4305,7 +4720,7 @@ function createSlotProps(sink, frame) {
|
|
|
4305
4720
|
sink.slot(occurrence, {
|
|
4306
4721
|
...args
|
|
4307
4722
|
});
|
|
4308
|
-
const ctx =
|
|
4723
|
+
const ctx = sharedConfig.context;
|
|
4309
4724
|
for (const b of opened) {
|
|
4310
4725
|
const key = b.key;
|
|
4311
4726
|
const ledgerKey = `${occurrence}:${key}`;
|
|
@@ -4523,20 +4938,9 @@ function frameFlightResponse({
|
|
|
4523
4938
|
});
|
|
4524
4939
|
}
|
|
4525
4940
|
|
|
4526
|
-
setContainerTraceResolver(
|
|
4941
|
+
setContainerTraceResolver(getProjectionTrace);
|
|
4527
4942
|
function asyncArg(value) {
|
|
4528
4943
|
return value;
|
|
4529
4944
|
}
|
|
4530
4945
|
|
|
4531
|
-
|
|
4532
|
-
exports.SERVER_COMPONENT_BOOTSTRAP = SERVER_COMPONENT_BOOTSTRAP;
|
|
4533
|
-
exports.ServerComponentPlugin = ServerComponentPlugin;
|
|
4534
|
-
exports.asyncArg = asyncArg;
|
|
4535
|
-
exports.createFrameSink = createFrameSink;
|
|
4536
|
-
exports.frameTransformDirectResult = frameTransformDirectResult;
|
|
4537
|
-
exports.frameTransformFlightResult = frameTransformFlightResult;
|
|
4538
|
-
exports.frameTransformResult = frameTransformResult;
|
|
4539
|
-
exports.isFrameStreamResponse = isFrameStreamResponse;
|
|
4540
|
-
exports.renderServerComponent = renderServerComponent;
|
|
4541
|
-
exports.renderToFrameStream = renderToFrameStream;
|
|
4542
|
-
exports.serverComponentResponse = serverComponentResponse;
|
|
4946
|
+
export { FRAME_STREAM_HEADER, SERVER_COMPONENT_BOOTSTRAP, ServerComponentPlugin, asyncArg, createFrameSink, frameTransformDirectResult, frameTransformFlightResult, frameTransformResult, isFrameStreamResponse, renderServerComponent, renderToFrameStream, serverComponentResponse };
|