@solidjs/web 2.0.0-rc.6 → 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 (50) hide show
  1. package/dist/server.cjs +105 -35
  2. package/dist/server.dev.cjs +3794 -0
  3. package/dist/server.dev.js +3627 -0
  4. package/dist/server.js +106 -36
  5. package/dist/web.cjs +39 -385
  6. package/dist/{dev.cjs → web.dev.cjs} +91 -396
  7. package/dist/{dev.js → web.dev.js} +93 -393
  8. package/dist/web.js +41 -382
  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 +234 -32
  14. package/frames/dist/server.dev.cjs +4584 -0
  15. package/frames/dist/server.dev.js +4571 -0
  16. package/frames/dist/server.js +234 -32
  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 +13 -14
  24. package/server-functions/dist/client.js +13 -14
  25. package/server-functions/dist/server.cjs +331 -83
  26. package/server-functions/dist/server.dev.cjs +338 -82
  27. package/server-functions/dist/server.dev.js +338 -82
  28. package/server-functions/dist/server.js +331 -83
  29. package/types/client.d.ts +0 -3
  30. package/types/frames/frame-client.d.ts +1 -1
  31. package/types/head.d.ts +3 -0
  32. package/types/index.d.ts +18 -7
  33. package/types/index.server.d.ts +31 -9
  34. package/types/render.d.ts +3 -1
  35. package/types/server-functions/flash.d.ts +12 -3
  36. package/types/server-functions/server.d.ts +27 -3
  37. package/types/server-mock.d.ts +43 -7
  38. package/types/server.d.ts +47 -5
  39. package/types-cjs/client.d.cts +0 -3
  40. package/types-cjs/frames/frame-client.d.cts +1 -1
  41. package/types-cjs/head.d.cts +3 -0
  42. package/types-cjs/index.d.cts +18 -7
  43. package/types-cjs/index.server.d.cts +31 -9
  44. package/types-cjs/render.d.cts +3 -1
  45. package/types-cjs/server-functions/flash.d.cts +12 -3
  46. package/types-cjs/server-functions/server.d.cts +27 -3
  47. package/types-cjs/server-mock.d.cts +43 -7
  48. package/types-cjs/server.d.cts +47 -5
  49. package/types/patch-driver.d.ts +0 -3
  50. package/types-cjs/patch-driver.d.cts +0 -3
@@ -293,6 +293,18 @@ const ERROR_HEADER = "X-Server-Function-Error";
293
293
  const BODY_FORMAT_HEADER = "X-Server-Function-Format";
294
294
  const REDIRECT_HEADER = "X-Server-Function-Redirect";
295
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
+ };
296
308
  function createChunk(data) {
297
309
  const encoder = new TextEncoder();
298
310
  const encodeData = encoder.encode(data);
@@ -428,12 +440,24 @@ function classifyHeadTag(desc) {
428
440
  resource: false
429
441
  };
430
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
+ }
431
454
  function resourceIdentity(tag, props) {
432
- 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;
433
457
  for (let i = 0; i < RESOURCE_QUALIFIERS.length; i++) {
434
458
  const q = RESOURCE_QUALIFIERS[i];
435
- const value = props[q];
436
- if (value != null) id += ":" + q + "=" + (value === true ? "" : value);
459
+ const value = qualifierValue(q, props[q]);
460
+ if (value !== null) id += ":" + q + "=" + value.length + ":" + value;
437
461
  }
438
462
  return id;
439
463
  }
