@solidjs/web 2.0.0-rc.5 → 2.0.0-rc.7

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 (52) hide show
  1. package/dist/server.cjs +122 -38
  2. package/dist/server.dev.cjs +3794 -0
  3. package/dist/server.dev.js +3627 -0
  4. package/dist/server.js +123 -39
  5. package/dist/web.cjs +102 -366
  6. package/dist/{dev.cjs → web.dev.cjs} +153 -376
  7. package/dist/{dev.js → web.dev.js} +155 -374
  8. package/dist/web.js +104 -364
  9. package/frames/dist/client.cjs +11 -3
  10. package/frames/dist/client.dev.cjs +11 -3
  11. package/frames/dist/client.dev.js +11 -3
  12. package/frames/dist/client.js +11 -3
  13. package/frames/dist/server.cjs +320 -53
  14. package/frames/dist/server.dev.cjs +4584 -0
  15. package/frames/dist/server.dev.js +4571 -0
  16. package/frames/dist/server.js +320 -53
  17. package/frames/package.json +10 -0
  18. package/package.json +78 -8
  19. package/serialization/dist/decode.cjs +18 -4
  20. package/serialization/dist/decode.js +18 -4
  21. package/serialization/dist/serialization.cjs +18 -4
  22. package/serialization/dist/serialization.js +18 -4
  23. package/server-functions/dist/client.cjs +27 -16
  24. package/server-functions/dist/client.js +27 -16
  25. package/server-functions/dist/server.cjs +529 -131
  26. package/server-functions/dist/server.dev.cjs +536 -130
  27. package/server-functions/dist/server.dev.js +536 -130
  28. package/server-functions/dist/server.js +529 -131
  29. package/types/client.d.ts +1 -3
  30. package/types/constants.d.ts +3 -1
  31. package/types/frames/frame-client.d.ts +1 -1
  32. package/types/head.d.ts +3 -0
  33. package/types/index.d.ts +18 -7
  34. package/types/index.server.d.ts +31 -9
  35. package/types/render.d.ts +3 -1
  36. package/types/server-functions/flash.d.ts +12 -3
  37. package/types/server-functions/server.d.ts +100 -5
  38. package/types/server-mock.d.ts +43 -7
  39. package/types/server.d.ts +47 -5
  40. package/types-cjs/client.d.cts +1 -3
  41. package/types-cjs/constants.d.cts +3 -1
  42. package/types-cjs/frames/frame-client.d.cts +1 -1
  43. package/types-cjs/head.d.cts +3 -0
  44. package/types-cjs/index.d.cts +18 -7
  45. package/types-cjs/index.server.d.cts +31 -9
  46. package/types-cjs/render.d.cts +3 -1
  47. package/types-cjs/server-functions/flash.d.cts +12 -3
  48. package/types-cjs/server-functions/server.d.cts +100 -5
  49. package/types-cjs/server-mock.d.cts +43 -7
  50. package/types-cjs/server.d.cts +47 -5
  51. package/types/patch-driver.d.ts +0 -3
  52. package/types-cjs/patch-driver.d.cts +0 -3
@@ -101,6 +101,8 @@ const ContainerTracePlugin = {
101
101
  }
102
102
  };
103
103
 
