@solidjs/web 2.0.0-rc.15 → 2.0.0-rc.17

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 (55) hide show
  1. package/README.md +1 -1
  2. package/dist/server.dev.js +361 -483
  3. package/dist/server.js +346 -391
  4. package/dist/server.observe.js +346 -391
  5. package/dist/web.dev.js +110 -55
  6. package/dist/web.js +51 -50
  7. package/dist/web.observe.js +61 -55
  8. package/frames/dist/client.dev.js +610 -621
  9. package/frames/dist/client.js +540 -566
  10. package/frames/dist/client.observe.js +571 -573
  11. package/frames/dist/regions.js +43 -2
  12. package/frames/dist/server.dev.js +793 -424
  13. package/frames/dist/server.js +792 -371
  14. package/frames/dist/server.observe.js +792 -371
  15. package/frames/dist/wire.js +371 -6
  16. package/package.json +11 -11
  17. package/serialization/dist/decode.js +9 -7
  18. package/serialization/dist/serialization.js +9 -7
  19. package/serialization/types/serializer-decode.d.ts +2 -2
  20. package/server-functions/dist/client.dev.js +13 -22
  21. package/server-functions/dist/client.js +11 -22
  22. package/server-functions/dist/client.observe.js +13 -22
  23. package/server-functions/dist/rich-args.js +84 -1
  24. package/server-functions/dist/server.dev.js +194 -20
  25. package/server-functions/dist/server.js +194 -20
  26. package/server-functions/dist/server.observe.js +194 -20
  27. package/skills/server-components/SKILL.md +74 -185
  28. package/types/client.d.ts +27 -5
  29. package/types/diagnostics.d.ts +16 -0
  30. package/types/frames/assets-tier.d.ts +2 -2
  31. package/types/frames/client.d.ts +8 -3
  32. package/types/frames/frame-client.d.ts +121 -157
  33. package/types/frames/frame-morph.d.ts +28 -0
  34. package/types/frames/frame-sink.d.ts +13 -9
  35. package/types/frames/frame-transport.d.ts +30 -1
  36. package/types/frames/regions-tier.d.ts +15 -0
  37. package/types/frames/serializer-decode.d.ts +2 -2
  38. package/types/frames/server.d.ts +0 -52
  39. package/types/frames/wire-tier.d.ts +54 -1
  40. package/types/index.d.ts +2 -2
  41. package/types/jsx.d.ts +11 -5
  42. package/types/observe.d.ts +14 -7
  43. package/types/render.d.ts +3 -1
  44. package/types/response.d.ts +5 -4
  45. package/types/serializer-decode.d.ts +2 -2
  46. package/types/server-functions/argument-codec.d.ts +30 -0
  47. package/types/server-functions/client.d.ts +27 -9
  48. package/types/server-functions/server.d.ts +23 -2
  49. package/types/server-functions/shared.d.ts +19 -0
  50. package/types/server-functions/uploads.d.ts +50 -0
  51. package/types/server-observe.d.ts +3 -2
  52. package/types/server.d.ts +58 -77
  53. package/frames/dist/bind.dev.js +0 -326
  54. package/frames/dist/bind.js +0 -295
  55. package/types/frames/bind-tier.d.ts +0 -60
@@ -1,7 +1,7 @@
1
1
  import { createRenderEffect, createMemo, OBSERVE, getOwner, createRoot, $PROXY, onCleanup, runWithOwner, createComponent, omit, getNextChildId } from 'solid-js';
2
2
  export { Errored, For, Hydration, Loading, Match, NoHydration, Repeat, Reveal, Show, Switch, createComponent, dynamicComponent, getOwner, merge as mergeProps, untrack } from 'solid-js';
3
- import { sharedConfig, ssrSanitizeError, reportServerError, viewOf, sourceOwners, ssrHandleError, inServerComponentScope, creationStamp, dynamicCore, getProjectionTrace, shareAsyncIterable } from 'solid-js/internal';
4
- export { ssrScope as scope, sharedConfig } from 'solid-js/internal';
3
+ import { sharedConfig, ssrSanitizeError, beginEdgesRender, reportServerError, viewOf, sourceOwners, ssrHandleError, inServerComponentScope, creationStamp, dynamicCore, getProjectionTrace, shareAsyncIterable } from 'solid-js/internal';
4
+ export { ssrScope as scope } from 'solid-js/internal';
5
5
  import { createStream, Serializer, getCrossReferenceHeader, Feature } from 'seroval';
6
6
  import { AbortSignalPlugin, CustomEventPlugin, DOMExceptionPlugin, EventPlugin, FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin } from 'seroval-plugins/web';
7
7
 
@@ -117,11 +117,9 @@ function parseTraceparent(value) {
117
117
  };
118
118
  }
119
119
  function randomHex(bytes) {
120
- const buffer = new Uint8Array(bytes);
121
- crypto.getRandomValues(buffer);
122
120
  let out = "";
123
- for (let i = 0; i < buffer.length; i++) out += (buffer[i] < 16 ? "0" : "") + buffer[i].toString(16);
124
- return out;
121
+ for (let i = 0; i < bytes; i += 4) out += (Math.random() * 0x100000000 >>> 0).toString(16).padStart(8, "0");
122
+ return out.length === bytes * 2 ? out : out.slice(0, bytes * 2);
125
123
  }
126
124
  function randomTraceId() {
127
125
  let id = randomHex(16);
@@ -687,7 +685,12 @@ function respond(value, init = {}) {
687
685
  }), value);
688
686
  }
689
687
  headers.set("Content-Type", "application/json");
