@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.
Files changed (88) hide show
  1. package/dist/server.dev.js +638 -124
  2. package/dist/server.js +445 -94
  3. package/dist/{server.dev.cjs → server.observe.js} +602 -416
  4. package/dist/web.dev.js +229 -49
  5. package/dist/web.js +194 -46
  6. package/dist/{web.cjs → web.observe.js} +290 -275
  7. package/frames/dist/client.dev.js +103 -4
  8. package/frames/dist/client.js +5 -2
  9. package/frames/dist/{client.dev.cjs → client.observe.js} +139 -79
  10. package/frames/dist/server.dev.js +540 -79
  11. package/frames/dist/server.js +371 -52
  12. package/frames/dist/{server.cjs → server.observe.js} +544 -140
  13. package/frames/package.json +15 -21
  14. package/package.json +145 -294
  15. package/serialization/decode/package.json +3 -9
  16. package/serialization/package.json +3 -9
  17. package/serialization/types/serializer-decode.d.ts +49 -2
  18. package/server-functions/dist/{client.cjs → client.dev.js} +140 -107
  19. package/server-functions/dist/client.js +74 -69
  20. package/server-functions/dist/client.observe.js +1102 -0
  21. package/server-functions/dist/server.dev.js +430 -41
  22. package/server-functions/dist/server.js +367 -40
  23. package/server-functions/dist/{server.cjs → server.observe.js} +430 -85
  24. package/server-functions/package.json +15 -21
  25. package/server-functions/rich-args/package.json +3 -9
  26. package/storage/package.json +3 -9
  27. package/types/client.d.ts +39 -1
  28. package/types/diagnostics.d.ts +24 -0
  29. package/types/frames/frame-transport.d.ts +1 -1
  30. package/types/frames/serializer-decode.d.ts +49 -2
  31. package/types/index.d.ts +25 -15
  32. package/types/index.server.d.ts +35 -8
  33. package/types/jsx.d.ts +15 -4
  34. package/types/observe.d.ts +294 -0
  35. package/types/response.d.ts +18 -0
  36. package/types/serializer-decode.d.ts +49 -2
  37. package/types/server-functions/client.d.ts +32 -22
  38. package/types/server-functions/server.d.ts +55 -41
  39. package/types/server-functions/shared.d.ts +39 -9
  40. package/types/server-mock.d.ts +26 -4
  41. package/types/server-observe.d.ts +39 -0
  42. package/types/server.d.ts +105 -6
  43. package/types/trace.d.ts +79 -0
  44. package/dist/server.cjs +0 -3708
  45. package/dist/web.dev.cjs +0 -2285
  46. package/frames/dist/client.cjs +0 -2043
  47. package/frames/dist/server.dev.cjs +0 -4584
  48. package/serialization/dist/decode.cjs +0 -155
  49. package/serialization/dist/serialization.cjs +0 -275
  50. package/serialization/types-cjs/index.d.cts +0 -101
  51. package/serialization/types-cjs/package.json +0 -3
  52. package/serialization/types-cjs/serializer-decode.d.cts +0 -172
  53. package/serialization/types-cjs/serializer.d.cts +0 -101
  54. package/server-functions/dist/rich-args.cjs +0 -11
  55. package/server-functions/dist/server.dev.cjs +0 -2409
  56. package/storage/dist/storage.cjs +0 -12
  57. package/storage/types-cjs/index.d.cts +0 -28
  58. package/storage/types-cjs/package.json +0 -3
  59. package/types-cjs/client.d.cts +0 -197
  60. package/types-cjs/constants.d.cts +0 -20
  61. package/types-cjs/cookies.d.cts +0 -41
  62. package/types-cjs/frames/client.d.cts +0 -36
  63. package/types-cjs/frames/frame-client.d.cts +0 -370
  64. package/types-cjs/frames/frame-container-plugin.d.cts +0 -71
  65. package/types-cjs/frames/frame-sink.d.cts +0 -92
  66. package/types-cjs/frames/frame-transport.d.cts +0 -189
  67. package/types-cjs/frames/serializer-decode.d.cts +0 -172
  68. package/types-cjs/frames/serializer.d.cts +0 -101
  69. package/types-cjs/frames/server.d.cts +0 -52
  70. package/types-cjs/head.d.cts +0 -19
  71. package/types-cjs/index.d.cts +0 -191
  72. package/types-cjs/index.server.d.cts +0 -147
  73. package/types-cjs/jsx-properties.d.cts +0 -93
  74. package/types-cjs/jsx.d.cts +0 -4146
  75. package/types-cjs/package.json +0 -3
  76. package/types-cjs/reconcile.d.cts +0 -1
  77. package/types-cjs/render.d.cts +0 -6
  78. package/types-cjs/response.d.cts +0 -81
  79. package/types-cjs/serializer-decode.d.cts +0 -172
  80. package/types-cjs/serializer.d.cts +0 -101
  81. package/types-cjs/server-functions/client.d.cts +0 -184
  82. package/types-cjs/server-functions/flash.d.cts +0 -36
  83. package/types-cjs/server-functions/registry.d.cts +0 -100
  84. package/types-cjs/server-functions/rich-args.d.cts +0 -1
  85. package/types-cjs/server-functions/server.d.cts +0 -546
  86. package/types-cjs/server-functions/shared.d.cts +0 -283
  87. package/types-cjs/server-mock.d.cts +0 -337
  88. package/types-cjs/server.d.cts +0 -408
@@ -1,8 +1,9 @@
1
- 'use strict';
2
-
3
- var solidJs = require('solid-js');
4
- var seroval = require('seroval');
5
- var web = require('seroval-plugins/web');
1
+ import { createRenderEffect, createMemo, OBSERVE, getOwner, sharedConfig, createRoot, $PROXY, runWithOwner, createComponent, omit, getNextChildId, untrack, NotReadyError, onCleanup } from 'solid-js';
2
+ export { Errored, For, Hydration, Loading, Match, NoHydration, Repeat, Reveal, Show, Switch, createComponent, getOwner, merge as mergeProps, sharedConfig, untrack } from 'solid-js';
3
+ import { inServerComponentScope, sourceOwners, viewOf, sourceKeys, SOURCE_PLAIN, sourceGet, reportServerError, ssrHandleError, creationStamp, ssrSanitizeError, SOURCE_PROXY, getProjectionTrace } from 'solid-js/internal';
4
+ export { ssrScope as scope } from 'solid-js/internal';
5
+ import { Feature, createStream, Serializer, getCrossReferenceHeader } from 'seroval';
6
+ import { AbortSignalPlugin, CustomEventPlugin, DOMExceptionPlugin, EventPlugin, FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin } from 'seroval-plugins/web';
6
7
 
7
8
  const DOMWithState = {
8
9
  INPUT: {
@@ -72,21 +73,181 @@ function effect(fn, effectFn, options) {
72
73
  ...options,
73
74
  transparent: !options.scope
74
75
  } : transparentOptions;
76
+ createRenderEffect(fn, effectFn, nodeOptions);
77
+ }
78
+ function memo(fn) {
79
+ return createMemo(() => fn(), syncOptions);
80
+ }
81
+
82
+ const PROVIDER = Symbol.for("solid-js/observe/server/provider");
83
+ function currentProvider() {
84
+ if (OBSERVE === undefined) return undefined;
85
+ const slot = OBSERVE.server.trace;
86
+ return slot && slot[PROVIDER];
87
+ }
88
+ const TRACEPARENT = /^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})(-.*)?$/;
89
+ const ZERO_TRACE = "00000000000000000000000000000000";
90
+ const ZERO_SPAN = "0000000000000000";
91
+ function parseTraceparent(value) {
92
+ if (!value) return undefined;
93
+ const m = TRACEPARENT.exec(value.trim());
94
+ if (!m) return undefined;
95
+ const [, version, traceId, parentId, flags, rest] = m;
96
+ if (version === "ff") return undefined;
97
+ if (version === "00" && rest !== undefined) return undefined;
98
+ if (traceId === ZERO_TRACE || parentId === ZERO_SPAN) return undefined;
99
+ return {
100
+ traceId,
101
+ parentId,
102
+ sampled: (parseInt(flags, 16) & 1) === 1
103
+ };
104
+ }
105
+ function randomHex(bytes) {
106
+ const buffer = new Uint8Array(bytes);
107
+ crypto.getRandomValues(buffer);
108
+ let out = "";
109
+ for (let i = 0; i < buffer.length; i++) out += (buffer[i] < 16 ? "0" : "") + buffer[i].toString(16);
110
+ return out;
111
+ }
112
+ function randomTraceId() {
113
+ let id = randomHex(16);
114
+ while (id === ZERO_TRACE) id = randomHex(16);
115
+ return id;
116
+ }
117
+ function randomSpanId() {
118
+ let id = randomHex(8);
119
+ while (id === ZERO_SPAN) id = randomHex(8);
120
+ return id;
121
+ }
122
+ function formatTraceparent(context) {
123
+ return `00-${context.traceId}-${context.spanId}-${context.sampled === true ? "01" : "00"}`;
124
+ }
125
+ const RECORDS_KEY = Symbol.for("@solidjs/web/trace/records");
126
+ function records() {
127
+ const g = globalThis;
128
+ return g[RECORDS_KEY] || (g[RECORDS_KEY] = new WeakMap());
129
+ }
130
+ function traceFor(key, request) {
131
+ const store = records();
132
+ let record = store.get(key);
133
+ if (record) return record;
134
+ const headers = request ? request.headers : undefined;
135
+ const incoming = headers ? parseTraceparent(headers.get("traceparent")) : undefined;
136
+ const context = {
137
+ traceId: incoming ? incoming.traceId : randomTraceId(),
138
+ spanId: randomSpanId(),
139
+ entries: {}
140
+ };
141
+ if (incoming) {
142
+ context.parentId = incoming.parentId;
143
+ context.sampled = incoming.sampled;
144
+ }
145
+ if (headers) {
146
+ const state = headers.get("tracestate");
147
+ if (state) context.state = state;
148
+ const baggage = headers.get("baggage");
149
+ if (baggage) context.baggage = baggage;
150
+ }
151
+ let answered = false;
152
+ let providedEntries;
75
153
  {
76
- solidJs.createRenderEffect(prev => {
77
- solidJs.getOwner();
78
- return fn(prev);
79
- }, (value, prev) => {
154
+ const provider = currentProvider();
155
+ if (provider) {
156
+ let answer;
80
157
  try {
81
- return effectFn(value, prev);
82
- } finally {
83
- }
84
- }, nodeOptions);
85
- return;
158
+ answer = provider(request);
159
+ } catch (error) {
160
+ console.error(error);
161
+ }
162
+ if (answer !== undefined && answer !== null) {
163
+ answered = true;
164
+ if (answer.traceId !== undefined) context.traceId = answer.traceId;
165
+ if (answer.spanId !== undefined) context.spanId = answer.spanId;
166
+ if (answer.parentId !== undefined) context.parentId = answer.parentId;
167
+ if (answer.sampled !== undefined) context.sampled = answer.sampled;
168
+ if (answer.state !== undefined) context.state = answer.state;
169
+ if (answer.baggage !== undefined) context.baggage = answer.baggage;
170
+ providedEntries = answer.entries;
171
+ }
172
+ }
173
+ }
174
+ context.entries.traceparent = formatTraceparent(context);
175
+ if (providedEntries) Object.assign(context.entries, providedEntries);
176
+ record = {
177
+ context,
178
+ emit: incoming !== undefined && incoming.sampled || answered
179
+ };
180
+ store.set(key, record);
181
+ return record;
182
+ }
183
+ const TOKEN = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
184
+ function splitServerTiming(value) {
185
+ const entries = [];
186
+ let start = 0;
187
+ let quoted = false;
188
+ for (let i = 0; i < value.length; i++) {
189
+ const c = value[i];
190
+ if (quoted) {
191
+ if (c === "\\") i++;else if (c === '"') quoted = false;
192
+ } else if (c === '"') quoted = true;else if (c === ",") {
193
+ entries.push(value.slice(start, i));
194
+ start = i + 1;
195
+ }
196
+ }
197
+ entries.push(value.slice(start));
198
+ return entries;
199
+ }
200
+ function metricName(entry) {
201
+ return entry.split(";")[0].trim().toLowerCase();
202
+ }
203
+ function namesOnServerTiming(headers) {
204
+ const names = new Set();
205
+ const existing = headers.get("server-timing");
206
+ if (existing) {
207
+ for (const entry of splitServerTiming(existing)) {
208
+ const name = metricName(entry);
209
+ if (name) names.add(name);
210
+ }
86
211
  }
212
+ return names;
87
213
  }
