@solidjs/web 2.0.0-rc.10 → 2.0.0-rc.13

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.js CHANGED
@@ -1,7 +1,7 @@
1
- import { createRenderEffect, createMemo, sharedConfig, createRoot, $PROXY, getOwner, runWithOwner, createComponent, omit, getNextChildId, untrack, NotReadyError, onCleanup } from 'solid-js';
2
- export { Errored, For, Hydration, Loading, Match, NoHydration, Repeat, Reveal, Show, Switch, createComponent, getOwner, merge as mergeProps, sharedConfig, untrack } from 'solid-js';
3
- import { inServerComponentScope, sourceOwners, viewOf, reportServerError, ssrHandleError, creationStamp, ssrSanitizeError, getProjectionTrace, shareAsyncIterable } from 'solid-js/internal';
4
- export { ssrScope as scope } from 'solid-js/internal';
1
+ import { createRenderEffect, createMemo, getOwner, createRoot, $PROXY, onCleanup, runWithOwner, createComponent, omit, getNextChildId, untrack, NotReadyError } from 'solid-js';
2
+ export { Errored, For, Hydration, Loading, Match, NoHydration, Repeat, Reveal, Show, Switch, createComponent, getOwner, merge as mergeProps, untrack } from 'solid-js';
3
+ import { sharedConfig, viewOf, sourceOwners, reportServerError, ssrHandleError, inServerComponentScope, creationStamp, ssrSanitizeError, getProjectionTrace, shareAsyncIterable } from 'solid-js/internal';
4
+ export { ssrScope as scope, sharedConfig } from 'solid-js/internal';
5
5
  import { Feature, createStream, Serializer, getCrossReferenceHeader } from 'seroval';
6
6
  import { AbortSignalPlugin, CustomEventPlugin, DOMExceptionPlugin, EventPlugin, FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin } from 'seroval-plugins/web';
7
7
 
@@ -79,6 +79,15 @@ function memo(fn) {
79
79
  return createMemo(() => fn(), syncOptions);
80
80
  }
81
81
 
82
+ const REQUEST_ERROR_HOOK = Symbol.for("solid-js/server/request-error-hook");
83
+ function hooks() {
84
+ const g = globalThis;
85
+ return g[REQUEST_ERROR_HOOK] || (g[REQUEST_ERROR_HOOK] = new WeakMap());
86
+ }
87
+ function setRequestErrorHook(event, hook) {
88
+ if (hook !== undefined) hooks().set(event, hook);
89
+ }
90
+
82
91
  const TRACEPARENT = /^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})(-.*)?$/;
83
92
  const ZERO_TRACE = "00000000000000000000000000000000";
84
93
  const ZERO_SPAN = "0000000000000000";
@@ -244,6 +253,96 @@ function traceMetaMarkup(record) {
244
253
  return markup;
245
254
  }
246
255
 
256
+ const DESCEND = Symbol("descend");
257
+ const CYCLE = {};
258
+ const TRACK = 16;
259
+ function rewriteTree(value, visit, withPath) {
260
+ if (value === null || typeof value !== "object") return value;
261
+ const path = undefined;
262
+ const state = {
263
+ memo: undefined,
264
+ ancestors: undefined
265
+ };
266
+ try {
267
+ return cow(value, visit, path, 0, state);
268
+ } catch (err) {
269
+ if (err !== CYCLE) throw err;
270
+ }
271
+ return clone(value, visit, path, state.memo || (state.memo = new Map()));
272
+ }
273
+ function shape(value) {
274
+ return Array.isArray(value) ? 1 : Object.getPrototypeOf(value) === Object.prototype ? 2 : 0;
275
+ }
276
+ function cow(value, visit, path, depth, state) {
277
+ const memo = state.memo;
278
+ if (memo !== undefined && memo.has(value)) return memo.get(value);
279
+ const r = visit(value, path);
280
+ if (r !== DESCEND) {
281
+ if (r !== value) (memo || (state.memo = new Map())).set(value, r);
282
+ return r;
283
+ }
284
+ const s = shape(value);
285
+ if (s === 0) return value;
286
+ let ancestors;
287
+ if (depth >= TRACK) {
288
+ ancestors = state.ancestors || (state.ancestors = new Set());
289
+ if (ancestors.has(value)) throw CYCLE;
290
+ ancestors.add(value);
291
+ }
292
+ let out = value;
293
+ if (s === 1) {
294
+ for (let i = 0; i < value.length; i++) {
295
+ const c = value[i];
296
+ if (c === null || typeof c !== "object") continue;
297
+ const next = cow(c, visit, undefined , depth + 1, state);
298
+ if (next !== c) {
299
+ if (out === value) out = value.slice();
300
+ out[i] = next;
301
+ }
302
+ }
303
+ } else {
304
+ for (const k of Object.keys(value)) {
305
+ const c = value[k];
306
+ if (c === null || typeof c !== "object") continue;
307
+ const next = cow(c, visit, undefined , depth + 1, state);
308
+ if (next !== c) {
309
+ if (out === value) out = {
310
+ ...value
311
+ };
312
+ out[k] = next;
313
+ }
314
+ }
315
+ }
316
+ if (ancestors !== undefined) ancestors.delete(value);
317
+ return out;
318
+ }
319
+ function clone(value, visit, path, memo) {
320
+ if (memo.has(value)) return memo.get(value);
321
+ const r = visit(value, path);
322
+ if (r !== DESCEND) {
323
+ memo.set(value, r);
324
+ return r;
325
+ }
326
+ const s = shape(value);
327
+ if (s === 0) return value;
328
+ const out = s === 1 ? value.slice() : {
329
+ ...value
330
+ };
331
+ memo.set(value, out);
332
+ if (s === 1) {
333
+ for (let i = 0; i < value.length; i++) {
334
+ const c = value[i];
335
+ if (c !== null && typeof c === "object") out[i] = clone(c, visit, undefined , memo);
336
+ }
337
+ } else {
338
+ for (const k of Object.keys(value)) {
339
+ const c = value[k];
340
+ if (c !== null && typeof c === "object") out[k] = clone(c, visit, undefined , memo);
341
+ }
342
+ }
343
+ return out;
344
+ }
345
+
247
346
  const STATE = Symbol.for("solid.container-trace-state");
