@solidjs/web 2.0.0-rc.20 → 2.0.0-rc.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/server.js CHANGED
@@ -2,7 +2,7 @@ import { createRenderEffect, createMemo, getOwner, createRoot, $PROXY, onCleanup
2
2
  export { Errored, For, Hydration, Loading, Match, NoHydration, Repeat, Reveal, Show, Switch, createComponent, dynamicComponent, getOwner, merge as mergeProps, untrack } from 'solid-js';
3
3
  import { sharedConfig, ssrSanitizeError, beginEdgesRender, reportServerError, viewOf, sourceOwners, ssrHandleError, inServerComponentScope, creationStamp, dynamicCore, getProjectionTrace, shareAsyncIterable } from 'solid-js/internal';
4
4
  export { ssrScope as scope } from 'solid-js/internal';
5
- import { createStream, Feature, getCrossReferenceHeader, crossSerializeStream } from 'seroval';
5
+ import { createStream, Feature, crossSerializeStream, isStream, getCrossReferenceHeader } from 'seroval';
6
6
  import { AbortSignalPlugin, CustomEventPlugin, DOMExceptionPlugin, EventPlugin, FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin } from 'seroval-plugins/web';
7
7
 
8
8
  const DOMWithState = {
@@ -467,7 +467,6 @@ function createKeyedSerializer(serialize, onError, onDone) {
467
467
  pendingWrites++;
468
468
  let settled = false;
469
469
  let failed = false;
470
- let started = false;
471
470
  let cancel = null;
472
471
  const settle = () => {
473
472
  if (settled) return;
@@ -488,10 +487,7 @@ function createKeyedSerializer(serialize, onError, onDone) {
488
487
  }
489
488
  }),
490
489
  onDone: settle
491
- }, initial => {
492
- if (initial) started = true;
493
- return !closed;
494
- });
490
+ }, () => !closed);
495
491
  } catch (err) {
496
492
  settle();
497
493
  throw err;
@@ -538,22 +534,66 @@ function createHydrationSerializer({
538
534
  onDone,
539
535
  scopeId,
540
536
  onError,
541
- plugins
537
+ plugins,
538
+ late
542
539
  }) {
543
540
  const resolvedPlugins = resolveSerializerPlugins(plugins);
544
541
  const disabledFeatures = defaultDisabledFeatures() | serializeOnlyDisabledFeatures();
545
542
  const refs = new Map();
546
- return createKeyedSerializer((key, value, callbacks, live) => crossSerializeStream(value, {
543
+ const serialize = (key, value, callbacks, live) => crossSerializeStream(value, {
547
544
  scopeId,
548
545
  refs,
549
546
  plugins: resolvedPlugins,
550
547
  disabledFeatures,
551
548
  onSerialize(data, initial) {
552
- if (!live(initial)) return;
549
+ if (!live()) return;
553
550
  onData(initial ? HYDRATION_GLOBAL + '["' + serializeKey(key) + '"]=' + data : data);
554
551
  },
555
552
  ...callbacks
556
- }), onError, onDone);
553
+ });
554
+ return createKeyedSerializer(late ? late(serialize, refs, onData, scopeId) : serialize, onError, onDone);
555
+ }
556
+ function rejectUnserializedKey(serialize, refs, onData, scopeId) {
557
+ let taken = 0;
558
+ let fresh = [];
559
+ const set = refs.set;
560
+ refs.set = (value, id) => {
561
+ taken++;
562
+ fresh.push(value);
563
+ return set.call(refs, value, id);
564
+ };
565
+ Object.defineProperty(refs, "size", {
566
+ get: () => taken
567
+ });
568
+ return (key, value, callbacks, live) => {
569
+ const sent = [];
570
+ const failed = () => {
571
+ for (const ref of fresh) refs.delete(ref);
572
+ fresh = [];
573
+ const ids = new Set();
574
+ for (const ref of sent) {
575
+ const id = refs.get(ref);
576
+ if (ref instanceof Promise) ids.add(id + 1);else if (isStream(ref) || Object.getPrototypeOf(ref) === Object.prototype && !Object.keys(ref).length) ids.add(id);
577
+ }
578
+ if (!ids.size) return;
579
+ const body = "for(const i of[" + [...ids] + "]){const v=$R[i];v&&(v.f?v.f(e):v.throw&&v.throw(e))}";
580
+ const message = JSON.stringify("Serialization failed: the hydration value for key " + JSON.stringify(key) + " could not be serialized on the server").replace(/[<\u2028\u2029]/g, c => KEY_ESCAPES[c]);
581
+ onData("($R=>{const e=new Error(" + message + ");" + body + "})(" + (scopeId == null ? "$R" : '$R["' + serializeKey(scopeId) + '"]') + ")");
582
+ };
583
+ return serialize(key, value, {
584
+ ...callbacks,
585
+ onError: callbacks.onError && (err => {
586
+ if (live()) failed();
587
+ callbacks.onError(err);
588
+ })
589
+ },
590
+ () => {
591
+ if (!live()) return false;
592
+ sent.push(...fresh);
593
+ fresh = [];
594
+ return true;
595
+ });
596
+ };
557
597
  }
558
598
  function getLocalHeaderScript(id) {
559
599
  return getCrossReferenceHeader(id) + ";";
@@ -872,7 +912,7 @@ function resolveAssets(moduleUrl, manifest) {
872
912
  if (!manifest) return null;
873
913
  const base = manifest._base;
874
914
  const entry = manifest[moduleUrl];
875
- if (!entry) return null;
915
+ if (!entry || typeof entry !== "object") return null;
876
916
  const css = [];
877
917
  const js = [];
878
918
  let preloads;
@@ -881,7 +921,7 @@ function resolveAssets(moduleUrl, manifest) {
881
921
  if (visited.has(key)) return;
882
922
  visited.add(key);
883
923
  const e = manifest[key];
884
- if (!e) return;
924
+ if (!e || typeof e !== "object") return;
885
925
  js.push(joinAssetPath(base, e.file));
886
926
  if (e.css) for (let i = 0; i < e.css.length; i++) css.push(joinAssetPath(base, e.css[i]));
887
927
  if (e.preloads) {
@@ -918,18 +958,19 @@ function registerEntryAssets(manifest) {
918
958
  const ctx = sharedConfig.context;
919
959
  if (!ctx?.registerAsset) return;
920
960
  for (const key in manifest) {
921
- if (manifest[key].isEntry) {
961
+ const entry = manifest[key];
962
+ if (entry && entry.isEntry) {
922
963
  const assets = resolveAssets(key, manifest);
923
964
  if (assets) {
924
965
  if (assets.preloads) for (let i = 0; i < assets.preloads.length; i++) ctx.registerAsset("preload", assets.preloads[i]);
925
966
  for (let i = 0; i < assets.css.length; i++) ctx.registerAsset("style", assets.css[i]);
926
- for (let i = 1; i < assets.js.length; i++) ctx.registerAsset("module", assets.js[i]);
967
+ for (let i = 1; i < assets.js.length; i++) ctx.registerAsset("module", assets.js[i], true);
927
968
  }
928
969
  return;
929
970
  }
930
971
  }
931
972
  }
932
- function createAssetTracking() {
973
+ function createAssetTracking(lowPriorityPreloads) {
933
974
  const boundaryModules = new Map();
934
975
  const boundaryStyles = new Map();
935
976
  const emittedAssets = new Set();
@@ -941,6 +982,7 @@ function createAssetTracking() {
941
982
  emittedAssets,
942
983
  inlineStyles,
943
984
  preloadLinks: null,
985
+ lowModules: lowPriorityPreloads !== false ? new Set() : null,
944
986
  registerInlineStyle(desc) {
945
987
  let entry = inlineStyles.get(desc.id);
946
988
  if (!entry) {
@@ -1245,7 +1287,7 @@ function emitHeadResource(registry, context, tracking, emitResource, nonce, desc
1245
1287
  if (plain && props.href != null) {
1246
1288
  const isCss = isCssUrl(props.href);
1247
1289
  if (rel === "stylesheet" ? isCss : !isCss) {
1248
- context.registerAsset(rel === "stylesheet" ? "style" : "module", props.href);
1290
+ context.registerAsset(rel === "stylesheet" ? "style" : "module", props.href, true);
1249
1291
  return;
1250
1292
  }
1251
1293
  }
@@ -1489,6 +1531,10 @@ function nonceDestination(tag, props) {
1489
1531
  return "script";
1490
1532
  }
1491
1533
  }
1534
+ function modulePreloadLink(url, scriptAttr, lowModules) {
1535
+ const priority = lowModules && !lowModules.has(url) ? ' fetchpriority="low"' : "";
1536
+ return `<link rel="modulepreload" href="${url}"${priority}${scriptAttr}>`;
1537
+ }
1492
1538
  function nonceAttr(nonce, destination) {
1493
1539
  if (!nonce || !destination) return "";
1494
1540
  return destination === "script" ? nonce.scriptAttr : nonce.styleAttr;
@@ -1602,7 +1648,7 @@ function renderToString(code, options = {}) {
1602
1648
  },
1603
1649
  onError: serializerErrorHook(options.onError)
1604
1650
  });
1605
- const tracking = createAssetTracking();
1651
+ const tracking = createAssetTracking(options.lowPriorityPreloads);
1606
1652
  const headRegistry = createHeadRegistry();
1607
1653
  let closed = false;
1608
1654
  sharedConfig.context = {
@@ -1622,7 +1668,7 @@ function renderToString(code, options = {}) {
1622
1668
  }
1623
1669
  serializer.write(id, p);
1624
1670
  },
1625
- registerAsset(type, value) {
1671
+ registerAsset(type, value, defaultPriority) {
1626
1672
  if (type === "preload") {
1627
1673
  registerPreloadLink(tracking, headRegistry, value, nonce);
1628
1674
  return;
@@ -1639,6 +1685,7 @@ function renderToString(code, options = {}) {
1639
1685
  }
1640
1686
  styles.add(value);
1641
1687
  }
1688
+ if (defaultPriority && tracking.lowModules) tracking.lowModules.add(value);
1642
1689
  tracking.emittedAssets.add(value);
1643
1690
  }
1644
1691
  };
@@ -1665,7 +1712,7 @@ function renderToString(code, options = {}) {
1665
1712
  closed = true;
1666
1713
  serializer.close();
1667
1714
  const head = renderShellHead(headRegistry, nonce, null, noScripts, traceMetaMarkup(context.trace));
1668
- const document = withShellEnd(assembleDocument(resolveSSRSelectValues(html), tracking.emittedAssets, tracking.preloadLinks, tracking.inlineStyles, scripts.length ? scripts : "", nonce, head, onHead), context, renderId, nonce, noScripts);
1715
+ const document = withShellEnd(assembleDocument(resolveSSRSelectValues(html), tracking.emittedAssets, tracking.preloadLinks, tracking.inlineStyles, scripts.length ? scripts : "", nonce, head, onHead, tracking.lowModules), context, renderId, nonce, noScripts);
1669
1716
  if (render) render.shell();
1670
1717
  if (requestEvent && requestEvent.response) {
1671
1718
  commitResponseStub(requestEvent.response, {
@@ -1714,9 +1761,7 @@ function renderToStream(code, options = {}) {
1714
1761
  let rootOwner;
1715
1762
  let serializer;
1716
1763
  let disconnected = false;
1717
- let failed = false;
1718
1764
  let onFailed;
1719
- let onDisconnectedBeforeShell;
1720
1765
  const defuse = p => {
1721
1766
  if (p && typeof p.then === "function") p.then(undefined, () => {});
1722
1767
  };
@@ -1728,18 +1773,18 @@ function renderToStream(code, options = {}) {
1728
1773
  close() {}
1729
1774
  };
1730
1775
  const onFailure = complete => {
1731
- if (failed) return complete(undefined);
1776
+ if (dead) return complete(undefined, disconnected || undefined);
1732
1777
  const prev = onFailed;
1733
- onFailed = prev ? sink => {
1734
- prev(sink);
1735
- complete(sink);
1778
+ onFailed = prev ? (sink, gone) => {
1779
+ prev(sink, gone);
1780
+ complete(sink, gone);
1736
1781
  } : complete;
1737
1782
  };
1738
1783
  const abandon = (disconnect, quiet) => {
1739
1784
  if (dead) return;
1740
1785
  dead = true;
1741
1786
  completed = true;
1742
- if (disconnect) disconnected = true;
1787
+ if (disconnect) disconnected = disconnect;
1743
1788
  if (render) settleRender(render, rootOwner, disconnect ? "abandoned" : "error");
1744
1789
  const sink = writable;
1745
1790
  buffer = {
@@ -1768,10 +1813,7 @@ function renderToStream(code, options = {}) {
1768
1813
  for (const p of stubBatch.values()) defuse(p);
1769
1814
  stubBatch = null;
1770
1815
  }
1771
- if (!disconnect) {
1772
- failed = true;
1773
- onFailed && onFailed(sink);
1774
- } else if (!sink && onDisconnectedBeforeShell) onDisconnectedBeforeShell();
1816
+ onFailed && onFailed(sink, disconnect);
1775
1817
  };
1776
1818
  const failRender = err => {
1777
1819
  reportFailure(err, "failed");
@@ -1830,21 +1872,31 @@ function renderToStream(code, options = {}) {
1830
1872
  let stableOrder = false;
1831
1873
  let parkedWrites = null;
1832
1874
  const byKey = (a, b) => a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0;
1875
+ let writing = 0;
1876
+ let stranded = false;
1877
+ const handOver = (id, value) => {
1878
+ writing++;
1879
+ try {
1880
+ serializer.write(id, value);
1881
+ } finally {
1882
+ writing--;
1883
+ }
1884
+ };
1833
1885
  const write = (id, value) => {
1834
- if (stableOrder && !dead) (parkedWrites ||= []).push([id, value]);else serializer.write(id, value);
1886
+ if (stableOrder && !dead) (parkedWrites ||= []).push([id, value]);else handOver(id, value);
1835
1887
  };
1836
1888
  const flushParkedWrites = () => {
1837
1889
  if (!parkedWrites) return;
1838
1890
  const writes = parkedWrites.sort(byKey);
1839
1891
  parkedWrites = null;
1840
- for (let i = 0; i < writes.length; i++) serializer.write(writes[i][0], writes[i][1]);
1892
+ for (let i = 0; i < writes.length; i++) handOver(writes[i][0], writes[i][1]);
1841
1893
  };
1842
1894
  const flushStubBatch = () => {
1843
1895
  if (!stubBatch) return;
1844
1896
  const entries = [...stubBatch];
1845
1897
  stubBatch = null;
1846
1898
  if (stableOrder) entries.sort(byKey);
1847
- for (let i = 0; i < entries.length; i++) serializer.write(entries[i][0], entries[i][1]);
1899
+ for (let i = 0; i < entries.length; i++) handOver(entries[i][0], entries[i][1]);
1848
1900
  };
1849
1901
  let headerEmitted = false;
1850
1902
  const pushTask = task => {
@@ -1862,6 +1914,7 @@ function renderToStream(code, options = {}) {
1862
1914
  const onDone = () => {
1863
1915
  if (dead) return;
1864
1916
  writeTasks();
1917
+ if (stranded) return abandon();
1865
1918
  lastBlockingSize = blockingPromises.size;
1866
1919
  doShell();
1867
1920
  onCompleteAll && onCompleteAll({
@@ -1905,7 +1958,7 @@ function renderToStream(code, options = {}) {
1905
1958
  },
1906
1959
  asset(type, value) {
1907
1960
  if (type === "module") {
1908
- buffer.write(`<link rel="modulepreload" href="${value}"${nonceAttr(nonce, "script")}>`);
1961
+ buffer.write(modulePreloadLink(value, nonceAttr(nonce, "script"), tracking.lowModules));
1909
1962
  } else if (type === "preload") {
1910
1963
  buffer.write(`<link${value.attrHtml}>`);
1911
1964
  } else if (type === "inline-style") {
@@ -1915,7 +1968,7 @@ function renderToStream(code, options = {}) {
1915
1968
  }
1916
1969
  },
1917
1970
  shell(shellHtml, meta) {
1918
- buffer.write(withShellEnd(assembleDocument(shellHtml, meta.preloads, meta.preloadLinks, meta.inlineStyles, meta.tasks.length ? meta.tasks : "", nonce, meta.head, onHead), context, renderId, nonce, noScripts));
1971
+ buffer.write(withShellEnd(assembleDocument(shellHtml, meta.preloads, meta.preloadLinks, meta.inlineStyles, meta.tasks.length ? meta.tasks : "", nonce, meta.head, onHead, tracking.lowModules), context, renderId, nonce, noScripts));
1919
1972
  },
1920
1973
  ...options.sink
1921
1974
  };
@@ -1924,7 +1977,11 @@ function renderToStream(code, options = {}) {
1924
1977
  plugins: options.plugins,
1925
1978
  onData: payload => sink.data(payload),
1926
1979
  onDone,
1927
- onError: err => reportFailure(err, "serialize")
1980
+ onError: err => {
1981
+ reportFailure(err, "serialize");
1982
+ if (!writing && !options.serializer && !firstFlushed) stranded = true;
1983
+ },
1984
+ late: rejectUnserializedKey
1928
1985
  });
1929
1986
  let rootAssetsSerialized = false;
1930
1987
  const serializeRootAssets = () => {
@@ -2076,7 +2133,7 @@ function renderToStream(code, options = {}) {
2076
2133
  tmp += payload;
2077
2134
  }
2078
2135
  };
2079
- const tracking = createAssetTracking();
2136
+ const tracking = createAssetTracking(options.lowPriorityPreloads);
2080
2137
  const headRegistry = createHeadRegistry();
2081
2138
  let headScriptFlushed = false;
2082
2139
  const emitHeadOps = (key, ops) => {
@@ -2101,7 +2158,7 @@ function renderToStream(code, options = {}) {
2101
2158
  }
2102
2159
  }, nonce, tags);
2103
2160
  },
2104
- registerAsset(type, value) {
2161
+ registerAsset(type, value, defaultPriority) {
2105
2162
  if (type === "preload") {
2106
2163
  const entry = registerPreloadLink(tracking, headRegistry, value, nonce);
2107
2164
  if (entry && firstFlushed) sink.asset("preload", entry);
@@ -2123,6 +2180,7 @@ function renderToStream(code, options = {}) {
2123
2180
  }
2124
2181
  styles.add(value);
2125
2182
  }
2183
+ if (defaultPriority && tracking.lowModules) tracking.lowModules.add(value);
2126
2184
  if (!tracking.emittedAssets.has(value)) {
2127
2185
  tracking.emittedAssets.add(value);
2128
2186
  if (firstFlushed) sink.asset(type, value);
@@ -2274,7 +2332,12 @@ function renderToStream(code, options = {}) {
2274
2332
  registerEntryAssets(manifest);
2275
2333
  context.writer = createHydrationWriter(context, () => !completed);
2276
2334
  const signal = options.signal;
2277
- const onAbort = signal ? () => abandon("signal", !!(signal.reason && signal.reason.quiet === true)) : undefined;
2335
+ let cancelled = false;
2336
+ const onAbort = signal ? () => {
2337
+ if (dead) return;
2338
+ cancelled = true;
2339
+ abandon("signal", !!(signal.reason && signal.reason.quiet === true));
2340
+ } : undefined;
2278
2341
  const endEdges = context.edges ? beginEdgesRender() : undefined;
2279
2342
  let html;
2280
2343
  try {
@@ -2436,9 +2499,12 @@ function renderToStream(code, options = {}) {
2436
2499
  const pipeToImpl = w => {
2437
2500
  let resolve;
2438
2501
  const p = new Promise(r => resolve = r);
2439
- onFailure(sink => {
2502
+ let closeOnAbort = () => w.close().catch(() => {});
2503
+ onFailure((sink, gone) => {
2440
2504
  try {
2441
- if (sink) sink.end();else w.close().catch(() => {});
2505
+ if (!gone) {
2506
+ if (sink) sink.end();else w.close().catch(() => {});
2507
+ } else if (gone === "signal") closeOnAbort();
2442
2508
  } catch (_) {}
2443
2509
  resolve();
2444
2510
  });
@@ -2453,6 +2519,7 @@ function renderToStream(code, options = {}) {
2453
2519
  return;
2454
2520
  }
2455
2521
  if (!shellCompleted) return flush();
2522
+ if (stranded) return abandon();
2456
2523
  const encoder = new TextEncoder();
2457
2524
  const writer = w.getWriter();
2458
2525
  let pendingWrites = Promise.resolve();
@@ -2464,6 +2531,10 @@ function renderToStream(code, options = {}) {
2464
2531
  }
2465
2532
  };
2466
2533
  writer.closed && writer.closed.catch(failed);
2534
+ closeOnAbort = () => {
2535
+ ended = true;
2536
+ pendingWrites.then(() => writer.close()).catch(() => {});
2537
+ };
2467
2538
  buffer = writable = coalesceWrites(payload => {
2468
2539
  pendingWrites = pendingWrites.then(() => writer.write(encoder.encode(payload))).catch(failed);
2469
2540
  }, () => {
@@ -2495,7 +2566,7 @@ function renderToStream(code, options = {}) {
2495
2566
  event: requestEvent
2496
2567
  });
2497
2568
  };
2498
- const p = new Promise(resolve => {
2569
+ const p = new Promise((resolve, reject) => {
2499
2570
  function complete() {
2500
2571
  freezeHead();
2501
2572
  dispose();
@@ -2508,11 +2579,12 @@ function renderToStream(code, options = {}) {
2508
2579
  complete();
2509
2580
  };
2510
2581
  } else onCompleteAll = complete;
2511
- onFailure(() => resolve(tmp));
2582
+ onFailure(() => cancelled ? reject(signal.reason) : resolve(tmp));
2512
2583
  function flush() {
2513
2584
  allSettled(blockingPromises).then(awaited => {
2514
2585
  scheduleFlush(() => {
2515
2586
  if (dead) return;
2587
+ sharedConfig.context = context;
2516
2588
  try {
2517
2589
  if (blockingPromises.size !== lastBlockingSize || !resolveRootHoles() || blockingPromises.size !== lastBlockingSize || !headShellReady(headRegistry, p => blockingPromises.add(p))) return flush();
2518
2590
  } catch (err) {
@@ -2530,15 +2602,12 @@ function renderToStream(code, options = {}) {
2530
2602
  pipe(w) {
2531
2603
  claimConsumer("pipe");
2532
2604
  const abandoned = w[SHELL_ABANDONED];
2533
- onFailure(sink => {
2605
+ onFailure((sink, gone) => {
2534
2606
  try {
2535
- sink ? sink.end() : abandoned ? abandoned() : w.end();
2607
+ if (!gone) sink ? sink.end() : abandoned ? abandoned() : w.end();else if (!sink && abandoned) abandoned();else if (gone === "signal") w.end();
2536
2608
  } catch (_) {}
2537
2609
  });
2538
- if (abandoned) {
2539
- w[ABANDON_RENDER] = abandon;
2540
- if (disconnected) abandoned();else onDisconnectedBeforeShell = abandoned;
2541
- }
2610
+ if (abandoned) w[ABANDON_RENDER] = abandon;
2542
2611
  function flush() {
2543
2612
  allSettled(blockingPromises).then(awaited => {
2544
2613
  scheduleFlush(() => {
@@ -2550,6 +2619,7 @@ function renderToStream(code, options = {}) {
2550
2619
  return;
2551
2620
  }
2552
2621
  if (!shellCompleted) return flush();
2622
+ if (stranded) return abandon();
2553
2623
  const sink = guardSink(w);
2554
2624
  buffer = writable = coalesceWrites(sink.write, sink.end);
2555
2625
  buffer.write(tmp);
@@ -3607,6 +3677,22 @@ function ssrElement(tag, props, children, needsId, skip, attrs) {
3607
3677
  };
3608
3678
  if (childOwner !== null) children = info.raw ? childOwner.children : escape(childOwner.children);
3609
3679
  if (typeof children === "function") children = children();
3680
+ let thunk = null;
3681
+ if (typeof children === "function" && (ctx === undefined || !ctx.liveHoles)) {
3682
+ thunk = children;
3683
+ ssrTextTail = false;
3684
+ try {
3685
+ children = thunk();
3686
+ } catch (err) {
3687
+ const res = {
3688
+ t: [""],
3689
+ h: [],
3690
+ p: []
3691
+ };
3692
+ pushSSRAsyncHole(res, err, thunk);
3693
+ return ssr([result + ">", info.close], res);
3694
+ }
3695
+ }
3610
3696
  const ct = typeof children;
3611
3697
  if (ct === "string" || ct === "number") return {
3612
3698
  t: result + ">" + children + info.close
@@ -3617,7 +3703,18 @@ function ssrElement(tag, props, children, needsId, skip, attrs) {
3617
3703
  if (ct === "object" && !children.h && typeof children.t === "string") return {
3618
3704
  t: result + ">" + children.t + info.close
3619
3705
  };
3620
- return ssr([result + ">", info.close], resolveSSRNode(children, undefined, true));
3706
+ if (thunk === null) return ssr([result + ">", info.close], resolveSSRNode(children, undefined, true));
3707
+ const res = {
3708
+ t: [""],
3709
+ h: [],
3710
+ p: []
3711
+ };
3712
+ try {
3713
+ resolveSSRNode(children, res, false, true);
3714
+ } catch (err) {
3715
+ pushSSRAsyncHole(res, err, thunk);
3716
+ }
3717
+ return ssr([result + ">", info.close], res);
3621
3718
  }
3622
3719
  function collectSpreadSources(props, viewKeys, owners) {
3623
3720
  for (let i = 0; i < props.length; i++) {
@@ -3912,7 +4009,7 @@ function withShellEnd(html, context, renderId, nonce, noScripts) {
3912
4009
  const at = html.indexOf("</body>", html.length - 512);
3913
4010
  return at < 0 ? html + marker : html.slice(0, at) + marker + html.slice(at);
3914
4011
  }
3915
- function assembleDocument(html, emittedAssets, preloadLinks, inlineStyles, scripts, nonce, headTags, onHead) {
4012
+ function assembleDocument(html, emittedAssets, preloadLinks, inlineStyles, scripts, nonce, headTags, onHead, lowModules) {
3916
4013
  const scriptTag = scripts ? `<script${nonceAttr(nonce, "script")}>${scripts}</script>` : "";
3917
4014
  const title = headTags ? headTags.title : null;
3918
4015
  let headTagsHtml = headTags ? headTags.html : "";
@@ -3936,7 +4033,7 @@ function assembleDocument(html, emittedAssets, preloadLinks, inlineStyles, scrip
3936
4033
  if (title != null) {
3937
4034
  titleHtml = headTags.noScripts ? `<title data-dh="title">${escape(title)}</title>` : `<script${nonceAttr(nonce, "script")}>(function(x,t){(t=document.querySelector("title"))?(t.hasAttribute("data-dh")||t.setAttribute("data-dhf",t.textContent),t.textContent=x):(document.title=x,t=document.querySelector("title"));t&&t.setAttribute("data-dh","title")})(${JSON.stringify(title).replace(/</g, "\\u003C")})</script>`;
3938
4035
  }
3939
- onHead(headPrelude + headTagsHtml + titleHtml + renderHeadAssets(emittedAssets, preloadLinks, inlineStyles, nonce));
4036
+ onHead(headPrelude + headTagsHtml + titleHtml + renderHeadAssets(emittedAssets, preloadLinks, inlineStyles, nonce, lowModules));
3940
4037
  }
3941
4038
  if (!scriptTag) return html;
3942
4039
  const xs = html.indexOf("<!--xs-->");
@@ -3956,19 +4053,19 @@ function assembleDocument(html, emittedAssets, preloadLinks, inlineStyles, scrip
3956
4053
  headTagsHtml = `<title data-dh="title">${winner}</title>` + headTagsHtml;
3957
4054
  }
3958
4055
  }
3959
- const head = headTagsHtml + renderHeadAssets(emittedAssets, preloadLinks, inlineStyles, nonce);
4056
+ const head = headTagsHtml + renderHeadAssets(emittedAssets, preloadLinks, inlineStyles, nonce, lowModules);
3960
4057
  if (!scriptTag) return html.slice(0, headIdx) + head + html.slice(headIdx);
3961
4058
  const xsIdx = html.indexOf("<!--xs-->");
3962
4059
  if (xsIdx === -1) return html.slice(0, headIdx) + head + html.slice(headIdx) + scriptTag;
3963
4060
  return xsIdx < headIdx ? html.slice(0, xsIdx) + scriptTag + html.slice(xsIdx, headIdx) + head + html.slice(headIdx) : html.slice(0, headIdx) + head + html.slice(headIdx, xsIdx) + scriptTag + html.slice(xsIdx);
3964
4061
  }
3965
- function renderHeadAssets(emittedAssets, preloadLinks, inlineStyles, nonce) {
4062
+ function renderHeadAssets(emittedAssets, preloadLinks, inlineStyles, nonce, lowModules) {
3966
4063
  let head = "";
3967
4064
  const styleAttr = nonceAttr(nonce, "style");
3968
4065
  const scriptAttr = nonceAttr(nonce, "script");
3969
4066
  if (emittedAssets && emittedAssets.size) {
3970
4067
  for (const url of emittedAssets) {
3971
- head += isCssUrl(url) ? `<link rel="stylesheet" href="${url}"${styleAttr}>` : `<link rel="modulepreload" href="${url}"${scriptAttr}>`;
4068
+ head += isCssUrl(url) ? `<link rel="stylesheet" href="${url}"${styleAttr}>` : modulePreloadLink(url, scriptAttr, lowModules);
3972
4069
  }
3973
4070
  }
3974
4071
  if (preloadLinks) {
@@ -4168,14 +4265,7 @@ function resolveSSRNode(node, result = {
4168
4265
  try {
4169
4266
  resolveSSRNode(node(), result, false, true);
4170
4267
  } catch (err) {
4171
- const wrap = buildAsyncWrap(err, node);
4172
- if (wrap) {
4173
- if (ssrTextTail) result.t[result.t.length - 1] += "<!--!$-->";
4174
- result.h.push(wrap.fn);
4175
- result.p.push(wrap.p);
4176
- result.t.push("");
4177
- ssrTextTail = true;
4178
- }
4268
+ pushSSRAsyncHole(result, err, node);
4179
4269
  } finally {
4180
4270
  if (scope) live.scope = scope;
4181
4271
  }
@@ -4183,6 +4273,16 @@ function resolveSSRNode(node, result = {
4183
4273
  }
4184
4274
  return result;
4185
4275
  }
4276
+ function pushSSRAsyncHole(result, err, node) {
4277
+ const wrap = buildAsyncWrap(err, node);
4278
+ if (wrap) {
4279
+ if (ssrTextTail) result.t[result.t.length - 1] += "<!--!$-->";
4280
+ result.h.push(wrap.fn);
4281
+ result.p.push(wrap.p);
4282
+ result.t.push("");
4283
+ ssrTextTail = true;
4284
+ }
4285
+ }
4186
4286
  function resolveSSRSync(node) {
4187
4287
  const res = resolveSSRNode(node);
4188
4288
  if (!res.h.length) return res.t[0];