88
- function memo(fn) {
89
- return solidJs.createMemo(() => fn(), syncOptions);
214
+ function quoteDesc(value) {
215
+ return value.replace(/[\x00-\x1f\x7f]/g, "").replace(/[\\"]/g, m => "\\" + m);
216
+ }
217
+ function appendTraceServerTiming(headers, record) {
218
+ if (!record.emit) return;
219
+ const entries = record.context.entries;
220
+ let present;
221
+ for (const name in entries) {
222
+ if (!TOKEN.test(name)) continue;
223
+ if (!present) present = namesOnServerTiming(headers);
224
+ if (present.has(name.toLowerCase())) continue;
225
+ headers.append("Server-Timing", `${name};desc="${quoteDesc(entries[name])}"`);
226
+ present.add(name.toLowerCase());
227
+ }
228
+ }
229
+ function mergeServerTiming(target, value) {
230
+ const present = namesOnServerTiming(target);
231
+ for (const entry of splitServerTiming(value)) {
232
+ const trimmed = entry.trim();
233
+ const name = metricName(trimmed);
234
+ if (!name || present.has(name)) continue;
235
+ target.append("Server-Timing", trimmed);
236
+ present.add(name);
237
+ }
238
+ }
239
+ function escapeAttr(value) {
240
+ return value.replace(/[&"<>]/g, c => c === "&" ? "&amp;" : c === '"' ? "&quot;" : c === "<" ? "&lt;" : "&gt;");
241
+ }
242
+ function traceMetaMarkup(record) {
243
+ if (!record.emit) return "";
244
+ let markup = "";
245
+ const entries = record.context.entries;
246
+ for (const name in entries) {
247
+ if (!TOKEN.test(name)) continue;
248
+ markup += `<meta name="${name}" content="${escapeAttr(entries[name])}">`;
249
+ }
250
+ return markup;
90
251
  }
91
252
 
92
253
  const STATE = Symbol.for("solid.container-trace-state");
@@ -151,7 +312,7 @@ const ContainerTracePlugin = {
151
312
  };
152
313
 
153
314
  setContainerTraceStreamMint(iterable => {
154
- const stream = seroval.createStream();
315
+ const stream = createStream();
155
316
  (async () => {
156
317
  try {
157
318
  for await (const value of iterable) stream.next(value);
@@ -162,20 +323,20 @@ setContainerTraceStreamMint(iterable => {
162
323
  })();
163
324
  return stream;
164
325
  });
165
- const DEFAULT_WEB_PLUGINS = Object.freeze([web.AbortSignalPlugin,
166
- web.CustomEventPlugin, web.DOMExceptionPlugin, web.EventPlugin,
167
- web.FormDataPlugin, web.HeadersPlugin, web.ReadableStreamPlugin, web.RequestPlugin, web.ResponsePlugin, web.URLSearchParamsPlugin, web.URLPlugin,
326
+ const DEFAULT_WEB_PLUGINS = Object.freeze([AbortSignalPlugin,
327
+ CustomEventPlugin, DOMExceptionPlugin, EventPlugin,
328
+ FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin,
168
329
  ContainerTracePlugin]);
169
330
  function resolveSerializerPlugins(customPlugins) {
170
331
  return customPlugins ? [...customPlugins, ...DEFAULT_WEB_PLUGINS] : [...DEFAULT_WEB_PLUGINS];
171
332
  }
172
- seroval.Feature.RegExp;
333
+ Feature.RegExp;
173
334
 
174
- const DEFAULT_DISABLED_FEATURES = seroval.Feature.AggregateError | seroval.Feature.BigIntTypedArray;
175
- const serializeOnlyDisabledFeatures = serializeErrorStacks => (serializeErrorStacks === undefined ? process.env.NODE_ENV === "development" : serializeErrorStacks) ? 0 : seroval.Feature.ErrorPrototypeStack;
335
+ const DEFAULT_DISABLED_FEATURES = Feature.AggregateError | Feature.BigIntTypedArray;
336
+ const serializeOnlyDisabledFeatures = serializeErrorStacks => (serializeErrorStacks === undefined ? process.env.NODE_ENV === "development" : serializeErrorStacks) ? 0 : Feature.ErrorPrototypeStack;
176
337
  const HYDRATION_GLOBAL = "_$HY.r";
177
338
  function createSerializer(options) {
178
- return new seroval.Serializer({
339
+ return new Serializer({
179
340
  ...options,
180
341
  plugins: resolveSerializerPlugins(options.plugins),
181
342
  disabledFeatures: (options.disabledFeatures === undefined ? DEFAULT_DISABLED_FEATURES : options.disabledFeatures) | serializeOnlyDisabledFeatures(options.serializeErrorStacks)
@@ -198,7 +359,7 @@ function createHydrationSerializer({
198
359
  });
199
360
  }
200
361
  function getLocalHeaderScript(id) {
201
- return seroval.getCrossReferenceHeader(id) + ";";
362
+ return getCrossReferenceHeader(id) + ";";
202
363
  }
203
364
 
204
365
  const ENVELOPE = Symbol.for("solid.ResponseEnvelope");
@@ -235,6 +396,7 @@ function isSafeError(value) {
235
396
  return !!(value && (typeof value === "object" || typeof value === "function") && value[SAFE_ERROR]);
236
397
  }
237
398
  const REVALIDATE_HEADER = "X-Revalidate";
399
+ const REVALIDATE_ALL = "*";
238
400
  const RESPONSE_HEADER_VALUE_LIMIT = 4096;
239
401
  function initWithRevalidate(init = {}) {
240
402
  const resolved = typeof init === "number" ? {
@@ -257,7 +419,11 @@ function initWithRevalidate(init = {}) {
257
419
  headers = new Headers(responseInit.headers);
258
420
  }
259
421
  if (revalidate !== undefined) {
260
- const keys = revalidate.toString();
422
+ const list = Array.isArray(revalidate) ? revalidate : [revalidate];
423
+ if (list.length > 1 && list.includes(REVALIDATE_ALL)) {
424
+ 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.`);
425
+ }
426
+ const keys = list.join(",");
261
427
  if (keys.length > RESPONSE_HEADER_VALUE_LIMIT) {
262
428
  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.`);
263
429
  }
@@ -357,7 +523,6 @@ function decodeSafe(text) {
357
523
  }
358
524
  }
359
525
  function serializeCookie(name, value, options = {}) {
360
- assertServableCookie(name, options);
361
526
  let cookie = `${encodeURIComponent(name)}=${encodeURIComponent(value)}`;
362
527
  cookie += `; Path=${options.path === undefined ? "/" : options.path}`;
363
528
  if (options.domain) cookie += `; Domain=${options.domain}`;
@@ -372,25 +537,6 @@ function serializeCookie(name, value, options = {}) {
372
537
  }
373
538
  return cookie;
374
539
  }
375
- function assertServableCookie(name, options) {
376
- const reject = reason => {
377
- throw new Error(`serializeCookie: every browser silently rejects this cookie — ${reason}. ` + `It would never come back on a request, with no error anywhere.`);
378
- };
379
- const lower = name.toLowerCase();
380
- if (lower.startsWith("__host-")) {
381
- if (!options.secure) reject(`the __Host- prefix on \`${name}\` requires \`secure: true\``);
382
- if (options.path !== undefined && options.path !== "/") reject(`the __Host- prefix on \`${name}\` requires \`Path=/\` (got \`${options.path}\`) — ` + `host-locking is the prefix's whole contract, so it cannot be path-scoped`);
383
- if (options.domain) reject(`the __Host- prefix on \`${name}\` forbids \`Domain\` (got \`${options.domain}\`)`);
384
- } else if (lower.startsWith("__secure-") && !options.secure) {
385
- reject(`the __Secure- prefix on \`${name}\` requires \`secure: true\``);
386
- }
387
- if (options.sameSite && options.sameSite.toLowerCase() === "none" && !options.secure) {
388
- reject("`SameSite=None` requires `secure: true`");
389
- }
390
- if (options.partitioned && !options.secure) {
391
- reject("`Partitioned` requires `secure: true`");
392
- }
393
- }
394
540
  const FLASH_COOKIE = "flash";
395
541
  const FLASH_MATCHER = new RegExp(`(?:^|;\\s*)${FLASH_COOKIE}=([^;]+)`);
396
542
  function hasFlashCookie(cookieHeader) {
@@ -405,6 +551,18 @@ const BODY_FORMAT_HEADER = "X-Server-Function-Format";
405
551
  const REDIRECT_HEADER = "X-Server-Function-Redirect";
406
552
  const SINGLE_FLIGHT_HEADER = "X-Single-Flight";
407
553
 
554
+ function emitFinding(finding, subject = getOwner()) {
555
+ if (OBSERVE === undefined) return;
556
+ OBSERVE.diagnostics.emit(finding, subject);
557
+ }
558
+ function recordFinding(finding, subject = getOwner()) {
559
+ if (OBSERVE !== undefined) OBSERVE.diagnostics.emit(finding, subject);
560
+ }
561
+ function errorText(error) {
562
+ if (error instanceof Error) return error.message ? `${error.name}: ${error.message}` : error.name;
563
+ return String(error);
564
+ }
565
+
408
566
  const HEAD_ELIGIBLE_TAGS = new Set(["title", "meta", "link", "style", "script", "base"]);
409
567
  const HEAD_ATTR_NAME = /^[a-zA-Z_][a-zA-Z0-9_:.-]*$/;
410
568
  const RESOURCE_LINK_RELS = new Set(["preload", "modulepreload", "prefetch", "preconnect", "dns-prefetch", "stylesheet"]);
@@ -488,7 +646,6 @@ function resolveHead(groups) {
488
646
  }
489
647
  for (const [identity, tags] of byIdentity) {
490
648
  if (identity === "title") {
491
- if (tags.length > 1) console.warn("Multiple <title> tags in one head group; the last one wins.");
492
649
  winners.set(identity, {
493
650
  seq: group.seq,
494
651
  tags: [tags[tags.length - 1]]
@@ -510,32 +667,6 @@ function joinAssetPath(base, file) {
510
667
  if (base[base.length - 1] !== "/") base += "/";
511
668
  return base + (file[0] === "/" ? file.slice(1) : file);
512
669
  }
513
- function eachCandidate(srcset, visit) {
514
- let i = 0;
515
- const n = srcset.length;
516
- while (i < n) {
517
- while (i < n && /[\s,]/.test(srcset[i])) i++;
518
- const start = i;
519
- while (i < n && !/\s/.test(srcset[i])) i++;
520
- if (i === start) return false;
521
- const raw = srcset.slice(start, i);
522
- const url = raw.replace(/,+$/, "");
523
- let descriptors = "";
524
- if (url === raw) {
525
- const from = i;
526
- while (i < n && srcset[i] !== ",") i++;
527
- descriptors = srcset.slice(from, i);
528
- }
529
- if (url && visit(url, descriptors)) return true;
530
- }
531
- return false;
532
- }
533
- function hasRelativeCandidate(srcset) {
534
- return eachCandidate(srcset, url => !/^(?:[a-zA-Z][a-zA-Z0-9+.-]*:|\/)/.test(url));
535
- }
536
- function hasWidthDescriptor(srcset) {
537
- return eachCandidate(srcset, (_, descriptors) => /(?:^|\s)\d+(?:\.\d+)?w(?=\s|$)/.test(descriptors));
538
- }
539
670
  function resolveAssets(moduleUrl, manifest) {
540
671
  if (!manifest) return null;
541
672
  const base = manifest._base;
@@ -567,10 +698,8 @@ function resolveAssets(moduleUrl, manifest) {
567
698
  href: bad,
568
699
  ...rest
569
700
  } = link;
570
- if (bad !== undefined) console.warn("Preload href must be a non-empty string; dropping it.", bad);
571
701
  preloads.push(rest);
572
702
  }
573
- if (srcset && hasRelativeCandidate(srcset)) console.warn("imagesrcset candidates are not joined with the manifest base — they resolve " + "against the document URL, so a relative candidate points somewhere else " + "than the joined href; the integration should emit resolved URLs.", srcset);
574
703
  }
575
704
  }
576
705
  if (e.imports) for (let i = 0; i < e.imports.length; i++) walk(e.imports[i]);
@@ -585,7 +714,7 @@ function resolveAssets(moduleUrl, manifest) {
585
714
  }
586
715
  function registerEntryAssets(manifest) {
587
716
  if (!manifest || typeof manifest === "function" || typeof manifest.resolve === "function") return;
588
- const ctx = solidJs.sharedConfig.context;
717
+ const ctx = sharedConfig.context;
589
718
  if (!ctx?.registerAsset) return;
590
719
  for (const key in manifest) {
591
720
  if (manifest[key].isEntry) {
@@ -709,11 +838,9 @@ function isSetAttr(value) {
709
838
  const PRELOAD_LINK_ATTRIBUTES = ["type", "crossorigin", "integrity", "referrerpolicy", "fetchpriority", "media", "imagesrcset", "imagesizes"];
710
839
  function registerPreloadLink(tracking, headRegistry, link, nonce) {
711
840
  if (!link || typeof link !== "object") {
712
- console.warn('registerAsset("preload") requires a descriptor object.', link);
713
841
  return null;
714
842
  }
715
843
  if (typeof link.as !== "string") {
716
- console.warn('registerAsset("preload") requires an as destination.');
717
844
  return null;
718
845
  }
719
846
  const as = asciiLowerCase(link.as);
@@ -729,11 +856,9 @@ function registerPreloadLink(tracking, headRegistry, link, nonce) {
729
856
  case "track":
730
857
  break;
731
858
  default:
732
- console.warn(`registerAsset("preload") received an unsupported as destination "${link.as}".`);
733
859
  return null;
734
860
  }
735
861
  const responsive = as === "image";
736
- if (!responsive && (isSetAttr(link.imagesrcset) || isSetAttr(link.imagesizes))) console.warn('registerAsset("preload") only supports imagesrcset and imagesizes with as="image".');
737
862
  let srcset = null;
738
863
  let sizes = null;
739
864
  if (responsive) {
@@ -741,19 +866,15 @@ function registerPreloadLink(tracking, headRegistry, link, nonce) {
741
866
  const value = link[name];
742
867
  if (!isSetAttr(value)) continue;
743
868
  if (typeof value !== "string") {
744
- console.warn(`registerAsset("preload") expects a string ${name}.`);
745
869
  continue;
746
870
  }
747
871
  if (name === "imagesrcset") srcset = value;else sizes = value;
748
872
  }
749
873
  }
750
874
  const href = typeof link.href === "string" && link.href ? link.href : null;
751
- if (!href && link.href != null && link.href !== false) console.warn("Preload href must be a non-empty string; dropping it.", link.href);
752
875
  if (!href && !srcset) {
753
- console.warn('registerAsset("preload") requires a non-empty string href or imagesrcset.');
754
876
  return null;
755
877
  }
756
- if (srcset && !sizes && hasWidthDescriptor(srcset)) console.warn("imagesrcset uses a width descriptor, so imagesizes is required; without it the " + "source size defaults to 100vw and the preload may not match the image.", srcset);
757
878
  const props = {
758
879
  rel: "preload"
759
880
  };
@@ -772,7 +893,6 @@ function registerPreloadLink(tracking, headRegistry, link, nonce) {
772
893
  }
773
894
  const identity = resourceIdentity("link", props);
774
895
  if (headRegistry.resources.has(identity)) return null;
775
- if (props.crossorigin == null && (as === "font" || as === "fetch")) console.warn(`registerAsset("preload") with as="${as}" has no crossorigin and may not match the eventual request.`);
776
896
  const attrs = headAttrRecord(props);
777
897
  const nonceValue = destination && nonce && nonce[destination];
778
898
  if (typeof nonceValue === "string" && nonceValue) attrs.nonce = nonceValue;
@@ -811,12 +931,11 @@ function registerHeadTags(registry, context, tracking, emitResource, nonce, tags
811
931
  return;
812
932
  }
813
933
  if (!Array.isArray(tags)) tags = [tags];
814
- const probe = solidJs.sharedConfig.context && solidJs.sharedConfig.context._loadingPhase;
934
+ const probe = sharedConfig.context && sharedConfig.context._loadingPhase;
815
935
  let replaceable = null;
816
936
  for (let i = 0; i < tags.length; i++) {
817
937
  const desc = tags[i];
818
938
  if (!desc || !HEAD_ELIGIBLE_TAGS.has(desc.tag)) {
819
- console.warn(`useHead: ignoring non-head tag`, desc);
820
939
  continue;
821
940
  }
822
941
  const cls = classifyHeadTag(desc);
@@ -827,7 +946,7 @@ function registerHeadTags(registry, context, tracking, emitResource, nonce, tags
827
946
  } : undefined);
828
947
  evalHeadValue(desc.key);
829
948
  } catch (err) {
830
- if (solidJs.ssrHandleError(err)) throw err;
949
+ if (ssrHandleError(err)) throw err;
831
950
  }
832
951
  }
833
952
  if (cls.resource) {
@@ -849,7 +968,7 @@ function registerHeadTags(registry, context, tracking, emitResource, nonce, tags
849
968
  function headShellReady(registry, block) {
850
969
  let ready = true;
851
970
  const pends = err => {
852
- const source = solidJs.ssrHandleError(err, true);
971
+ const source = ssrHandleError(err, true);
853
972
  if (!source) return false;
854
973
  block(source);
855
974
  ready = false;
@@ -868,7 +987,6 @@ function headShellReady(registry, block) {
868
987
  } : undefined);
869
988
  } catch (err) {
870
989
  if (pends(err)) continue;
871
- console.warn(`useHead: error evaluating resource tag props`, err);
872
990
  parked.splice(i, 1);
873
991
  continue;
874
992
  }
@@ -899,9 +1017,9 @@ function emitHeadResource(registry, context, tracking, emitResource, nonce, desc
899
1017
  rel
900
1018
  } : undefined);
901
1019
  } catch (err) {
902
- const loadingPhase = solidJs.sharedConfig.context && solidJs.sharedConfig.context._loadingPhase;
903
- if (loadingPhase && solidJs.ssrHandleError(err)) throw err;
904
- if (!loadingPhase && !context._currentBoundaryId && !registry.shellFlushed && typeof context.block === "function" && solidJs.ssrHandleError(err, true)) {
1020
+ const loadingPhase = sharedConfig.context && sharedConfig.context._loadingPhase;
1021
+ if (loadingPhase && ssrHandleError(err)) throw err;
1022
+ if (!loadingPhase && !context._currentBoundaryId && !registry.shellFlushed && typeof context.block === "function" && ssrHandleError(err, true)) {
905
1023
  registry.parkedResources.push({
906
1024
  desc,
907
1025
  rel,
@@ -909,7 +1027,6 @@ function emitHeadResource(registry, context, tracking, emitResource, nonce, desc
909
1027
  });
910
1028
  return;
911
1029
  }
912
- console.warn(`useHead: error evaluating resource tag props`, err);
913
1030
  return;
914
1031
  }
915
1032
  const identity = resourceIdentity(desc.tag, props);
@@ -971,7 +1088,6 @@ function commitHeadBoundary(registry, boundary, isPendingFragment) {
971
1088
  try {
972
1089
  resolved = reg.list();
973
1090
  } catch (err) {
974
- console.warn(`useHead: error evaluating head group membership`, err);
975
1091
  continue;
976
1092
  }
977
1093
  if (!Array.isArray(resolved)) resolved = [resolved];
@@ -979,7 +1095,6 @@ function commitHeadBoundary(registry, boundary, isPendingFragment) {
979
1095
  for (let j = 0; j < resolved.length; j++) {
980
1096
  const desc = resolved[j];
981
1097
  if (!desc || !HEAD_ELIGIBLE_TAGS.has(desc.tag)) {
982
- console.warn(`useHead: ignoring non-head tag`, desc);
983
1098
  continue;
984
1099
  }
985
1100
  const cls = classifyHeadTag(desc);
@@ -1005,12 +1120,10 @@ function commitHeadBoundary(registry, boundary, isPendingFragment) {
1005
1120
  } : undefined);
1006
1121
  key = evalHeadValue(desc.key);
1007
1122
  } catch (err) {
1008
- console.warn(`useHead: error evaluating tag props`, err);
1009
1123
  continue;
1010
1124
  }
1011
1125
  const identity = replaceableIdentity(desc.tag, props, key, "u:" + registry.uniq++);
1012
1126
  if ((identity === "base" || identity === "charset") && registry.shellFlushed) {
1013
- console.warn(`useHead: <${desc.tag}> (${identity}) registered after shell flush is ignored`);
1014
1127
  continue;
1015
1128
  }
1016
1129
  tags.push({
@@ -1044,7 +1157,7 @@ function headGroupSignature(winner) {
1044
1157
  }
1045
1158
  return sig;
1046
1159
  }
1047
- function renderShellHead(registry, nonce, isPendingFragment, noScripts) {
1160
+ function renderShellHead(registry, nonce, isPendingFragment, noScripts, traceMetas = "") {
1048
1161
  commitHeadBoundary(registry, "", isPendingFragment);
1049
1162
  registry.shellFlushed = true;
1050
1163
  const winners = resolveHead(registry.committed);
@@ -1070,7 +1183,7 @@ function renderShellHead(registry, nonce, isPendingFragment, noScripts) {
1070
1183
  }
1071
1184
  return {
1072
1185
  prelude,
1073
- html: registry.eagerHtml + links + metas + others + scripts,
1186
+ html: registry.eagerHtml + links + metas + traceMetas + others + scripts,
1074
1187
  title,
1075
1188
  noScripts
1076
1189
  };
@@ -1100,7 +1213,6 @@ function flushHeadFragment(registry, boundary, nonce) {
1100
1213
  for (const name in t.props) {
1101
1214
  if (name === "children" || name === "ref" || name.slice(0, 2) === "on") continue;
1102
1215
  if (!HEAD_ATTR_NAME.test(name)) {
1103
- console.warn(`useHead: ignoring invalid attribute name "${name}"`);
1104
1216
  continue;
1105
1217
  }
1106
1218
  const v = t.props[name];
@@ -1190,7 +1302,6 @@ function renderHeadAttrHtml(props) {
1190
1302
  for (const name in props) {
1191
1303
  if (name === "children" || name === "ref" || name.slice(0, 2) === "on") continue;
1192
1304
  if (!HEAD_ATTR_NAME.test(name)) {
1193
- console.warn(`useHead: ignoring invalid attribute name "${name}"`);
1194
1305
  continue;
1195
1306
  }
1196
1307
  const v = props[name];
@@ -1221,9 +1332,8 @@ function renderHeadTagMarkup(tag, props, identity, nonce) {
1221
1332
  return `<${tag}${attrs}>${body}</${tag}>`;
1222
1333
  }
1223
1334
  function useHead(tags) {
1224
- const ctx = solidJs.sharedConfig.context;
1335
+ const ctx = sharedConfig.context;
1225
1336
  if (!ctx || !ctx.registerHeadTags) {
1226
- console.warn("useHead() called outside of a server render; registration ignored.");
1227
1337
  return;
1228
1338
  }
1229
1339
  ctx.registerHeadTags(tags);
@@ -1250,20 +1360,21 @@ function renderToString(code, options = {}) {
1250
1360
  }
1251
1361
  scripts += script + ";";
1252
1362
  },
1253
- onError: options.onError
1363
+ onError: serializerErrorHook(options.onError)
1254
1364
  });
1255
1365
  const tracking = createAssetTracking();
1256
1366
  const headRegistry = createHeadRegistry();
1257
- solidJs.sharedConfig.context = {
1367
+ sharedConfig.context = {
1258
1368
  nonce: options.nonce,
1259
1369
  escape: escape,
1260
1370
  resolve: resolveSSRNode,
1261
1371
  ssr: ssr,
1372
+ errorPolicy: options.onError,
1262
1373
  registerHeadTags(tags) {
1263
- registerHeadTags(headRegistry, solidJs.sharedConfig.context, tracking, null, nonce, tags);
1374
+ registerHeadTags(headRegistry, sharedConfig.context, tracking, null, nonce, tags);
1264
1375
  },
1265
1376
  serialize(id, p) {
1266
- if (solidJs.sharedConfig.context.noHydrate) return;
1377
+ if (sharedConfig.context.noHydrate) return;
1267
1378
  if (p != null && typeof p === "object" && (typeof p.then === "function" || typeof p[Symbol.asyncIterator] === "function")) {
1268
1379
  throw new Error("Cannot serialize async value in renderToString (id: " + id + "). " + "Use renderToStream for async data.");
1269
1380
  }
@@ -1289,19 +1400,34 @@ function renderToString(code, options = {}) {
1289
1400
  tracking.emittedAssets.add(value);
1290
1401
  }
1291
1402
  };
1292
- applyAssetTracking(solidJs.sharedConfig.context, tracking, manifest, noScripts);
1403
+ applyAssetTracking(sharedConfig.context, tracking, manifest, noScripts);
1293
1404
  registerEntryAssets(manifest);
1294
- let html = solidJs.createRoot(d => {
1295
- setTimeout(d);
1296
- return resolveSSRSync(escape(code()));
1297
- }, {
1298
- id: renderId
1299
- });
1300
- serializeFragmentAssets("", tracking.boundaryModules, solidJs.sharedConfig.context, renderId);
1301
- solidJs.sharedConfig.context.noHydrate = true;
1302
- serializer.close();
1303
- const head = renderShellHead(headRegistry, nonce, null, noScripts);
1304
- return assembleDocument(resolveSSRSelectValues(html), tracking.emittedAssets, tracking.preloadLinks, tracking.inlineStyles, scripts.length ? scripts : "", nonce, head, onHead);
1405
+ const context = sharedConfig.context;
1406
+ const requestEvent = peekRequestEvent();
1407
+ context.trace = requestEvent ? traceForEvent(requestEvent) : traceFor(context, undefined);
1408
+ let dispose;
1409
+ try {
1410
+ const html = createRoot(d => {
1411
+ dispose = d;
1412
+ return resolveSSRSync(escape(code()));
1413
+ }, {
1414
+ id: renderId
1415
+ });
1416
+ serializeFragmentAssets("", tracking.boundaryModules, sharedConfig.context, renderId);
1417
+ sharedConfig.context.noHydrate = true;
1418
+ serializer.close();
1419
+ const head = renderShellHead(headRegistry, nonce, null, noScripts, traceMetaMarkup(context.trace));
1420
+ const document = assembleDocument(resolveSSRSelectValues(html), tracking.emittedAssets, tracking.preloadLinks, tracking.inlineStyles, scripts.length ? scripts : "", nonce, head, onHead);
1421
+ if (requestEvent && requestEvent.response) {
1422
+ commitResponseStub(requestEvent.response, {
1423
+ event: requestEvent
1424
+ });
1425
+ }
1426
+ return document;
1427
+ } finally {
1428
+ context.trace = undefined;
1429
+ if (dispose) dispose();
1430
+ }
1305
1431
  }
1306
1432
  function renderToStream(code, options = {}) {
1307
1433
  let {
@@ -1316,8 +1442,19 @@ function renderToStream(code, options = {}) {
1316
1442
  const requestEvent = peekRequestEvent();
1317
1443
  let dispose;
1318
1444
  let dead = false;
1319
- const abandon = () => {
1445
+ const abandon = disconnect => {
1320
1446
  if (dead) return;
1447
+ if (disconnect) emitFinding({
1448
+ code: "SSR_STREAM_ABANDONED",
1449
+ kind: "ssr",
1450
+ severity: "warn",
1451
+ message: `[SSR_STREAM_ABANDONED] The response stream was abandoned mid-render (${disconnect}) ` + `with ${registry.size} fragment(s) still pending; the render was torn down.`,
1452
+ data: {
1453
+ reason: disconnect,
1454
+ shellFlushed: firstFlushed,
1455
+ pendingFragments: registry.size
1456
+ }
1457
+ }, null);
1321
1458
  dead = true;
1322
1459
  completed = true;
1323
1460
  buffer = {
@@ -1333,11 +1470,26 @@ function renderToStream(code, options = {}) {
1333
1470
  }
1334
1471
  };
1335
1472
  const failRender = err => {
1336
- try {
1337
- options.onError ? options.onError(err) : console.error(err);
1338
- } catch (_) {}
1473
+ reportServerError(err, {
1474
+ kind: "render",
1475
+ handling: "failed"
1476
+ }, null);
1477
+ if (!options.onError && ambientServerErrorHook() === undefined) console.error(err);
1339
1478
  abandon();
1340
1479
  };
1480
+ const failRootRender = err => {
1481
+ emitFinding({
1482
+ code: "SSR_RENDER_ERROR_CONTAINED",
1483
+ kind: "ssr",
1484
+ severity: "error",
1485
+ message: `[SSR_RENDER_ERROR_CONTAINED] Render error outside any boundary — the request failed: ` + errorText(err),
1486
+ data: {
1487
+ handling: "failed",
1488
+ error: err
1489
+ }
1490
+ }, null);
1491
+ failRender(err);
1492
+ };
1341
1493
  const coalesceWrites = (writeRaw, endRaw) => {
1342
1494
  let buf = "";
1343
1495
  let scheduled = false;
@@ -1370,7 +1522,7 @@ function renderToStream(code, options = {}) {
1370
1522
  try {
1371
1523
  w.write(payload);
1372
1524
  } catch (_) {
1373
- abandon();
1525
+ abandon("sink");
1374
1526
  }
1375
1527
  },
1376
1528
  end() {
@@ -1378,7 +1530,7 @@ function renderToStream(code, options = {}) {
1378
1530
  try {
1379
1531
  w.end();
1380
1532
  } catch (_) {
1381
- abandon();
1533
+ abandon("sink");
1382
1534
  }
1383
1535
  }
1384
1536
  });
@@ -1475,7 +1627,7 @@ function renderToStream(code, options = {}) {
1475
1627
  plugins: options.plugins,
1476
1628
  onData: payload => sink.data(payload),
1477
1629
  onDone,
1478
- onError: options.onError
1630
+ onError: serializerErrorHook(options.onError)
1479
1631
  });
1480
1632
  let rootAssetsSerialized = false;
1481
1633
  const serializeRootAssets = () => {
@@ -1500,6 +1652,34 @@ function renderToStream(code, options = {}) {
1500
1652
  };
1501
1653
  const registry = new Map();
1502
1654
  const pendingSerialized = new Map();
1655
+ const guardedChannels = new WeakMap();
1656
+ const verdictNow = error => {
1657
+ throw ssrSanitizeError(error, null);
1658
+ };
1659
+ const guardChannel = p => {
1660
+ if (!p || typeof p !== "object" || "__SEROVAL_STREAM__" in p) return p;
1661
+ const thenable = typeof p.then === "function";
1662
+ const iterable = !thenable && typeof p[Symbol.asyncIterator] === "function";
1663
+ if (!thenable && !iterable) return p;
1664
+ let guarded = guardedChannels.get(p);
1665
+ if (guarded === undefined) {
1666
+ guarded = thenable ? p.then(undefined, verdictNow) : {
1667
+ [Symbol.asyncIterator]() {
1668
+ const iterator = p[Symbol.asyncIterator]();
1669
+ return {
1670
+ next: value => iterator.next(value).then(undefined, verdictNow),
1671
+ return: value => iterator.return ? iterator.return(value) : Promise.resolve({
1672
+ done: true,
1673
+ value
1674
+ }),
1675
+ throw: error => iterator.throw ? iterator.throw(error) : Promise.reject(error)
1676
+ };
1677
+ }
1678
+ };
1679
+ guardedChannels.set(p, guarded);
1680
+ }
1681
+ return guarded;
1682
+ };
1503
1683
  const trackSerialized = (id, p) => {
1504
1684
  let settle;
1505
1685
  const raced = Promise.race([p, new Promise(r => settle = r)]);
@@ -1508,19 +1688,35 @@ function renderToStream(code, options = {}) {
1508
1688
  p.then(drop, drop);
1509
1689
  return raced;
1510
1690
  };
1511
- const abandonSubtree = key => {
1691
+ const abandonSubtree = (key, error) => {
1692
+ let fragments = 0;
1693
+ let serialized = 0;
1512
1694
  for (const [k, entry] of registry) {
1513
1695
  if (k.length > key.length && k.startsWith(key)) {
1514
1696
  registry.delete(k);
1515
1697
  entry.resolve();
1698
+ fragments++;
1516
1699
  }
1517
1700
  }
1518
1701
  for (const [id, settle] of pendingSerialized) {
1519
1702
  if (id.startsWith(key)) {
1520
1703
  pendingSerialized.delete(id);
1521
1704
  settle();
1705
+ serialized++;
1522
1706
  }
1523
1707
  }
1708
+ if ((fragments || serialized)) emitFinding({
1709
+ code: "SSR_SUBTREE_ABANDONED",
1710
+ kind: "ssr",
1711
+ severity: "warn",
1712
+ 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.`,
1713
+ data: {
1714
+ fragment: key,
1715
+ fragments,
1716
+ serialized,
1717
+ error
1718
+ }
1719
+ }, null);
1524
1720
  };
1525
1721
  const writeTasks = () => {
1526
1722
  if (tasks.length && !completed && firstFlushed) {
@@ -1576,7 +1772,7 @@ function renderToStream(code, options = {}) {
1576
1772
  emitTask(`${!headScriptFlushed ? HEAD_SCRIPT : ""}(_$HY.hp=_$HY.hp||{})[${JSON.stringify(key)}]=${payload}`);
1577
1773
  headScriptFlushed = true;
1578
1774
  };
1579
- solidJs.sharedConfig.context = context = {
1775
+ sharedConfig.context = context = {
1580
1776
  async: true,
1581
1777
  nonce: options.nonce,
1582
1778
  live: {},
@@ -1640,7 +1836,8 @@ function renderToStream(code, options = {}) {
1640
1836
  html = html.slice(0, first) + resolveSSRSync(escape(payloadFn())) + html.slice(last + placeholder.length + 1);
1641
1837
  },
1642
1838
  serialize(id, p, deferStream) {
1643
- if (solidJs.sharedConfig.context.noHydrate) return;
1839
+ if (sharedConfig.context.noHydrate) return;
1840
+ p = guardChannel(p);
1644
1841
  if (p && typeof p === "object" && typeof p.then === "function") {
1645
1842
  if (!firstFlushed && deferStream) {
1646
1843
  blockingPromises.add(p);
@@ -1683,7 +1880,7 @@ function renderToStream(code, options = {}) {
1683
1880
  const p = new Promise((r, rej) => (resolve = r, reject = rej));
1684
1881
  registry.set(key, {
1685
1882
  resolve: err => queue(() => queue(() => {
1686
- err ? reject(err) : resolve(true);
1883
+ err ? reject(ssrSanitizeError(err, null)) : resolve(true);
1687
1884
  queue(flushEnd);
1688
1885
  }))
1689
1886
  });
@@ -1693,8 +1890,8 @@ function renderToStream(code, options = {}) {
1693
1890
  if (registry.has(key)) {
1694
1891
  const item = registry.get(key);
1695
1892
  registry.delete(key);
1696
- if (error) abandonSubtree(key);
1697
- if (item.children) {
1893
+ if (error) abandonSubtree(key, error);
1894
+ if (item.children && !error) {
1698
1895
  for (const k in item.children) {
1699
1896
  value = replacePlaceholder(value, k, item.children[k]);
1700
1897
  }
@@ -1724,7 +1921,7 @@ function renderToStream(code, options = {}) {
1724
1921
  sink.fragment(key, resolveSSRSelectValues(value !== undefined ? value : " "), {
1725
1922
  styles,
1726
1923
  revealGroup,
1727
- error
1924
+ error: error ? ssrSanitizeError(error, null) : error
1728
1925
  });
1729
1926
  item.resolve(error);
1730
1927
  }
@@ -1750,9 +1947,15 @@ function renderToStream(code, options = {}) {
1750
1947
  };
1751
1948
  applyAssetTracking(context, tracking, manifest, noScripts);
1752
1949
  context.failRender = failRender;
1950
+ context.errorPolicy = options.onError;
1951
+ context.flushed = () => firstFlushed;
1952
+ context.trace = requestEvent ? traceForEvent(requestEvent) : traceFor(context, undefined);
1753
1953
  registerEntryAssets(manifest);
1754
- let html = solidJs.createRoot(d => {
1755
- dispose = d;
1954
+ let html = createRoot(d => {
1955
+ dispose = () => {
1956
+ context.trace = undefined;
1957
+ d();
1958
+ };
1756
1959
  const res = resolveSSRNode(escape(code()));
1757
1960
  if (!res.h.length) return res.t[0];
1758
1961
  rootHoles = [];
@@ -1804,7 +2007,7 @@ function renderToStream(code, options = {}) {
1804
2007
  }
1805
2008
  function doShell() {
1806
2009
  if (shellCompleted) return;
1807
- solidJs.sharedConfig.context = context;
2010
+ sharedConfig.context = context;
1808
2011
  if (blockingPromises.size !== lastBlockingSize) return;
1809
2012
  if (!resolveRootHoles()) return;
1810
2013
  if (blockingPromises.size !== lastBlockingSize) return;
@@ -1815,7 +2018,7 @@ function renderToStream(code, options = {}) {
1815
2018
  }
1816
2019
  serializeRootAssets();
1817
2020
  flushStubBatch();
1818
- const head = renderShellHead(headRegistry, nonce, k => registry.has(k), noScripts);
2021
+ const head = renderShellHead(headRegistry, nonce, k => registry.has(k), noScripts, traceMetaMarkup(context.trace));
1819
2022
  sink.shell(resolveSSRSelectValues(html), {
1820
2023
  preloads: tracking.emittedAssets,
1821
2024
  preloadLinks: tracking.preloadLinks,
@@ -1870,7 +2073,7 @@ function renderToStream(code, options = {}) {
1870
2073
  try {
1871
2074
  doShell();
1872
2075
  } catch (err) {
1873
- failRender(err);
2076
+ failRootRender(err);
1874
2077
  return resolve();
1875
2078
  }
1876
2079
  if (!shellCompleted) return flush();
@@ -1880,7 +2083,7 @@ function renderToStream(code, options = {}) {
1880
2083
  let ended = false;
1881
2084
  const failed = () => {
1882
2085
  if (!ended) {
1883
- abandon();
2086
+ abandon("consumer");
1884
2087
  resolve();
1885
2088
  }
1886
2089
  };
@@ -1911,7 +2114,9 @@ function renderToStream(code, options = {}) {
1911
2114
  return {
1912
2115
  then(onFulfilled, onRejected) {
1913
2116
  const freezeHead = () => {
1914
- if (requestEvent && requestEvent.response) commitResponseStub(requestEvent.response);
2117
+ if (requestEvent && requestEvent.response) commitResponseStub(requestEvent.response, {
2118
+ event: requestEvent
2119
+ });
1915
2120
  };
1916
2121
  const p = new Promise(resolve => {
1917
2122
  function complete() {
@@ -1932,7 +2137,7 @@ function renderToStream(code, options = {}) {
1932
2137
  try {
1933
2138
  if (blockingPromises.size !== lastBlockingSize || !resolveRootHoles() || blockingPromises.size !== lastBlockingSize || !headShellReady(headRegistry, p => blockingPromises.add(p))) return flush();
1934
2139
  } catch (err) {
1935
- failRender(err);
2140
+ failRootRender(err);
1936
2141
  return resolve(tmp);
1937
2142
  }
1938
2143
  queue(flushEnd);
@@ -1952,7 +2157,7 @@ function renderToStream(code, options = {}) {
1952
2157
  try {
1953
2158
  doShell();
1954
2159
  } catch (err) {
1955
- failRender(err);
2160
+ failRootRender(err);
1956
2161
  try {
1957
2162
  w.end();
1958
2163
  } catch (_) {}
@@ -1989,7 +2194,7 @@ function renderToStream(code, options = {}) {
1989
2194
  };
1990
2195
  }
1991
2196
  function HydrationScript(props) {
1992
- const nonce = scriptNonce(solidJs.sharedConfig.context && solidJs.sharedConfig.context.nonce);
2197
+ const nonce = scriptNonce(sharedConfig.context && sharedConfig.context.nonce);
1993
2198
  return ssr(generateHydrationScript({
1994
2199
  nonce,
1995
2200
  ...props
@@ -2000,14 +2205,14 @@ function ssrGroup(fn, n) {
2000
2205
  return fn;
2001
2206
  }
2002
2207
  function buildAsyncWrap(err, node) {
2003
- const p = solidJs.ssrHandleError(err);
2208
+ const p = ssrHandleError(err);
2004
2209
  if (!p) return null;
2005
2210
  if (node.$rw) return {
2006
2211
  fn: node,
2007
2212
  p
2008
2213
  };
2009
- const owner = solidJs.getOwner();
2010
- const live = solidJs.sharedConfig.context && solidJs.sharedConfig.context.liveHoles;
2214
+ const owner = getOwner();
2215
+ const live = sharedConfig.context && sharedConfig.context.liveHoles;
2011
2216
  const suppress = node.$lhSuppress || live && (live.suppressed || live.sweeping);
2012
2217
  if (!owner) {
2013
2218
  if (suppress) node.$lhSuppress = true;
@@ -2016,7 +2221,7 @@ function buildAsyncWrap(err, node) {
2016
2221
  p
2017
2222
  };
2018
2223
  }
2019
- const fn = () => solidJs.runWithOwner(owner, node);
2224
+ const fn = () => runWithOwner(owner, node);
2020
2225
  fn.$rw = true;
2021
2226
  if (suppress) fn.$lhSuppress = true;
2022
2227
  if (node.$lhSkip) fn.$lhSkip = true;
@@ -2082,6 +2287,10 @@ function ssrGroupSlot(fn, idx) {
2082
2287
  }
2083
2288
  };
2084
2289
  }
2290
+ function wireErrorMessage(err) {
2291
+ const wire = ssrSanitizeError(err, null);
2292
+ return String(wire && wire.message || wire);
2293
+ }
2085
2294
  const holePositionCache = new WeakMap();
2086
2295
  function holeContentPositions(t) {
2087
2296
  let cached = holePositionCache.get(t);
@@ -2143,16 +2352,16 @@ function holeContentPositions(t) {
2143
2352
  }
2144
2353
  function createLiveHoles(sink, scoped) {
2145
2354
  let nextId = 0;
2146
- const stamp = typeof solidJs.creationStamp === "function" ? solidJs.creationStamp : () => 0;
2147
- const inScope = scoped && typeof solidJs.inServerComponentScope === "function" ? solidJs.inServerComponentScope : null;
2355
+ const stamp = typeof creationStamp === "function" ? creationStamp : () => 0;
2356
+ const inScope = scoped && typeof inServerComponentScope === "function" ? inServerComponentScope : null;
2148
2357
  const stripMarkers = html => html.replace(/<!--lh:\/?\d+-->/g, "");
2149
2358
  const swept = (owner, ctx, fn) => {
2150
- const prev = solidJs.sharedConfig.context;
2151
- solidJs.sharedConfig.context = ctx;
2359
+ const prev = sharedConfig.context;
2360
+ sharedConfig.context = ctx;
2152
2361
  try {
2153
- return owner ? solidJs.runWithOwner(owner, fn) : fn();
2362
+ return owner ? runWithOwner(owner, fn) : fn();
2154
2363
  } finally {
2155
- solidJs.sharedConfig.context = prev;
2364
+ sharedConfig.context = prev;
2156
2365
  }
2157
2366
  };
2158
2367
  function resolveHoleValue(hole) {
@@ -2219,8 +2428,8 @@ function createLiveHoles(sink, scoped) {
2219
2428
  if (inScope && !inScope()) return null;
2220
2429
  const recordsBefore = engine.recordStamp;
2221
2430
  const ownersBefore = stamp();
2222
- const owner = solidJs.getOwner();
2223
- const holeCtx = solidJs.sharedConfig.context;
2431
+ const owner = getOwner();
2432
+ const holeCtx = sharedConfig.context;
2224
2433
  const b = {
2225
2434
  key: null,
2226
2435
  children: [],
@@ -2238,7 +2447,7 @@ function createLiveHoles(sink, scoped) {
2238
2447
  } catch (err) {
2239
2448
  b.closed = true;
2240
2449
  sink.closeBinding(b.key);
2241
- sink.error(b.key, String(err && err.message || err));
2450
+ sink.error(b.key, wireErrorMessage(err));
2242
2451
  return;
2243
2452
  } finally {
2244
2453
  engine.sweeping = prevSweeping;
@@ -2341,8 +2550,8 @@ function createLiveHoles(sink, scoped) {
2341
2550
  return !inScope || inScope();
2342
2551
  },
2343
2552
  attr(cap) {
2344
- const owner = solidJs.getOwner();
2345
- const holeCtx = solidJs.sharedConfig.context;
2553
+ const owner = getOwner();
2554
+ const holeCtx = sharedConfig.context;
2346
2555
  const b = {
2347
2556
  key: "lha:" + cap.id,
2348
2557
  children: [],
@@ -2380,10 +2589,10 @@ function createLiveHoles(sink, scoped) {
2380
2589
  };
2381
2590
  swept(owner, holeCtx, run);
2382
2591
  } catch (err) {
2383
- if (solidJs.ssrHandleError(err, true)) return;
2592
+ if (ssrHandleError(err, true)) return;
2384
2593
  b.closed = true;
2385
2594
  sink.closeBinding(b.key);
2386
- sink.error("lha:" + cap.id, String(err && err.message || err));
2595
+ sink.error("lha:" + cap.id, wireErrorMessage(err));
2387
2596
  return;
2388
2597
  } finally {
2389
2598
  engine.sweeping = prevSweeping;
@@ -2423,7 +2632,7 @@ function ssr(t) {
2423
2632
  let lastGroup = null;
2424
2633
  let lastGroupVal = null;
2425
2634
  let lastGroupIdx = 0;
2426
- const live = solidJs.sharedConfig.context && solidJs.sharedConfig.context.liveHoles;
2635
+ const live = sharedConfig.context && sharedConfig.context.liveHoles;
2427
2636
  const hp = live ? holeContentPositions(t) : null;
2428
2637
  let lastOpen = null;
2429
2638
  let cap = null;
@@ -2675,45 +2884,93 @@ function ssrStyle(value) {
2675
2884
  function ssrStyleProperty(name, value) {
2676
2885
  return value != null ? name + value : "";
2677
2886
  }
2678
- function ssrElement(tag, props, children, needsId) {
2887
+ function ssrElement(tag, props, children, needsId, skip) {
2679
2888
  const hk = needsId ? ssrHydrationKey() : "";
2680
2889
  if (typeof props === "function") props = props();
2681
- if (props == null) props = {};
2890
+ let sources = null;
2891
+ let kind = SOURCE_PLAIN;
2892
+ let viewKeys = null;
2893
+ let owners = null;
2894
+ if (Array.isArray(props)) {
2895
+ let i = 0;
2896
+ for (; i < props.length; i++) {
2897
+ const s = props[i];
2898
+ if (s == null || typeof s === "function" || $PROXY in s) break;
2899
+ }
2900
+ if (i === props.length) sources = props;else {
2901
+ viewKeys = [];
2902
+ owners = [];
2903
+ for (let i = 0; i < props.length; i++) {
2904
+ let s = props[i];
2905
+ if (typeof s === "function") s = s();
2906
+ if (s != null) sourceOwners(s, viewKeys, owners);
2907
+ }
2908
+ }
2909
+ } else if (props == null) {
2910
+ props = {};
2911
+ } else if ($PROXY in props) {
2912
+ if (viewOf(props) !== undefined) {
2913
+ viewKeys = [];
2914
+ owners = [];
2915
+ sourceOwners(props, viewKeys, owners);
2916
+ } else kind = SOURCE_PROXY;
2917
+ }
2682
2918
  const skipChildren = VOID_ELEMENTS.test(tag);
2683
- const keys = Object.keys(props);
2684
- let result = `<${tag}${hk} `;
2685
- for (let i = 0; i < keys.length; i++) {
2686
- const prop = keys[i];
2687
- const value = props[prop];
2688
- if (tag === "textarea" && (prop === "value" || prop === "defaultValue")) {
2689
- if (value !== null) children = escape(value);
2690
- continue;
2691
- }
2692
- if (ChildProperties.has(prop)) {
2693
- if (children === undefined && !skipChildren) children = tag === "script" || tag === "style" || prop === "innerHTML" ? props[prop] : escape(props[prop]);
2694
- continue;
2695
- }
2696
- if (prop === "style") {
2697
- result += `style="${ssrStyle(value)}"`;
2698
- } else if (prop === "class") {
2699
- result += `class="${ssrClassName(value)}"`;
2700
- } else if (value == undefined || prop === "ref" || prop.slice(0, 2) === "on" || prop.slice(0, 5) === "prop:") {
2701
- if (typeof value === "function" && value[CLAIM_PROP] !== undefined && (prop === "ref" || prop.slice(0, 2) === "on")) {
2702
- console.warn(`A spread on a server-rendered <${tag}> carries \`${prop}\` from client props — ` + `spreads don't participate in behavior claims, so this drops. ` + `Write the position out: \`${prop}={props.${String(value[CLAIM_PROP])}}\`.`);
2919
+ let result = `<${tag}${hk}`;
2920
+ const last = sources === null ? 0 : sources.length - 1;
2921
+ let keysOf = null;
2922
+ if (sources !== null) {
2923
+ keysOf = new Array(last + 1);
2924
+ for (let s = 0; s <= last; s++) keysOf[s] = Object.keys(sources[s]);
2925
+ }
2926
+ for (let s = 0; s <= last; s++) {
2927
+ const keys = owners !== null ? viewKeys : keysOf !== null ? keysOf[s] : sourceKeys(props, kind);
2928
+ if (sources !== null) props = sources[s];
2929
+ nextKey: for (let i = 0; i < keys.length; i++) {
2930
+ const prop = keys[i];
2931
+ if (typeof prop !== "string" || skip !== undefined && skip(prop)) continue;
2932
+ if (owners !== null) props = owners[i];
2933
+ for (let j = s + 1; j <= last; j++) {
2934
+ if (keysOf[j].includes(prop)) continue nextKey;
2935
+ }
2936
+ if (tag === "textarea" && (prop === "value" || prop === "defaultValue")) {
2937
+ const value = sourceGet(props, kind, prop);
2938
+ if (value !== null) children = escape(value);
2939
+ continue;
2940
+ }
2941
+ if (ChildProperties.has(prop)) {
2942
+ if (children === undefined && !skipChildren) children = tag === "script" || tag === "style" || prop === "innerHTML" ? sourceGet(props, kind, prop) : escape(sourceGet(props, kind, prop));
2943
+ continue;
2944
+ }
2945
+ const value = sourceGet(props, kind, prop);
2946
+ if (value == undefined || prop === "ref" || prop.slice(0, 2) === "on" || prop.slice(0, 5) === "prop:") {
2947
+ continue;
2948
+ } else if (prop === "style") {
2949
+ result += ` style="${ssrStyle(value)}"`;
2950
+ } else if (prop === "class") {
2951
+ result += ` class="${ssrClassName(value)}"`;
2952
+ } else if (typeof value === "boolean") {
2953
+ if (!value) continue;
2954
+ result += ` ${escape(prop)}`;
2955
+ } else {
2956
+ result += value === "" ? ` ${escape(prop)}` : ` ${escape(prop)}="${escape(value, true)}"`;
2703
2957
  }
2704
- continue;
2705
- } else if (typeof value === "boolean") {
2706
- if (!value) continue;
2707
- result += escape(prop);
2708
- } else {
2709
- result += value === "" ? escape(prop) : `${escape(prop)}="${escape(value, true)}"`;
2710
2958
  }
2711
- if (i !== keys.length - 1) result += " ";
2712
2959
  }
2713
2960
  if (skipChildren) return {
2714
- t: result + "/>"
2961
+ t: result + " />"
2715
2962
  };
2716
2963
  if (typeof children === "function") children = children();
2964
+ const ct = typeof children;
2965
+ if (ct === "string" || ct === "number") return {
2966
+ t: result + ">" + children + "</" + tag + ">"
2967
+ };
2968
+ if (children == null || ct === "boolean") return {
2969
+ t: result + "></" + tag + ">"
2970
+ };
2971
+ if (ct === "object" && !children.h && typeof children.t === "string") return {
2972
+ t: result + ">" + children.t + "</" + tag + ">"
2973
+ };
2717
2974
  return ssr([result + ">", `</${tag}>`], resolveSSRNode(children, undefined, true));
2718
2975
  }
2719
2976
  function ssrAttribute(key, value) {
@@ -2731,8 +2988,8 @@ function encodeClaimKey(key) {
2731
2988
  return String(key).replace(CLAIM_UNSAFE, c => encodeURIComponent(c));
2732
2989
  }
2733
2990
  function ssrClaim(map) {
2734
- const mode = solidJs.sharedConfig.context && solidJs.sharedConfig.context.claims;
2735
- if (!mode || mode === CLAIMS_DOCUMENT && !(typeof solidJs.inServerComponentScope === "function" && solidJs.inServerComponentScope())) {
2991
+ const mode = sharedConfig.context && sharedConfig.context.claims;
2992
+ if (!mode || mode === CLAIMS_DOCUMENT && !(typeof inServerComponentScope === "function" && inServerComponentScope())) {
2736
2993
  return "";
2737
2994
  }
2738
2995
  let out = "";
@@ -2742,9 +2999,6 @@ function ssrClaim(map) {
2742
2999
  for (const fn of list) {
2743
3000
  const prop = typeof fn === "function" && fn[CLAIM_PROP] || undefined;
2744
3001
  if (prop === undefined) {
2745
- {
2746
- console.warn(`A \`${pos}\` position on a server-rendered element received a server-local ` + `${typeof fn} — this handler can never run. Pass the function through the ` + `server component's props from the client (compose on the client before ` + `passing), or bind a mutation to \`action=\`.`);
2747
- }
2748
3002
  continue;
2749
3003
  }
2750
3004
  out += `${out ? "," : ""}${pos}=${encodeClaimKey(prop)}`;
@@ -2863,10 +3117,13 @@ function escape(s, attr) {
2863
3117
  if (!attr && Array.isArray(s)) {
2864
3118
  const joined = tryJoinPlainSSRArray(s);
2865
3119
  if (joined !== undefined) return joined;
3120
+ const src = s;
2866
3121
  s = s.slice();
2867
3122
  for (let i = 0; i < s.length; i++) s[i] = escape(s[i]);
3123
+ if (src.$slot) s.$slot = true;
2868
3124
  return s;
2869
3125
  }
3126
+ if (!attr && t === "function") return escapeLate(s);
2870
3127
  if (attr) {
2871
3128
  if (s == null || t === "boolean" || t === "number") return s;
2872
3129
  return escape(String(s), attr);
@@ -2877,6 +3134,15 @@ function escape(s, attr) {
2877
3134
  if (i < 0) return s;
2878
3135
  return escapeSlow(s, attr, i);
2879
3136
  }
3137
+ function escapeLate(fn) {
3138
+ if (fn.$esc) return fn;
3139
+ const w = () => escape(fn());
3140
+ w.$esc = true;
3141
+ if (fn.$lhSkip) w.$lhSkip = true;
3142
+ if (fn.$lhSuppress) w.$lhSuppress = true;
3143
+ if (fn.$lhBinding) w.$lhBinding = fn.$lhBinding;
3144
+ return w;
3145
+ }
2880
3146
  const ESCAPE_CONTENT = /[&<]/;
2881
3147
  const ESCAPE_ATTR = /[&"<]/;
2882
3148
  function escapeSlow(s, attr, start) {
@@ -2957,8 +3223,8 @@ function tryJoinPlainSSRArray(nodes) {
2957
3223
  return out;
2958
3224
  }
2959
3225
  function getHydrationKey() {
2960
- const hydrate = solidJs.sharedConfig.context;
2961
- return hydrate && solidJs.sharedConfig.getNextContextId();
3226
+ const hydrate = sharedConfig.context;
3227
+ return hydrate && sharedConfig.getNextContextId();
2962
3228
  }
2963
3229
  function applyRef(r, element) {
2964
3230
  Array.isArray(r) ? r.flat(Infinity).forEach(f => f && f(element)) : r(element);
@@ -3140,23 +3406,26 @@ function flattenClassList(list, result) {
3140
3406
  else if (typeof item !== "boolean" && (item || item === 0)) result[item] = true;
3141
3407
  }
3142
3408
  }
3143
- function tryResolveString(node) {
3409
+ let ssrTextTail = false;
3410
+ function tryResolveString(node, nested) {
3411
+ if (!nested) ssrTextTail = false;
3144
3412
  const t = typeof node;
3145
- if (t === "string") return node;
3146
- if (t === "number") return "" + node;
3413
+ if (t === "string" || t === "number") {
3414
+ const s = ssrTextTail ? "<!--!$-->" + node : "" + node;
3415
+ ssrTextTail = true;
3416
+ return s;
3417
+ }
3147
3418
  if (node == null || t === "boolean") return "";
3148
3419
  if (t === "object") {
3149
3420
  if (Array.isArray(node)) {
3150
3421
  const joined = tryJoinPlainSSRArray(node);
3151
- if (joined !== undefined) return joined;
3422
+ if (joined !== undefined) {
3423
+ ssrTextTail = false;
3424
+ return joined;
3425
+ }
3152
3426
  let s = "";
3153
- let prevNonObj = false;
3154
3427
  for (let i = 0, len = node.length; i < len; i++) {
3155
- const item = node[i];
3156
- const itemNonObj = item !== null && typeof item !== "object";
3157
- if (prevNonObj && itemNonObj) s += "<!--!$-->";
3158
- prevNonObj = itemNonObj;
3159
- const r = tryResolveString(item);
3428
+ const r = tryResolveString(node[i], true);
3160
3429
  if (typeof r !== "string") return {
3161
3430
  bail: node
3162
3431
  };
@@ -3168,9 +3437,9 @@ function tryResolveString(node) {
3168
3437
  merge: node
3169
3438
  };
3170
3439
  if (node.t === undefined) {
3171
- console.warn(`Unrecognized value. Skipped inserting`, node);
3172
3440
  return "";
3173
3441
  }
3442
+ ssrTextTail = false;
3174
3443
  return Array.isArray(node.t) ? node.t[0] : node.t;
3175
3444
  }
3176
3445
  if (t === "function") {
@@ -3178,9 +3447,11 @@ function tryResolveString(node) {
3178
3447
  try {
3179
3448
  v = node();
3180
3449
  } catch (err) {
3181
- return buildAsyncWrap(err, node) || "";
3450
+ const wrap = buildAsyncWrap(err, node);
3451
+ if (wrap) ssrTextTail = true;
3452
+ return wrap || "";
3182
3453
  }
3183
- return tryResolveString(v);
3454
+ return tryResolveString(v, true);
3184
3455
  }
3185
3456
  return "";
3186
3457
  }
@@ -3188,21 +3459,19 @@ function resolveSSRNode(node, result = {
3188
3459
  t: [""],
3189
3460
  h: [],
3190
3461
  p: []
3191
- }, top) {
3462
+ }, top, nested) {
3463
+ if (!nested) ssrTextTail = false;
3192
3464
  const t = typeof node;
3193
3465
  if (t === "string" || t === "number") {
3194
- result.t[result.t.length - 1] += node;
3466
+ result.t[result.t.length - 1] += ssrTextTail ? "<!--!$-->" + node : node;
3467
+ ssrTextTail = true;
3195
3468
  } else if (node == null || t === "boolean") ; else if (Array.isArray(node)) {
3196
- const slotLive = node.$slot && solidJs.sharedConfig.context && solidJs.sharedConfig.context.liveHoles;
3469
+ const slotLive = node.$slot && sharedConfig.context && sharedConfig.context.liveHoles;
3197
3470
  if (slotLive) slotLive.suppressed++;
3198
3471
  try {
3199
- let prevNonObj = false;
3200
3472
  for (let i = 0, len = node.length; i < len; i++) {
3201
- const item = node[i];
3202
- const itemNonObj = item !== null && typeof item !== "object";
3203
- if (!top && prevNonObj && itemNonObj) result.t[result.t.length - 1] += `<!--!$-->`;
3204
- prevNonObj = itemNonObj;
3205
- resolveSSRNode(item, result);
3473
+ if (top) ssrTextTail = false;
3474
+ resolveSSRNode(node[i], result, false, true);
3206
3475
  }
3207
3476
  } finally {
3208
3477
  if (slotLive) slotLive.suppressed--;
@@ -3215,23 +3484,30 @@ function resolveSSRNode(node, result = {
3215
3484
  result.h.push(...node.h);
3216
3485
  result.p.push(...node.p);
3217
3486
  }
3487
+ ssrTextTail = false;
3218
3488
  } else if (node.t !== undefined) {
3219
3489
  result.t[result.t.length - 1] += node.t;
3220
- } else console.warn(`Unrecognized value. Skipped inserting`, node);
3490
+ ssrTextTail = false;
3491
+ } else ;
3221
3492
  } else if (t === "function") {
3222
- const live = solidJs.sharedConfig.context && solidJs.sharedConfig.context.liveHoles;
3493
+ const live = sharedConfig.context && sharedConfig.context.liveHoles;
3223
3494
  let liveNode = null;
3224
3495
  if (live && (liveNode = live.content(node)) !== null) {
3225
- if (typeof liveNode === "string") result.t[result.t.length - 1] += liveNode;else resolveSSRNode(liveNode, result);
3496
+ if (typeof liveNode === "string") {
3497
+ result.t[result.t.length - 1] += ssrTextTail ? "<!--!$-->" + liveNode : liveNode;
3498
+ ssrTextTail = true;
3499
+ } else resolveSSRNode(liveNode, result, false, true);
3226
3500
  } else {
3227
3501
  try {
3228
- resolveSSRNode(node(), result);
3502
+ resolveSSRNode(node(), result, false, true);
3229
3503
  } catch (err) {
3230
3504
  const wrap = buildAsyncWrap(err, node);
3231
3505
  if (wrap) {
3506
+ if (ssrTextTail) result.t[result.t.length - 1] += "<!--!$-->";
3232
3507
  result.h.push(wrap.fn);
3233
3508
  result.p.push(wrap.p);
3234
3509
  result.t.push("");
3510
+ ssrTextTail = true;
3235
3511
  }
3236
3512
  }
3237
3513
  }
@@ -3244,13 +3520,49 @@ function resolveSSRSync(node) {
3244
3520
  throw new Error("This value cannot be rendered synchronously. Are you missing a boundary?");
3245
3521
  }
3246
3522
  const RequestContext = Symbol.for("solid.RequestContext");
3523
+ const ServerErrors = Symbol.for("solid-js/server/errors");
3524
+ function serializerErrorHook(hook) {
3525
+ return hook === undefined ? undefined : err => {
3526
+ reportServerError(err, {
3527
+ kind: "render",
3528
+ handling: "serialize"
3529
+ }, null);
3530
+ };
3531
+ }
3532
+ function ambientServerErrorHook() {
3533
+ const slot = globalThis[ServerErrors];
3534
+ return slot === undefined ? undefined : slot.hook;
3535
+ }
3536
+ function configureServerErrors(config) {
3537
+ const g = globalThis;
3538
+ if (config && config.onError !== undefined && typeof config.onError !== "function") {
3539
+ throw new TypeError(`Invalid onError: expected a function, received ${typeof config.onError}.`);
3540
+ }
3541
+ (g[ServerErrors] ||= {}).hook = config ? config.onError : undefined;
3542
+ }
3247
3543
  function getRequestEvent() {
3248
- return globalThis[RequestContext] ? globalThis[RequestContext].getStore() || solidJs.sharedConfig.context && solidJs.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;
3544
+ 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;
3249
3545
  }
3250
3546
  function peekRequestEvent() {
3251
3547
  const store = globalThis[RequestContext];
3252
3548
  return store ? store.getStore() : undefined;
3253
3549
  }
3550
+ function traceForEvent(event) {
3551
+ return traceFor(event.request || event, event.request);
3552
+ }
3553
+ function getTraceContext() {
3554
+ const event = peekRequestEvent();
3555
+ if (event) return traceForEvent(event).context;
3556
+ const ctx = sharedConfig.context;
3557
+ return ctx && ctx.trace ? ctx.trace.context : undefined;
3558
+ }
3559
+ function traceForStub(stub, event) {
3560
+ if (!event) {
3561
+ event = peekRequestEvent();
3562
+ if (!event || event.response !== stub) return undefined;
3563
+ }
3564
+ return traceForEvent(event);
3565
+ }
3254
3566
  function createResponseStub() {
3255
3567
  return {
3256
3568
  status: undefined,
@@ -3268,15 +3580,30 @@ function createRequestEvent(request, init) {
3268
3580
  };
3269
3581
  }
3270
3582
  function reportLostHeaderWrite(method, name) {
3271
- 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).";
3272
- throw new Error(message);
3583
+ 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).";
3584
+ recordFinding({
3585
+ code: "LATE_HEADER_WRITE",
3586
+ kind: "head",
3587
+ severity: "error",
3588
+ message,
3589
+ data: {
3590
+ method,
3591
+ name: String(name)
3592
+ }
3593
+ });
3594
+ console.error(message);
3273
3595
  }
3274
3596
  function commitResponseStub(stub, {
3275
- allowLateLocation = false
3597
+ allowLateLocation = false,
3598
+ event
3276
3599
  } = {}) {
3277
3600
  if (!stub || stub.committed) return stub;
3278
- stub.committed = true;
3279
3601
  const headers = stub.headers;
3602
+ if (headers && typeof headers.append === "function") {
3603
+ const trace = traceForStub(stub, event);
3604
+ if (trace) appendTraceServerTiming(headers, trace);
3605
+ }
3606
+ stub.committed = true;
3280
3607
  if (!headers || typeof headers.set !== "function") return stub;
3281
3608
  for (const method of ["set", "append", "delete"]) {
3282
3609
  const original = headers[method].bind(headers);
@@ -3297,7 +3624,7 @@ function getExpectedRedirectStatus(response) {
3297
3624
  function mergeStubHeaders(target, stub) {
3298
3625
  if (!stub) return target;
3299
3626
  stub.headers.forEach((value, key) => {
3300
- if (key !== "set-cookie") target.set(key, value);
3627
+ if (key === "server-timing") mergeServerTiming(target, value);else if (key !== "set-cookie") target.set(key, value);
3301
3628
  });
3302
3629
  const setCookies = stub.headers.getSetCookie ? stub.headers.getSetCookie() : [];
3303
3630
  for (const cookie of setCookies) target.append("set-cookie", cookie);
@@ -3321,19 +3648,35 @@ function fillsStubGap(key, headers, response) {
3321
3648
  }
3322
3649
  function commitEventResponse(response, event = getRequestEvent()) {
3323
3650
  const stub = event && event.response;
3324
- if (!stub || !stub.headers || stub.committed) return response;
3651
+ if (!stub || !stub.headers || stub.committed) {
3652
+ if (!event || stub) return response;
3653
+ const trace = traceForEvent(event);
3654
+ if (!trace.emit) return response;
3655
+ const headers = copyInitHeaders(response.headers);
3656
+ appendTraceServerTiming(headers, trace);
3657
+ return new Response(response.body, {
3658
+ status: response.status,
3659
+ statusText: response.statusText,
3660
+ headers
3661
+ });
3662
+ }
3325
3663
  const cookies = stub.headers.getSetCookie ? stub.headers.getSetCookie() : [];
3326
- commitResponseStub(stub);
3664
+ commitResponseStub(stub, {
3665
+ event
3666
+ });
3327
3667
  let hasGaps = false;
3328
3668
  stub.headers.forEach((value, key) => {
3329
3669
  if (fillsStubGap(key, response.headers, response)) hasGaps = true;
3330
3670
  });
3331
- if (!cookies.length && !hasGaps) return response;
3671
+ const timing = stub.headers.get("server-timing");
3672
+ const mergesTiming = timing !== null && response.headers.has("server-timing");
3673
+ if (!cookies.length && !hasGaps && !mergesTiming) return response;
3332
3674
  const headers = copyInitHeaders(response.headers);
3333
3675
  for (const cookie of cookies) headers.append("Set-Cookie", cookie);
3334
3676
  stub.headers.forEach((value, key) => {
3335
3677
  if (fillsStubGap(key, headers, response)) headers.set(key, value);
3336
3678
  });
3679
+ if (mergesTiming) mergeServerTiming(headers, timing);
3337
3680
  return new Response(response.body, {
3338
3681
  status: response.status,
3339
3682
  statusText: response.statusText,
@@ -3359,7 +3702,9 @@ function createSSRResponse(result, event, options = {}) {
3359
3702
  } = options;
3360
3703
  const nonce = normalizeNonce(options.nonce);
3361
3704
  if (typeof result === "string") {
3362
- if (stub) commitResponseStub(stub);
3705
+ if (stub) commitResponseStub(stub, {
3706
+ event
3707
+ });
3363
3708
  const head = deriveHead(stub, responseInit);
3364
3709
  if (stub && stub.headers.get("Location")) {
3365
3710
  return new Response(null, {
@@ -3394,7 +3739,8 @@ function createSSRResponse(result, event, options = {}) {
3394
3739
  if (!flushed) {
3395
3740
  flushed = true;
3396
3741
  if (stub) commitResponseStub(stub, {
3397
- allowLateLocation: true
3742
+ allowLateLocation: true,
3743
+ event
3398
3744
  });
3399
3745
  const head = deriveHead(stub, responseInit);
3400
3746
  if (stub && stub.headers.get("Location")) {
@@ -3464,23 +3810,29 @@ function notSup() {
3464
3810
  throw new Error("Client-only API called on the server side. Run client-only code in onMount, or conditionally run client-only component with <Show>.");
3465
3811
  }
3466
3812
 
3467
- setContainerTraceResolver(solidJs.getProjectionTrace);
3813
+ setContainerTraceResolver(getProjectionTrace);
3468
3814
  const isServer = true;
3469
- const isDev = true;
3815
+ const isDev = false;
3470
3816
  function dynamic(source, options) {
3471
- const cached = solidJs.createMemo(source, {
3817
+ if (options?.static) {
3818
+ const component = untrack(source);
3819
+ if (typeof component === "function") return props => component(props);
3820
+ if (typeof component === "string") return props => ssrElement(component, props, undefined, true);
3821
+ return () => undefined;
3822
+ }
3823
+ const cached = createMemo(source, {
3472
3824
  serialize: false
3473
3825
  });
3474
3826
  const deferStream = !!options?.deferStream;
3475
3827
  return props => {
3476
- const ctx = solidJs.sharedConfig.context;
3828
+ const ctx = sharedConfig.context;
3477
3829
  let gated = !deferStream || !ctx?.async;
3478
- return solidJs.createMemo(() => {
3830
+ return createMemo(() => {
3479
3831
  let c;
3480
3832
  try {
3481
3833
  c = cached();
3482
3834
  } catch (err) {
3483
- if (!gated && err instanceof solidJs.NotReadyError) {
3835
+ if (!gated && err instanceof NotReadyError) {
3484
3836
  gated = true;
3485
3837
  ctx.block(Promise.resolve(err.source).then(() => {}, () => {}));
3486
3838
  }
@@ -3499,15 +3851,15 @@ function dynamic(source, options) {
3499
3851
  }
3500
3852
  function Dynamic(props) {
3501
3853
  const Comp = dynamic(() => props.component);
3502
- return solidJs.createComponent(Comp, solidJs.omit(props, "component"));
3854
+ return createComponent(Comp, omit(props, "component"));
3503
3855
  }
3504
3856
  function Portal(props) {
3505
- const o = solidJs.getOwner();
3506
- if (o?.id != null) solidJs.getNextChildId(o);
3857
+ const o = getOwner();
3858
+ if (o?.id != null) getNextChildId(o);
3507
3859
  return undefined;
3508
3860
  }
3509
3861
  function registerClientOnlyPreload(moduleUrl) {
3510
- const ctx = solidJs.sharedConfig.context;
3862
+ const ctx = sharedConfig.context;
3511
3863
  if (!ctx?.registerAsset || !ctx.resolveAssets) return;
3512
3864
  const registerAsset = ctx.registerAsset;
3513
3865
  const resolve = ctx.resolveAssets;
@@ -3544,7 +3896,7 @@ function registerClientOnlyPreload(moduleUrl) {
3544
3896
  function clientOnly(_fn, _options = {}, moduleUrl) {
3545
3897
  return props => {
3546
3898
  if (moduleUrl) registerClientOnlyPreload(moduleUrl);
3547
- return solidJs.createMemo(() => props.fallback);
3899
+ return createMemo(() => props.fallback);
3548
3900
  };
3549
3901
  }
3550
3902
  const statusLedgers = /* @__PURE__ */new WeakMap();
@@ -3571,7 +3923,7 @@ function httpStatus(code, text) {
3571
3923
  ledger.live.push(declaration);
3572
3924
  response.status = code;
3573
3925
  response.statusText = text;
3574
- solidJs.onCleanup(() => {
3926
+ onCleanup(() => {
3575
3927
  if (response.committed) return;
3576
3928
  const index = ledger.live.indexOf(declaration);
3577
3929
  if (index < 0) return;
@@ -3606,7 +3958,7 @@ function httpHeader(name, value, options) {
3606
3958
  };
3607
3959
  ledger.live.push(declaration);
3608
3960
  if (declaration.append) headers.append(name, value);else headers.set(name, value);
3609
- solidJs.onCleanup(() => {
3961
+ onCleanup(() => {
3610
3962
  if (response.committed) return;
3611
3963
  const index = ledger.live.indexOf(declaration);
3612
3964
  if (index < 0) return;
@@ -3625,170 +3977,4 @@ function httpHeader(name, value, options) {
3625
3977
  }
3626
3978
  }
3627
3979
 
3628
- Object.defineProperty(exports, "Errored", {
3629
- enumerable: true,
3630
- get: function () { return solidJs.Errored; }
3631
- });
3632
- Object.defineProperty(exports, "For", {
3633
- enumerable: true,
3634
- get: function () { return solidJs.For; }
3635
- });
3636
- Object.defineProperty(exports, "Hydration", {
3637
- enumerable: true,
3638
- get: function () { return solidJs.Hydration; }
3639
- });
3640
- Object.defineProperty(exports, "Loading", {
3641
- enumerable: true,
3642
- get: function () { return solidJs.Loading; }
3643
- });
3644
- Object.defineProperty(exports, "Match", {
3645
- enumerable: true,
3646
- get: function () { return solidJs.Match; }
3647
- });
3648
- Object.defineProperty(exports, "NoHydration", {
3649
- enumerable: true,
3650
- get: function () { return solidJs.NoHydration; }
3651
- });
3652
- Object.defineProperty(exports, "Repeat", {
3653
- enumerable: true,
3654
- get: function () { return solidJs.Repeat; }
3655
- });
3656
- Object.defineProperty(exports, "Reveal", {
3657
- enumerable: true,
3658
- get: function () { return solidJs.Reveal; }
3659
- });
3660
- Object.defineProperty(exports, "Show", {
3661
- enumerable: true,
3662
- get: function () { return solidJs.Show; }
3663
- });
3664
- Object.defineProperty(exports, "Switch", {
3665
- enumerable: true,
3666
- get: function () { return solidJs.Switch; }
3667
- });
3668
- Object.defineProperty(exports, "createComponent", {
3669
- enumerable: true,
3670
- get: function () { return solidJs.createComponent; }
3671
- });
3672
- Object.defineProperty(exports, "getOwner", {
3673
- enumerable: true,
3674
- get: function () { return solidJs.getOwner; }
3675
- });
3676
- Object.defineProperty(exports, "mergeProps", {
3677
- enumerable: true,
3678
- get: function () { return solidJs.merge; }
3679
- });
3680
- Object.defineProperty(exports, "scope", {
3681
- enumerable: true,
3682
- get: function () { return solidJs.ssrScope; }
3683
- });
3684
- Object.defineProperty(exports, "sharedConfig", {
3685
- enumerable: true,
3686
- get: function () { return solidJs.sharedConfig; }
3687
- });
3688
- Object.defineProperty(exports, "untrack", {
3689
- enumerable: true,
3690
- get: function () { return solidJs.untrack; }
3691
- });
3692
- exports.CLAIMS_DOCUMENT = CLAIMS_DOCUMENT;
3693
- exports.CLAIMS_STREAM = CLAIMS_STREAM;
3694
- exports.CLAIM_PROP = CLAIM_PROP;
3695
- exports.ChildProperties = ChildProperties;
3696
- exports.DOMElements = DOMElements;
3697
- exports.DOMWithState = DOMWithState;
3698
- exports.DelegatedEvents = DelegatedEvents;
3699
- exports.Dynamic = Dynamic;
3700
- exports.HREF = HREF;
3701
- exports.HydrationScript = HydrationScript;
3702
- exports.MathMLElements = MathMLElements;
3703
- exports.NULL_BODY_STATUSES = NULL_BODY_STATUSES;
3704
- exports.Namespaces = Namespaces;
3705
- exports.Portal = Portal;
3706
- exports.RESPONSE_HEADER_VALUE_LIMIT = RESPONSE_HEADER_VALUE_LIMIT;
3707
- exports.REVALIDATE_HEADER = REVALIDATE_HEADER;
3708
- exports.RawTextElements = RawTextElements;
3709
- exports.RequestContext = RequestContext;
3710
- exports.ResponseEnvelope = ResponseEnvelope;
3711
- exports.SAFE_ERROR = SAFE_ERROR;
3712
- exports.SVGElements = SVGElements;
3713
- exports.VoidElements = VoidElements;
3714
- exports.acquireAsset = notSup;
3715
- exports.addEvent = notSup;
3716
- exports.applyRef = applyRef;
3717
- exports.assign = notSup;
3718
- exports.claimElement = claimElement;
3719
- exports.claimElementTree = claimElementTree;
3720
- exports.className = notSup;
3721
- exports.clearFlashCookie = clearFlashCookie;
3722
- exports.clientOnly = clientOnly;
3723
- exports.commitEventResponse = commitEventResponse;
3724
- exports.commitResponseStub = commitResponseStub;
3725
- exports.composeMiddleware = composeMiddleware;
3726
- exports.createLiveHoles = createLiveHoles;
3727
- exports.createRequestEvent = createRequestEvent;
3728
- exports.createResponseStub = createResponseStub;
3729
- exports.createSSRResponse = createSSRResponse;
3730
- exports.delegateEvents = notSup;
3731
- exports.dynamic = dynamic;
3732
- exports.dynamicProperty = notSup;
3733
- exports.effect = effect;
3734
- exports.escape = escape;
3735
- exports.generateHydrationScript = generateHydrationScript;
3736
- exports.getDelegatedRoot = notSup;
3737
- exports.getExpectedRedirectStatus = getExpectedRedirectStatus;
3738
- exports.getHydrationKey = getHydrationKey;
3739
- exports.getNextElement = notSup;
3740
- exports.getNextMarker = notSup;
3741
- exports.getNextMatch = notSup;
3742
- exports.getRequestEvent = getRequestEvent;
3743
- exports.getServerFunctionMetadata = getServerFunctionMetadata;
3744
- exports.getServerFunctionRPC = getServerFunctionRPC;
3745
- exports.hasFlashCookie = hasFlashCookie;
3746
- exports.httpHeader = httpHeader;
3747
- exports.httpStatus = httpStatus;
3748
- exports.hydrate = notSup;
3749
- exports.insert = notSup;
3750
- exports.isDev = isDev;
3751
- exports.isHref = isHref;
3752
- exports.isResponseEnvelope = isResponseEnvelope;
3753
- exports.isSafeError = isSafeError;
3754
- exports.isServer = isServer;
3755
- exports.isServerFunction = isServerFunction;
3756
- exports.markSafeError = markSafeError;
3757
- exports.memo = memo;
3758
- exports.parseCookieHeader = parseCookieHeader;
3759
- exports.redirect = redirect;
3760
- exports.ref = notSup;
3761
- exports.registerDelegatedContainer = notSup;
3762
- exports.registerDelegatedRoot = notSup;
3763
- exports.registerElementClaim = registerElementClaim;
3764
- exports.reload = reload;
3765
- exports.render = notSup;
3766
- exports.renderToStream = renderToStream;
3767
- exports.renderToString = renderToString;
3768
- exports.resolveSSRNode = resolveSSRNode;
3769
- exports.resolveSSRSelectValues = resolveSSRSelectValues;
3770
- exports.respond = respond;
3771
- exports.runHydrationEvents = notSup;
3772
- exports.scriptNonce = scriptNonce;
3773
- exports.serializeCookie = serializeCookie;
3774
- exports.setAttribute = notSup;
3775
- exports.setAttributeNS = notSup;
3776
- exports.setProperty = notSup;
3777
- exports.setStyleProperty = notSup;
3778
- exports.spread = notSup;
3779
- exports.ssr = ssr;
3780
- exports.ssrAttribute = ssrAttribute;
3781
- exports.ssrClaim = ssrClaim;
3782
- exports.ssrClassName = ssrClassName;
3783
- exports.ssrElement = ssrElement;
3784
- exports.ssrGroup = ssrGroup;
3785
- exports.ssrHydrationKey = ssrHydrationKey;
3786
- exports.ssrSelectValues = ssrSelectValues;
3787
- exports.ssrStyle = ssrStyle;
3788
- exports.ssrStyleProperty = ssrStyleProperty;
3789
- exports.style = notSup;
3790
- exports.styleNonce = styleNonce;
3791
- exports.template = notSup;
3792
- exports.unregisterDelegatedContainer = notSup;
3793
- exports.unregisterDelegatedRoot = notSup;
3794
- exports.useHead = useHead;
3980
+ 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 };