104
+ const COMPOSED_BODY_FRAMING = /*#__PURE__*/new Set(["content-length", "content-encoding", "transfer-encoding"]);
105
+
104
106
  setContainerTraceStreamMint(iterable => {
105
107
  const stream = seroval.createStream();
106
108
  (async () => {
@@ -291,6 +293,18 @@ const ERROR_HEADER = "X-Server-Function-Error";
291
293
  const BODY_FORMAT_HEADER = "X-Server-Function-Format";
292
294
  const REDIRECT_HEADER = "X-Server-Function-Redirect";
293
295
  const SINGLE_FLIGHT_HEADER = "X-Single-Flight";
296
+ const BodyFormat = {
297
+ Serialized: "0",
298
+ String: "1",
299
+ FormData: "2",
300
+ URLSearchParams: "3",
301
+ Blob: "4",
302
+ File: "5",
303
+ ArrayBuffer: "6",
304
+ Uint8Array: "7",
305
+ Json: "8",
306
+ Void: "9"
307
+ };
294
308
  function createChunk(data) {
295
309
  const encoder = new TextEncoder();
296
310
  const encodeData = encoder.encode(data);
@@ -426,12 +440,24 @@ function classifyHeadTag(desc) {
426
440
  resource: false
427
441
  };
428
442
  }
443
+ function qualifierValue(name, value) {
444
+ if (value == null || value === false) return null;
445
+ if (name === "imagesrcset" || name === "imagesizes") return typeof value === "string" && value !== "" ? value : null;
446
+ const v = value === true ? "" : String(value);
447
+ if (name === "as") return asciiLowerCase(v);
448
+ if (name !== "crossorigin") return v;
449
+ return v.length === 15 && v.toLowerCase() === "use-credentials" ? v.toLowerCase() : "anonymous";
450
+ }
451
+ function asciiLowerCase(value) {
452
+ return value.replace(/[A-Z]/g, c => String.fromCharCode(c.charCodeAt(0) + 32));
453
+ }
429
454
  function resourceIdentity(tag, props) {
430
- let id = "res:" + tag + ":" + (props.rel || "") + ":" + (props.href || props.src || "");
455
+ const url = String(props.href || props.src || "");
456
+ let id = "res:" + tag + ":" + (props.rel || "") + ":" + url.length + ":" + url;
431
457
  for (let i = 0; i < RESOURCE_QUALIFIERS.length; i++) {
432
458
  const q = RESOURCE_QUALIFIERS[i];
433
- const value = props[q];
434
- if (value != null) id += ":" + q + "=" + (value === true ? "" : value);
459
+ const value = qualifierValue(q, props[q]);
460
+ if (value !== null) id += ":" + q + "=" + value.length + ":" + value;
435
461
  }
436
462
  return id;
437
463
  }
@@ -505,12 +531,20 @@ function resolveAssets(moduleUrl, manifest) {
505
531
  if (e.preloads) {
506
532
  for (let i = 0; i < e.preloads.length; i++) {
507
533
  const link = e.preloads[i];
508
- if (!link || typeof link.href !== "string" || !link.href) continue;
534
+ const href = link && typeof link.href === "string" && link.href;
535
+ const srcset = link && typeof link.imagesrcset === "string" && link.imagesrcset;
536
+ if (!href && !srcset) continue;
509
537
  if (!preloads) preloads = [];
510
- preloads.push({
538
+ if (href) preloads.push({
511
539
  ...link,
512
- href: joinAssetPath(base, link.href)
513
- });
540
+ href: joinAssetPath(base, href)
541
+ });else {
542
+ const {
543
+ href: bad,
544
+ ...rest
545
+ } = link;
546
+ preloads.push(rest);
547
+ }
514
548
  }
515
549
  }
516
550
  if (e.imports) for (let i = 0; i < e.imports.length; i++) walk(e.imports[i]);
@@ -642,9 +676,13 @@ function isCssUrl(url) {
642
676
  const q = url.search(/[?#]/);
643
677
  return (q === -1 ? url : url.slice(0, q)).endsWith(".css");
644
678
  }
645
- const PRELOAD_LINK_ATTRIBUTES = ["type", "crossorigin", "integrity", "referrerpolicy", "fetchpriority", "media"];
679
+ const RESPONSIVE_ATTRIBUTES = ["imagesrcset", "imagesizes"];
680
+ function isSetAttr(value) {
681
+ return value != null && value !== false && value !== "";
682
+ }
683
+ const PRELOAD_LINK_ATTRIBUTES = ["type", "crossorigin", "integrity", "referrerpolicy", "fetchpriority", "media", "imagesrcset", "imagesizes"];
646
684
  function registerPreloadLink(tracking, headRegistry, link, nonce) {
647
- if (!link || typeof link !== "object" || typeof link.href !== "string" || !link.href) {
685
+ if (!link || typeof link !== "object") {
648
686
  return null;
649
687
  }
650
688
  if (typeof link.as !== "string") {
@@ -665,13 +703,35 @@ function registerPreloadLink(tracking, headRegistry, link, nonce) {
665
703
  default:
666
704
  return null;
667
705
  }
706
+ const responsive = as === "image";
707
+ let srcset = null;
708
+ let sizes = null;
709
+ if (responsive) {
710
+ for (const name of RESPONSIVE_ATTRIBUTES) {
711
+ const value = link[name];
712
+ if (!isSetAttr(value)) continue;
713
+ if (typeof value !== "string") {
714
+ continue;
715
+ }
716
+ if (name === "imagesrcset") srcset = value;else sizes = value;
717
+ }
718
+ }
719
+ const href = typeof link.href === "string" && link.href ? link.href : null;
720
+ if (!href && !srcset) {
721
+ return null;
722
+ }
668
723
  const props = {
669
- rel: "preload",
670
- href: link.href,
671
- as
724
+ rel: "preload"
672
725
  };
726
+ if (href) props.href = href;
727
+ props.as = as;
673
728
  for (let i = 0; i < PRELOAD_LINK_ATTRIBUTES.length; i++) {
674
729
  const name = PRELOAD_LINK_ATTRIBUTES[i];
730
+ if (RESPONSIVE_ATTRIBUTES.indexOf(name) !== -1) {
731
+ const value = name === "imagesrcset" ? srcset : sizes;
732
+ if (value !== null) props[name] = value;
733
+ continue;
734
+ }
675
735
  const value = link[name];
676
736
  if (value == null || value === false) continue;
677
737
  props[name] = value === true ? "" : String(value);
@@ -1036,9 +1096,6 @@ function normalizeNonce(nonce) {
1036
1096
  styleAttr: typeof style === "string" && style ? ` nonce="${escape(style, true)}"` : ""
1037
1097
  };
1038
1098
  }
1039
- function asciiLowerCase(value) {
1040
- return value.replace(/[A-Z]/g, c => String.fromCharCode(c.charCodeAt(0) + 32));
1041
- }
1042
1099
  function hasNonceProp(props) {
1043
1100
  for (const name in props) if (name.length === 5 && asciiLowerCase(name) === "nonce" && props[name] != null) return true;
1044
1101
  return false;
@@ -1119,6 +1176,7 @@ function renderToStream(code, options = {}) {
1119
1176
  onHead
1120
1177
  } = options;
1121
1178
  const nonce = normalizeNonce(options.nonce);
1179
+ const requestEvent = peekRequestEvent();
1122
1180
  let dispose;
1123
1181
  let dead = false;
1124
1182
  const abandon = () => {
@@ -1220,6 +1278,7 @@ function renderToStream(code, options = {}) {
1220
1278
  };
1221
1279
  const onDone = () => {
1222
1280
  writeTasks();
1281
+ lastBlockingSize = blockingPromises.size;
1223
1282
  doShell();
1224
1283
  onCompleteAll && onCompleteAll({
1225
1284
  write(v) {
@@ -1609,9 +1668,9 @@ function renderToStream(code, options = {}) {
1609
1668
  function doShell() {
1610
1669
  if (shellCompleted) return;
1611
1670
  solidJs.sharedConfig.context = context;
1612
- const blockersBefore = blockingPromises.size;
1671
+ if (blockingPromises.size !== lastBlockingSize) return;
1613
1672
  if (!resolveRootHoles()) return;
1614
- if (blockingPromises.size !== blockersBefore) return;
1673
+ if (blockingPromises.size !== lastBlockingSize) return;
1615
1674
  if (!headShellReady(headRegistry, p => blockingPromises.add(p))) return;
1616
1675
  headStyles = new Set();
1617
1676
  for (const url of tracking.emittedAssets) {
@@ -1639,7 +1698,7 @@ function renderToStream(code, options = {}) {
1639
1698
  let lastBlockingSize = -1;
1640
1699
  let lastRegistrySize = -1;
1641
1700
  let drainTurn = 0;
1642
- const scheduleFlush = fn => {
1701
+ const scheduleFlush = (fn, awaited) => {
1643
1702
  const attempt = () => {
1644
1703
  flushStubBatch();
1645
1704
  if (registry.size !== lastRegistrySize || drainTurn++ < MIN_DRAIN_TURNS) {
@@ -1650,8 +1709,8 @@ function renderToStream(code, options = {}) {
1650
1709
  }
1651
1710
  fn();
1652
1711
  };
1653
- const progressed = blockingPromises.size !== lastBlockingSize;
1654
- lastBlockingSize = blockingPromises.size;
1712
+ const progressed = awaited !== lastBlockingSize;
1713
+ lastBlockingSize = awaited;
1655
1714
  lastRegistrySize = -1;
1656
1715
  drainTurn = 0;
1657
1716
  progressed ? queue(attempt) : setTimeout(attempt);
@@ -1668,7 +1727,7 @@ function renderToStream(code, options = {}) {
1668
1727
  let resolve;
1669
1728
  const p = new Promise(r => resolve = r);
1670
1729
  function flush() {
1671
- allSettled(blockingPromises).then(() => {
1730
+ allSettled(blockingPromises).then(awaited => {
1672
1731
  scheduleFlush(() => {
1673
1732
  if (dead) return resolve();
1674
1733
  try {
@@ -1706,7 +1765,7 @@ function renderToStream(code, options = {}) {
1706
1765
  dispose();
1707
1766
  writable.end();
1708
1767
  } else flushEnd();
1709
- });
1768
+ }, awaited);
1710
1769
  });
1711
1770
  }
1712
1771
  flush();
@@ -1714,8 +1773,12 @@ function renderToStream(code, options = {}) {
1714
1773
  };
1715
1774
  return {
1716
1775
  then(onFulfilled, onRejected) {
1776
+ const freezeHead = () => {
1777
+ if (requestEvent && requestEvent.response) commitResponseStub(requestEvent.response);
1778
+ };
1717
1779
  const p = new Promise(resolve => {
1718
1780
  function complete() {
1781
+ freezeHead();
1719
1782
  dispose();
1720
1783
  resolve(tmp);
1721
1784
  }
@@ -1727,17 +1790,16 @@ function renderToStream(code, options = {}) {
1727
1790
  };
1728
1791
  } else onCompleteAll = complete;
1729
1792
  function flush() {
1730
- allSettled(blockingPromises).then(() => {
1793
+ allSettled(blockingPromises).then(awaited => {
1731
1794
  scheduleFlush(() => {
1732
1795
  try {
1733
- const blockersBefore = blockingPromises.size;
1734
- if (!resolveRootHoles() || blockingPromises.size !== blockersBefore || !headShellReady(headRegistry, p => blockingPromises.add(p))) return flush();
1796
+ if (blockingPromises.size !== lastBlockingSize || !resolveRootHoles() || blockingPromises.size !== lastBlockingSize || !headShellReady(headRegistry, p => blockingPromises.add(p))) return flush();
1735
1797
  } catch (err) {
1736
1798
  failRender(err);
1737
1799
  return resolve(tmp);
1738
1800
  }
1739
1801
  queue(flushEnd);
1740
- });
1802
+ }, awaited);
1741
1803
  });
1742
1804
  }
1743
1805
  flush();
@@ -1747,7 +1809,7 @@ function renderToStream(code, options = {}) {
1747
1809
  pipe(w) {
1748
1810
  claimConsumer("pipe");
1749
1811
  function flush() {
1750
- allSettled(blockingPromises).then(() => {
1812
+ allSettled(blockingPromises).then(awaited => {
1751
1813
  scheduleFlush(() => {
1752
1814
  if (dead) return;
1753
1815
  try {
@@ -1769,7 +1831,7 @@ function renderToStream(code, options = {}) {
1769
1831
  dispose();
1770
1832
  writable.end();
1771
1833
  } else flushEnd();
1772
- });
1834
+ }, awaited);
1773
1835
  });
1774
1836
  }
1775
1837
  flush();
@@ -2541,7 +2603,7 @@ function allSettled(promises) {
2541
2603
  let size = promises.size;
2542
2604
  return Promise.allSettled(promises).then(() => {
2543
2605
  if (promises.size !== size) return allSettled(promises);
2544
- return;
2606
+ return size;
2545
2607
  });
2546
2608
  }
2547
2609
  function assembleDocument(html, emittedAssets, preloadLinks, inlineStyles, scripts, nonce, headTags, onHead) {
@@ -2791,12 +2853,195 @@ function resolveSSRSync(node) {
2791
2853
  if (!res.h.length) return res.t[0];
2792
2854
  throw new Error("This value cannot be rendered synchronously. Are you missing a boundary?");
2793
2855
  }
2794
- /*#__PURE__*/new Set([ERROR_HEADER, BODY_FORMAT_HEADER, SINGLE_FLIGHT_HEADER, REVALIDATE_HEADER, REDIRECT_HEADER, "Location"].map(header => header.toLowerCase()));
2856
+ const RequestContext = Symbol.for("solid.RequestContext");
2857
+ function peekRequestEvent() {
2858
+ const store = globalThis[RequestContext];
2859
+ return store ? store.getStore() : undefined;
2860
+ }
2861
+ function reportLostHeaderWrite(method, name) {
2862
+ const message = `Response header write dropped: headers.${method}(${JSON.stringify(String(name))}) ` + "ran after the response head was sent. Write headers before the shell flushes " + "(or before the handler returns).";
2863
+ console.error(message);
2864
+ }
2865
+ function commitResponseStub(stub, {
2866
+ allowLateLocation = false
2867
+ } = {}) {
2868
+ if (!stub || stub.committed) return stub;
2869
+ stub.committed = true;
2870
+ const headers = stub.headers;
2871
+ if (!headers || typeof headers.set !== "function") return stub;
2872
+ for (const method of ["set", "append", "delete"]) {
2873
+ const original = headers[method].bind(headers);
2874
+ headers[method] = function (name, ...rest) {
2875
+ if (allowLateLocation && method === "set" && String(name).toLowerCase() === "location") {
2876
+ return original(name, ...rest);
2877
+ }
2878
+ reportLostHeaderWrite(method, name);
2879
+ };
2880
+ }
2881
+ return stub;
2882
+ }
2883
+ /*#__PURE__*/new Set([ERROR_HEADER, BODY_FORMAT_HEADER, SINGLE_FLIGHT_HEADER, REVALIDATE_HEADER, REDIRECT_HEADER, "Location",
2884
+ ...COMPOSED_BODY_FRAMING].map(header => header.toLowerCase()));
2795
2885
 
2886
+ function scopeDeferredResult(value, scope) {
2887
+ const bound = bindDeferredBody(value, scope);
2888
+ if (bound !== value || value === null || typeof value !== "object") return bound;
2889
+ return scopeDeferredContents(value, scope);
2890
+ }
2891
+ class ScopeFrame {
2892
+ constructor(value, next, keys, descriptors) {
2893
+ this.value = value;
2894
+ this.next = next;
2895
+ this.keys = keys;
2896
+ this.descriptors = descriptors;
2897
+ this.i = 0;
2898
+ this.changed = false;
2899
+ }
2900
+ }
2901
+ function enterScopeCarrier(value, state) {
2902
+ if (value === null || typeof value !== "object" && typeof value !== "function") return value;
2903
+ if (state.seen.has(value)) {
2904
+ state.cyclic.add(value);
2905
+ return state.seen.get(value);
2906
+ }
2907
+ const bound = bindDeferredBody(value, state.scope);
2908
+ if (bound !== value) {
2909
+ state.seen.set(value, bound);
2910
+ return bound;
2911
+ }
2912
+ if (typeof value !== "object") return value;
2913
+ if (Array.isArray(value)) {
2914
+ if (Object.isFrozen(value)) {
2915
+ state.seen.set(value, value);
2916
+ return value;
2917
+ }
2918
+ const next = value.slice();
2919
+ state.seen.set(value, next);
2920
+ return new ScopeFrame(value, next, null, null);
2921
+ }
2922
+ const prototype = Object.getPrototypeOf(value);
2923
+ if (prototype !== Object.prototype && prototype !== null || Object.isFrozen(value)) {
2924
+ state.seen.set(value, value);
2925
+ return value;
2926
+ }
2927
+ const descriptors = Object.getOwnPropertyDescriptors(value);
2928
+ const next = Object.create(prototype, descriptors);
2929
+ state.seen.set(value, next);
2930
+ return new ScopeFrame(value, next, Object.keys(value), descriptors);
2931
+ }
2932
+ function scopeDeferredContents(root, scope) {
2933
+ const state = {
2934
+ seen: new Map(),
2935
+ cyclic: new Set(),
2936
+ scope
2937
+ };
2938
+ const entered = enterScopeCarrier(root, state);
2939
+ if (!(entered instanceof ScopeFrame)) return entered;
2940
+ const stack = [entered];
2941
+ let delivered = NOTHING;
2942
+ for (;;) {
2943
+ const top = stack[stack.length - 1];
2944
+ const length = top.keys ? top.keys.length : top.value.length;
2945
+ let pushed = null;
2946
+ while (top.i < length) {
2947
+ const i = top.i;
2948
+ let original;
2949
+ let writable = true;
2950
+ if (top.keys) {
2951
+ const descriptor = top.descriptors[top.keys[i]];
2952
+ writable = "value" in descriptor && descriptor.writable === true;
2953
+ original = writable ? descriptor.value : undefined;
2954
+ } else {
2955
+ original = top.value[i];
2956
+ }
2957
+ if (!writable) {
2958
+ top.i++;
2959
+ continue;
2960
+ }
2961
+ let bound;
2962
+ if (delivered !== NOTHING) {
2963
+ bound = delivered;
2964
+ delivered = NOTHING;
2965
+ } else {
2966
+ bound = enterScopeCarrier(original, state);
2967
+ if (bound instanceof ScopeFrame) {
2968
+ pushed = bound;
2969
+ break;
2970
+ }
2971
+ }
2972
+ if (bound !== original) {
2973
+ if (top.keys) top.next[top.keys[i]] = bound;else top.next[i] = bound;
2974
+ top.changed = true;
2975
+ }
2976
+ top.i++;
2977
+ }
2978
+ if (pushed !== null) {
2979
+ stack.push(pushed);
2980
+ continue;
2981
+ }
2982
+ stack.pop();
2983
+ let out;
2984
+ if (top.changed || state.cyclic.has(top.value)) {
2985
+ out = top.next;
2986
+ } else {
2987
+ state.seen.set(top.value, top.value);
2988
+ out = top.value;
2989
+ }
2990
+ if (stack.length === 0) return out;
2991
+ delivered = out;
2992
+ }
2993
+ }
2994
+ function bindDeferredBody(value, scope) {
2995
+ if (value === null || typeof value !== "object" && typeof value !== "function") return value;
2996
+ const promised = scope(() => nativePromise(value));
2997
+ if (promised) {
2998
+ return promised.then(result => scope(() => scopeDeferredResult(result, scope)));
2999
+ }
3000
+ if (typeof ReadableStream !== "undefined" && value instanceof ReadableStream) {
3001
+ let reader;
3002
+ return new ReadableStream({
3003
+ async pull(controller) {
3004
+ try {
3005
+ const step = await scope(() => {
3006
+ if (!reader) reader = value.getReader();
3007
+ return reader.read();
3008
+ });
3009
+ if (step.done) controller.close();else controller.enqueue(step.value);
3010
+ } catch (error) {
3011
+ controller.error(error);
3012
+ }
3013
+ },
3014
+ cancel(reason) {
3015
+ return scope(() => reader ? reader.cancel(reason) : value.cancel(reason));
3016
+ }
3017
+ }, {
3018
+ highWaterMark: 0
3019
+ });
3020
+ }
3021
+ const scopedIterator = symbol => ({
3022
+ [symbol]() {
3023
+ const iterator = scope(() => value[symbol]());
3024
+ return new Proxy(iterator, {
3025
+ get(target, property) {
3026
+ const member = Reflect.get(target, property, target);
3027
+ return typeof member === "function" && (property === "next" || property === "return" || property === "throw") ? (...args) => scope(() => member.apply(target, args)) : member;
3028
+ }
3029
+ });
3030
+ }
3031
+ });
3032
+ if (typeof value[Symbol.asyncIterator] === "function") {
3033
+ return scopedIterator(Symbol.asyncIterator);
3034
+ }
3035
+ if (typeof value[Symbol.iterator] === "function" && !Array.isArray(value) && !(value instanceof Map) && !(value instanceof Set) && !ArrayBuffer.isView(value)) {
3036
+ return scopedIterator(Symbol.iterator);
3037
+ }
3038
+ return value;
3039
+ }
2796
3040
  const INVOCATIONS = new WeakMap();
2797
3041
  function getEventServerFunctionInvocation(event) {
2798
3042
  return event && INVOCATIONS.get(event);
2799
3043
  }
3044
+ new Set(Object.values(BodyFormat));
2800
3045
  function guardFailures(value, state) {
2801
3046
  if (!state) state = {
2802
3047
  seen: new WeakMap(),
@@ -2857,14 +3102,11 @@ function guardFailures(value, state) {
2857
3102
  top.next.add(guarded);
2858
3103
  if (guarded !== original) top.changed = true;
2859
3104
  } else if (guarded !== original || top.accessorRead === i) {
2860
- Object.defineProperty(top.next, items[i], top.accessorRead === i ? {
2861
- enumerable: true,
2862
- configurable: true,
3105
+ Object.defineProperty(top.next, items[i], {
3106
+ value: guarded,
2863
3107
  writable: true,
2864
- value: guarded
2865
- } : {
2866
- ...top.descriptors[items[i]],
2867
- value: guarded
3108
+ configurable: true,
3109
+ enumerable: top.descriptors[items[i]].enumerable
2868
3110
  });
2869
3111
  top.changed = true;
2870
3112
  }
@@ -2899,6 +3141,9 @@ class Frame {
2899
3141
  this.pendingKey = undefined;
2900
3142
  }
2901
3143
  }
3144
+ function guardOperation(state, run) {
3145
+ return state.scope ? state.scope(run) : run();
3146
+ }
2902
3147
  function enterGuard(value, state) {
2903
3148
  if (value === null || typeof value !== "object") return value;
2904
3149
  if (state.seen.has(value)) {
@@ -2913,7 +3158,7 @@ function enterGuard(value, state) {
2913
3158
  if (finished) return;
2914
3159
  finished = true;
2915
3160
  try {
2916
- const cancelled = reader ? reader.cancel() : value.cancel();
3161
+ const cancelled = guardOperation(state, () => reader ? reader.cancel() : value.cancel());
2917
3162
  if (cancelled && typeof cancelled.then === "function") cancelled.then(undefined, () => {});
2918
3163
  } catch {}
2919
3164
  };
@@ -2925,19 +3170,19 @@ function enterGuard(value, state) {
2925
3170
  controller.close();
2926
3171
  return;
2927
3172
  }
2928
- if (!reader) reader = value.getReader();
3173
+ if (!reader) reader = guardOperation(state, () => value.getReader());
2929
3174
  const {
2930
3175
  done,
2931
3176
  value: chunk
2932
- } = await reader.read();
2933
- done ? controller.close() : controller.enqueue(guardFailures(chunk, state));
3177
+ } = await guardOperation(state, () => reader.read());
3178
+ done ? controller.close() : controller.enqueue(guardOperation(state, () => guardFailures(chunk, state)));
2934
3179
  } catch (error) {
2935
- controller.error(sanitizeServerError(error));
3180
+ controller.error(guardOperation(state, () => sanitizeServerError(error)));
2936
3181
  }
2937
3182
  },
2938
3183
  cancel(reason) {
2939
3184
  finished = true;
2940
- return reader ? reader.cancel(reason) : value.cancel(reason);
3185
+ return guardOperation(state, () => reader ? reader.cancel(reason) : value.cancel(reason));
2941
3186
  }
2942
3187
  });
2943
3188
  if (gate) gate.onOpen(close);
@@ -2945,9 +3190,10 @@ function enterGuard(value, state) {
2945
3190
  return guardedStream;
2946
3191
  }
2947
3192
  if (typeof value.then === "function") {
2948
- const guardedPromise = Promise.resolve(value).then(resolved => guardFailures(resolved, state), error => {
2949
- throw sanitizeServerError(error);
3193
+ const guardedPromise = Promise.resolve(value).then(resolved => guardOperation(state, () => guardFailures(resolved, state)), error => {
3194
+ throw guardOperation(state, () => sanitizeServerError(error));
2950
3195
  });
3196
+ guardedPromise.catch(() => {});
2951
3197
  state.seen.set(value, guardedPromise);
2952
3198
  return guardedPromise;
2953
3199
  }
@@ -2956,13 +3202,13 @@ function enterGuard(value, state) {
2956
3202
  const gate = state.gate;
2957
3203
  const guardedIterable = {
2958
3204
  [Symbol.asyncIterator]() {
2959
- const iterator = source[Symbol.asyncIterator]();
3205
+ const iterator = guardOperation(state, () => source[Symbol.asyncIterator]());
2960
3206
  let finished = false;
2961
3207
  const close = () => {
2962
3208
  if (finished) return;
2963
3209
  finished = true;
2964
3210
  try {
2965
- const returned = iterator.return && iterator.return();
3211
+ const returned = iterator.return && guardOperation(state, () => iterator.return());
2966
3212
  if (returned && typeof returned.then === "function") returned.then(undefined, () => {});
2967
3213
  } catch {}
2968
3214
  };
@@ -2970,17 +3216,17 @@ function enterGuard(value, state) {
2970
3216
  const step = () => finished ? Promise.resolve({
2971
3217
  done: true,
2972
3218
  value: undefined
2973
- }) : iterator.next().then(step => {
3219
+ }) : guardOperation(state, () => iterator.next()).then(step => {
2974
3220
  if (step.done) {
2975
3221
  finished = true;
2976
3222
  return step;
2977
3223
  }
2978
3224
  return {
2979
3225
  done: false,
2980
- value: guardFailures(step.value, state)
3226
+ value: guardOperation(state, () => guardFailures(step.value, state))
2981
3227
  };
2982
3228
  }, error => {
2983
- throw sanitizeServerError(error);
3229
+ throw guardOperation(state, () => sanitizeServerError(error));
2984
3230
  });
2985
3231
  return {
2986
3232
  next: () => finished || !gate || gate.wantsMore() ? step() : gate.awaitDemand().then(step),
@@ -2997,6 +3243,11 @@ function enterGuard(value, state) {
2997
3243
  state.seen.set(value, guardedIterable);
2998
3244
  return guardedIterable;
2999
3245
  }
3246
+ if (state.scope && typeof value[Symbol.iterator] === "function" && !Array.isArray(value) && !(value instanceof Map) && !(value instanceof Set) && !ArrayBuffer.isView(value)) {
3247
+ const scopedIterable = scopeDeferredResult(value, state.scope);
3248
+ state.seen.set(value, scopedIterable);
3249
+ return scopedIterable;
3250
+ }
3000
3251
  if (Array.isArray(value)) {
3001
3252
  const next = value.slice();
3002
3253
  state.seen.set(value, next);
@@ -3015,14 +3266,22 @@ function enterGuard(value, state) {
3015
3266
  return new Frame(SET, value, next, [...value], null);
3016
3267
  }
3017
3268
  const prototype = Object.getPrototypeOf(value);
3018
- if (prototype !== Object.prototype && prototype !== null) {
3269
+ if (prototype !== Object.prototype && prototype !== null && !(value instanceof Error)) {
3019
3270
  state.seen.set(value, value);
3020
3271
  return value;
3021
3272
  }
3022
3273
  const descriptors = Object.getOwnPropertyDescriptors(value);
3274
+ for (const key of Object.keys(descriptors)) {
3275
+ descriptors[key].configurable = true;
3276
+ if ("value" in descriptors[key]) descriptors[key].writable = true;
3277
+ }
3023
3278
  const next = Object.create(prototype, descriptors);
3024
3279
  state.seen.set(value, next);
3025
- return new Frame(OBJECT, value, next, Object.keys(descriptors), descriptors);
3280
+ const children = !(value instanceof Error) ? Object.keys(value) : Object.getOwnPropertyNames(value).filter(key => {
3281
+ const descriptor = descriptors[key];
3282
+ return descriptor.enumerable || "value" in descriptor;
3283
+ });
3284
+ return new Frame(OBJECT, value, next, children, descriptors);
3026
3285
  }
3027
3286
  function keepGuarded(value, next, changed, state) {
3028
3287
  if (changed || state.cyclic.has(value)) return next;
@@ -3034,6 +3293,12 @@ function sanitizeServerError(value) {
3034
3293
  if (isSafeError(value)) return value;
3035
3294
  return new Error(GENERIC_SERVER_ERROR_MESSAGE);
3036
3295
  }
3296
+ function nativePromise(value) {
3297
+ if (value instanceof Promise) return value;
3298
+ try {
3299
+ if (Object.prototype.toString.call(value) === "[object Promise]") return Promise.prototype.then.call(value, value => value);
3300
+ } catch {}
3301
+ }
3037
3302
 
3038
3303
  const FRAME_STREAM_HEADER = "X-Frame-Stream";
3039
3304
  function isFrameStreamResponse(response) {
@@ -3104,9 +3369,11 @@ function serverComponentScope(render) {
3104
3369
  return solidJs.runInServerComponentScope ? solidJs.runInServerComponentScope(render) : render();
3105
3370
  }
3106
3371
  function wirePreload(entry) {
3107
- return {
3372
+ return entry.href ? {
3108
3373
  href: entry.href,
3109
3374
  attrs: entry.attrs
3375
+ } : {
3376
+ attrs: entry.attrs
3110
3377
  };
3111
3378
  }
3112
3379
  const SERVER_COMPONENT_BOOTSTRAP_EXPR = "(self._$SC||(self._$SC={c:{},a:{},r(i,a){a&&(this.a[a]=i,this.reg&&this.reg(a,i));return this.c[i]||(this.c[i]=(p,b)=>self._$SC.impl(i,p,b))}}))";