@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.
@@ -2,7 +2,7 @@ import { createRenderEffect, createMemo, OBSERVE, getOwner, createRoot, $PROXY,
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 = {
@@ -551,7 +551,6 @@ function createKeyedSerializer(serialize, onError, onDone) {
551
551
  pendingWrites++;
552
552
  let settled = false;
553
553
  let failed = false;
554
- let started = false;
555
554
  let cancel = null;
556
555
  const settle = () => {
557
556
  if (settled) return;
@@ -572,10 +571,7 @@ function createKeyedSerializer(serialize, onError, onDone) {
572
571
  }
573
572
  }),
574
573
  onDone: settle
575
- }, initial => {
576
- if (initial) started = true;
577
- return !closed;
578
- });
574
+ }, () => !closed);
579
575
  } catch (err) {
580
576
  settle();
581
577
  throw err;
@@ -622,22 +618,66 @@ function createHydrationSerializer({
622
618
  onDone,
623
619
  scopeId,
624
620
  onError,
625
- plugins
621
+ plugins,
622
+ late
626
623
  }) {
627
624
  const resolvedPlugins = resolveSerializerPlugins(plugins);
628
625
  const disabledFeatures = defaultDisabledFeatures() | serializeOnlyDisabledFeatures();
629
626
  const refs = new Map();
630
- return createKeyedSerializer((key, value, callbacks, live) => crossSerializeStream(value, {
627
+ const serialize = (key, value, callbacks, live) => crossSerializeStream(value, {
631
628
  scopeId,
632
629
  refs,
633
630
  plugins: resolvedPlugins,
634
631
  disabledFeatures,
635
632
  onSerialize(data, initial) {
636
- if (!live(initial)) return;
633
+ if (!live()) return;
637
634
  onData(initial ? HYDRATION_GLOBAL + '["' + serializeKey(key) + '"]=' + data : data);
638
635
  },
639
636
  ...callbacks
640
- }), onError, onDone);
637
+ });
638
+ return createKeyedSerializer(late ? late(serialize, refs, onData, scopeId) : serialize, onError, onDone);
639
+ }
640
+ function rejectUnserializedKey(serialize, refs, onData, scopeId) {
641
+ let taken = 0;
642
+ let fresh = [];
643
+ const set = refs.set;
644
+ refs.set = (value, id) => {
645
+ taken++;
646
+ fresh.push(value);
647
+ return set.call(refs, value, id);
648
+ };
649
+ Object.defineProperty(refs, "size", {
650
+ get: () => taken
651
+ });
652
+ return (key, value, callbacks, live) => {
653
+ const sent = [];
654
+ const failed = () => {
655
+ for (const ref of fresh) refs.delete(ref);
656
+ fresh = [];
657
+ const ids = new Set();
658
+ for (const ref of sent) {
659
+ const id = refs.get(ref);
660
+ if (ref instanceof Promise) ids.add(id + 1);else if (isStream(ref) || Object.getPrototypeOf(ref) === Object.prototype && !Object.keys(ref).length) ids.add(id);
661
+ }
662
+ if (!ids.size) return;
663
+ const body = "for(const i of[" + [...ids] + "]){const v=$R[i];v&&(v.f?v.f(e):v.throw&&v.throw(e))}";
664
+ 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]);
665
+ onData("($R=>{const e=new Error(" + message + ");" + body + "})(" + (scopeId == null ? "$R" : '$R["' + serializeKey(scopeId) + '"]') + ")");
666
+ };
667
+ return serialize(key, value, {
668
+ ...callbacks,
669
+ onError: callbacks.onError && (err => {
670
+ if (live()) failed();
671
+ callbacks.onError(err);
672
+ })
673
+ },
674
+ () => {
675
+ if (!live()) return false;
676
+ sent.push(...fresh);
677
+ fresh = [];
678
+ return true;
679
+ });
680
+ };
641
681
  }