@@ -507,12 +531,20 @@ function resolveAssets(moduleUrl, manifest) {
507
531
  if (e.preloads) {
508
532
  for (let i = 0; i < e.preloads.length; i++) {
509
533
  const link = e.preloads[i];
510
- 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;
511
537
  if (!preloads) preloads = [];
512
- preloads.push({
538
+ if (href) preloads.push({
513
539
  ...link,
514
- href: joinAssetPath(base, link.href)
515
- });
540
+ href: joinAssetPath(base, href)
541
+ });else {
542
+ const {
543
+ href: bad,
544
+ ...rest
545
+ } = link;
546
+ preloads.push(rest);
547
+ }
516
548
  }
517
549
  }
518
550
  if (e.imports) for (let i = 0; i < e.imports.length; i++) walk(e.imports[i]);
@@ -644,9 +676,13 @@ function isCssUrl(url) {
644
676
  const q = url.search(/[?#]/);
645
677
  return (q === -1 ? url : url.slice(0, q)).endsWith(".css");
646
678
  }
647
- 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"];
648
684
  function registerPreloadLink(tracking, headRegistry, link, nonce) {
649
- if (!link || typeof link !== "object" || typeof link.href !== "string" || !link.href) {
685
+ if (!link || typeof link !== "object") {
650
686
  return null;
651
687
  }
652
688
  if (typeof link.as !== "string") {
@@ -667,13 +703,35 @@ function registerPreloadLink(tracking, headRegistry, link, nonce) {
667
703
  default:
668
704
  return null;
669
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
+ }
670
723
  const props = {
671
- rel: "preload",
672
- href: link.href,
673
- as
724
+ rel: "preload"
674
725
  };
726
+ if (href) props.href = href;
727
+ props.as = as;
675
728
  for (let i = 0; i < PRELOAD_LINK_ATTRIBUTES.length; i++) {
676
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
+ }
677
735
  const value = link[name];
678
736
  if (value == null || value === false) continue;
679
737
  props[name] = value === true ? "" : String(value);
@@ -1038,9 +1096,6 @@ function normalizeNonce(nonce) {
1038
1096
  styleAttr: typeof style === "string" && style ? ` nonce="${escape(style, true)}"` : ""
1039
1097
  };
1040
1098
  }
1041
- function asciiLowerCase(value) {
1042
- return value.replace(/[A-Z]/g, c => String.fromCharCode(c.charCodeAt(0) + 32));
1043
- }
1044
1099
  function hasNonceProp(props) {
1045
1100
  for (const name in props) if (name.length === 5 && asciiLowerCase(name) === "nonce" && props[name] != null) return true;
1046
1101
  return false;
@@ -1121,6 +1176,7 @@ function renderToStream(code, options = {}) {
1121
1176
  onHead
1122
1177
  } = options;
1123
1178
  const nonce = normalizeNonce(options.nonce);
1179
+ const requestEvent = peekRequestEvent();
1124
1180
  let dispose;
1125
1181
  let dead = false;
1126
1182
  const abandon = () => {
@@ -1222,6 +1278,7 @@ function renderToStream(code, options = {}) {
1222
1278
  };
1223
1279
  const onDone = () => {
1224
1280
  writeTasks();
1281
+ lastBlockingSize = blockingPromises.size;
1225
1282
  doShell();
1226
1283
  onCompleteAll && onCompleteAll({
1227
1284
  write(v) {
@@ -1611,9 +1668,9 @@ function renderToStream(code, options = {}) {
1611
1668
  function doShell() {
1612
1669
  if (shellCompleted) return;
1613
1670
  solidJs.sharedConfig.context = context;
1614
- const blockersBefore = blockingPromises.size;
1671
+ if (blockingPromises.size !== lastBlockingSize) return;
1615
1672
  if (!resolveRootHoles()) return;
1616
- if (blockingPromises.size !== blockersBefore) return;
1673
+ if (blockingPromises.size !== lastBlockingSize) return;
1617
1674
  if (!headShellReady(headRegistry, p => blockingPromises.add(p))) return;
1618
1675
  headStyles = new Set();
1619
1676
  for (const url of tracking.emittedAssets) {
@@ -1641,7 +1698,7 @@ function renderToStream(code, options = {}) {
1641
1698
  let lastBlockingSize = -1;
1642
1699
  let lastRegistrySize = -1;
1643
1700
  let drainTurn = 0;
1644
- const scheduleFlush = fn => {
1701
+ const scheduleFlush = (fn, awaited) => {
1645
1702
  const attempt = () => {
1646
1703
  flushStubBatch();
1647
1704
  if (registry.size !== lastRegistrySize || drainTurn++ < MIN_DRAIN_TURNS) {
@@ -1652,8 +1709,8 @@ function renderToStream(code, options = {}) {
1652
1709
  }
1653
1710
  fn();
1654
1711
  };
1655
- const progressed = blockingPromises.size !== lastBlockingSize;
1656
- lastBlockingSize = blockingPromises.size;
1712
+ const progressed = awaited !== lastBlockingSize;
1713
+ lastBlockingSize = awaited;
1657
1714
  lastRegistrySize = -1;
1658
1715
  drainTurn = 0;
1659
1716
  progressed ? queue(attempt) : setTimeout(attempt);
@@ -1670,7 +1727,7 @@ function renderToStream(code, options = {}) {
1670
1727
  let resolve;
1671
1728
  const p = new Promise(r => resolve = r);
1672
1729
  function flush() {
1673
- allSettled(blockingPromises).then(() => {
1730
+ allSettled(blockingPromises).then(awaited => {
1674
1731
  scheduleFlush(() => {
1675
1732
  if (dead) return resolve();
1676
1733
  try {
@@ -1708,7 +1765,7 @@ function renderToStream(code, options = {}) {
1708
1765
  dispose();
1709
1766
  writable.end();
1710
1767
  } else flushEnd();
1711
- });
1768
+ }, awaited);
1712
1769
  });
1713
1770
  }
1714
1771
  flush();
@@ -1716,8 +1773,12 @@ function renderToStream(code, options = {}) {
1716
1773
  };
1717
1774
  return {
1718
1775
  then(onFulfilled, onRejected) {
1776
+ const freezeHead = () => {
1777
+ if (requestEvent && requestEvent.response) commitResponseStub(requestEvent.response);
1778
+ };
1719
1779
  const p = new Promise(resolve => {
1720
1780
  function complete() {
1781
+ freezeHead();
1721
1782
  dispose();
1722
1783
  resolve(tmp);
1723
1784
  }
@@ -1729,17 +1790,16 @@ function renderToStream(code, options = {}) {
1729
1790
  };
1730
1791
  } else onCompleteAll = complete;
1731
1792
  function flush() {
1732
- allSettled(blockingPromises).then(() => {
1793
+ allSettled(blockingPromises).then(awaited => {
1733
1794
  scheduleFlush(() => {
1734
1795
  try {
1735
- const blockersBefore = blockingPromises.size;
1736
- 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();
1737
1797
  } catch (err) {
1738
1798
  failRender(err);
1739
1799
  return resolve(tmp);
1740
1800
  }
1741
1801
  queue(flushEnd);
1742
- });
1802
+ }, awaited);
1743
1803
  });
1744
1804
  }
1745
1805
  flush();
@@ -1749,7 +1809,7 @@ function renderToStream(code, options = {}) {
1749
1809
  pipe(w) {
1750
1810
  claimConsumer("pipe");
1751
1811
  function flush() {
1752
- allSettled(blockingPromises).then(() => {
1812
+ allSettled(blockingPromises).then(awaited => {
1753
1813
  scheduleFlush(() => {
1754
1814
  if (dead) return;
1755
1815
  try {
@@ -1771,7 +1831,7 @@ function renderToStream(code, options = {}) {
1771
1831
  dispose();
1772
1832
  writable.end();
1773
1833
  } else flushEnd();
1774
- });
1834
+ }, awaited);
1775
1835
  });
1776
1836
  }
1777
1837
  flush();
@@ -2543,7 +2603,7 @@ function allSettled(promises) {
2543
2603
  let size = promises.size;
2544
2604
  return Promise.allSettled(promises).then(() => {
2545
2605
  if (promises.size !== size) return allSettled(promises);
2546
- return;
2606
+ return size;
2547
2607
  });
2548
2608
  }
2549
2609
  function assembleDocument(html, emittedAssets, preloadLinks, inlineStyles, scripts, nonce, headTags, onHead) {
@@ -2793,10 +2853,145 @@ function resolveSSRSync(node) {
2793
2853
  if (!res.h.length) return res.t[0];
2794
2854
  throw new Error("This value cannot be rendered synchronously. Are you missing a boundary?");
2795
2855
  }
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
+ }
2796
2883
  /*#__PURE__*/new Set([ERROR_HEADER, BODY_FORMAT_HEADER, SINGLE_FLIGHT_HEADER, REVALIDATE_HEADER, REDIRECT_HEADER, "Location",
2797
2884
  ...COMPOSED_BODY_FRAMING].map(header => header.toLowerCase()));
2798
2885
 
2799
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) {
2800
2995
  if (value === null || typeof value !== "object" && typeof value !== "function") return value;
2801
2996
  const promised = scope(() => nativePromise(value));
2802
2997
  if (promised) {
@@ -2846,6 +3041,7 @@ const INVOCATIONS = new WeakMap();
2846
3041
  function getEventServerFunctionInvocation(event) {
2847
3042
  return event && INVOCATIONS.get(event);
2848
3043
  }
3044
+ new Set(Object.values(BodyFormat));
2849
3045
  function guardFailures(value, state) {
2850
3046
  if (!state) state = {
2851
3047
  seen: new WeakMap(),
@@ -3070,7 +3266,7 @@ function enterGuard(value, state) {
3070
3266
  return new Frame(SET, value, next, [...value], null);
3071
3267
  }
3072
3268
  const prototype = Object.getPrototypeOf(value);
3073
- if (prototype !== Object.prototype && prototype !== null) {
3269
+ if (prototype !== Object.prototype && prototype !== null && !(value instanceof Error)) {
3074
3270
  state.seen.set(value, value);
3075
3271
  return value;
3076
3272
  }
@@ -3081,7 +3277,11 @@ function enterGuard(value, state) {
3081
3277
  }
3082
3278
  const next = Object.create(prototype, descriptors);
3083
3279
  state.seen.set(value, next);
3084
- return new Frame(OBJECT, value, next, Object.keys(value), 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);
3085
3285
  }
3086
3286
  function keepGuarded(value, next, changed, state) {
3087
3287
  if (changed || state.cyclic.has(value)) return next;
@@ -3169,9 +3369,11 @@ function serverComponentScope(render) {
3169
3369
  return solidJs.runInServerComponentScope ? solidJs.runInServerComponentScope(render) : render();
3170
3370
  }
3171
3371
  function wirePreload(entry) {
3172
- return {
3372
+ return entry.href ? {
3173
3373
  href: entry.href,
3174
3374
  attrs: entry.attrs
3375
+ } : {
3376
+ attrs: entry.attrs
3175
3377
  };
3176
3378
  }
3177
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))}}))";