690
- return new ResponseEnvelope(new Response(JSON.stringify(value), {
688
+ return new ResponseEnvelope(new Response(new ReadableStream({
689
+ pull(controller) {
690
+ controller.enqueue(new TextEncoder().encode(JSON.stringify(value)));
691
+ controller.close();
692
+ }
693
+ }), {
691
694
  ...responseInit,
692
695
  headers
693
696
  }), value);
@@ -1469,12 +1472,6 @@ function destinationNonce(nonce, destination) {
1469
1472
  const value = typeof nonce === "string" ? nonce : nonce[destination];
1470
1473
  return typeof value === "string" && value ? value : undefined;
1471
1474
  }
1472
- function scriptNonce(nonce) {
1473
- return destinationNonce(nonce, "script");
1474
- }
1475
- function styleNonce(nonce) {
1476
- return destinationNonce(nonce, "style");
1477
- }
1478
1475
  function hasNonceProp(props) {
1479
1476
  for (const name in props) if (name.length === 5 && asciiLowerCase(name) === "nonce" && props[name] != null) return true;
1480
1477
  return false;
@@ -1603,6 +1600,8 @@ function renderToString(code, options = {}) {
1603
1600
  onHead
1604
1601
  } = options;
1605
1602
  const nonce = normalizeNonce(options.nonce);
1603
+ const requestEvent = peekRequestEvent();
1604
+ const errorScope = requestEvent || {};
1606
1605
  let scripts = "";
1607
1606
  const serializer = createHydrationSerializer({
1608
1607
  scopeId: renderId,
@@ -1625,6 +1624,7 @@ function renderToString(code, options = {}) {
1625
1624
  resolve: resolveSSRNode,
1626
1625
  ssr: ssr,
1627
1626
  errorPolicy: options.onError,
1627
+ _errorScope: errorScope,
1628
1628
  registerHeadTags(tags) {
1629
1629
  registerHeadTags(headRegistry, sharedConfig.context, tracking, null, nonce, tags);
1630
1630
  },
@@ -1659,7 +1659,6 @@ function renderToString(code, options = {}) {
1659
1659
  registerEntryAssets(manifest);
1660
1660
  const context = sharedConfig.context;
1661
1661
  context.writer = createHydrationWriter(context, () => !closed);
1662
- const requestEvent = peekRequestEvent();
1663
1662
  if (requestEvent) setRequestErrorHook(requestEvent, options.onError);
1664
1663
  context.trace = requestEvent ? traceForEvent(requestEvent) : traceFor(context, undefined);
1665
1664
  const render = timeDocument(context, context.trace, "string", requestEvent);
@@ -1679,7 +1678,7 @@ function renderToString(code, options = {}) {
1679
1678
  closed = true;
1680
1679
  serializer.close();
1681
1680
  const head = renderShellHead(headRegistry, nonce, null, noScripts, traceMetaMarkup(context.trace));
1682
- const document = assembleDocument(resolveSSRSelectValues(html), tracking.emittedAssets, tracking.preloadLinks, tracking.inlineStyles, scripts.length ? scripts : "", nonce, head, onHead) + shellEndMarker(context, renderId, nonce, noScripts);
1681
+ const document = withShellEnd(assembleDocument(resolveSSRSelectValues(html), tracking.emittedAssets, tracking.preloadLinks, tracking.inlineStyles, scripts.length ? scripts : "", nonce, head, onHead), context, renderId, nonce, noScripts);
1683
1682
  if (render) render.shell();
1684
1683
  if (requestEvent && requestEvent.response) {
1685
1684
  commitResponseStub(requestEvent.response, {
@@ -1692,7 +1691,7 @@ function renderToString(code, options = {}) {
1692
1691
  reportServerError(err, {
1693
1692
  kind: "render",
1694
1693
  handling: "failed"
1695
- }, null, options.onError);
1694
+ }, null, options.onError, errorScope);
1696
1695
  throw err;
1697
1696
  } finally {
1698
1697
  if (render) settleRender(render, rootOwner, rendered ? "complete" : "error");
@@ -1714,6 +1713,14 @@ function renderToStream(code, options = {}) {
1714
1713
  const nonce = normalizeNonce(options.nonce);
1715
1714
  const requestEvent = peekRequestEvent();
1716
1715
  if (requestEvent) setRequestErrorHook(requestEvent, options.onError);
1716
+ const errorScope = requestEvent || {};
1717
+ const reportFailure = (err, handling) => {
1718
+ reportServerError(err, {
1719
+ kind: "render",
1720
+ handling
1721
+ }, null, options.onError, errorScope);
1722
+ if (!options.onError && ambientServerErrorHook() === undefined) console.error(err);
1723
+ };
1717
1724
  let dispose;
1718
1725
  let dead = false;
1719
1726
  let render;
@@ -1777,7 +1784,7 @@ function renderToStream(code, options = {}) {
1777
1784
  reportServerError(err, {
1778
1785
  kind: "render",
1779
1786
  handling: "serialize"
1780
- }, null, options.onError);
1787
+ }, null, options.onError, errorScope);
1781
1788
  }
1782
1789
  }
1783
1790
  serializer = abandonedSerializer;
@@ -1791,11 +1798,7 @@ function renderToStream(code, options = {}) {
1791
1798
  } else if (!sink && onDisconnectedBeforeShell) onDisconnectedBeforeShell();
1792
1799
  };
1793
1800
  const failRender = err => {
1794
- reportServerError(err, {
1795
- kind: "render",
1796
- handling: "failed"
1797
- }, null, options.onError);
1798
- if (!options.onError && ambientServerErrorHook() === undefined) console.error(err);
1801
+ reportFailure(err, "failed");
1799
1802
  abandon();
1800
1803
  };
1801
1804
  const failRootRender = err => {
@@ -1859,6 +1862,18 @@ function renderToStream(code, options = {}) {
1859
1862
  const canBatchStubs = !options.serializer && !options.sink;
1860
1863
  let stubBatch = null;
1861
1864
  const STUB_BATCH_KEY = "$B";
1865
+ let stableOrder = false;
1866
+ let parkedWrites = null;
1867
+ const byKey = (a, b) => a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0;
1868
+ const write = (id, value) => {
1869
+ if (stableOrder && !dead) (parkedWrites ||= []).push([id, value]);else serializer.write(id, value);
1870
+ };
1871
+ const flushParkedWrites = () => {
1872
+ if (!parkedWrites) return;
1873
+ const writes = parkedWrites.sort(byKey);
1874
+ parkedWrites = null;
1875
+ for (let i = 0; i < writes.length; i++) serializer.write(writes[i][0], writes[i][1]);
1876
+ };
1862
1877
  const flushStubBatch = () => {
1863
1878
  if (!stubBatch) return;
1864
1879
  const batch = stubBatch;
@@ -1869,7 +1884,9 @@ function renderToStream(code, options = {}) {
1869
1884
  return;
1870
1885
  }
1871
1886
  const obj = {};
1872
- for (const [id, p] of batch) obj[id] = p;
1887
+ const entries = [...batch];
1888
+ if (stableOrder) entries.sort(byKey);
1889
+ for (const [id, p] of entries) obj[id] = p;
1873
1890
  serializer.write(STUB_BATCH_KEY, obj);
1874
1891
  pushTask(`(b=>{for(var k in b)_$HY.r[k]=b[k];delete _$HY.r["${STUB_BATCH_KEY}"]})(_$HY.r["${STUB_BATCH_KEY}"])`);
1875
1892
  };
@@ -1941,7 +1958,7 @@ function renderToStream(code, options = {}) {
1941
1958
  }
1942
1959
  },
1943
1960
  shell(shellHtml, meta) {
1944
- buffer.write(assembleDocument(shellHtml, meta.preloads, meta.preloadLinks, meta.inlineStyles, meta.tasks.length ? meta.tasks : "", nonce, meta.head, onHead) + shellEndMarker(context, renderId, nonce, noScripts));
1961
+ buffer.write(withShellEnd(assembleDocument(shellHtml, meta.preloads, meta.preloadLinks, meta.inlineStyles, meta.tasks.length ? meta.tasks : "", nonce, meta.head, onHead), context, renderId, nonce, noScripts));
1945
1962
  },
1946
1963
  ...options.sink
1947
1964
  };
@@ -1950,7 +1967,7 @@ function renderToStream(code, options = {}) {
1950
1967
  plugins: options.plugins,
1951
1968
  onData: payload => sink.data(payload),
1952
1969
  onDone,
1953
- onError: serializerErrorHook(options.onError)
1970
+ onError: err => reportFailure(err, "serialize")
1954
1971
  });
1955
1972
  let rootAssetsSerialized = false;
1956
1973
  const serializeRootAssets = () => {
@@ -1969,6 +1986,7 @@ function renderToStream(code, options = {}) {
1969
1986
  end();
1970
1987
  }
1971
1988
  flushStubBatch();
1989
+ flushParkedWrites();
1972
1990
  serializer.flush();
1973
1991
  }));
1974
1992
  }
@@ -1977,7 +1995,7 @@ function renderToStream(code, options = {}) {
1977
1995
  const pendingSerialized = new Map();
1978
1996
  const guardedChannels = new WeakMap();
1979
1997
  const verdictNow = error => {
1980
- throw ssrSanitizeError(error, null);
1998
+ throw ssrSanitizeError(error, null, undefined, undefined, errorScope);
1981
1999
  };
1982
2000
  const borderForm = value => toBorderForm(value);
1983
2001
  const guardIterable = iterable => ({
@@ -2125,6 +2143,7 @@ function renderToStream(code, options = {}) {
2125
2143
  async: true,
2126
2144
  nonce: options.nonce,
2127
2145
  document: !options.sink,
2146
+ edges: !!options.plugins && options.plugins.some(p => p.tag === "solid/server-component"),
2128
2147
  live: {},
2129
2148
  registerHeadTags(tags) {
2130
2149
  registerHeadTags(headRegistry, context, tracking,
@@ -2190,7 +2209,7 @@ function renderToStream(code, options = {}) {
2190
2209
  if (p && typeof p === "object" && typeof p.then === "function") {
2191
2210
  if (!firstFlushed && deferStream) {
2192
2211
  blockingPromises.add(p);
2193
- p.then(d => serializer.write(id, d)).catch(e => serializer.write(id, e));
2212
+ p.then(d => write(id, d)).catch(e => write(id, e));
2194
2213
  return;
2195
2214
  }
2196
2215
  p = trackSerialized(id, p);
@@ -2199,7 +2218,7 @@ function renderToStream(code, options = {}) {
2199
2218
  return;
2200
2219
  }
2201
2220
  }
2202
- serializer.write(id, p);
2221
+ write(id, p);
2203
2222
  },
2204
2223
  escape: escape,
2205
2224
  resolve: resolveSSRNode,
@@ -2230,11 +2249,11 @@ function renderToStream(code, options = {}) {
2230
2249
  defuse(p);
2231
2250
  registry.set(key, {
2232
2251
  resolve: err => queue(() => queue(() => {
2233
- err ? reject(ssrSanitizeError(err, null)) : resolve(true);
2252
+ err ? reject(ssrSanitizeError(err, null, undefined, undefined, errorScope)) : resolve(true);
2234
2253
  queue(flushEnd);
2235
2254
  }))
2236
2255
  });
2237
- if (canBatchStubs && !shellCompleted && !dead) (stubBatch ||= new Map()).set(key + "_fr", p);else serializer.write(key + "_fr", p);
2256
+ if (canBatchStubs && !shellCompleted && !dead) (stubBatch ||= new Map()).set(key + "_fr", p);else write(key + "_fr", p);
2238
2257
  }
2239
2258
  return (value, error, escaped) => {
2240
2259
  if (registry.has(key)) {
@@ -2242,7 +2261,7 @@ function renderToStream(code, options = {}) {
2242
2261
  registry.delete(key);
2243
2262
  if (error) abandonSubtree(key, error);
2244
2263
  if (error && escaped) {
2245
- const wire = ssrSanitizeError(error, null);
2264
+ const wire = ssrSanitizeError(error, null, undefined, undefined, errorScope);
2246
2265
  const message = wire instanceof Error ? wire.message : String(wire);
2247
2266
  if (sink.error) sink.error("", message);else if (context.live && context.live.error) context.live.error(escaped.frame, message);
2248
2267
  }
@@ -2276,7 +2295,7 @@ function renderToStream(code, options = {}) {
2276
2295
  sink.fragment(key, resolveSSRSelectValues(value !== undefined ? value : " "), {
2277
2296
  styles,
2278
2297
  revealGroup,
2279
- error: error ? ssrSanitizeError(error, null) : error
2298
+ error: error ? ssrSanitizeError(error, null, undefined, undefined, errorScope) : error
2280
2299
  });
2281
2300
  item.resolve(error);
2282
2301
  }
@@ -2303,6 +2322,7 @@ function renderToStream(code, options = {}) {
2303
2322
  applyAssetTracking(context, tracking, manifest, noScripts);
2304
2323
  context.failRender = failRender;
2305
2324
  context.errorPolicy = options.onError;
2325
+ context._errorScope = errorScope;
2306
2326
  context.flushed = () => firstFlushed;
2307
2327
  context.trace = requestEvent ? traceForEvent(requestEvent) : traceFor(context, undefined);
2308
2328
  render = timeDocument(context, context.trace, "stream", requestEvent);
@@ -2310,40 +2330,52 @@ function renderToStream(code, options = {}) {
2310
2330
  context.writer = createHydrationWriter(context, () => !completed);
2311
2331
  const signal = options.signal;
2312
2332
  const onAbort = signal ? () => abandon("signal", !!(signal.reason && signal.reason.quiet === true)) : undefined;
2313
- let html = createRoot(d => {
2314
- dispose = () => {
2315
- context.trace = undefined;
2316
- if (onAbort) signal.removeEventListener("abort", onAbort);
2317
- d();
2318
- };
2319
- rootOwner = claimRenderRoot(context);
2320
- if (requestEvent) claimEventRender(requestEvent, context);
2321
- let res;
2322
- try {
2323
- res = resolveSSRNode(escape(code()));
2324
- } catch (err) {
2325
- reportServerError(err, {
2326
- kind: "render",
2327
- handling: "failed"
2328
- }, null, options.onError);
2329
- throw err;
2330
- }
2331
- if (!res.h.length) return res.t[0];
2332
- rootHoles = [];
2333
- let out = res.t[0];
2334
- for (let i = 0; i < res.h.length; i++) {
2335
- const id = nextHoleId++;
2336
- rootHoles.push({
2337
- id,
2338
- fn: res.h[i]
2339
- });
2340
- out += `<!--rh${id}-->` + res.t[i + 1];
2341
- }
2342
- for (const p of res.p) blockingPromises.add(p);
2343
- return out;
2344
- }, {
2345
- id: renderId
2346
- });
2333
+ const endEdges = context.edges ? beginEdgesRender() : undefined;
2334
+ let html;
2335
+ try {
2336
+ html = createRoot(d => {
2337
+ dispose = () => {
2338
+ context.trace = undefined;
2339
+ if (onAbort) signal.removeEventListener("abort", onAbort);
2340
+ if (endEdges) endEdges();
2341
+ try {
2342
+ d();
2343
+ } catch (err) {
2344
+ reportFailure(err, "failed");
2345
+ }
2346
+ };
2347
+ rootOwner = claimRenderRoot(context);
2348
+ if (requestEvent) claimEventRender(requestEvent, context);
2349
+ let res;
2350
+ try {
2351
+ res = resolveSSRNode(escape(code()));
2352
+ } catch (err) {
2353
+ reportServerError(err, {
2354
+ kind: "render",
2355
+ handling: "failed"
2356
+ }, null, options.onError, errorScope);
2357
+ throw err;
2358
+ }
2359
+ if (!res.h.length) return res.t[0];
2360
+ rootHoles = [];
2361
+ let out = res.t[0];
2362
+ for (let i = 0; i < res.h.length; i++) {
2363
+ const id = nextHoleId++;
2364
+ rootHoles.push({
2365
+ id,
2366
+ fn: res.h[i]
2367
+ });
2368
+ out += `<!--rh${id}-->` + res.t[i + 1];
2369
+ }
2370
+ for (const p of res.p) blockingPromises.add(p);
2371
+ return out;
2372
+ }, {
2373
+ id: renderId
2374
+ });
2375
+ } catch (err) {
2376
+ if (endEdges) endEdges();
2377
+ throw err;
2378
+ }
2347
2379
  if (onAbort) {
2348
2380
  if (signal.aborted) onAbort();else signal.addEventListener("abort", onAbort, {
2349
2381
  once: true
@@ -2422,21 +2454,30 @@ function renderToStream(code, options = {}) {
2422
2454
  let lastBlockingSize = -1;
2423
2455
  let lastRegistrySize = -1;
2424
2456
  let drainTurn = 0;
2457
+ let graced = false;
2425
2458
  const scheduleFlush = (fn, awaited) => {
2426
2459
  const attempt = () => {
2427
- flushStubBatch();
2460
+ if (!stableOrder) flushStubBatch();
2428
2461
  if (registry.size !== lastRegistrySize || drainTurn++ < MIN_DRAIN_TURNS) {
2429
2462
  if (registry.size !== lastRegistrySize) drainTurn = 0;
2430
2463
  lastRegistrySize = registry.size;
2431
2464
  queue(attempt);
2432
2465
  return;
2433
2466
  }
2467
+ if (!graced && registry.size) {
2468
+ graced = true;
2469
+ lastRegistrySize = -1;
2470
+ drainTurn = 0;
2471
+ deferFlush(attempt);
2472
+ return;
2473
+ }
2434
2474
  fn();
2435
2475
  };
2436
2476
  const progressed = awaited !== lastBlockingSize;
2437
2477
  lastBlockingSize = awaited;
2438
2478
  lastRegistrySize = -1;
2439
2479
  drainTurn = 0;
2480
+ graced = false;
2440
2481
  progressed ? queue(attempt) : setTimeout(attempt);
2441
2482
  };
2442
2483
  let cachedReadable;
@@ -2503,6 +2544,7 @@ function renderToStream(code, options = {}) {
2503
2544
  };
2504
2545
  return {
2505
2546
  then(onFulfilled, onRejected) {
2547
+ if (canBatchStubs) stableOrder = true;
2506
2548
  const freezeHead = () => {
2507
2549
  if (requestEvent && requestEvent.response) commitResponseStub(requestEvent.response, {
2508
2550
  event: requestEvent
@@ -2601,7 +2643,7 @@ function HydrationScript(props) {
2601
2643
  nonce: sharedConfig.context && sharedConfig.context.nonce,
2602
2644
  ...props
2603
2645
  };
2604
- return ssr(hydrationBootstrap(eventNames, scriptNonce(nonce), true));
2646
+ return ssr(hydrationBootstrap(eventNames, destinationNonce(nonce, "script"), true));
2605
2647
  }
2606
2648
  function ssrGroup(fn, n) {
2607
2649
  fn.$g = n;
@@ -2690,8 +2732,8 @@ function ssrGroupSlot(fn, idx) {
2690
2732
  }
2691
2733
  };
2692
2734
  }
2693
- function wireErrorMessage(err) {
2694
- const wire = ssrSanitizeError(err, null);
2735
+ function wireErrorMessage(err, scope) {
2736
+ const wire = ssrSanitizeError(err, null, undefined, undefined, scope);
2695
2737
  return String(wire && wire.message || wire);
2696
2738
  }
2697
2739
  const holePositionCache = new WeakMap();
@@ -2753,7 +2795,7 @@ function holeContentPositions(t) {
2753
2795
  holePositionCache.set(t, cached);
2754
2796
  return cached;
2755
2797
  }
2756
- function createLiveHoles(sink, scoped) {
2798
+ function createLiveHoles(sink, scoped, settled, errorScope) {
2757
2799
  let nextId = 0;
2758
2800
  const stamp = typeof creationStamp === "function" ? creationStamp : () => 0;
2759
2801
  const inScope = scoped && typeof inServerComponentScope === "function" ? inServerComponentScope : null;
@@ -2761,20 +2803,70 @@ function createLiveHoles(sink, scoped) {
2761
2803
  const swept = (owner, ctx, fn) => {
2762
2804
  const prev = sharedConfig.context;
2763
2805
  sharedConfig.context = ctx;
2806
+ let dispose;
2807
+ let before;
2808
+ const run = () => createRoot(d => {
2809
+ dispose = d;
2810
+ before = stamp();
2811
+ return fn();
2812
+ }, {
2813
+ transparent: true
2814
+ });
2764
2815
  try {
2765
- return owner ? runWithOwner(owner, fn) : fn();
2816
+ return owner ? runWithOwner(owner, run) : run();
2766
2817
  } finally {
2767
2818
  sharedConfig.context = prev;
2819
+ engine.sweptOwners = before !== undefined && stamp() !== before;
2820
+ if (dispose) dispose();
2768
2821
  }
2769
2822
  };
2823
+ const stripRow = html => html.replace(/<!--lh:\/?\d+-->| data-lha="\d+"|<!--lr-->/g, "");
2824
+ const rowsOf = v => Array.isArray(v) && v.$rows ? v : null;
2825
+ function holeValue(hole) {
2826
+ const b = hole.$lhBinding;
2827
+ if (b) {
2828
+ const v = hole();
2829
+ return b.fn && rowsOf(b.fn()) || v;
2830
+ }
2831
+ if (!hole.$fn) return hole();
2832
+ const v = hole.$fn();
2833
+ return rowsOf(v) || escape(v);
2834
+ }
2835
+ function resolveValue(value, res) {
2836
+ if (!Array.isArray(value) || !value.$rows) {
2837
+ resolveSSRNode(value, res);
2838
+ return null;
2839
+ }
2840
+ let rows = [];
2841
+ for (const row of value) {
2842
+ const r = resolveSSRNode(escape(row));
2843
+ res.t[res.t.length - 1] += "<!--lr-->" + r.t[0];
2844
+ if (r.h.length) {
2845
+ res.t.push(...r.t.slice(1));
2846
+ res.h.push(...r.h);
2847
+ res.p.push(...r.p);
2848
+ rows = null;
2849
+ } else if (rows) rows.push(engine.sweeping ? r.t[0] : stripRow(r.t[0]));
2850
+ }
2851
+ return rows;
2852
+ }
2853
+ function rowOps(last, rows) {
2854
+ const ops = [];
2855
+ for (let i = 0; i < rows.length; i++) if (i >= last.length || rows[i] !== last[i]) ops.push([i, rows[i]]);
2856
+ return ops.length < rows.length ? {
2857
+ n: rows.length,
2858
+ r: ops
2859
+ } : null;
2860
+ }
2770
2861
  function resolveHoleValue(hole) {
2771
2862
  const result = {
2772
2863
  t: [""],
2773
2864
  h: [],
2774
- p: []
2865
+ p: [],
2866
+ rows: null
2775
2867
  };
2776
2868
  try {
2777
- resolveSSRNode(hole(), result);
2869
+ result.rows = resolveValue(holeValue(hole), result);
2778
2870
  } catch (err) {
2779
2871
  const wrap = buildAsyncWrap(err, hole);
2780
2872
  if (!wrap) throw err;
@@ -2792,12 +2884,88 @@ function createLiveHoles(sink, scoped) {
2792
2884
  }
2793
2885
  b.children.length = 0;
2794
2886
  }
2887
+ let tops = 0;
2888
+ const ids = new Map();
2889
+ const scopeFor = hole => {
2890
+ const p = engine.scope;
2891
+ return {
2892
+ id: undefined,
2893
+ p,
2894
+ i: p ? p.c++ : tops++,
2895
+ n: null,
2896
+ c: 0,
2897
+ h: hole
2898
+ };
2899
+ };
2900
+ const scopeId = s => s.id !== undefined ? s.id : s.id = s.p ? scopeId(s.p) + "." + s.i : String(s.i);
2901
+ const collect = (v, id, forget) => (v.occ || (v.occ = new Map())).set(id, forget);
2902
+ function rescope(b, hole, fn) {
2903
+ const prevScope = engine.scope;
2904
+ const prevVisit = engine.visit;
2905
+ engine.scope = {
2906
+ id: scopeId(b.scope),
2907
+ p: null,
2908
+ i: 0,
2909
+ n: null,
2910
+ c: 0,
2911
+ h: hole
2912
+ };
2913
+ const visit = engine.visit = {
2914
+ occ: null
2915
+ };
2916
+ try {
2917
+ return fn();
2918
+ } finally {
2919
+ engine.scope = prevScope;
2920
+ engine.visit = prevVisit;
2921
+ b.next = visit.occ;
2922
+ }
2923
+ }
2924
+ function settleOccurrences(b) {
2925
+ const occ = b.next;
2926
+ b.next = null;
2927
+ if (b.occ) for (const [id, forget] of b.occ) if (!occ || !occ.has(id)) forget();
2928
+ b.occ = occ;
2929
+ if (occ) for (let a = b.up; a; a = a.up) for (const [id, forget] of occ) collect(a, id, forget);
2930
+ }
2931
+ function leave(b, parent, scope, visit) {
2932
+ engine.parent = parent;
2933
+ engine.scope = scope;
2934
+ engine.visit = visit;
2935
+ if (visit && b.occ) for (const [id, forget] of b.occ) collect(visit, id, forget);
2936
+ }
2795
2937
  const engine = {
2796
2938
  suppressed: 0,
2797
2939
  sweeping: false,
2798
2940
  parent: null,
2799
- recordStamp: 0,
2800
2941
  gateHit: false,
2942
+ sweptOwners: false,
2943
+ scope: null,
2944
+ visit: null,
2945
+ dry: false,
2946
+ slotId(prop, given) {
2947
+ const s = engine.scope;
2948
+ if (!s) return given;
2949
+ const n = s.n || (s.n = Object.create(null));
2950
+ const i = n[prop] || 0;
2951
+ n[prop] = i + 1;
2952
+ const sid = scopeId(s);
2953
+ const at = sid + "." + i + "\0" + prop;
2954
+ if (given !== undefined) {
2955
+ ids.set(at, given);
2956
+ return given;
2957
+ }
2958
+ return ids.get(at) || `${prop}#~${sid}.${i}`;
2959
+ },
2960
+ seen(id, forget) {
2961
+ if (engine.visit) collect(engine.visit, id, forget);
2962
+ },
2963
+ nest(hole) {
2964
+ const s = engine.scope;
2965
+ if (!s || s.h === hole || hole.$lhSkip || inScope && !inScope()) return undefined;
2966
+ engine.scope = scopeFor(hole);
2967
+ return s;
2968
+ },
2801
2969
  content(hole) {
2802
2970
  if (hole.$lhSuppress) {
2803
2971
  const r = {
@@ -2805,10 +2973,12 @@ function createLiveHoles(sink, scoped) {
2805
2973
  h: [],
2806
2974
  p: []
2807
2975
  };
2808
- engine.suppressed++;
2809
- try {
2976
+ let rows = null;
2977
+ const b = hole.$lhBinding;
2978
+ const run = () => {
2979
+ engine.suppressed++;
2810
2980
  try {
2811
- resolveSSRNode(hole(), r);
2981
+ rows = resolveValue(holeValue(hole), r);
2812
2982
  } catch (err) {
2813
2983
  const wrap = buildAsyncWrap(err, hole);
2814
2984
  if (wrap) {
@@ -2816,20 +2986,21 @@ function createLiveHoles(sink, scoped) {
2816
2986
  r.p.push(wrap.p);
2817
2987
  r.t.push("");
2818
2988
  }
2989
+ } finally {
2990
+ engine.suppressed--;
2819
2991
  }
2820
- } finally {
2821
- engine.suppressed--;
2822
- }
2823
- const b = hole.$lhBinding;
2992
+ };
2993
+ b && !engine.sweeping ? rescope(b, hole, run) : run();
2824
2994
  if (b && !b.closed && !r.h.length && !engine.sweeping) {
2825
2995
  b.last = stripMarkers(r.t[0]);
2996
+ b.rows = rows;
2997
+ settleOccurrences(b);
2826
2998
  }
2827
2999
  return r.h.length ? r : r.t[0];
2828
3000
  }
2829
3001
  if (engine.suppressed || engine.sweeping) return null;
2830
3002
  if (hole.$lhSkip) return null;
2831
3003
  if (inScope && !inScope()) return null;
2832
- const recordsBefore = engine.recordStamp;
2833
3004
  const ownersBefore = stamp();
2834
3005
  const owner = getOwner();
2835
3006
  const holeCtx = sharedConfig.context;
@@ -2837,25 +3008,31 @@ function createLiveHoles(sink, scoped) {
2837
3008
  key: null,
2838
3009
  children: [],
2839
3010
  last: null,
3011
+ rows: null,
3012
+ fn: hole.$fn,
2840
3013
  closed: false,
3014
+ scope: undefined,
3015
+ occ: null,
3016
+ next: null,
3017
+ up: engine.parent,
2841
3018
  sweep() {
2842
3019
  if (b.closed) return;
2843
3020
  const prevSweeping = engine.sweeping;
2844
3021
  engine.sweeping = true;
2845
- engine.gateHit = false;
2846
- const sweepOwnersBefore = stamp();
3022
+ engine.dry = b.last === null;
2847
3023
  let res;
2848
3024
  try {
2849
- res = swept(owner, holeCtx, () => resolveHoleValue(hole));
3025
+ res = rescope(b, hole, () => swept(owner, holeCtx, () => resolveHoleValue(hole)));
2850
3026
  } catch (err) {
2851
3027
  b.closed = true;
2852
3028
  sink.closeBinding(b.key);
2853
- sink.error(b.key, wireErrorMessage(err));
3029
+ sink.error(b.key, wireErrorMessage(err, errorScope));
2854
3030
  return;
2855
3031
  } finally {
2856
3032
  engine.sweeping = prevSweeping;
3033
+ engine.dry = false;
2857
3034
  }
2858
- if (engine.gateHit || stamp() !== sweepOwnersBefore) {
3035
+ if (engine.sweptOwners && res.h.length) {
2859
3036
  b.closed = true;
2860
3037
  sink.closeBinding(b.key);
2861
3038
  return;
@@ -2863,29 +3040,38 @@ function createLiveHoles(sink, scoped) {
2863
3040
  if (res.h.length) return;
2864
3041
  const html = res.t[0];
2865
3042
  if (b.last === null || html === b.last) return;
3043
+ const ops = b.rows && res.rows && rowOps(b.rows, res.rows);
2866
3044
  b.last = html;
3045
+ if (ops && !ops.r.length && ops.n === b.rows.length) return;
3046
+ b.rows = res.rows;
2867
3047
  closeChildren(b);
2868
- sink.hole(b.key, html);
3048
+ settleOccurrences(b);
3049
+ sink.hole(b.key, html, ops && !html.includes("<!--slot:") ? ops : null);
2869
3050
  }
2870
3051
  };
2871
3052
  if (engine.parent) engine.parent.children.push(b);
2872
3053
  const prevParent = engine.parent;
3054
+ const prevScope = engine.scope;
3055
+ const prevVisit = engine.visit;
3056
+ const scope = b.scope = scopeFor(hole);
2873
3057
  engine.parent = b;
3058
+ engine.scope = scope;
3059
+ engine.visit = b;
2874
3060
  let value;
2875
3061
  let escalated = null;
2876
3062
  try {
2877
- value = hole();
3063
+ value = holeValue(hole);
2878
3064
  } catch (err) {
2879
3065
  const wrap = buildAsyncWrap(err, hole);
2880
3066
  if (!wrap) {
2881
- engine.parent = prevParent;
3067
+ leave(b, prevParent, prevScope, prevVisit);
2882
3068
  closeChildren(b);
2883
3069
  return "";
2884
3070
  }
2885
3071
  escalated = wrap;
2886
3072
  }
2887
3073
  if (!escalated && (typeof value === "function" && value.$lhSkip || value !== null && typeof value === "object" && value.$slot)) {
2888
- engine.parent = prevParent;
3074
+ leave(b, prevParent, prevScope, prevVisit);
2889
3075
  const r = {
2890
3076
  t: [""],
2891
3077
  h: [],
@@ -2900,6 +3086,7 @@ function createLiveHoles(sink, scoped) {
2900
3086
  return r.h.length ? r : r.t[0];
2901
3087
  }
2902
3088
  let res;
3089
+ let rows = null;
2903
3090
  if (escalated) {
2904
3091
  closeChildren(b);
2905
3092
  escalated.fn.$lhSuppress = true;
@@ -2916,23 +3103,25 @@ function createLiveHoles(sink, scoped) {
2916
3103
  p: []
2917
3104
  };
2918
3105
  try {
2919
- resolveSSRNode(value, res);
3106
+ rows = resolveValue(value, res);
2920
3107
  } catch (_) {
2921
- engine.parent = prevParent;
3108
+ leave(b, prevParent, prevScope, prevVisit);
2922
3109
  closeChildren(b);
2923
3110
  return "";
2924
3111
  }
2925
3112
  }
2926
- engine.parent = prevParent;
2927
- if (engine.recordStamp !== recordsBefore || stamp() !== ownersBefore) {
3113
+ leave(b, prevParent, prevScope, prevVisit);
3114
+ if (stamp() !== ownersBefore) {
2928
3115
  return res.h.length ? res : res.t[0];
2929
3116
  }
3117
+ if (!res.h.length && settled && settled()) return res.t[0];
2930
3118
  const id = nextId++;
2931
3119
  const key = b.key = "lh:" + id;
2932
3120
  const open = `<!--lh:${id}-->`;
2933
3121
  const close = `<!--lh:/${id}-->`;
2934
3122
  if (!res.h.length) {
2935
3123
  b.last = stripMarkers(res.t[0]);
3124
+ b.rows = rows;
2936
3125
  sink.openBinding(key, b);
2937
3126
  return open + res.t[0] + close;
2938
3127
  }
@@ -2950,7 +3139,7 @@ function createLiveHoles(sink, scoped) {
2950
3139
  return nextId++;
2951
3140
  },
2952
3141
  active() {
2953
- return !inScope || inScope();
3142
+ return (!inScope || inScope()) && !(settled && settled());
2954
3143
  },
2955
3144
  attr(cap) {
2956
3145
  const owner = getOwner();
@@ -2963,9 +3152,10 @@ function createLiveHoles(sink, scoped) {
2963
3152
  sweep() {
2964
3153
  if (b.closed) return;
2965
3154
  const prevSweeping = engine.sweeping;
3155
+ const prevScope = engine.scope;
2966
3156
  engine.sweeping = true;
3157
+ engine.scope = null;
2967
3158
  engine.gateHit = false;
2968
- const sweepOwnersBefore = stamp();
2969
3159
  let html = "";
2970
3160
  try {
2971
3161
  let group = null;
@@ -2992,15 +3182,21 @@ function createLiveHoles(sink, scoped) {
2992
3182
  };
2993
3183
  swept(owner, holeCtx, run);
2994
3184
  } catch (err) {
2995
- if (ssrHandleError(err, true)) return;
3185
+ if (ssrHandleError(err, true)) {
3186
+ if (!engine.sweptOwners) return;
3187
+ b.closed = true;
3188
+ sink.closeBinding(b.key);
3189
+ return;
3190
+ }
2996
3191
  b.closed = true;
2997
3192
  sink.closeBinding(b.key);
2998
- sink.error("lha:" + cap.id, wireErrorMessage(err));
3193
+ sink.error("lha:" + cap.id, wireErrorMessage(err, errorScope));
2999
3194
  return;
3000
3195
  } finally {
3001
3196
  engine.sweeping = prevSweeping;
3197
+ engine.scope = prevScope;
3002
3198
  }
3003
- if (engine.gateHit || stamp() !== sweepOwnersBefore) {
3199
+ if (engine.gateHit) {
3004
3200
  b.closed = true;
3005
3201
  sink.closeBinding(b.key);
3006
3202
  return;
@@ -3065,7 +3261,9 @@ function ssr(t) {
3065
3261
  cap = {
3066
3262
  id,
3067
3263
  parts: [prefix],
3068
- base: prefix
3264
+ base: prefix,
3265
+ at: lastOpen.seg,
3266
+ inject
3069
3267
  };
3070
3268
  return true;
3071
3269
  };
@@ -3114,7 +3312,10 @@ function ssr(t) {
3114
3312
  });
3115
3313
  }
3116
3314
  } else {
3117
- cap = null;
3315
+ if (cap) {
3316
+ result.t[cap.at] = result.t[cap.at].replace(cap.inject, "");
3317
+ cap = null;
3318
+ }
3118
3319
  result.h.push(ssrGroupSlot(lastGroupVal.fn, lastGroupIdx++));
3119
3320
  result.p.push(lastGroupVal.p);
3120
3321
  result.t.push("");
@@ -3176,12 +3377,15 @@ function ssr(t) {
3176
3377
  f: hole
3177
3378
  });
3178
3379
  } else {
3380
+ result.t[cap.at] = result.t[cap.at].replace(cap.inject, "");
3179
3381
  cap = null;
3180
3382
  }
3181
3383
  }
3182
3384
  } else {
3183
3385
  const capturing = live && !hp.pos[i - 1] && captureStart();
3386
+ const scope = live && hp.pos[i - 1] && live.nest(hole);
3184
3387
  const r = tryResolveFunctionHole(hole);
3388
+ if (scope) live.scope = scope;
3185
3389
  if (typeof r === "string") {
3186
3390
  s += r;
3187
3391
  if (capturing) {
@@ -3191,7 +3395,10 @@ function ssr(t) {
3191
3395
  });
3192
3396
  }
3193
3397
  } else {
3194
- if (capturing) cap = null;
3398
+ if (capturing) {
3399
+ s = s.replace(cap.inject, "");
3400
+ cap = null;
3401
+ }
3195
3402
  result = {
3196
3403
  t: [s],
3197
3404
  h: [],
@@ -3255,14 +3462,12 @@ function ssrClassName(value) {
3255
3462
  if (typeof value === "number") return "" + value;
3256
3463
  if (!value) return "";
3257
3464
  if (typeof value === "string") return escape(value, true);
3258
- if (isSlotValue(value)) return "";
3259
3465
  value = classListToObject(value);
3260
3466
  let classKeys = Object.keys(value),
3261
3467
  result = "";
3262
3468
  for (let i = 0, len = classKeys.length; i < len; i++) {
3263
3469
  const key = classKeys[i];
3264
- let classValue = value[key];
3265
- if (isSlotValue(classValue)) classValue = slotValueInline();
3470
+ const classValue = value[key];
3266
3471
  if (!key || key === "undefined" || !classValue) continue;
3267
3472
  result && (result += " ");
3268
3473
  result += escape(key, true);
@@ -3272,13 +3477,11 @@ function ssrClassName(value) {
3272
3477
  function ssrStyle(value) {
3273
3478
  if (!value) return "";
3274
3479
  if (typeof value === "string") return escape(value, true);
3275
- if (isSlotValue(value)) return "";
3276
3480
  let result = "";
3277
3481
  const k = Object.keys(value);
3278
3482
  for (let i = 0; i < k.length; i++) {
3279
3483
  const s = escape(k[i], true);
3280
- let v = value[k[i]];
3281
- if (isSlotValue(v)) v = slotValueInline();
3484
+ const v = value[k[i]];
3282
3485
  if (v != undefined) {
3283
3486
  const r = escape(v, true);
3284
3487
  if (r != undefined && r !== "undefined") {
@@ -3290,7 +3493,6 @@ function ssrStyle(value) {
3290
3493
  return result;
3291
3494
  }
3292
3495
  function ssrStyleProperty(name, value) {
3293
- if (isSlotValue(value)) value = slotValueInline();
3294
3496
  return value != null ? name + value : "";
3295
3497
  }
3296
3498
  function ssrStyleProperties(...entries) {
@@ -3301,30 +3503,25 @@ function ssrStyleProperties(...entries) {
3301
3503
  }
3302
3504
  return result;
3303
3505
  }
3304
- function ssrElement(tag, props, children, needsId, skip, attrs, claims) {
3506
+ function ssrElement(tag, props, children, needsId, skip, attrs) {
3305
3507
  const hk = needsId ? ssrHydrationKey() : "";
3306
3508
  if (typeof props === "function") props = props();
3307
3509
  let sources = null;
3308
3510
  let proxy = false;
3309
3511
  let viewKeys = null;
3310
3512
  let owners = null;
3311
- let ownerIndex = null;
3312
3513
  const ctx = renderConfig.context;
3313
- const slots = ctx !== undefined && ctx.claims !== undefined;
3314
3514
  const link = tag === "a" && ctx !== undefined && ctx.linkClaim !== undefined ? {} : null;
3315
3515
  if (Array.isArray(props)) {
3316
- if (slots && props.$slot === true) props = slotSpreadSource();else {
3317
- let i = 0;
3318
- for (; i < props.length; i++) {
3319
- const s = props[i];
3320
- if (s == null || typeof s === "function" || $PROXY in s || slots && s.$slot === true) break;
3321
- }
3322
- if (i === props.length) sources = props;else {
3323
- viewKeys = [];
3324
- owners = [];
3325
- if (slots) ownerIndex = [];
3326
- collectSpreadSources(tag, props, viewKeys, owners, slots, ownerIndex);
3327
- }
3516
+ let i = 0;
3517
+ for (; i < props.length; i++) {
3518
+ const s = props[i];
3519
+ if (s == null || typeof s === "function" || $PROXY in s) break;
3520
+ }
3521
+ if (i === props.length) sources = props;else {
3522
+ viewKeys = [];
3523
+ owners = [];
3524
+ collectSpreadSources(props, viewKeys, owners);
3328
3525
  }
3329
3526
  } else if (props == null) {
3330
3527
  props = {};
@@ -3334,13 +3531,10 @@ function ssrElement(tag, props, children, needsId, skip, attrs, claims) {
3334
3531
  owners = [];
3335
3532
  sourceOwners(props, viewKeys, owners);
3336
3533
  } else proxy = true;
3337
- } else if (slots && props.$slot === true) {
3338
- props = slotSpreadSource();
3339
3534
  }
3340
3535
  const info = tagInfo(tag);
3341
3536
  const skipChildren = info.isVoid;
3342
3537
  let result = info.open + hk;
3343
- let behaviors = null;
3344
3538
  let childOwner = null;
3345
3539
  const last = sources === null ? 0 : sources.length - 1;
3346
3540
  let keysOf = null;
@@ -3375,21 +3569,9 @@ function ssrElement(tag, props, children, needsId, skip, attrs, claims) {
3375
3569
  if (prop === undefined) continue;
3376
3570
  }
3377
3571
  const value = props[key];
3378
- if (value == undefined) {
3379
- if (slots && claims !== undefined && (prop === "ref" || isEventName(prop))) behaviors = spreadBehaviorPosition(behaviors, prop, value, ctx.claims, ownerIndex !== null ? ownerIndex[i] : s, true);
3380
- continue;
3381
- }
3382
- if (prop.startsWith("prop:")) {
3383
- continue;
3384
- }
3385
- if (prop === "ref" || isEventName(prop)) {
3386
- if (slots) behaviors = spreadBehaviorPosition(behaviors, prop, value, ctx.claims, ownerIndex !== null ? ownerIndex[i] : s, claims !== undefined);
3387
- continue;
3388
- }
3572
+ if (value == undefined || prop.startsWith("prop:") || prop === "ref" || isEventName(prop)) continue;
3389
3573
  if (link !== null && LinkAttributes.has(prop)) link[prop] = value;
3390
- if (slots && typeof value === "object") {
3391
- result += spreadObjectAttribute(prop, value);
3392
- } else if (prop === "style") {
3574
+ if (prop === "style") {
3393
3575
  result += ` style="${ssrStyle(value)}"`;
3394
3576
  } else if (prop === "class") {
3395
3577
  result += ` class="${ssrClassName(value)}"`;
@@ -3400,7 +3582,6 @@ function ssrElement(tag, props, children, needsId, skip, attrs, claims) {
3400
3582
  }
3401
3583
  }
3402
3584
  }
3403
- if (slots && (behaviors !== null || claims !== undefined)) result += spreadBehaviorMarkers(behaviors, claims, ctx.claims);
3404
3585
  if (attrs !== undefined) result += typeof attrs === "function" ? attrs() : attrs;
3405
3586
  if (link !== null && link.href !== undefined) result += ssrLinkClaim(link);
3406
3587
  if (skipChildren) return {
@@ -3420,6 +3601,13 @@ function ssrElement(tag, props, children, needsId, skip, attrs, claims) {
3420
3601
  };
3421
3602
  return ssr([result + ">", info.close], resolveSSRNode(children, undefined, true));
3422
3603
  }
3604
+ function collectSpreadSources(props, viewKeys, owners) {
3605
+ for (let i = 0; i < props.length; i++) {
3606
+ let s = props[i];
3607
+ if (typeof s === "function") s = s();
3608
+ if (s != null) sourceOwners(s, viewKeys, owners);
3609
+ }
3610
+ }
3423
3611
  function spreadFormAttribute(prop, info, keys, keysOf, skip) {
3424
3612
  const defaultProp = info.formDefaults[prop];
3425
3613
  if (defaultProp !== undefined && (skip === undefined || !skip(defaultProp))) {
@@ -3435,19 +3623,14 @@ function spreadFormAttribute(prop, info, keys, keysOf, skip) {
3435
3623
  }
3436
3624
  function ssrElementAttribute(key, value) {
3437
3625
  if (value == undefined) return "";
3438
- if (key === "style" || key === "class") {
3439
- return typeof value === "object" ? slotClassOrStyle(key, value) : ` ${key}="${key === "class" ? ssrClassName(value) : ssrStyle(value)}"`;
3440
- }
3441
- if (isSlotValue(value)) return slotAttribute(key, value);
3626
+ if (key === "style" || key === "class") return ` ${key}="${key === "class" ? ssrClassName(value) : ssrStyle(value)}"`;
3442
3627
  if (typeof value === "boolean") return value ? ` ${key}` : "";
3443
3628
  return value === "" ? ` ${key}` : ` ${key}="${escape(value, true)}"`;
3444
3629
  }
3445
3630
  function ssrAttribute(key, value) {
3446
3631
  if (typeof value === "string") return ` ${key}="${value}"`;
3447
3632
  if (value == null || value === false) return "";
3448
- if (typeof value === "object") {
3449
- return isSlotValue(value) ? slotAttribute(key, value) : ` ${key}="${escape(String(value), true)}"`;
3450
- }
3633
+ if (typeof value === "object") return ` ${key}="${escape(String(value), true)}"`;
3451
3634
  if (typeof value === "function") return ` ${key}="${escape(String(value), true)}"`;
3452
3635
  return value === true ? ` ${key}` : ` ${key}="${value}"`;
3453
3636
  }
@@ -3455,232 +3638,6 @@ function ssrHydrationKey() {
3455
3638
  const hk = getHydrationKey();
3456
3639
  return hk ? ` _hk=${hk}` : "";
3457
3640
  }
3458
- const CLAIMS_STREAM = 1;
3459
- const CLAIMS_DOCUMENT = 2;
3460
- const SLOT_VALUE = /*#__PURE__*/Symbol.for("solid.slot-value");
3461
- const SLOT_MARKER = "_s:";
3462
- const SLOT_FACE_STREAM = 0;
3463
- const SLOT_FACE_DATA = 1;
3464
- const SLOT_FACE_MARKUP = 2;
3465
- function isSlotValue(value) {
3466
- return value !== null && typeof value === "object" && value[SLOT_VALUE] !== undefined;
3467
- }
3468
- function slotValue(occurrence, key, value, face) {
3469
- const sv = {
3470
- [SLOT_VALUE]: occurrence,
3471
- k: key,
3472
- v: value,
3473
- f: face
3474
- };
3475
- Object.defineProperty(sv, Symbol.toPrimitive, {
3476
- value: hint => slotValueString()
3477
- });
3478
- Object.defineProperty(sv, "toString", {
3479
- value: () => slotValueString()
3480
- });
3481
- Object.defineProperty(sv, "w", {
3482
- value: () => slotText(sv)
3483
- });
3484
- return sv;
3485
- }
3486
- function slotValueString(sv, reason) {
3487
- return "";
3488
- }
3489
- function slotText(sv) {
3490
- const v = sv.f === SLOT_FACE_DATA ? sv.v : undefined;
3491
- const text = typeof v === "string" || typeof v === "number" ? escape("" + v) : "";
3492
- return `<!--${SLOT_MARKER}t=${slotEntry(sv)}-->${text}<!--/${SLOT_MARKER}t-->`;
3493
- }
3494
- function slotValueInline(kind, sv) {
3495
- return undefined;
3496
- }
3497
- const SLOT_KEY_UNSAFE = /[^A-Za-z0-9_.!~*'()-]/g;
3498
- function encodeSlotKey(key) {
3499
- return String(key).replace(SLOT_KEY_UNSAFE, c => encodeURIComponent(c));
3500
- }
3501
- function slotEntry(sv, name) {
3502
- return `${sv[SLOT_VALUE]}:${encodeSlotKey(sv.k)}${name !== undefined ? "=" + encodeSlotKey(name) : ""}`;
3503
- }
3504
- function slotMarker(position, entries) {
3505
- return ` ${SLOT_MARKER}${position}="${entries}"`;
3506
- }
3507
- function eventSlotStamp(mode) {
3508
- return mode === CLAIMS_DOCUMENT ? " _hk" : "";
3509
- }
3510
- function slotAttribute(key, sv) {
3511
- let out = "";
3512
- if (sv.f === SLOT_FACE_DATA) {
3513
- const v = sv.v;
3514
- if (v != null && v !== false) {
3515
- out = v === true || v === "" ? ` ${key}` : ` ${key}="${escape(String(v), true)}"`;
3516
- }
3517
- }
3518
- return out + slotMarker(key, slotEntry(sv));
3519
- }
3520
- function slotClassOrStyle(key, value) {
3521
- const isClass = key === "class";
3522
- if (isSlotValue(value)) {
3523
- let out = "";
3524
- if (value.f === SLOT_FACE_DATA && value.v != null) {
3525
- out = ` ${key}="${isClass ? ssrClassName(value.v) : ssrStyle(value.v)}"`;
3526
- }
3527
- return out + slotMarker(key, slotEntry(value));
3528
- }
3529
- if (typeof value === "object" && value !== null) {
3530
- const obj = isClass ? classListToObject(value) : value;
3531
- let entries = "";
3532
- let inner = "";
3533
- for (const name of Object.keys(obj)) {
3534
- let v = obj[name];
3535
- if (isSlotValue(v)) {
3536
- entries += (entries ? "," : "") + slotEntry(v, name);
3537
- v = v.f === SLOT_FACE_DATA ? v.v : undefined;
3538
- }
3539
- if (isClass) {
3540
- if (!name || name === "undefined" || !v) continue;
3541
- inner += (inner ? " " : "") + escape(name, true);
3542
- } else if (v != undefined) {
3543
- const r = escape(v, true);
3544
- if (r != undefined && r !== "undefined") {
3545
- inner += (inner ? ";" : "") + `${escape(name, true)}:${r}`;
3546
- }
3547
- }
3548
- }
3549
- if (entries === "") return ` ${key}="${inner}"`;
3550
- return (inner ? ` ${key}="${inner}"` : "") + slotMarker(key, entries);
3551
- }
3552
- return ` ${key}="${isClass ? ssrClassName(value) : ssrStyle(value)}"`;
3553
- }
3554
- function eventPosition(prop) {
3555
- return prop.slice(2).toLowerCase();
3556
- }
3557
- function spreadBehaviorPosition(behaviors, prop, value, mode, index, settle) {
3558
- if (!isAttrName(prop)) return behaviors;
3559
- const pos = prop === "ref" ? "ref" : eventPosition(prop);
3560
- const entries = value == null ? "" : claimEntries(pos, value);
3561
- if (!settle) {
3562
- if (entries) (behaviors ||= new Map()).set(pos, entries);
3563
- return behaviors;
3564
- }
3565
- behaviors ||= new Map();
3566
- const b = behaviors.get(pos);
3567
- if (b === undefined) behaviors.set(pos, {
3568
- e: entries,
3569
- at: index
3570
- });else {
3571
- b.e = entries;
3572
- b.at = index;
3573
- }
3574
- return behaviors;
3575
- }
3576
- function spreadBehaviorMarkers(behaviors, claims, mode) {
3577
- if (claims !== undefined) {
3578
- const segments = claims();
3579
- for (const k in segments) {
3580
- const map = segments[k];
3581
- for (const pos in map) {
3582
- const value = map[pos];
3583
- behaviors ||= new Map();
3584
- const b = behaviors.get(pos);
3585
- if (pos === "ref") {
3586
- if (value == null) continue;
3587
- const entries = claimEntries("ref", value);
3588
- if (!entries) continue;
3589
- if (b === undefined) behaviors.set("ref", {
3590
- e: entries,
3591
- at: -1
3592
- });else b.e = b.e ? b.e + "," + entries : entries;
3593
- continue;
3594
- }
3595
- if (b !== undefined && b.at >= +k) continue;
3596
- const entries = value == null ? "" : claimEntries(pos, value);
3597
- if (b === undefined) behaviors.set(pos, {
3598
- e: entries,
3599
- at: -1
3600
- });else b.e = entries;
3601
- }
3602
- }
3603
- }
3604
- let out = "";
3605
- let events = false;
3606
- if (behaviors !== null) {
3607
- for (const [pos, b] of behaviors) {
3608
- const e = claims === undefined ? b : b.e;
3609
- if (!e) continue;
3610
- if (pos === "ref") out += slotMarker("ref", e);else {
3611
- out += slotMarker("on:" + pos, e);
3612
- events = true;
3613
- }
3614
- }
3615
- }
3616
- return events ? out + eventSlotStamp(mode) : out;
3617
- }
3618
- function collectSpreadSources(tag, props, viewKeys, owners, slots, ownerIndex) {
3619
- for (let i = 0; i < props.length; i++) {
3620
- let s = props[i];
3621
- if (typeof s === "function") s = s();
3622
- if (s != null) {
3623
- if (slots && !($PROXY in s) && s.$slot === true) s = slotSpreadSource();
3624
- if (ownerIndex === null) sourceOwners(s, viewKeys, owners);else {
3625
- const ks = [];
3626
- const os = [];
3627
- sourceOwners(s, ks, os);
3628
- for (let j = 0; j < ks.length; j++) {
3629
- const at = viewKeys.indexOf(ks[j]);
3630
- if (at !== -1) {
3631
- viewKeys.splice(at, 1);
3632
- owners.splice(at, 1);
3633
- ownerIndex.splice(at, 1);
3634
- }
3635
- viewKeys.push(ks[j]);
3636
- owners.push(os[j]);
3637
- ownerIndex.push(i);
3638
- }
3639
- }
3640
- }
3641
- }
3642
- }
3643
- function spreadObjectAttribute(prop, value) {
3644
- if (prop === "style" || prop === "class") return slotClassOrStyle(prop, value);
3645
- if (!isAttrName(prop)) return "";
3646
- if (value[SLOT_VALUE] !== undefined) return slotAttribute(prop, value);
3647
- return ` ${prop}="${escape(value, true)}"`;
3648
- }
3649
- function slotSpreadSource(tag, source) {
3650
- return {};
3651
- }
3652
- function ssrClaim(map) {
3653
- const mode = sharedConfig.context && sharedConfig.context.claims;
3654
- if (!mode) return "";
3655
- let out = "";
3656
- let events = false;
3657
- for (const pos in map) {
3658
- const entries = claimEntries(pos, map[pos]);
3659
- if (!entries) continue;
3660
- if (pos === "ref") out += slotMarker("ref", entries);else {
3661
- out += slotMarker("on:" + pos, entries);
3662
- events = true;
3663
- }
3664
- }
3665
- return events ? out + eventSlotStamp(mode) : out;
3666
- }
3667
- function claimEntries(pos, value, mode) {
3668
- if (Array.isArray(value) && pos !== "ref") {
3669
- return "";
3670
- }
3671
- if (Array.isArray(value)) {
3672
- let entries = "";
3673
- for (const v of value) {
3674
- const inner = claimEntries(pos, v);
3675
- if (inner) entries += (entries ? "," : "") + inner;
3676
- }
3677
- return entries;
3678
- }
3679
- if (isSlotValue(value)) {
3680
- return slotEntry(value);
3681
- }
3682
- return "";
3683
- }
3684
3641
  function ssrLinkClaim(attrs) {
3685
3642
  const ctx = renderConfig.context;
3686
3643
  if (ctx === undefined || ctx.linkClaim === undefined || attrs["aria-current"] != null) return "";
@@ -3806,7 +3763,6 @@ function escape(s, attr) {
3806
3763
  if (!attr && t === "function") return escapeLate(s);
3807
3764
  if (attr) {
3808
3765
  if (s == null || t === "boolean" || t === "number") return s;
3809
- if (t === "object" && s[SLOT_VALUE] !== undefined) return s;
3810
3766
  return escape(String(s), attr);
3811
3767
  }
3812
3768
  return s;
@@ -3819,6 +3775,7 @@ function escapeLate(fn) {
3819
3775
  if (fn.$esc) return fn;
3820
3776
  const w = () => escape(fn());
3821
3777
  w.$esc = true;
3778
+ w.$fn = fn;
3822
3779
  if (fn.$lhSkip) w.$lhSkip = true;
3823
3780
  if (fn.$lhSuppress) w.$lhSuppress = true;
3824
3781
  if (fn.$lhBinding) w.$lhBinding = fn.$lhBinding;
@@ -3914,7 +3871,7 @@ function generateHydrationScript({
3914
3871
  eventNames,
3915
3872
  nonce
3916
3873
  } = {}) {
3917
- return hydrationBootstrap(eventNames, scriptNonce(nonce), false);
3874
+ return hydrationBootstrap(eventNames, destinationNonce(nonce, "script"), false);
3918
3875
  }
3919
3876
  function hydrationBootstrap(eventNames = ["click", "input"], nonce, ledger) {
3920
3877
  return `<script${nonce ? ` nonce="${escape(String(nonce), true)}"` : ""}>window._$HY||(e=>{let t=e=>e&&e.hasAttribute&&(e.hasAttribute("_hk")?e:t(e.host&&e.host.nodeType?e.host:e.parentNode));["${eventNames.join('","')}"].forEach((o=>document.addEventListener(o,(o=>{if(!e.events)return;let s=t(o.composedPath&&o.composedPath()[0]||o.target);s&&!e.completed.has(s)&&e.events.push([s,o])}))))})(_$HY={events:[],completed:new WeakSet,r:new Proxy({},{set:(r,k,v)=>(v instanceof Promise&&v.catch(()=>{}),r[k]=v,!0)}),${ledger ? "s:{}," : ""}fe(){}});</script><!--xs-->`;
@@ -3930,10 +3887,12 @@ function allSettled(promises) {
3930
3887
  return size;
3931
3888
  });
3932
3889
  }
3933
- function shellEndMarker(context, renderId, nonce, noScripts) {
3934
- if (noScripts || !context || !context.bootstrap) return "";
3890
+ function withShellEnd(html, context, renderId, nonce, noScripts) {
3891
+ if (noScripts || !context || !context.bootstrap) return html;
3935
3892
  const id = JSON.stringify(renderId).replace(/</g, "\\u003C");
3936
- return `<script${nonceAttr(nonce, "script")}>_$HY.s[${id}]=1,_$HY.sw&&_$HY.sw(${id})</script>`;
3893
+ const marker = `<script${nonceAttr(nonce, "script")}>_$HY.s[${id}]=1,_$HY.sw&&_$HY.sw(${id})</script>`;
3894
+ const at = html.indexOf("</body>", html.length - 512);
3895
+ return at < 0 ? html + marker : html.slice(0, at) + marker + html.slice(at);
3937
3896
  }
3938
3897
  function assembleDocument(html, emittedAssets, preloadLinks, inlineStyles, scripts, nonce, headTags, onHead) {
3939
3898
  const scriptTag = scripts ? `<script${nonceAttr(nonce, "script")}>${scripts}</script>` : "";
@@ -4125,10 +4084,6 @@ function tryResolveString(node, nested) {
4125
4084
  if (node.h && node.h.length > 0) return {
4126
4085
  merge: node
4127
4086
  };
4128
- if (node[SLOT_VALUE] !== undefined) {
4129
- ssrTextTail = false;
4130
- return node.w();
4131
- }
4132
4087
  if (node.t === undefined) {
4133
4088
  return "";
4134
4089
  }
@@ -4181,9 +4136,6 @@ function resolveSSRNode(node, result = {
4181
4136
  } else if (node.t !== undefined) {
4182
4137
  result.t[result.t.length - 1] += node.t;
4183
4138
  ssrTextTail = false;
4184
- } else if (node[SLOT_VALUE] !== undefined) {
4185
- result.t[result.t.length - 1] += node.w();
4186
- ssrTextTail = false;
4187
4139
  } else ;
4188
4140
  } else if (t === "function") {
4189
4141
  const live = sharedConfig.context && sharedConfig.context.liveHoles;
@@ -4194,6 +4146,7 @@ function resolveSSRNode(node, result = {
4194
4146
  ssrTextTail = true;
4195
4147
  } else resolveSSRNode(liveNode, result, false, true);
4196
4148
  } else {
4149
+ const scope = live && live.nest(node);
4197
4150
  try {
4198
4151
  resolveSSRNode(node(), result, false, true);
4199
4152
  } catch (err) {
@@ -4205,6 +4158,8 @@ function resolveSSRNode(node, result = {
4205
4158
  result.t.push("");
4206
4159
  ssrTextTail = true;
4207
4160
  }
4161
+ } finally {
4162
+ if (scope) live.scope = scope;
4208
4163
  }
4209
4164
  }
4210
4165
  }
@@ -4624,7 +4579,7 @@ function dispatchAsInteraction(_e, fn) {
4624
4579
  return fn();
4625
4580
  }
4626
4581
  function notSup() {
4627
- 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>.");
4582
+ throw new Error("Client-only API called on the server side. Run client-only code in onSettled, or conditionally run client-only component with <Show>.");
4628
4583
  }
4629
4584
 
4630
4585
  setContainerTraceResolver(getProjectionTrace);
@@ -4763,4 +4718,4 @@ function httpHeader(name, value, options) {
4763
4718
  }
4764
4719
  }
4765
4720
 
4766
- 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, dispatchAsInteraction, 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, hasServerLinkState, 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, reportRequestFailure, resolveSSRNode, resolveSSRSelectValues, respond, notSup as runHydrationEvents, scriptNonce, serializeCookie, notSup as setAttribute, notSup as setAttributeNS, setLinkClaim, notSup as setProperty, notSup as setStyleProperty, slotValue, notSup as spread, ssr, ssrAttribute, ssrClaim, ssrClassName, ssrElement, ssrElementAttribute, ssrGroup, ssrHydrationKey, ssrLinkClaim, ssrSelectValues, ssrStyle, ssrStyleProperties, ssrStyleProperty, notSup as style, styleNonce, takeHydrationValue, notSup as template, notSup as unregisterDelegatedContainer, notSup as unregisterDelegatedRoot, useHead };
4721
+ export { 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, dispatchAsInteraction, 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, hasServerLinkState, 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, reportRequestFailure, resolveSSRNode, resolveSSRSelectValues, respond, notSup as runHydrationEvents, serializeCookie, notSup as setAttribute, notSup as setAttributeNS, setLinkClaim, notSup as setProperty, notSup as setStatefulProperty, notSup as setStyleProperty, notSup as spread, ssr, ssrAttribute, ssrClassName, ssrElement, ssrElementAttribute, ssrGroup, ssrHydrationKey, ssrLinkClaim, ssrSelectValues, ssrStyle, ssrStyleProperties, ssrStyleProperty, notSup as style, takeHydrationValue, notSup as template, notSup as unregisterDelegatedContainer, notSup as unregisterDelegatedRoot, useHead };