642
682
  function getLocalHeaderScript(id) {
643
683
  return getCrossReferenceHeader(id) + ";";
@@ -968,7 +1008,7 @@ function resolveAssets(moduleUrl, manifest) {
968
1008
  if (!manifest) return null;
969
1009
  const base = manifest._base;
970
1010
  const entry = manifest[moduleUrl];
971
- if (!entry) return null;
1011
+ if (!entry || typeof entry !== "object") return null;
972
1012
  const css = [];
973
1013
  const js = [];
974
1014
  let preloads;
@@ -977,7 +1017,7 @@ function resolveAssets(moduleUrl, manifest) {
977
1017
  if (visited.has(key)) return;
978
1018
  visited.add(key);
979
1019
  const e = manifest[key];
980
- if (!e) return;
1020
+ if (!e || typeof e !== "object") return;
981
1021
  js.push(joinAssetPath(base, e.file));
982
1022
  if (e.css) for (let i = 0; i < e.css.length; i++) css.push(joinAssetPath(base, e.css[i]));
983
1023
  if (e.preloads) {
@@ -1014,18 +1054,19 @@ function registerEntryAssets(manifest) {
1014
1054
  const ctx = sharedConfig.context;
1015
1055
  if (!ctx?.registerAsset) return;
1016
1056
  for (const key in manifest) {
1017
- if (manifest[key].isEntry) {
1057
+ const entry = manifest[key];
1058
+ if (entry && entry.isEntry) {
1018
1059
  const assets = resolveAssets(key, manifest);
1019
1060
  if (assets) {
1020
1061
  if (assets.preloads) for (let i = 0; i < assets.preloads.length; i++) ctx.registerAsset("preload", assets.preloads[i]);
1021
1062
  for (let i = 0; i < assets.css.length; i++) ctx.registerAsset("style", assets.css[i]);
1022
- for (let i = 1; i < assets.js.length; i++) ctx.registerAsset("module", assets.js[i]);
1063
+ for (let i = 1; i < assets.js.length; i++) ctx.registerAsset("module", assets.js[i], true);
1023
1064
  }
1024
1065
  return;
1025
1066
  }
1026
1067
  }
1027
1068
  }
1028
- function createAssetTracking() {
1069
+ function createAssetTracking(lowPriorityPreloads) {
1029
1070
  const boundaryModules = new Map();
1030
1071
  const boundaryStyles = new Map();
1031
1072
  const emittedAssets = new Set();
@@ -1037,6 +1078,7 @@ function createAssetTracking() {
1037
1078
  emittedAssets,
1038
1079
  inlineStyles,
1039
1080
  preloadLinks: null,
1081
+ lowModules: lowPriorityPreloads !== false ? new Set() : null,
1040
1082
  registerInlineStyle(desc) {
1041
1083
  let entry = inlineStyles.get(desc.id);
1042
1084
  if (!entry) {
@@ -1341,7 +1383,7 @@ function emitHeadResource(registry, context, tracking, emitResource, nonce, desc
1341
1383
  if (plain && props.href != null) {
1342
1384
  const isCss = isCssUrl(props.href);
1343
1385
  if (rel === "stylesheet" ? isCss : !isCss) {
1344
- context.registerAsset(rel === "stylesheet" ? "style" : "module", props.href);
1386
+ context.registerAsset(rel === "stylesheet" ? "style" : "module", props.href, true);
1345
1387
  return;
1346
1388
  }
1347
1389
  }
@@ -1585,6 +1627,10 @@ function nonceDestination(tag, props) {
1585
1627
  return "script";
1586
1628
  }
1587
1629
  }
1630
+ function modulePreloadLink(url, scriptAttr, lowModules) {
1631
+ const priority = lowModules && !lowModules.has(url) ? ' fetchpriority="low"' : "";
1632
+ return `<link rel="modulepreload" href="${url}"${priority}${scriptAttr}>`;
1633
+ }
1588
1634
  function nonceAttr(nonce, destination) {
1589
1635
  if (!nonce || !destination) return "";
1590
1636
  return destination === "script" ? nonce.scriptAttr : nonce.styleAttr;
@@ -1698,7 +1744,7 @@ function renderToString(code, options = {}) {
1698
1744
  },
1699
1745
  onError: serializerErrorHook(options.onError)
1700
1746
  });
1701
- const tracking = createAssetTracking();
1747
+ const tracking = createAssetTracking(options.lowPriorityPreloads);
1702
1748
  const headRegistry = createHeadRegistry();
1703
1749
  let closed = false;
1704
1750
  sharedConfig.context = {
@@ -1718,7 +1764,7 @@ function renderToString(code, options = {}) {
1718
1764
  }
1719
1765
  serializer.write(id, p);
1720
1766
  },
1721
- registerAsset(type, value) {
1767
+ registerAsset(type, value, defaultPriority) {
1722
1768
  if (type === "preload") {
1723
1769
  registerPreloadLink(tracking, headRegistry, value, nonce);
1724
1770
  return;
@@ -1735,6 +1781,7 @@ function renderToString(code, options = {}) {
1735
1781
  }
1736
1782
  styles.add(value);
1737
1783
  }
1784
+ if (defaultPriority && tracking.lowModules) tracking.lowModules.add(value);
1738
1785
  tracking.emittedAssets.add(value);
1739
1786
  }
1740
1787
  };
@@ -1761,7 +1808,7 @@ function renderToString(code, options = {}) {
1761
1808
  closed = true;
1762
1809
  serializer.close();
1763
1810
  const head = renderShellHead(headRegistry, nonce, null, noScripts, traceMetaMarkup(context.trace));
1764
- const document = withShellEnd(assembleDocument(resolveSSRSelectValues(html), tracking.emittedAssets, tracking.preloadLinks, tracking.inlineStyles, scripts.length ? scripts : "", nonce, head, onHead), context, renderId, nonce, noScripts);
1811
+ const document = withShellEnd(assembleDocument(resolveSSRSelectValues(html), tracking.emittedAssets, tracking.preloadLinks, tracking.inlineStyles, scripts.length ? scripts : "", nonce, head, onHead, tracking.lowModules), context, renderId, nonce, noScripts);
1765
1812
  if (render) render.shell();
1766
1813
  if (requestEvent && requestEvent.response) {
1767
1814
  commitResponseStub(requestEvent.response, {
@@ -1810,9 +1857,7 @@ function renderToStream(code, options = {}) {
1810
1857
  let rootOwner;
1811
1858
  let serializer;
1812
1859
  let disconnected = false;
1813
- let failed = false;
1814
1860
  let onFailed;
1815
- let onDisconnectedBeforeShell;
1816
1861
  const defuse = p => {
1817
1862
  if (p && typeof p.then === "function") p.then(undefined, () => {});
1818
1863
  };
@@ -1824,11 +1869,11 @@ function renderToStream(code, options = {}) {
1824
1869
  close() {}
1825
1870
  };
1826
1871
  const onFailure = complete => {
1827
- if (failed) return complete(undefined);
1872
+ if (dead) return complete(undefined, disconnected || undefined);
1828
1873
  const prev = onFailed;
1829
- onFailed = prev ? sink => {
1830
- prev(sink);
1831
- complete(sink);
1874
+ onFailed = prev ? (sink, gone) => {
1875
+ prev(sink, gone);
1876
+ complete(sink, gone);
1832
1877
  } : complete;
1833
1878
  };
1834
1879
  const abandon = (disconnect, quiet) => {
@@ -1846,7 +1891,7 @@ function renderToStream(code, options = {}) {
1846
1891
  }, null);
1847
1892
  dead = true;
1848
1893
  completed = true;
1849
- if (disconnect) disconnected = true;
1894
+ if (disconnect) disconnected = disconnect;
1850
1895
  if (render) settleRender(render, rootOwner, disconnect ? "abandoned" : "error");
1851
1896
  const sink = writable;
1852
1897
  buffer = {
@@ -1875,10 +1920,7 @@ function renderToStream(code, options = {}) {
1875
1920
  for (const p of stubBatch.values()) defuse(p);
1876
1921
  stubBatch = null;
1877
1922
  }
1878
- if (!disconnect) {
1879
- failed = true;
1880
- onFailed && onFailed(sink);
1881
- } else if (!sink && onDisconnectedBeforeShell) onDisconnectedBeforeShell();
1923
+ onFailed && onFailed(sink, disconnect);
1882
1924
  };
1883
1925
  const failRender = err => {
1884
1926
  reportFailure(err, "failed");
@@ -1947,21 +1989,31 @@ function renderToStream(code, options = {}) {
1947
1989
  let stableOrder = false;
1948
1990
  let parkedWrites = null;
1949
1991
  const byKey = (a, b) => a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0;
1992
+ let writing = 0;
1993
+ let stranded = false;
1994
+ const handOver = (id, value) => {
1995
+ writing++;
1996
+ try {
1997
+ serializer.write(id, value);
1998
+ } finally {
1999
+ writing--;
2000
+ }
2001
+ };
1950
2002
  const write = (id, value) => {
1951
- if (stableOrder && !dead) (parkedWrites ||= []).push([id, value]);else serializer.write(id, value);
2003
+ if (stableOrder && !dead) (parkedWrites ||= []).push([id, value]);else handOver(id, value);
1952
2004
  };
1953
2005
  const flushParkedWrites = () => {
1954
2006
  if (!parkedWrites) return;
1955
2007
  const writes = parkedWrites.sort(byKey);
1956
2008
  parkedWrites = null;
1957
- for (let i = 0; i < writes.length; i++) serializer.write(writes[i][0], writes[i][1]);
2009
+ for (let i = 0; i < writes.length; i++) handOver(writes[i][0], writes[i][1]);
1958
2010
  };
1959
2011
  const flushStubBatch = () => {
1960
2012
  if (!stubBatch) return;
1961
2013
  const entries = [...stubBatch];
1962
2014
  stubBatch = null;
1963
2015
  if (stableOrder) entries.sort(byKey);
1964
- for (let i = 0; i < entries.length; i++) serializer.write(entries[i][0], entries[i][1]);
2016
+ for (let i = 0; i < entries.length; i++) handOver(entries[i][0], entries[i][1]);
1965
2017
  };
1966
2018
  let headerEmitted = false;
1967
2019
  const pushTask = task => {
@@ -1979,6 +2031,7 @@ function renderToStream(code, options = {}) {
1979
2031
  const onDone = () => {
1980
2032
  if (dead) return;
1981
2033
  writeTasks();
2034
+ if (stranded) return abandon();
1982
2035
  lastBlockingSize = blockingPromises.size;
1983
2036
  doShell();
1984
2037
  onCompleteAll && onCompleteAll({
@@ -2022,7 +2075,7 @@ function renderToStream(code, options = {}) {
2022
2075
  },
2023
2076
  asset(type, value) {
2024
2077
  if (type === "module") {
2025
- buffer.write(`<link rel="modulepreload" href="${value}"${nonceAttr(nonce, "script")}>`);
2078
+ buffer.write(modulePreloadLink(value, nonceAttr(nonce, "script"), tracking.lowModules));
2026
2079
  } else if (type === "preload") {
2027
2080
  buffer.write(`<link${value.attrHtml}>`);
2028
2081
  } else if (type === "inline-style") {
@@ -2032,7 +2085,7 @@ function renderToStream(code, options = {}) {
2032
2085
  }
2033
2086
  },
2034
2087
  shell(shellHtml, meta) {
2035
- buffer.write(withShellEnd(assembleDocument(shellHtml, meta.preloads, meta.preloadLinks, meta.inlineStyles, meta.tasks.length ? meta.tasks : "", nonce, meta.head, onHead), context, renderId, nonce, noScripts));
2088
+ 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));
2036
2089
  },
2037
2090
  ...options.sink
2038
2091
  };
@@ -2041,7 +2094,11 @@ function renderToStream(code, options = {}) {
2041
2094
  plugins: options.plugins,
2042
2095
  onData: payload => sink.data(payload),
2043
2096
  onDone,
2044
- onError: err => reportFailure(err, "serialize")
2097
+ onError: err => {
2098
+ reportFailure(err, "serialize");
2099
+ if (!writing && !options.serializer && !firstFlushed) stranded = true;
2100
+ },
2101
+ late: rejectUnserializedKey
2045
2102
  });
2046
2103
  let rootAssetsSerialized = false;
2047
2104
  const serializeRootAssets = () => {
@@ -2209,7 +2266,7 @@ function renderToStream(code, options = {}) {
2209
2266
  tmp += payload;
2210
2267
  }
2211
2268
  };
2212
- const tracking = createAssetTracking();
2269
+ const tracking = createAssetTracking(options.lowPriorityPreloads);
2213
2270
  const headRegistry = createHeadRegistry();
2214
2271
  let headScriptFlushed = false;
2215
2272
  const emitHeadOps = (key, ops) => {
@@ -2234,7 +2291,7 @@ function renderToStream(code, options = {}) {
2234
2291
  }
2235
2292
  }, nonce, tags);
2236
2293
  },
2237
- registerAsset(type, value) {
2294
+ registerAsset(type, value, defaultPriority) {
2238
2295
  if (type === "preload") {
2239
2296
  const entry = registerPreloadLink(tracking, headRegistry, value, nonce);
2240
2297
  if (entry && firstFlushed) sink.asset("preload", entry);
@@ -2256,6 +2313,7 @@ function renderToStream(code, options = {}) {
2256
2313
  }
2257
2314
  styles.add(value);
2258
2315
  }
2316
+ if (defaultPriority && tracking.lowModules) tracking.lowModules.add(value);
2259
2317
  if (!tracking.emittedAssets.has(value)) {
2260
2318
  tracking.emittedAssets.add(value);
2261
2319
  if (firstFlushed) sink.asset(type, value);
@@ -2407,7 +2465,12 @@ function renderToStream(code, options = {}) {
2407
2465
  registerEntryAssets(manifest);
2408
2466
  context.writer = createHydrationWriter(context, () => !completed);
2409
2467
  const signal = options.signal;
2410
- const onAbort = signal ? () => abandon("signal", !!(signal.reason && signal.reason.quiet === true)) : undefined;
2468
+ let cancelled = false;
2469
+ const onAbort = signal ? () => {
2470
+ if (dead) return;
2471
+ cancelled = true;
2472
+ abandon("signal", !!(signal.reason && signal.reason.quiet === true));
2473
+ } : undefined;
2411
2474
  const endEdges = context.edges ? beginEdgesRender() : undefined;
2412
2475
  let html;
2413
2476
  try {
@@ -2569,9 +2632,12 @@ function renderToStream(code, options = {}) {
2569
2632
  const pipeToImpl = w => {
2570
2633
  let resolve;
2571
2634
  const p = new Promise(r => resolve = r);
2572
- onFailure(sink => {
2635
+ let closeOnAbort = () => w.close().catch(() => {});
2636
+ onFailure((sink, gone) => {
2573
2637
  try {
2574
- if (sink) sink.end();else w.close().catch(() => {});
2638
+ if (!gone) {
2639
+ if (sink) sink.end();else w.close().catch(() => {});
2640
+ } else if (gone === "signal") closeOnAbort();
2575
2641
  } catch (_) {}
2576
2642
  resolve();
2577
2643
  });
@@ -2586,6 +2652,7 @@ function renderToStream(code, options = {}) {
2586
2652
  return;
2587
2653
  }
2588
2654
  if (!shellCompleted) return flush();
2655
+ if (stranded) return abandon();
2589
2656
  const encoder = new TextEncoder();
2590
2657
  const writer = w.getWriter();
2591
2658
  let pendingWrites = Promise.resolve();
@@ -2597,6 +2664,10 @@ function renderToStream(code, options = {}) {
2597
2664
  }
2598
2665
  };
2599
2666
  writer.closed && writer.closed.catch(failed);
2667
+ closeOnAbort = () => {
2668
+ ended = true;
2669
+ pendingWrites.then(() => writer.close()).catch(() => {});
2670
+ };
2600
2671
  buffer = writable = coalesceWrites(payload => {
2601
2672
  pendingWrites = pendingWrites.then(() => writer.write(encoder.encode(payload))).catch(failed);
2602
2673
  }, () => {
@@ -2628,7 +2699,7 @@ function renderToStream(code, options = {}) {
2628
2699
  event: requestEvent
2629
2700
  });
2630
2701
  };
2631
- const p = new Promise(resolve => {
2702
+ const p = new Promise((resolve, reject) => {
2632
2703
  function complete() {
2633
2704
  freezeHead();
2634
2705
  dispose();
@@ -2641,11 +2712,12 @@ function renderToStream(code, options = {}) {
2641
2712
  complete();
2642
2713
  };
2643
2714
  } else onCompleteAll = complete;
2644
- onFailure(() => resolve(tmp));
2715
+ onFailure(() => cancelled ? reject(signal.reason) : resolve(tmp));
2645
2716
  function flush() {
2646
2717
  allSettled(blockingPromises).then(awaited => {
2647
2718
  scheduleFlush(() => {
2648
2719
  if (dead) return;
2720
+ sharedConfig.context = context;
2649
2721
  try {
2650
2722
  if (blockingPromises.size !== lastBlockingSize || !resolveRootHoles() || blockingPromises.size !== lastBlockingSize || !headShellReady(headRegistry, p => blockingPromises.add(p))) return flush();
2651
2723
  } catch (err) {
@@ -2663,15 +2735,12 @@ function renderToStream(code, options = {}) {
2663
2735
  pipe(w) {
2664
2736
  claimConsumer("pipe");
2665
2737
  const abandoned = w[SHELL_ABANDONED];
2666
- onFailure(sink => {
2738
+ onFailure((sink, gone) => {
2667
2739
  try {
2668
- sink ? sink.end() : abandoned ? abandoned() : w.end();
2740
+ if (!gone) sink ? sink.end() : abandoned ? abandoned() : w.end();else if (!sink && abandoned) abandoned();else if (gone === "signal") w.end();
2669
2741
  } catch (_) {}
2670
2742
  });
2671
- if (abandoned) {
2672
- w[ABANDON_RENDER] = abandon;
2673
- if (disconnected) abandoned();else onDisconnectedBeforeShell = abandoned;
2674
- }
2743
+ if (abandoned) w[ABANDON_RENDER] = abandon;
2675
2744
  function flush() {
2676
2745
  allSettled(blockingPromises).then(awaited => {
2677
2746
  scheduleFlush(() => {
@@ -2683,6 +2752,7 @@ function renderToStream(code, options = {}) {
2683
2752
  return;
2684
2753
  }
2685
2754
  if (!shellCompleted) return flush();
2755
+ if (stranded) return abandon();
2686
2756
  const sink = guardSink(w);
2687
2757
  buffer = writable = coalesceWrites(sink.write, sink.end);
2688
2758
  buffer.write(tmp);
@@ -3740,6 +3810,22 @@ function ssrElement(tag, props, children, needsId, skip, attrs) {
3740
3810
  };
3741
3811
  if (childOwner !== null) children = info.raw ? childOwner.children : escape(childOwner.children);
3742
3812
  if (typeof children === "function") children = children();
3813
+ let thunk = null;
3814
+ if (typeof children === "function" && (ctx === undefined || !ctx.liveHoles)) {
3815
+ thunk = children;
3816
+ ssrTextTail = false;
3817
+ try {
3818
+ children = thunk();
3819
+ } catch (err) {
3820
+ const res = {
3821
+ t: [""],
3822
+ h: [],
3823
+ p: []
3824
+ };
3825
+ pushSSRAsyncHole(res, err, thunk);
3826
+ return ssr([result + ">", info.close], res);
3827
+ }
3828
+ }
3743
3829
  const ct = typeof children;
3744
3830
  if (ct === "string" || ct === "number") return {
3745
3831
  t: result + ">" + children + info.close
@@ -3750,7 +3836,18 @@ function ssrElement(tag, props, children, needsId, skip, attrs) {
3750
3836
  if (ct === "object" && !children.h && typeof children.t === "string") return {
3751
3837
  t: result + ">" + children.t + info.close
3752
3838
  };
3753
- return ssr([result + ">", info.close], resolveSSRNode(children, undefined, true));
3839
+ if (thunk === null) return ssr([result + ">", info.close], resolveSSRNode(children, undefined, true));
3840
+ const res = {
3841
+ t: [""],
3842
+ h: [],
3843
+ p: []
3844
+ };
3845
+ try {
3846
+ resolveSSRNode(children, res, false, true);
3847
+ } catch (err) {
3848
+ pushSSRAsyncHole(res, err, thunk);
3849
+ }
3850
+ return ssr([result + ">", info.close], res);
3754
3851
  }
3755
3852
  function collectSpreadSources(props, viewKeys, owners) {
3756
3853
  for (let i = 0; i < props.length; i++) {
@@ -4045,7 +4142,7 @@ function withShellEnd(html, context, renderId, nonce, noScripts) {
4045
4142
  const at = html.indexOf("</body>", html.length - 512);
4046
4143
  return at < 0 ? html + marker : html.slice(0, at) + marker + html.slice(at);
4047
4144
  }
4048
- function assembleDocument(html, emittedAssets, preloadLinks, inlineStyles, scripts, nonce, headTags, onHead) {
4145
+ function assembleDocument(html, emittedAssets, preloadLinks, inlineStyles, scripts, nonce, headTags, onHead, lowModules) {
4049
4146
  const scriptTag = scripts ? `<script${nonceAttr(nonce, "script")}>${scripts}</script>` : "";
4050
4147
  const title = headTags ? headTags.title : null;
4051
4148
  let headTagsHtml = headTags ? headTags.html : "";
@@ -4069,7 +4166,7 @@ function assembleDocument(html, emittedAssets, preloadLinks, inlineStyles, scrip
4069
4166
  if (title != null) {
4070
4167
  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>`;
4071
4168
  }
4072
- onHead(headPrelude + headTagsHtml + titleHtml + renderHeadAssets(emittedAssets, preloadLinks, inlineStyles, nonce));
4169
+ onHead(headPrelude + headTagsHtml + titleHtml + renderHeadAssets(emittedAssets, preloadLinks, inlineStyles, nonce, lowModules));
4073
4170
  }
4074
4171
  if (!scriptTag) return html;
4075
4172
  const xs = html.indexOf("<!--xs-->");
@@ -4089,19 +4186,19 @@ function assembleDocument(html, emittedAssets, preloadLinks, inlineStyles, scrip
4089
4186
  headTagsHtml = `<title data-dh="title">${winner}</title>` + headTagsHtml;
4090
4187
  }
4091
4188
  }
4092
- const head = headTagsHtml + renderHeadAssets(emittedAssets, preloadLinks, inlineStyles, nonce);
4189
+ const head = headTagsHtml + renderHeadAssets(emittedAssets, preloadLinks, inlineStyles, nonce, lowModules);
4093
4190
  if (!scriptTag) return html.slice(0, headIdx) + head + html.slice(headIdx);
4094
4191
  const xsIdx = html.indexOf("<!--xs-->");
4095
4192
  if (xsIdx === -1) return html.slice(0, headIdx) + head + html.slice(headIdx) + scriptTag;
4096
4193
  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);
4097
4194
  }
4098
- function renderHeadAssets(emittedAssets, preloadLinks, inlineStyles, nonce) {
4195
+ function renderHeadAssets(emittedAssets, preloadLinks, inlineStyles, nonce, lowModules) {
4099
4196
  let head = "";
4100
4197
  const styleAttr = nonceAttr(nonce, "style");
4101
4198
  const scriptAttr = nonceAttr(nonce, "script");
4102
4199
  if (emittedAssets && emittedAssets.size) {
4103
4200
  for (const url of emittedAssets) {
4104
- head += isCssUrl(url) ? `<link rel="stylesheet" href="${url}"${styleAttr}>` : `<link rel="modulepreload" href="${url}"${scriptAttr}>`;
4201
+ head += isCssUrl(url) ? `<link rel="stylesheet" href="${url}"${styleAttr}>` : modulePreloadLink(url, scriptAttr, lowModules);
4105
4202
  }
4106
4203
  }
4107
4204
  if (preloadLinks) {
@@ -4301,14 +4398,7 @@ function resolveSSRNode(node, result = {
4301
4398
  try {
4302
4399
  resolveSSRNode(node(), result, false, true);
4303
4400
  } catch (err) {
4304
- const wrap = buildAsyncWrap(err, node);
4305
- if (wrap) {
4306
- if (ssrTextTail) result.t[result.t.length - 1] += "<!--!$-->";
4307
- result.h.push(wrap.fn);
4308
- result.p.push(wrap.p);
4309
- result.t.push("");
4310
- ssrTextTail = true;
4311
- }
4401
+ pushSSRAsyncHole(result, err, node);
4312
4402
  } finally {
4313
4403
  if (scope) live.scope = scope;
4314
4404
  }
@@ -4316,6 +4406,16 @@ function resolveSSRNode(node, result = {
4316
4406
  }
4317
4407
  return result;
4318
4408
  }
4409
+ function pushSSRAsyncHole(result, err, node) {
4410
+ const wrap = buildAsyncWrap(err, node);
4411
+ if (wrap) {
4412
+ if (ssrTextTail) result.t[result.t.length - 1] += "<!--!$-->";
4413
+ result.h.push(wrap.fn);
4414
+ result.p.push(wrap.p);
4415
+ result.t.push("");
4416
+ ssrTextTail = true;
4417
+ }
4418
+ }
4319
4419
  function resolveSSRSync(node) {
4320
4420
  const res = resolveSSRNode(node);
4321
4421
  if (!res.h.length) return res.t[0];
package/dist/web.dev.js CHANGED
@@ -540,16 +540,11 @@ function render(code, element, init, options = {}) {
540
540
  createRoot(dispose => {
541
541
  disposer = dispose;
542
542
  if (options.onError) getOwner()[ROOT_ERROR_HOOK] = options.onError;
543
- if (element === document) {
544
- const tree = code();
545
- effect(() => flatten(tree), () => {});
546
- } else {
547
- const tree = code();
548
- insert(element, () => tree, element.firstChild ? null : undefined, init, {
549
- ...options.insertOptions,
550
- schedule: true
551
- });
552
- }
543
+ const tree = code();
544
+ if (element === document) effect(() => flatten(tree), () => {});else insert(element, () => tree, element.firstChild ? null : undefined, init, {
545
+ ...options.insertOptions,
546
+ schedule: true
547
+ });
553
548
  }, {
554
549
  id: options.renderId
555
550
  });
@@ -572,7 +567,8 @@ function create(html, bypassGuard, flag) {
572
567
  if (/^<(html|head|body)[\s>]/i.test(html)) throw new Error("Document shell templates (<html>, <head>, <body>) cannot be client-created: " + "a <template> parse strips those tags. Render this component through hydrate(), " + "where the document shell already exists.");
573
568
  const t = document.createElement("template");
574
569
  t.innerHTML = html;
575
- return flag === 2 ? t.content.firstChild.firstChild : t.content.firstChild;
570
+ const node = t.content.firstChild;
571
+ return flag === 2 ? node.firstChild : node;
576
572
  }
577
573
  function template(html, flag) {
578
574
  let node;
@@ -581,8 +577,7 @@ function template(html, flag) {
581
577
  return fn;
582
578
  }
583
579
  function delegateEvents(eventNames) {
584
- for (let i = 0, l = eventNames.length; i < l; i++) {
585
- const name = eventNames[i];
580
+ for (const name of eventNames) {
586
581
  if (!delegatedEvents.has(name)) {
587
582
  delegatedEvents.add(name);
588
583
  delegatedContainers.forEach((state, container) => attachDelegatedEvent(name, container, state));
@@ -650,9 +645,10 @@ function dispatchAsInteraction(e, fn) {
650
645
  function getDelegatedRoot(node) {
651
646
  while (node) {
652
647
  if (delegatedContainers.get(node)?.roots) return node;
653
- node = node._$host || node.parentNode || node.host;
648
+ node = parentOf(node);
654
649
  }
655
650
  }
651
+ const parentOf = node => node._$host || node.parentNode || node.host;
656
652
  function findOwner(target, state) {
657
653
  let node = target;
658
654
  let distance = 0;
@@ -662,7 +658,7 @@ function findOwner(target, state) {
662
658
  distance
663
659
  };
664
660
  distance++;
665
- node = node._$host || node.parentNode || node.host;
661
+ node = parentOf(node);
666
662
  }
667
663
  }
668
664
  function setProperty(node, name, value) {
@@ -1244,7 +1240,7 @@ function trackAssetLoad(entry, adopted) {
1244
1240
  }
1245
1241
  entry.loadState = "pending";
1246
1242
  entry.loadPromise = new Promise(resolve => {
1247
- const settle = state => {
1243
+ const settle = entry.settle = state => {
1248
1244
  entry.loadState = state;
1249
1245
  resolve();
1250
1246
  };
@@ -1356,6 +1352,7 @@ function acquireAsset(descriptor) {
1356
1352
  entry.timer = setTimeout(() => {
1357
1353
  assetRegistry.delete(key);
1358
1354
  entry.element && entry.element.remove();
1355
+ if (entry.loadState === "pending") entry.settle("errored");
1359
1356
  }, ASSET_REMOVAL_GRACE);
1360
1357
  };
1361
1358
  }
@@ -1983,11 +1980,9 @@ function eventHandler(e, container, state) {
1983
1980
  node.host && typeof node.host !== "string" && !node.host._$host && node.contains(e.target) && retarget(node.host);
1984
1981
  return true;
1985
1982
  };
1983
+ const atOwner = () => node === owner || node.parentNode === owner;
1986
1984
  const walkUpTree = () => {
1987
- while (node && handleNode()) {
1988
- if (node === owner || node.parentNode === owner) break;
1989
- node = node._$host || node.parentNode || node.host;
1990
- }
1985
+ while (node && handleNode() && !atOwner()) node = parentOf(node);
1991
1986
  };
1992
1987
  Object.defineProperty(e, "currentTarget", {
1993
1988
  configurable: true,
@@ -1996,7 +1991,7 @@ function eventHandler(e, container, state) {
1996
1991
  }
1997
1992
  });
1998
1993
  if (resumeNode) {
1999
- if (resumeNode === e.target) node = resumeNode._$host || resumeNode.parentNode || resumeNode.host;
1994
+ if (resumeNode === e.target) node = parentOf(resumeNode);
2000
1995
  if (node && node !== owner) walkUpTree();
2001
1996
  } else if (e.composedPath) {
2002
1997
  const path = e.composedPath();
@@ -2010,9 +2005,7 @@ function eventHandler(e, container, state) {
2010
2005
  walkUpTree();
2011
2006
  break;
2012
2007
  }
2013
- if (node === owner || node.parentNode === owner) {
2014
- break;
2015
- }
2008
+ if (atOwner()) break;
2016
2009
  }
2017
2010
  } else walkUpTree();
2018
2011
  }