248
347
  const state = globalThis[STATE] || (globalThis[STATE] = {
249
348
  materialized: new WeakMap(),
@@ -263,32 +362,10 @@ function toBorderForm(value, envelopeContainers) {
263
362
  if (value == null || typeof value !== "object") return value;
264
363
  const share = state.shareIterable;
265
364
  if (!share) return value;
266
- if (share && isShareableIterable(value)) return share(value);
267
- if (Array.isArray(value)) {
268
- let out = value;
269
- for (let i = 0; i < value.length; i++) {
270
- const next = toBorderForm(value[i]);
271
- if (next !== value[i]) {
272
- if (out === value) out = value.slice();
273
- out[i] = next;
274
- }
275
- }
276
- return out;
277
- }
278
- if (Object.getPrototypeOf(value) === Object.prototype) {
279
- let out = value;
280
- for (const key of Object.keys(value)) {
281
- const next = toBorderForm(value[key]);
282
- if (next !== value[key]) {
283
- if (out === value) out = {
284
- ...value
285
- };
286
- out[key] = next;
287
- }
288
- }
289
- return out;
290
- }
291
- return value;
365
+ return rewriteTree(value, v => {
366
+ if (share && isShareableIterable(v)) return share(v);
367
+ return DESCEND;
368
+ });
292
369
  }
293
370
  function isShareableIterable(value) {
294
371
  try {
@@ -687,6 +764,7 @@ function resolveHead(groups) {
687
764
  return winners;
688
765
  }
689
766
 
767
+ const renderConfig = sharedConfig;
690
768
  function joinAssetPath(base, file) {
691
769
  if (/^(?:[a-z][a-z0-9+.-]*:)?\/\//i.test(file)) return file;
692
770
  if (typeof base !== "string" || !base) base = "/";
@@ -840,6 +918,7 @@ function applyAssetTracking(context, tracking, manifest, noScripts) {
840
918
  });
841
919
  context.registerModule = tracking.registerModule;
842
920
  context.getBoundaryModules = tracking.getBoundaryModules;
921
+ context._lazyAssets = new Map();
843
922
  if (typeof manifest === "function") {
844
923
  context.resolveAssets = guard(manifest);
845
924
  } else if (manifest && typeof manifest.resolve === "function") {
@@ -1412,6 +1491,7 @@ function renderToString(code, options = {}) {
1412
1491
  });
1413
1492
  const tracking = createAssetTracking();
1414
1493
  const headRegistry = createHeadRegistry();
1494
+ let closed = false;
1415
1495
  sharedConfig.context = {
1416
1496
  nonce: options.nonce,
1417
1497
  escape: escape,
@@ -1422,7 +1502,7 @@ function renderToString(code, options = {}) {
1422
1502
  registerHeadTags(headRegistry, sharedConfig.context, tracking, null, nonce, tags);
1423
1503
  },
1424
1504
  serialize(id, p) {
1425
- if (sharedConfig.context.noHydrate) return;
1505
+ if (closed) return;
1426
1506
  if (p != null && typeof p === "object" && (typeof p.then === "function" || typeof p[Symbol.asyncIterator] === "function")) {
1427
1507
  throw new Error("Cannot serialize async value in renderToString (id: " + id + "). " + "Use renderToStream for async data.");
1428
1508
  }
@@ -1451,20 +1531,25 @@ function renderToString(code, options = {}) {
1451
1531
  applyAssetTracking(sharedConfig.context, tracking, manifest, noScripts);
1452
1532
  registerEntryAssets(manifest);
1453
1533
  const context = sharedConfig.context;
1534
+ context.writer = createHydrationWriter(context, () => !closed);
1454
1535
  const requestEvent = peekRequestEvent();
1536
+ if (requestEvent) setRequestErrorHook(requestEvent, options.onError);
1455
1537
  context.trace = requestEvent ? traceForEvent(requestEvent) : traceFor(context, undefined);
1456
1538
  const render = timeDocument(context, context.trace);
1457
1539
  let dispose;
1540
+ let rootOwner;
1458
1541
  let rendered = false;
1459
1542
  try {
1460
1543
  const html = createRoot(d => {
1461
1544
  dispose = d;
1545
+ rootOwner = claimRenderRoot(context);
1546
+ if (requestEvent) claimEventRender(requestEvent, context);
1462
1547
  return resolveSSRSync(escape(code()));
1463
1548
  }, {
1464
1549
  id: renderId
1465
1550
  });
1466
1551
  serializeFragmentAssets("", tracking.boundaryModules, sharedConfig.context, renderId);
1467
- sharedConfig.context.noHydrate = true;
1552
+ closed = true;
1468
1553
  serializer.close();
1469
1554
  const head = renderShellHead(headRegistry, nonce, null, noScripts, traceMetaMarkup(context.trace));
1470
1555
  const document = assembleDocument(resolveSSRSelectValues(html), tracking.emittedAssets, tracking.preloadLinks, tracking.inlineStyles, scripts.length ? scripts : "", nonce, head, onHead);
@@ -1477,7 +1562,7 @@ function renderToString(code, options = {}) {
1477
1562
  rendered = true;
1478
1563
  return document;
1479
1564
  } finally {
1480
- if (render) render.settle(rendered ? "complete" : "error");
1565
+ if (render) settleRender(render, rootOwner, rendered ? "complete" : "error");
1481
1566
  context.trace = undefined;
1482
1567
  if (dispose) dispose();
1483
1568
  }
@@ -1493,9 +1578,11 @@ function renderToStream(code, options = {}) {
1493
1578
  } = options;
1494
1579
  const nonce = normalizeNonce(options.nonce);
1495
1580
  const requestEvent = peekRequestEvent();
1581
+ if (requestEvent) setRequestErrorHook(requestEvent, options.onError);
1496
1582
  let dispose;
1497
1583
  let dead = false;
1498
1584
  let render;
1585
+ let rootOwner;
1499
1586
  let serializer;
1500
1587
  let disconnected = false;
1501
1588
  let failed = false;
@@ -1523,7 +1610,7 @@ function renderToStream(code, options = {}) {
1523
1610
  dead = true;
1524
1611
  completed = true;
1525
1612
  if (disconnect) disconnected = true;
1526
- if (render) render.settle(disconnect ? "abandoned" : "error");
1613
+ if (render) settleRender(render, rootOwner, disconnect ? "abandoned" : "error");
1527
1614
  const sink = writable;
1528
1615
  buffer = {
1529
1616
  write() {}
@@ -1560,7 +1647,7 @@ function renderToStream(code, options = {}) {
1560
1647
  reportServerError(err, {
1561
1648
  kind: "render",
1562
1649
  handling: "failed"
1563
- }, null);
1650
+ }, null, options.onError);
1564
1651
  if (!options.onError && ambientServerErrorHook() === undefined) console.error(err);
1565
1652
  abandon();
1566
1653
  };
@@ -1654,7 +1741,7 @@ function renderToStream(code, options = {}) {
1654
1741
  });
1655
1742
  writable && writable.end();
1656
1743
  completed = true;
1657
- if (render) render.settle("complete");
1744
+ if (render) settleRender(render, rootOwner, "complete");
1658
1745
  if (firstFlushed) dispose();
1659
1746
  };
1660
1747
  const sink = {
@@ -1920,7 +2007,6 @@ function renderToStream(code, options = {}) {
1920
2007
  html = html.slice(0, first) + resolveSSRSync(escape(payloadFn())) + html.slice(last + placeholder.length + 1);
1921
2008
  },
1922
2009
  serialize(id, p, deferStream) {
1923
- if (sharedConfig.context.noHydrate) return;
1924
2010
  p = guardChannel(p);
1925
2011
  if (p && typeof p === "object" && typeof p.then === "function") {
1926
2012
  if (!firstFlushed && deferStream) {
@@ -2037,6 +2123,7 @@ function renderToStream(code, options = {}) {
2037
2123
  context.trace = requestEvent ? traceForEvent(requestEvent) : traceFor(context, undefined);
2038
2124
  render = timeDocument(context, context.trace);
2039
2125
  registerEntryAssets(manifest);
2126
+ context.writer = createHydrationWriter(context, () => !completed);
2040
2127
  const signal = options.signal;
2041
2128
  const onAbort = signal ? () => abandon("signal") : undefined;
2042
2129
  let html = createRoot(d => {
@@ -2045,6 +2132,8 @@ function renderToStream(code, options = {}) {
2045
2132
  if (onAbort) signal.removeEventListener("abort", onAbort);
2046
2133
  d();
2047
2134
  };
2135
+ rootOwner = claimRenderRoot(context);
2136
+ if (requestEvent) claimEventRender(requestEvent, context);
2048
2137
  const res = resolveSSRNode(escape(code()));
2049
2138
  if (!res.h.length) return res.t[0];
2050
2139
  rootHoles = [];
@@ -2957,14 +3046,16 @@ function ssrClassName(value) {
2957
3046
  if (typeof value === "number") return "" + value;
2958
3047
  if (!value) return "";
2959
3048
  if (typeof value === "string") return escape(value, true);
3049
+ if (isSlotValue(value)) return "";
2960
3050
  value = classListToObject(value);
2961
3051
  let classKeys = Object.keys(value),
2962
3052
  result = "";
2963
3053
  for (let i = 0, len = classKeys.length; i < len; i++) {
2964
- const key = classKeys[i],
2965
- classValue = !!value[key];
3054
+ const key = classKeys[i];
3055
+ let classValue = value[key];
3056
+ if (isSlotValue(classValue)) classValue = slotValueInline();
2966
3057
  if (!key || key === "undefined" || !classValue) continue;
2967
- i && (result += " ");
3058
+ result && (result += " ");
2968
3059
  result += escape(key, true);
2969
3060
  }
2970
3061
  return result;
@@ -2972,15 +3063,17 @@ function ssrClassName(value) {
2972
3063
  function ssrStyle(value) {
2973
3064
  if (!value) return "";
2974
3065
  if (typeof value === "string") return escape(value, true);
3066
+ if (isSlotValue(value)) return "";
2975
3067
  let result = "";
2976
3068
  const k = Object.keys(value);
2977
3069
  for (let i = 0; i < k.length; i++) {
2978
3070
  const s = escape(k[i], true);
2979
- const v = value[k[i]];
3071
+ let v = value[k[i]];
3072
+ if (isSlotValue(v)) v = slotValueInline();
2980
3073
  if (v != undefined) {
2981
- if (i) result += ";";
2982
3074
  const r = escape(v, true);
2983
3075
  if (r != undefined && r !== "undefined") {
3076
+ if (result) result += ";";
2984
3077
  result += `${s}:${r}`;
2985
3078
  }
2986
3079
  }
@@ -2988,28 +3081,31 @@ function ssrStyle(value) {
2988
3081
  return result;
2989
3082
  }
2990
3083
  function ssrStyleProperty(name, value) {
3084
+ if (isSlotValue(value)) value = slotValueInline();
2991
3085
  return value != null ? name + value : "";
2992
3086
  }
2993
- function ssrElement(tag, props, children, needsId, skip, attrs) {
3087
+ function ssrElement(tag, props, children, needsId, skip, attrs, claims) {
2994
3088
  const hk = needsId ? ssrHydrationKey() : "";
2995
3089
  if (typeof props === "function") props = props();
2996
3090
  let sources = null;
2997
3091
  let proxy = false;
2998
3092
  let viewKeys = null;
2999
3093
  let owners = null;
3094
+ let ownerIndex = null;
3095
+ const ctx = renderConfig.context;
3096
+ const slots = ctx !== undefined && ctx.claims !== undefined;
3000
3097
  if (Array.isArray(props)) {
3001
- let i = 0;
3002
- for (; i < props.length; i++) {
3003
- const s = props[i];
3004
- if (s == null || typeof s === "function" || $PROXY in s) break;
3005
- }
3006
- if (i === props.length) sources = props;else {
3007
- viewKeys = [];
3008
- owners = [];
3009
- for (let i = 0; i < props.length; i++) {
3010
- let s = props[i];
3011
- if (typeof s === "function") s = s();
3012
- if (s != null) sourceOwners(s, viewKeys, owners);
3098
+ if (slots && props.$slot === true) props = slotSpreadSource();else {
3099
+ let i = 0;
3100
+ for (; i < props.length; i++) {
3101
+ const s = props[i];
3102
+ if (s == null || typeof s === "function" || $PROXY in s || slots && s.$slot === true) break;
3103
+ }
3104
+ if (i === props.length) sources = props;else {
3105
+ viewKeys = [];
3106
+ owners = [];
3107
+ if (slots) ownerIndex = [];
3108
+ collectSpreadSources(tag, props, viewKeys, owners, slots, ownerIndex);
3013
3109
  }
3014
3110
  }
3015
3111
  } else if (props == null) {
@@ -3020,10 +3116,13 @@ function ssrElement(tag, props, children, needsId, skip, attrs) {
3020
3116
  owners = [];
3021
3117
  sourceOwners(props, viewKeys, owners);
3022
3118
  } else proxy = true;
3119
+ } else if (slots && props.$slot === true) {
3120
+ props = slotSpreadSource();
3023
3121
  }
3024
3122
  const info = tagInfo(tag);
3025
3123
  const skipChildren = info.isVoid;
3026
3124
  let result = info.open + hk;
3125
+ let behaviors = null;
3027
3126
  const last = sources === null ? 0 : sources.length - 1;
3028
3127
  let keysOf = null;
3029
3128
  if (sources !== null) {
@@ -3050,8 +3149,19 @@ function ssrElement(tag, props, children, needsId, skip, attrs) {
3050
3149
  continue;
3051
3150
  }
3052
3151
  const value = props[prop];
3053
- if (value == undefined || prop === "ref" || prop.startsWith("on") || prop.startsWith("prop:")) {
3152
+ if (value == undefined) {
3153
+ if (slots && claims !== undefined && (prop === "ref" || prop.startsWith("on"))) behaviors = spreadBehaviorPosition(behaviors, prop, value, ctx.claims, ownerIndex !== null ? ownerIndex[i] : s, true);
3154
+ continue;
3155
+ }
3156
+ if (prop.startsWith("prop:")) {
3054
3157
  continue;
3158
+ }
3159
+ if (prop === "ref" || prop.startsWith("on")) {
3160
+ if (slots) behaviors = spreadBehaviorPosition(behaviors, prop, value, ctx.claims, ownerIndex !== null ? ownerIndex[i] : s, claims !== undefined);
3161
+ continue;
3162
+ }
3163
+ if (slots && typeof value === "object") {
3164
+ result += spreadObjectAttribute(prop, value);
3055
3165
  } else if (prop === "style") {
3056
3166
  result += ` style="${ssrStyle(value)}"`;
3057
3167
  } else if (prop === "class") {
@@ -3064,6 +3174,7 @@ function ssrElement(tag, props, children, needsId, skip, attrs) {
3064
3174
  }
3065
3175
  }
3066
3176
  }
3177
+ if (slots && (behaviors !== null || claims !== undefined)) result += spreadBehaviorMarkers(behaviors, claims, ctx.claims);
3067
3178
  if (attrs !== undefined) result += typeof attrs === "function" ? attrs() : attrs;
3068
3179
  if (skipChildren) return {
3069
3180
  t: result + " />"
@@ -3083,43 +3194,226 @@ function ssrElement(tag, props, children, needsId, skip, attrs) {
3083
3194
  }
3084
3195
  function ssrElementAttribute(key, value) {
3085
3196
  if (value == undefined) return "";
3086
- if (key === "style") return ` style="${ssrStyle(value)}"`;
3087
- if (key === "class") return ` class="${ssrClassName(value)}"`;
3197
+ if (key === "style" || key === "class") {
3198
+ return typeof value === "object" ? slotClassOrStyle(key, value) : ` ${key}="${key === "class" ? ssrClassName(value) : ssrStyle(value)}"`;
3199
+ }
3200
+ if (isSlotValue(value)) return slotAttribute(key, value);
3088
3201
  if (typeof value === "boolean") return value ? ` ${key}` : "";
3089
3202
  return value === "" ? ` ${key}` : ` ${key}="${escape(value, true)}"`;
3090
3203
  }
3091
3204
  function ssrAttribute(key, value) {
3092
- return value == null || value === false ? "" : value === true ? ` ${key}` : ` ${key}="${value}"`;
3205
+ if (value == null || value === false) return "";
3206
+ if (typeof value === "object") {
3207
+ return isSlotValue(value) ? slotAttribute(key, value) : ` ${key}="${escape(String(value), true)}"`;
3208
+ }
3209
+ return value === true ? ` ${key}` : ` ${key}="${value}"`;
3093
3210
  }
3094
3211
  function ssrHydrationKey() {
3095
3212
  const hk = getHydrationKey();
3096
3213
  return hk ? ` _hk=${hk}` : "";
3097
3214
  }
3098
- const CLAIM_PROP = /*#__PURE__*/Symbol.for("solid.claim-prop");
3099
3215
  const CLAIMS_STREAM = 1;
3100
3216
  const CLAIMS_DOCUMENT = 2;
3101
- const CLAIM_UNSAFE = /[^A-Za-z0-9_.!~*'()-]/g;
3102
- function encodeClaimKey(key) {
3103
- return String(key).replace(CLAIM_UNSAFE, c => encodeURIComponent(c));
3217
+ const SLOT_VALUE = /*#__PURE__*/Symbol.for("solid.slot-value");
3218
+ const SLOT_MARKER = "_s:";
3219
+ const SLOT_FACE_STREAM = 0;
3220
+ const SLOT_FACE_DATA = 1;
3221
+ const SLOT_FACE_MARKUP = 2;
3222
+ function isSlotValue(value) {
3223
+ return value !== null && typeof value === "object" && value[SLOT_VALUE] !== undefined;
3224
+ }
3225
+ function slotValue(occurrence, key, value, face) {
3226
+ const sv = {
3227
+ [SLOT_VALUE]: occurrence,
3228
+ k: key,
3229
+ v: value,
3230
+ f: face
3231
+ };
3232
+ Object.defineProperty(sv, Symbol.toPrimitive, {
3233
+ value: hint => slotValueString()
3234
+ });
3235
+ Object.defineProperty(sv, "toString", {
3236
+ value: () => slotValueString()
3237
+ });
3238
+ return sv;
3239
+ }
3240
+ function slotValueString(sv, reason) {
3241
+ return "";
3242
+ }
3243
+ function slotTextPosition(sv) {
3244
+ return "";
3245
+ }
3246
+ function slotValueInline(kind, sv) {
3247
+ return undefined;
3248
+ }
3249
+ const SLOT_KEY_UNSAFE = /[^A-Za-z0-9_.!~*'()-]/g;
3250
+ function encodeSlotKey(key) {
3251
+ return String(key).replace(SLOT_KEY_UNSAFE, c => encodeURIComponent(c));
3252
+ }
3253
+ function slotEntry(sv, name) {
3254
+ return `${sv[SLOT_VALUE]}:${encodeSlotKey(sv.k)}${name !== undefined ? "=" + encodeSlotKey(name) : ""}`;
3255
+ }
3256
+ function slotMarker(position, entries) {
3257
+ return ` ${SLOT_MARKER}${position}="${entries}"`;
3258
+ }
3259
+ function slotAttribute(key, sv) {
3260
+ let out = "";
3261
+ if (sv.f === SLOT_FACE_DATA) {
3262
+ const v = sv.v;
3263
+ if (v != null && v !== false) {
3264
+ out = v === true || v === "" ? ` ${key}` : ` ${key}="${escape(String(v), true)}"`;
3265
+ }
3266
+ }
3267
+ return out + slotMarker(key, slotEntry(sv));
3268
+ }
3269
+ function slotClassOrStyle(key, value) {
3270
+ const isClass = key === "class";
3271
+ if (isSlotValue(value)) {
3272
+ let out = "";
3273
+ if (value.f === SLOT_FACE_DATA && value.v != null) {
3274
+ out = ` ${key}="${isClass ? ssrClassName(value.v) : ssrStyle(value.v)}"`;
3275
+ }
3276
+ return out + slotMarker(key, slotEntry(value));
3277
+ }
3278
+ if (typeof value === "object" && value !== null) {
3279
+ const obj = isClass ? classListToObject(value) : value;
3280
+ let entries = "";
3281
+ let inner = "";
3282
+ for (const name of Object.keys(obj)) {
3283
+ let v = obj[name];
3284
+ if (isSlotValue(v)) {
3285
+ entries += (entries ? "," : "") + slotEntry(v, name);
3286
+ v = v.f === SLOT_FACE_DATA ? v.v : undefined;
3287
+ }
3288
+ if (isClass) {
3289
+ if (!name || name === "undefined" || !v) continue;
3290
+ inner += (inner ? " " : "") + escape(name, true);
3291
+ } else if (v != undefined) {
3292
+ const r = escape(v, true);
3293
+ if (r != undefined && r !== "undefined") {
3294
+ inner += (inner ? ";" : "") + `${escape(name, true)}:${r}`;
3295
+ }
3296
+ }
3297
+ }
3298
+ if (entries === "") return ` ${key}="${inner}"`;
3299
+ return (inner ? ` ${key}="${inner}"` : "") + slotMarker(key, entries);
3300
+ }
3301
+ return ` ${key}="${isClass ? ssrClassName(value) : ssrStyle(value)}"`;
3302
+ }
3303
+ function eventPosition(prop) {
3304
+ return prop.slice(2).toLowerCase();
3305
+ }
3306
+ function spreadBehaviorPosition(behaviors, prop, value, mode, index, settle) {
3307
+ const pos = prop === "ref" ? "ref" : eventPosition(prop);
3308
+ const entries = value == null ? "" : claimEntries(pos, value);
3309
+ if (!settle) {
3310
+ if (entries) (behaviors ||= new Map()).set(pos, entries);
3311
+ return behaviors;
3312
+ }
3313
+ behaviors ||= new Map();
3314
+ const b = behaviors.get(pos);
3315
+ if (b === undefined) behaviors.set(pos, {
3316
+ e: entries,
3317
+ at: index
3318
+ });else {
3319
+ b.e = entries;
3320
+ b.at = index;
3321
+ }
3322
+ return behaviors;
3323
+ }
3324
+ function spreadBehaviorMarkers(behaviors, claims, mode) {
3325
+ if (claims !== undefined) {
3326
+ const segments = claims();
3327
+ for (const k in segments) {
3328
+ const map = segments[k];
3329
+ for (const pos in map) {
3330
+ const value = map[pos];
3331
+ behaviors ||= new Map();
3332
+ const b = behaviors.get(pos);
3333
+ if (pos === "ref") {
3334
+ if (value == null) continue;
3335
+ const entries = claimEntries("ref", value);
3336
+ if (!entries) continue;
3337
+ if (b === undefined) behaviors.set("ref", {
3338
+ e: entries,
3339
+ at: -1
3340
+ });else b.e = b.e ? b.e + "," + entries : entries;
3341
+ continue;
3342
+ }
3343
+ if (b !== undefined && b.at >= +k) continue;
3344
+ const entries = value == null ? "" : claimEntries(pos, value);
3345
+ if (b === undefined) behaviors.set(pos, {
3346
+ e: entries,
3347
+ at: -1
3348
+ });else b.e = entries;
3349
+ }
3350
+ }
3351
+ }
3352
+ let out = "";
3353
+ if (behaviors !== null) {
3354
+ for (const [pos, b] of behaviors) {
3355
+ const e = claims === undefined ? b : b.e;
3356
+ if (e) out += slotMarker(pos === "ref" ? "ref" : "on:" + pos, e);
3357
+ }
3358
+ }
3359
+ return out;
3360
+ }
3361
+ function collectSpreadSources(tag, props, viewKeys, owners, slots, ownerIndex) {
3362
+ for (let i = 0; i < props.length; i++) {
3363
+ let s = props[i];
3364
+ if (typeof s === "function") s = s();
3365
+ if (s != null) {
3366
+ if (slots && !($PROXY in s) && s.$slot === true) s = slotSpreadSource();
3367
+ if (ownerIndex === null) sourceOwners(s, viewKeys, owners);else {
3368
+ const ks = [];
3369
+ const os = [];
3370
+ sourceOwners(s, ks, os);
3371
+ for (let j = 0; j < ks.length; j++) {
3372
+ const at = viewKeys.indexOf(ks[j]);
3373
+ if (at !== -1) {
3374
+ viewKeys.splice(at, 1);
3375
+ owners.splice(at, 1);
3376
+ ownerIndex.splice(at, 1);
3377
+ }
3378
+ viewKeys.push(ks[j]);
3379
+ owners.push(os[j]);
3380
+ ownerIndex.push(i);
3381
+ }
3382
+ }
3383
+ }
3384
+ }
3385
+ }
3386
+ function spreadObjectAttribute(prop, value) {
3387
+ if (prop === "style" || prop === "class") return slotClassOrStyle(prop, value);
3388
+ if (value[SLOT_VALUE] !== undefined) return slotAttribute(attrName(prop), value);
3389
+ return ` ${attrName(prop)}="${escape(value, true)}"`;
3390
+ }
3391
+ function slotSpreadSource(tag, source) {
3392
+ return {};
3104
3393
  }
3105
3394
  function ssrClaim(map) {
3106
3395
  const mode = sharedConfig.context && sharedConfig.context.claims;
3107
- if (!mode || mode === CLAIMS_DOCUMENT && !(typeof inServerComponentScope === "function" && inServerComponentScope())) {
3108
- return "";
3109
- }
3396
+ if (!mode) return "";
3110
3397
  let out = "";
3111
3398
  for (const pos in map) {
3112
- const value = map[pos];
3113
- const list = Array.isArray(value) ? value : [value];
3114
- for (const fn of list) {
3115
- const prop = typeof fn === "function" && fn[CLAIM_PROP] || undefined;
3116
- if (prop === undefined) {
3117
- continue;
3118
- }
3119
- out += `${out ? "," : ""}${pos}=${encodeClaimKey(prop)}`;
3399
+ const entries = claimEntries(pos, map[pos]);
3400
+ if (entries) out += slotMarker(pos === "ref" ? "ref" : "on:" + pos, entries);
3401
+ }
3402
+ return out;
3403
+ }
3404
+ function claimEntries(pos, value, mode) {
3405
+ if (Array.isArray(value)) {
3406
+ let entries = "";
3407
+ for (const v of value) {
3408
+ const inner = claimEntries(pos, v);
3409
+ if (inner) entries += (entries ? "," : "") + inner;
3120
3410
  }
3411
+ return entries;
3121
3412
  }
3122
- return out ? ` _bnd="${out}"` : "";
3413
+ if (isSlotValue(value)) {
3414
+ return slotEntry(value);
3415
+ }
3416
+ return "";
3123
3417
  }
3124
3418
  function decodeSSREntities(s) {
3125
3419
  return s.indexOf("&") < 0 ? s : s.replace(/&quot;/g, '"').replace(/&lt;/g, "<").replace(/&amp;/g, "&");
@@ -3241,6 +3535,7 @@ function escape(s, attr) {
3241
3535
  if (!attr && t === "function") return escapeLate(s);
3242
3536
  if (attr) {
3243
3537
  if (s == null || t === "boolean" || t === "number") return s;
3538
+ if (t === "object" && s[SLOT_VALUE] !== undefined) return s;
3244
3539
  return escape(String(s), attr);
3245
3540
  }
3246
3541
  return s;
@@ -3603,6 +3898,10 @@ function resolveSSRNode(node, result = {
3603
3898
  } else if (node.t !== undefined) {
3604
3899
  result.t[result.t.length - 1] += node.t;
3605
3900
  ssrTextTail = false;
3901
+ } else if (node[SLOT_VALUE] !== undefined) {
3902
+ const text = escape(slotTextPosition());
3903
+ result.t[result.t.length - 1] += ssrTextTail ? "<!--!$-->" + text : text;
3904
+ ssrTextTail = true;
3606
3905
  } else ;
3607
3906
  } else if (t === "function") {
3608
3907
  const live = sharedConfig.context && sharedConfig.context.liveHoles;
@@ -3641,7 +3940,7 @@ function serializerErrorHook(hook) {
3641
3940
  reportServerError(err, {
3642
3941
  kind: "render",
3643
3942
  handling: "serialize"
3644
- }, null);
3943
+ }, null, hook);
3645
3944
  };
3646
3945
  }
3647
3946
  function ambientServerErrorHook() {
@@ -3656,7 +3955,66 @@ function configureServerErrors(config) {
3656
3955
  (g[ServerErrors] ||= {}).hook = config ? config.onError : undefined;
3657
3956
  }
3658
3957
  function getRequestEvent() {
3659
- 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;
3958
+ const store = globalThis[RequestContext];
3959
+ if (!store) return undefined;
3960
+ const event = store.getStore();
3961
+ if (event) return event;
3962
+ const ctx = renderContextOf(getOwner());
3963
+ return ctx && ctx.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.");
3964
+ }
3965
+ const RENDER_ROOTS = Symbol.for("@solidjs/web/render-roots");
3966
+ function renderRoots() {
3967
+ const g = globalThis;
3968
+ return g[RENDER_ROOTS] || (g[RENDER_ROOTS] = new WeakMap());
3969
+ }
3970
+ function claimRenderRoot(context) {
3971
+ const owner = getOwner();
3972
+ const roots = renderRoots();
3973
+ roots.set(owner, context);
3974
+ onCleanup(() => roots.delete(owner));
3975
+ return owner;
3976
+ }
3977
+ function settleRender(render, root, outcome) {
3978
+ runWithOwner(root || null, () => render.settle(outcome));
3979
+ }
3980
+ const eventRenders = new WeakMap();
3981
+ function claimEventRender(event, context) {
3982
+ let renders = eventRenders.get(event);
3983
+ if (!renders) eventRenders.set(event, renders = new Set());
3984
+ renders.add(context);
3985
+ onCleanup(() => renders.delete(context));
3986
+ }
3987
+ function createHydrationWriter(context, isOpen) {
3988
+ const keys = new Set();
3989
+ return {
3990
+ async: !!context.async,
3991
+ write(key, value, options) {
3992
+ if (!isOpen() || keys.has(key)) return false;
3993
+ context.serialize(key, value, options && options.deferStream);
3994
+ keys.add(key);
3995
+ return true;
3996
+ }
3997
+ };
3998
+ }
3999
+ function getHydrationWriter() {
4000
+ let ctx = renderContextOf(getOwner());
4001
+ if (!ctx) {
4002
+ const event = peekRequestEvent();
4003
+ const renders = event && eventRenders.get(event);
4004
+ if (renders && renders.size === 1) for (const c of renders) ctx = c;
4005
+ }
4006
+ return ctx && ctx.writer;
4007
+ }
4008
+ function takeHydrationValue(_key) {
4009
+ return undefined;
4010
+ }
4011
+ function renderContextOf(owner) {
4012
+ const roots = globalThis[RENDER_ROOTS];
4013
+ if (!roots) return undefined;
4014
+ for (; owner; owner = owner._parent) {
4015
+ const context = roots.get(owner);
4016
+ if (context) return context;
4017
+ }
3660
4018
  }
3661
4019
  function peekRequestEvent() {
3662
4020
  const store = globalThis[RequestContext];
@@ -3668,7 +4026,7 @@ function timeDocument(context, trace, mode, requestEvent) {
3668
4026
  function getTraceContext() {
3669
4027
  const event = peekRequestEvent();
3670
4028
  if (event) return traceForEvent(event).context;
3671
- const ctx = sharedConfig.context;
4029
+ const ctx = renderContextOf(getOwner());
3672
4030
  return ctx && ctx.trace ? ctx.trace.context : undefined;
3673
4031
  }
3674
4032
  function traceForStub(stub, event) {
@@ -4113,4 +4471,4 @@ function httpHeader(name, value, options) {
4113
4471
  }
4114
4472
  }
4115
4473
 
4116
- 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, ssrElementAttribute, ssrGroup, ssrHydrationKey, ssrSelectValues, ssrStyle, ssrStyleProperty, notSup as style, styleNonce, notSup as template, notSup as unregisterDelegatedContainer, notSup as unregisterDelegatedRoot, useHead };
4474
+ export { CLAIMS_DOCUMENT, CLAIMS_STREAM, 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, SLOT_FACE_DATA, SLOT_FACE_MARKUP, SLOT_FACE_STREAM, SLOT_MARKER, SLOT_VALUE, 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, getHydrationWriter, 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, isSlotValue, 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, slotValue, notSup as spread, ssr, ssrAttribute, ssrClaim, ssrClassName, ssrElement, ssrElementAttribute, ssrGroup, ssrHydrationKey, ssrSelectValues, ssrStyle, ssrStyleProperty, notSup as style, styleNonce, takeHydrationValue, notSup as template, notSup as unregisterDelegatedContainer, notSup as unregisterDelegatedRoot, useHead };