@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.
@@ -1,7 +1,7 @@
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, reportServerError, ssrHandleError, creationStamp, ssrSanitizeError, getProjectionTrace, shareAsyncIterable } from 'solid-js/internal';
4
- export { ssrScope as scope } from 'solid-js/internal';
1
+ import { createRenderEffect, createMemo, OBSERVE, 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 PROVIDER = Symbol.for("solid-js/observe/server/provider");
83
92
  function currentProvider() {
84
93
  if (OBSERVE === undefined) return undefined;
@@ -294,6 +303,7 @@ function observeRender(trace, mode, event) {
294
303
  };
295
304
  trace.render = record;
296
305
  let settled = false;
306
+ let route;
297
307
  return {
298
308
  shell() {
299
309
  if (!settled && record.shellMs === undefined) record.shellMs = performance.now() - record.at;
@@ -301,11 +311,21 @@ function observeRender(trace, mode, event) {
301
311
  boundary() {
302
312
  if (!settled) record.boundaries++;
303
313
  },
314
+ route(ref) {
315
+ if (!settled) route = ref;
316
+ },
304
317
  settle(outcome) {
305
318
  if (settled) return;
306
319
  settled = true;
307
320
  record.durationMs = performance.now() - record.at;
308
321
  record.outcome = outcome;
322
+ if (route !== undefined) {
323
+ const r = {};
324
+ if (route.name !== undefined) r.name = route.name;
325
+ if (route.to !== undefined) r.to = route.to;
326
+ if (route.params !== undefined) r.params = route.params;
327
+ record.route = r;
328
+ }
309
329
  const channel = records();
310
330
  if (!channel.observed("render")) return;
311
331
  const live = {
@@ -317,6 +337,96 @@ function observeRender(trace, mode, event) {
317
337
  };
318
338
  }
319
339
 
340
+ const DESCEND = Symbol("descend");
341
+ const CYCLE = {};
342
+ const TRACK = 16;
343
+ function rewriteTree(value, visit, withPath) {
344
+ if (value === null || typeof value !== "object") return value;
345
+ const path = undefined;
346
+ const state = {
347
+ memo: undefined,
348
+ ancestors: undefined
349
+ };
350
+ try {
351
+ return cow(value, visit, path, 0, state);
352
+ } catch (err) {
353
+ if (err !== CYCLE) throw err;
354
+ }
355
+ return clone(value, visit, path, state.memo || (state.memo = new Map()));
356
+ }
357
+ function shape(value) {
358
+ return Array.isArray(value) ? 1 : Object.getPrototypeOf(value) === Object.prototype ? 2 : 0;
359
+ }
360
+ function cow(value, visit, path, depth, state) {
361
+ const memo = state.memo;
362
+ if (memo !== undefined && memo.has(value)) return memo.get(value);
363
+ const r = visit(value, path);
364
+ if (r !== DESCEND) {
365
+ if (r !== value) (memo || (state.memo = new Map())).set(value, r);
366
+ return r;
367
+ }
368
+ const s = shape(value);
369
+ if (s === 0) return value;
370
+ let ancestors;
371
+ if (depth >= TRACK) {
372
+ ancestors = state.ancestors || (state.ancestors = new Set());
373
+ if (ancestors.has(value)) throw CYCLE;
374
+ ancestors.add(value);
375
+ }
376
+ let out = value;
377
+ if (s === 1) {
378
+ for (let i = 0; i < value.length; i++) {
379
+ const c = value[i];
380
+ if (c === null || typeof c !== "object") continue;
381
+ const next = cow(c, visit, undefined , depth + 1, state);
382
+ if (next !== c) {
383
+ if (out === value) out = value.slice();
384
+ out[i] = next;
385
+ }
386
+ }
387
+ } else {
388
+ for (const k of Object.keys(value)) {
389
+ const c = value[k];
390
+ if (c === null || typeof c !== "object") continue;
391
+ const next = cow(c, visit, undefined , depth + 1, state);
392
+ if (next !== c) {
393
+ if (out === value) out = {
394
+ ...value
395
+ };
396
+ out[k] = next;
397
+ }
398
+ }
399
+ }
400
+ if (ancestors !== undefined) ancestors.delete(value);
401
+ return out;
402
+ }
403
+ function clone(value, visit, path, memo) {
404
+ if (memo.has(value)) return memo.get(value);
405
+ const r = visit(value, path);
406
+ if (r !== DESCEND) {
407
+ memo.set(value, r);
408
+ return r;
409
+ }
410
+ const s = shape(value);
411
+ if (s === 0) return value;
412
+ const out = s === 1 ? value.slice() : {
413
+ ...value
414
+ };
415
+ memo.set(value, out);
416
+ if (s === 1) {
417
+ for (let i = 0; i < value.length; i++) {
418
+ const c = value[i];
419
+ if (c !== null && typeof c === "object") out[i] = clone(c, visit, undefined , memo);
420
+ }
421
+ } else {
422
+ for (const k of Object.keys(value)) {
423
+ const c = value[k];
424
+ if (c !== null && typeof c === "object") out[k] = clone(c, visit, undefined , memo);
425
+ }
426
+ }
427
+ return out;
428
+ }
429
+
320
430
  const STATE = Symbol.for("solid.container-trace-state");
321
431
  const state = globalThis[STATE] || (globalThis[STATE] = {
322
432
  materialized: new WeakMap(),
@@ -336,32 +446,10 @@ function toBorderForm(value, envelopeContainers) {
336
446
  if (value == null || typeof value !== "object") return value;
337
447
  const share = state.shareIterable;
338
448
  if (!share) return value;
339
- if (share && isShareableIterable(value)) return share(value);
340
- if (Array.isArray(value)) {
341
- let out = value;
342
- for (let i = 0; i < value.length; i++) {
343
- const next = toBorderForm(value[i]);
344
- if (next !== value[i]) {
345
- if (out === value) out = value.slice();
346
- out[i] = next;
347
- }
348
- }
349
- return out;
350
- }
351
- if (Object.getPrototypeOf(value) === Object.prototype) {
352
- let out = value;
353
- for (const key of Object.keys(value)) {
354
- const next = toBorderForm(value[key]);
355
- if (next !== value[key]) {
356
- if (out === value) out = {
357
- ...value
358
- };
359
- out[key] = next;
360
- }
361
- }
362
- return out;
363
- }
364
- return value;
449
+ return rewriteTree(value, v => {
450
+ if (share && isShareableIterable(v)) return share(v);
451
+ return DESCEND;
452
+ });
365
453
  }
366
454
  function isShareableIterable(value) {
367
455
  try {
@@ -772,6 +860,7 @@ function resolveHead(groups) {
772
860
  return winners;
773
861
  }
774
862
 
863
+ const renderConfig = sharedConfig;
775
864
  function joinAssetPath(base, file) {
776
865
  if (/^(?:[a-z][a-z0-9+.-]*:)?\/\//i.test(file)) return file;
777
866
  if (typeof base !== "string" || !base) base = "/";
@@ -925,6 +1014,7 @@ function applyAssetTracking(context, tracking, manifest, noScripts) {
925
1014
  });
926
1015
  context.registerModule = tracking.registerModule;
927
1016
  context.getBoundaryModules = tracking.getBoundaryModules;
1017
+ context._lazyAssets = new Map();
928
1018
  if (typeof manifest === "function") {
929
1019
  context.resolveAssets = guard(manifest);
930
1020
  } else if (manifest && typeof manifest.resolve === "function") {
@@ -1497,6 +1587,7 @@ function renderToString(code, options = {}) {
1497
1587
  });
1498
1588
  const tracking = createAssetTracking();
1499
1589
  const headRegistry = createHeadRegistry();
1590
+ let closed = false;
1500
1591
  sharedConfig.context = {
1501
1592
  nonce: options.nonce,
1502
1593
  escape: escape,
@@ -1507,7 +1598,7 @@ function renderToString(code, options = {}) {
1507
1598
  registerHeadTags(headRegistry, sharedConfig.context, tracking, null, nonce, tags);
1508
1599
  },
1509
1600
  serialize(id, p) {
1510
- if (sharedConfig.context.noHydrate) return;
1601
+ if (closed) return;
1511
1602
  if (p != null && typeof p === "object" && (typeof p.then === "function" || typeof p[Symbol.asyncIterator] === "function")) {
1512
1603
  throw new Error("Cannot serialize async value in renderToString (id: " + id + "). " + "Use renderToStream for async data.");
1513
1604
  }
@@ -1536,20 +1627,25 @@ function renderToString(code, options = {}) {
1536
1627
  applyAssetTracking(sharedConfig.context, tracking, manifest, noScripts);
1537
1628
  registerEntryAssets(manifest);
1538
1629
  const context = sharedConfig.context;
1630
+ context.writer = createHydrationWriter(context, () => !closed);
1539
1631
  const requestEvent = peekRequestEvent();
1632
+ if (requestEvent) setRequestErrorHook(requestEvent, options.onError);
1540
1633
  context.trace = requestEvent ? traceForEvent(requestEvent) : traceFor(context, undefined);
1541
1634
  const render = timeDocument(context, context.trace, "string", requestEvent);
1542
1635
  let dispose;
1636
+ let rootOwner;
1543
1637
  let rendered = false;
1544
1638
  try {
1545
1639
  const html = createRoot(d => {
1546
1640
  dispose = d;
1641
+ rootOwner = claimRenderRoot(context);
1642
+ if (requestEvent) claimEventRender(requestEvent, context);
1547
1643
  return resolveSSRSync(escape(code()));
1548
1644
  }, {
1549
1645
  id: renderId
1550
1646
  });
1551
1647
  serializeFragmentAssets("", tracking.boundaryModules, sharedConfig.context, renderId);
1552
- sharedConfig.context.noHydrate = true;
1648
+ closed = true;
1553
1649
  serializer.close();
1554
1650
  const head = renderShellHead(headRegistry, nonce, null, noScripts, traceMetaMarkup(context.trace));
1555
1651
  const document = assembleDocument(resolveSSRSelectValues(html), tracking.emittedAssets, tracking.preloadLinks, tracking.inlineStyles, scripts.length ? scripts : "", nonce, head, onHead);
@@ -1562,7 +1658,7 @@ function renderToString(code, options = {}) {
1562
1658
  rendered = true;
1563
1659
  return document;
1564
1660
  } finally {
1565
- if (render) render.settle(rendered ? "complete" : "error");
1661
+ if (render) settleRender(render, rootOwner, rendered ? "complete" : "error");
1566
1662
  context.trace = undefined;
1567
1663
  if (dispose) dispose();
1568
1664
  }
@@ -1578,9 +1674,11 @@ function renderToStream(code, options = {}) {
1578
1674
  } = options;
1579
1675
  const nonce = normalizeNonce(options.nonce);
1580
1676
  const requestEvent = peekRequestEvent();
1677
+ if (requestEvent) setRequestErrorHook(requestEvent, options.onError);
1581
1678
  let dispose;
1582
1679
  let dead = false;
1583
1680
  let render;
1681
+ let rootOwner;
1584
1682
  let serializer;
1585
1683
  let disconnected = false;
1586
1684
  let failed = false;
@@ -1619,7 +1717,7 @@ function renderToStream(code, options = {}) {
1619
1717
  dead = true;
1620
1718
  completed = true;
1621
1719
  if (disconnect) disconnected = true;
1622
- if (render) render.settle(disconnect ? "abandoned" : "error");
1720
+ if (render) settleRender(render, rootOwner, disconnect ? "abandoned" : "error");
1623
1721
  const sink = writable;
1624
1722
  buffer = {
1625
1723
  write() {}
@@ -1656,7 +1754,7 @@ function renderToStream(code, options = {}) {
1656
1754
  reportServerError(err, {
1657
1755
  kind: "render",
1658
1756
  handling: "failed"
1659
- }, null);
1757
+ }, null, options.onError);
1660
1758
  if (!options.onError && ambientServerErrorHook() === undefined) console.error(err);
1661
1759
  abandon();
1662
1760
  };
@@ -1760,7 +1858,7 @@ function renderToStream(code, options = {}) {
1760
1858
  });
1761
1859
  writable && writable.end();
1762
1860
  completed = true;
1763
- if (render) render.settle("complete");
1861
+ if (render) settleRender(render, rootOwner, "complete");
1764
1862
  if (firstFlushed) dispose();
1765
1863
  };
1766
1864
  const sink = {
@@ -2042,7 +2140,6 @@ function renderToStream(code, options = {}) {
2042
2140
  html = html.slice(0, first) + resolveSSRSync(escape(payloadFn())) + html.slice(last + placeholder.length + 1);
2043
2141
  },
2044
2142
  serialize(id, p, deferStream) {
2045
- if (sharedConfig.context.noHydrate) return;
2046
2143
  p = guardChannel(p);
2047
2144
  if (p && typeof p === "object" && typeof p.then === "function") {
2048
2145
  if (!firstFlushed && deferStream) {
@@ -2159,6 +2256,7 @@ function renderToStream(code, options = {}) {
2159
2256
  context.trace = requestEvent ? traceForEvent(requestEvent) : traceFor(context, undefined);
2160
2257
  render = timeDocument(context, context.trace, "stream", requestEvent);
2161
2258
  registerEntryAssets(manifest);
2259
+ context.writer = createHydrationWriter(context, () => !completed);
2162
2260
  const signal = options.signal;
2163
2261
  const onAbort = signal ? () => abandon("signal") : undefined;
2164
2262
  let html = createRoot(d => {
@@ -2167,6 +2265,8 @@ function renderToStream(code, options = {}) {
2167
2265
  if (onAbort) signal.removeEventListener("abort", onAbort);
2168
2266
  d();
2169
2267
  };
2268
+ rootOwner = claimRenderRoot(context);
2269
+ if (requestEvent) claimEventRender(requestEvent, context);
2170
2270
  const res = resolveSSRNode(escape(code()));
2171
2271
  if (!res.h.length) return res.t[0];
2172
2272
  rootHoles = [];
@@ -3079,14 +3179,16 @@ function ssrClassName(value) {
3079
3179
  if (typeof value === "number") return "" + value;
3080
3180
  if (!value) return "";
3081
3181
  if (typeof value === "string") return escape(value, true);
3182
+ if (isSlotValue(value)) return "";
3082
3183
  value = classListToObject(value);
3083
3184
  let classKeys = Object.keys(value),
3084
3185
  result = "";
3085
3186
  for (let i = 0, len = classKeys.length; i < len; i++) {
3086
- const key = classKeys[i],
3087
- classValue = !!value[key];
3187
+ const key = classKeys[i];
3188
+ let classValue = value[key];
3189
+ if (isSlotValue(classValue)) classValue = slotValueInline();
3088
3190
  if (!key || key === "undefined" || !classValue) continue;
3089
- i && (result += " ");
3191
+ result && (result += " ");
3090
3192
  result += escape(key, true);
3091
3193
  }
3092
3194
  return result;
@@ -3094,15 +3196,17 @@ function ssrClassName(value) {
3094
3196
  function ssrStyle(value) {
3095
3197
  if (!value) return "";
3096
3198
  if (typeof value === "string") return escape(value, true);
3199
+ if (isSlotValue(value)) return "";
3097
3200
  let result = "";
3098
3201
  const k = Object.keys(value);
3099
3202
  for (let i = 0; i < k.length; i++) {
3100
3203
  const s = escape(k[i], true);
3101
- const v = value[k[i]];
3204
+ let v = value[k[i]];
3205
+ if (isSlotValue(v)) v = slotValueInline();
3102
3206
  if (v != undefined) {
3103
- if (i) result += ";";
3104
3207
  const r = escape(v, true);
3105
3208
  if (r != undefined && r !== "undefined") {
3209
+ if (result) result += ";";
3106
3210
  result += `${s}:${r}`;
3107
3211
  }
3108
3212
  }
@@ -3110,28 +3214,31 @@ function ssrStyle(value) {
3110
3214
  return result;
3111
3215
  }
3112
3216
  function ssrStyleProperty(name, value) {
3217
+ if (isSlotValue(value)) value = slotValueInline();
3113
3218
  return value != null ? name + value : "";
3114
3219
  }
3115
- function ssrElement(tag, props, children, needsId, skip, attrs) {
3220
+ function ssrElement(tag, props, children, needsId, skip, attrs, claims) {
3116
3221
  const hk = needsId ? ssrHydrationKey() : "";
3117
3222
  if (typeof props === "function") props = props();
3118
3223
  let sources = null;
3119
3224
  let proxy = false;
3120
3225
  let viewKeys = null;
3121
3226
  let owners = null;
3227
+ let ownerIndex = null;
3228
+ const ctx = renderConfig.context;
3229
+ const slots = ctx !== undefined && ctx.claims !== undefined;
3122
3230
  if (Array.isArray(props)) {
3123
- let i = 0;
3124
- for (; i < props.length; i++) {
3125
- const s = props[i];
3126
- if (s == null || typeof s === "function" || $PROXY in s) break;
3127
- }
3128
- if (i === props.length) sources = props;else {
3129
- viewKeys = [];
3130
- owners = [];
3131
- for (let i = 0; i < props.length; i++) {
3132
- let s = props[i];
3133
- if (typeof s === "function") s = s();
3134
- if (s != null) sourceOwners(s, viewKeys, owners);
3231
+ if (slots && props.$slot === true) props = slotSpreadSource();else {
3232
+ let i = 0;
3233
+ for (; i < props.length; i++) {
3234
+ const s = props[i];
3235
+ if (s == null || typeof s === "function" || $PROXY in s || slots && s.$slot === true) break;
3236
+ }
3237
+ if (i === props.length) sources = props;else {
3238
+ viewKeys = [];
3239
+ owners = [];
3240
+ if (slots) ownerIndex = [];
3241
+ collectSpreadSources(tag, props, viewKeys, owners, slots, ownerIndex);
3135
3242
  }
3136
3243
  }
3137
3244
  } else if (props == null) {
@@ -3142,10 +3249,13 @@ function ssrElement(tag, props, children, needsId, skip, attrs) {
3142
3249
  owners = [];
3143
3250
  sourceOwners(props, viewKeys, owners);
3144
3251
  } else proxy = true;
3252
+ } else if (slots && props.$slot === true) {
3253
+ props = slotSpreadSource();
3145
3254
  }
3146
3255
  const info = tagInfo(tag);
3147
3256
  const skipChildren = info.isVoid;
3148
3257
  let result = info.open + hk;
3258
+ let behaviors = null;
3149
3259
  const last = sources === null ? 0 : sources.length - 1;
3150
3260
  let keysOf = null;
3151
3261
  if (sources !== null) {
@@ -3172,8 +3282,19 @@ function ssrElement(tag, props, children, needsId, skip, attrs) {
3172
3282
  continue;
3173
3283
  }
3174
3284
  const value = props[prop];
3175
- if (value == undefined || prop === "ref" || prop.startsWith("on") || prop.startsWith("prop:")) {
3285
+ if (value == undefined) {
3286
+ if (slots && claims !== undefined && (prop === "ref" || prop.startsWith("on"))) behaviors = spreadBehaviorPosition(behaviors, prop, value, ctx.claims, ownerIndex !== null ? ownerIndex[i] : s, true);
3287
+ continue;
3288
+ }
3289
+ if (prop.startsWith("prop:")) {
3290
+ continue;
3291
+ }
3292
+ if (prop === "ref" || prop.startsWith("on")) {
3293
+ if (slots) behaviors = spreadBehaviorPosition(behaviors, prop, value, ctx.claims, ownerIndex !== null ? ownerIndex[i] : s, claims !== undefined);
3176
3294
  continue;
3295
+ }
3296
+ if (slots && typeof value === "object") {
3297
+ result += spreadObjectAttribute(prop, value);
3177
3298
  } else if (prop === "style") {
3178
3299
  result += ` style="${ssrStyle(value)}"`;
3179
3300
  } else if (prop === "class") {
@@ -3186,6 +3307,7 @@ function ssrElement(tag, props, children, needsId, skip, attrs) {
3186
3307
  }
3187
3308
  }
3188
3309
  }
3310
+ if (slots && (behaviors !== null || claims !== undefined)) result += spreadBehaviorMarkers(behaviors, claims, ctx.claims);
3189
3311
  if (attrs !== undefined) result += typeof attrs === "function" ? attrs() : attrs;
3190
3312
  if (skipChildren) return {
3191
3313
  t: result + " />"
@@ -3205,43 +3327,226 @@ function ssrElement(tag, props, children, needsId, skip, attrs) {
3205
3327
  }
3206
3328
  function ssrElementAttribute(key, value) {
3207
3329
  if (value == undefined) return "";
3208
- if (key === "style") return ` style="${ssrStyle(value)}"`;
3209
- if (key === "class") return ` class="${ssrClassName(value)}"`;
3330
+ if (key === "style" || key === "class") {
3331
+ return typeof value === "object" ? slotClassOrStyle(key, value) : ` ${key}="${key === "class" ? ssrClassName(value) : ssrStyle(value)}"`;
3332
+ }
3333
+ if (isSlotValue(value)) return slotAttribute(key, value);
3210
3334
  if (typeof value === "boolean") return value ? ` ${key}` : "";
3211
3335
  return value === "" ? ` ${key}` : ` ${key}="${escape(value, true)}"`;
3212
3336
  }
3213
3337
  function ssrAttribute(key, value) {
3214
- return value == null || value === false ? "" : value === true ? ` ${key}` : ` ${key}="${value}"`;
3338
+ if (value == null || value === false) return "";
3339
+ if (typeof value === "object") {
3340
+ return isSlotValue(value) ? slotAttribute(key, value) : ` ${key}="${escape(String(value), true)}"`;
3341
+ }
3342
+ return value === true ? ` ${key}` : ` ${key}="${value}"`;
3215
3343
  }
3216
3344
  function ssrHydrationKey() {
3217
3345
  const hk = getHydrationKey();
3218
3346
  return hk ? ` _hk=${hk}` : "";
3219
3347
  }
3220
- const CLAIM_PROP = /*#__PURE__*/Symbol.for("solid.claim-prop");
3221
3348
  const CLAIMS_STREAM = 1;
3222
3349
  const CLAIMS_DOCUMENT = 2;
3223
- const CLAIM_UNSAFE = /[^A-Za-z0-9_.!~*'()-]/g;
3224
- function encodeClaimKey(key) {
3225
- return String(key).replace(CLAIM_UNSAFE, c => encodeURIComponent(c));
3350
+ const SLOT_VALUE = /*#__PURE__*/Symbol.for("solid.slot-value");
3351
+ const SLOT_MARKER = "_s:";
3352
+ const SLOT_FACE_STREAM = 0;
3353
+ const SLOT_FACE_DATA = 1;
3354
+ const SLOT_FACE_MARKUP = 2;
3355
+ function isSlotValue(value) {
3356
+ return value !== null && typeof value === "object" && value[SLOT_VALUE] !== undefined;
3357
+ }
3358
+ function slotValue(occurrence, key, value, face) {
3359
+ const sv = {
3360
+ [SLOT_VALUE]: occurrence,
3361
+ k: key,
3362
+ v: value,
3363
+ f: face
3364
+ };
3365
+ Object.defineProperty(sv, Symbol.toPrimitive, {
3366
+ value: hint => slotValueString()
3367
+ });
3368
+ Object.defineProperty(sv, "toString", {
3369
+ value: () => slotValueString()
3370
+ });
3371
+ return sv;
3372
+ }
3373
+ function slotValueString(sv, reason) {
3374
+ return "";
3375
+ }
3376
+ function slotTextPosition(sv) {
3377
+ return "";
3378
+ }
3379
+ function slotValueInline(kind, sv) {
3380
+ return undefined;
3381
+ }
3382
+ const SLOT_KEY_UNSAFE = /[^A-Za-z0-9_.!~*'()-]/g;
3383
+ function encodeSlotKey(key) {
3384
+ return String(key).replace(SLOT_KEY_UNSAFE, c => encodeURIComponent(c));
3385
+ }
3386
+ function slotEntry(sv, name) {
3387
+ return `${sv[SLOT_VALUE]}:${encodeSlotKey(sv.k)}${name !== undefined ? "=" + encodeSlotKey(name) : ""}`;
3388
+ }
3389
+ function slotMarker(position, entries) {
3390
+ return ` ${SLOT_MARKER}${position}="${entries}"`;
3391
+ }
3392
+ function slotAttribute(key, sv) {
3393
+ let out = "";
3394
+ if (sv.f === SLOT_FACE_DATA) {
3395
+ const v = sv.v;
3396
+ if (v != null && v !== false) {
3397
+ out = v === true || v === "" ? ` ${key}` : ` ${key}="${escape(String(v), true)}"`;
3398
+ }
3399
+ }
3400
+ return out + slotMarker(key, slotEntry(sv));
3401
+ }
3402
+ function slotClassOrStyle(key, value) {
3403
+ const isClass = key === "class";
3404
+ if (isSlotValue(value)) {
3405
+ let out = "";
3406
+ if (value.f === SLOT_FACE_DATA && value.v != null) {
3407
+ out = ` ${key}="${isClass ? ssrClassName(value.v) : ssrStyle(value.v)}"`;
3408
+ }
3409
+ return out + slotMarker(key, slotEntry(value));
3410
+ }
3411
+ if (typeof value === "object" && value !== null) {
3412
+ const obj = isClass ? classListToObject(value) : value;
3413
+ let entries = "";
3414
+ let inner = "";
3415
+ for (const name of Object.keys(obj)) {
3416
+ let v = obj[name];
3417
+ if (isSlotValue(v)) {
3418
+ entries += (entries ? "," : "") + slotEntry(v, name);
3419
+ v = v.f === SLOT_FACE_DATA ? v.v : undefined;
3420
+ }
3421
+ if (isClass) {
3422
+ if (!name || name === "undefined" || !v) continue;
3423
+ inner += (inner ? " " : "") + escape(name, true);
3424
+ } else if (v != undefined) {
3425
+ const r = escape(v, true);
3426
+ if (r != undefined && r !== "undefined") {
3427
+ inner += (inner ? ";" : "") + `${escape(name, true)}:${r}`;
3428
+ }
3429
+ }
3430
+ }
3431
+ if (entries === "") return ` ${key}="${inner}"`;
3432
+ return (inner ? ` ${key}="${inner}"` : "") + slotMarker(key, entries);
3433
+ }
3434
+ return ` ${key}="${isClass ? ssrClassName(value) : ssrStyle(value)}"`;
3435
+ }
3436
+ function eventPosition(prop) {
3437
+ return prop.slice(2).toLowerCase();
3438
+ }
3439
+ function spreadBehaviorPosition(behaviors, prop, value, mode, index, settle) {
3440
+ const pos = prop === "ref" ? "ref" : eventPosition(prop);
3441
+ const entries = value == null ? "" : claimEntries(pos, value);
3442
+ if (!settle) {
3443
+ if (entries) (behaviors ||= new Map()).set(pos, entries);
3444
+ return behaviors;
3445
+ }
3446
+ behaviors ||= new Map();
3447
+ const b = behaviors.get(pos);
3448
+ if (b === undefined) behaviors.set(pos, {
3449
+ e: entries,
3450
+ at: index
3451
+ });else {
3452
+ b.e = entries;
3453
+ b.at = index;
3454
+ }
3455
+ return behaviors;
3456
+ }
3457
+ function spreadBehaviorMarkers(behaviors, claims, mode) {
3458
+ if (claims !== undefined) {
3459
+ const segments = claims();
3460
+ for (const k in segments) {
3461
+ const map = segments[k];
3462
+ for (const pos in map) {
3463
+ const value = map[pos];
3464
+ behaviors ||= new Map();
3465
+ const b = behaviors.get(pos);
3466
+ if (pos === "ref") {
3467
+ if (value == null) continue;
3468
+ const entries = claimEntries("ref", value);
3469
+ if (!entries) continue;
3470
+ if (b === undefined) behaviors.set("ref", {
3471
+ e: entries,
3472
+ at: -1
3473
+ });else b.e = b.e ? b.e + "," + entries : entries;
3474
+ continue;
3475
+ }
3476
+ if (b !== undefined && b.at >= +k) continue;
3477
+ const entries = value == null ? "" : claimEntries(pos, value);
3478
+ if (b === undefined) behaviors.set(pos, {
3479
+ e: entries,
3480
+ at: -1
3481
+ });else b.e = entries;
3482
+ }
3483
+ }
3484
+ }
3485
+ let out = "";
3486
+ if (behaviors !== null) {
3487
+ for (const [pos, b] of behaviors) {
3488
+ const e = claims === undefined ? b : b.e;
3489
+ if (e) out += slotMarker(pos === "ref" ? "ref" : "on:" + pos, e);
3490
+ }
3491
+ }
3492
+ return out;
3493
+ }
3494
+ function collectSpreadSources(tag, props, viewKeys, owners, slots, ownerIndex) {
3495
+ for (let i = 0; i < props.length; i++) {
3496
+ let s = props[i];
3497
+ if (typeof s === "function") s = s();
3498
+ if (s != null) {
3499
+ if (slots && !($PROXY in s) && s.$slot === true) s = slotSpreadSource();
3500
+ if (ownerIndex === null) sourceOwners(s, viewKeys, owners);else {
3501
+ const ks = [];
3502
+ const os = [];
3503
+ sourceOwners(s, ks, os);
3504
+ for (let j = 0; j < ks.length; j++) {
3505
+ const at = viewKeys.indexOf(ks[j]);
3506
+ if (at !== -1) {
3507
+ viewKeys.splice(at, 1);
3508
+ owners.splice(at, 1);
3509
+ ownerIndex.splice(at, 1);
3510
+ }
3511
+ viewKeys.push(ks[j]);
3512
+ owners.push(os[j]);
3513
+ ownerIndex.push(i);
3514
+ }
3515
+ }
3516
+ }
3517
+ }
3518
+ }
3519
+ function spreadObjectAttribute(prop, value) {
3520
+ if (prop === "style" || prop === "class") return slotClassOrStyle(prop, value);
3521
+ if (value[SLOT_VALUE] !== undefined) return slotAttribute(attrName(prop), value);
3522
+ return ` ${attrName(prop)}="${escape(value, true)}"`;
3523
+ }
3524
+ function slotSpreadSource(tag, source) {
3525
+ return {};
3226
3526
  }
3227
3527
  function ssrClaim(map) {
3228
3528
  const mode = sharedConfig.context && sharedConfig.context.claims;
3229
- if (!mode || mode === CLAIMS_DOCUMENT && !(typeof inServerComponentScope === "function" && inServerComponentScope())) {
3230
- return "";
3231
- }
3529
+ if (!mode) return "";
3232
3530
  let out = "";
3233
3531
  for (const pos in map) {
3234
- const value = map[pos];
3235
- const list = Array.isArray(value) ? value : [value];
3236
- for (const fn of list) {
3237
- const prop = typeof fn === "function" && fn[CLAIM_PROP] || undefined;
3238
- if (prop === undefined) {
3239
- continue;
3240
- }
3241
- out += `${out ? "," : ""}${pos}=${encodeClaimKey(prop)}`;
3532
+ const entries = claimEntries(pos, map[pos]);
3533
+ if (entries) out += slotMarker(pos === "ref" ? "ref" : "on:" + pos, entries);
3534
+ }
3535
+ return out;
3536
+ }
3537
+ function claimEntries(pos, value, mode) {
3538
+ if (Array.isArray(value)) {
3539
+ let entries = "";
3540
+ for (const v of value) {
3541
+ const inner = claimEntries(pos, v);
3542
+ if (inner) entries += (entries ? "," : "") + inner;
3242
3543
  }
3544
+ return entries;
3545
+ }
3546
+ if (isSlotValue(value)) {
3547
+ return slotEntry(value);
3243
3548
  }
3244
- return out ? ` _bnd="${out}"` : "";
3549
+ return "";
3245
3550
  }
3246
3551
  function decodeSSREntities(s) {
3247
3552
  return s.indexOf("&") < 0 ? s : s.replace(/&quot;/g, '"').replace(/&lt;/g, "<").replace(/&amp;/g, "&");
@@ -3363,6 +3668,7 @@ function escape(s, attr) {
3363
3668
  if (!attr && t === "function") return escapeLate(s);
3364
3669
  if (attr) {
3365
3670
  if (s == null || t === "boolean" || t === "number") return s;
3671
+ if (t === "object" && s[SLOT_VALUE] !== undefined) return s;
3366
3672
  return escape(String(s), attr);
3367
3673
  }
3368
3674
  return s;
@@ -3725,6 +4031,10 @@ function resolveSSRNode(node, result = {
3725
4031
  } else if (node.t !== undefined) {
3726
4032
  result.t[result.t.length - 1] += node.t;
3727
4033
  ssrTextTail = false;
4034
+ } else if (node[SLOT_VALUE] !== undefined) {
4035
+ const text = escape(slotTextPosition());
4036
+ result.t[result.t.length - 1] += ssrTextTail ? "<!--!$-->" + text : text;
4037
+ ssrTextTail = true;
3728
4038
  } else ;
3729
4039
  } else if (t === "function") {
3730
4040
  const live = sharedConfig.context && sharedConfig.context.liveHoles;
@@ -3763,7 +4073,7 @@ function serializerErrorHook(hook) {
3763
4073
  reportServerError(err, {
3764
4074
  kind: "render",
3765
4075
  handling: "serialize"
3766
- }, null);
4076
+ }, null, hook);
3767
4077
  };
3768
4078
  }
3769
4079
  function ambientServerErrorHook() {
@@ -3778,7 +4088,66 @@ function configureServerErrors(config) {
3778
4088
  (g[ServerErrors] ||= {}).hook = config ? config.onError : undefined;
3779
4089
  }
3780
4090
  function getRequestEvent() {
3781
- 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;
4091
+ const store = globalThis[RequestContext];
4092
+ if (!store) return undefined;
4093
+ const event = store.getStore();
4094
+ if (event) return event;
4095
+ const ctx = renderContextOf(getOwner());
4096
+ 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.");
4097
+ }
4098
+ const RENDER_ROOTS = Symbol.for("@solidjs/web/render-roots");
4099
+ function renderRoots() {
4100
+ const g = globalThis;
4101
+ return g[RENDER_ROOTS] || (g[RENDER_ROOTS] = new WeakMap());
4102
+ }
4103
+ function claimRenderRoot(context) {
4104
+ const owner = getOwner();
4105
+ const roots = renderRoots();
4106
+ roots.set(owner, context);
4107
+ onCleanup(() => roots.delete(owner));
4108
+ return owner;
4109
+ }
4110
+ function settleRender(render, root, outcome) {
4111
+ runWithOwner(root || null, () => render.settle(outcome));
4112
+ }
4113
+ const eventRenders = new WeakMap();
4114
+ function claimEventRender(event, context) {
4115
+ let renders = eventRenders.get(event);
4116
+ if (!renders) eventRenders.set(event, renders = new Set());
4117
+ renders.add(context);
4118
+ onCleanup(() => renders.delete(context));
4119
+ }
4120
+ function createHydrationWriter(context, isOpen) {
4121
+ const keys = new Set();
4122
+ return {
4123
+ async: !!context.async,
4124
+ write(key, value, options) {
4125
+ if (!isOpen() || keys.has(key)) return false;
4126
+ context.serialize(key, value, options && options.deferStream);
4127
+ keys.add(key);
4128
+ return true;
4129
+ }
4130
+ };
4131
+ }
4132
+ function getHydrationWriter() {
4133
+ let ctx = renderContextOf(getOwner());
4134
+ if (!ctx) {
4135
+ const event = peekRequestEvent();
4136
+ const renders = event && eventRenders.get(event);
4137
+ if (renders && renders.size === 1) for (const c of renders) ctx = c;
4138
+ }
4139
+ return ctx && ctx.writer;
4140
+ }
4141
+ function takeHydrationValue(_key) {
4142
+ return undefined;
4143
+ }
4144
+ function renderContextOf(owner) {
4145
+ const roots = globalThis[RENDER_ROOTS];
4146
+ if (!roots) return undefined;
4147
+ for (; owner; owner = owner._parent) {
4148
+ const context = roots.get(owner);
4149
+ if (context) return context;
4150
+ }
3782
4151
  }
3783
4152
  function peekRequestEvent() {
3784
4153
  const store = globalThis[RequestContext];
@@ -3787,6 +4156,7 @@ function peekRequestEvent() {
3787
4156
  function timeDocument(context, trace, mode, requestEvent) {
3788
4157
  if (records() === undefined) return undefined;
3789
4158
  const render = observeRender(trace, mode, requestEvent);
4159
+ if (render) context._declareRoute = ref => render.route(ref);
3790
4160
  if (timesServerWork("boundary")) {
3791
4161
  context._recordBoundary = event => {
3792
4162
  trace.timing.push({
@@ -3801,7 +4171,7 @@ function timeDocument(context, trace, mode, requestEvent) {
3801
4171
  function getTraceContext() {
3802
4172
  const event = peekRequestEvent();
3803
4173
  if (event) return traceForEvent(event).context;
3804
- const ctx = sharedConfig.context;
4174
+ const ctx = renderContextOf(getOwner());
3805
4175
  return ctx && ctx.trace ? ctx.trace.context : undefined;
3806
4176
  }
3807
4177
  function traceForStub(stub, event) {
@@ -4265,4 +4635,4 @@ function httpHeader(name, value, options) {
4265
4635
  }
4266
4636
  }
4267
4637
 
4268
- 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 };
4638
+ 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 };