@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
package/dist/server.cjs CHANGED
@@ -49,6 +49,15 @@ const Namespaces = {
49
49
  const VoidElements = /*#__PURE__*/new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"]);
50
50
  const RawTextElements = /*#__PURE__*/new Set(["style", "script", "noscript", "template", "textarea", "title"]);
51
51
  const DOMElements = /*#__PURE__*/new Set(/*#__PURE__*/"a,abbr,acronym,address,applet,area,article,aside,audio,b,base,basefont,bdi,bdo,bgsound,big,blink,blockquote,body,br,button,canvas,caption,center,cite,code,col,colgroup,content,data,datalist,dd,del,details,dfn,dialog,dir,div,dl,dt,em,embed,fieldset,figcaption,figure,font,footer,form,frame,frameset,h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,i,iframe,image,img,input,ins,isindex,kbd,keygen,label,legend,li,link,listing,main,map,mark,marquee,math,menu,menuitem,meta,meter,multicol,nav,nextid,nobr,noembed,noframes,noindex,noscript,object,ol,optgroup,option,output,p,param,picture,plaintext,portal,pre,progress,q,rb,rp,rt,rtc,ruby,s,samp,script,search,section,select,shadow,slot,small,source,spacer,span,strike,strong,style,sub,summary,sup,svg,table,tbody,td,template,textarea,tfoot,th,thead,time,title,tr,track,tt,u,ul,var,video,wbr,webview,xmp".split(","));
52
+ const COMPOSED_BODY_FRAMING = /*#__PURE__*/new Set(["content-length", "content-encoding", "transfer-encoding"]);
53
+ function isHttpNavigationTarget(target) {
54
+ try {
55
+ const protocol = new URL(target, "http://base.invalid").protocol;
56
+ return protocol === "http:" || protocol === "https:";
57
+ } catch {
58
+ return false;
59
+ }
60
+ }
52
61
 
53
62
  const transparentOptions = {
54
63
  transparent: true,
@@ -58,11 +67,12 @@ const syncOptions = {
58
67
  sync: true
59
68
  };
60
69
  function effect(fn, effectFn, options) {
61
- solidJs.createRenderEffect(fn, effectFn, options ? {
70
+ const nodeOptions = options ? {
62
71
  sync: true,
63
72
  ...options,
64
73
  transparent: !options.scope
65
- } : transparentOptions);
74
+ } : transparentOptions;
75
+ solidJs.createRenderEffect(fn, effectFn, nodeOptions);
66
76
  }
67
77
  function memo(fn) {
68
78
  return solidJs.createMemo(() => fn(), syncOptions);
@@ -286,6 +296,7 @@ function respond(value, init = {}) {
286
296
  responseInit,
287
297
  headers
288
298
  } = initWithRevalidate(init);
299
+ for (const header of COMPOSED_BODY_FRAMING) headers.delete(header);
289
300
  if (NULL_BODY_STATUSES.has(responseInit.status)) {
290
301
  return new ResponseEnvelope(new Response(null, {
291
302
  ...responseInit,
@@ -395,12 +406,24 @@ function classifyHeadTag(desc) {
395
406
  resource: false
396
407
  };
397
408
  }
409
+ function qualifierValue(name, value) {
410
+ if (value == null || value === false) return null;
411
+ if (name === "imagesrcset" || name === "imagesizes") return typeof value === "string" && value !== "" ? value : null;
412
+ const v = value === true ? "" : String(value);
413
+ if (name === "as") return asciiLowerCase(v);
414
+ if (name !== "crossorigin") return v;
415
+ return v.length === 15 && v.toLowerCase() === "use-credentials" ? v.toLowerCase() : "anonymous";
416
+ }
417
+ function asciiLowerCase(value) {
418
+ return value.replace(/[A-Z]/g, c => String.fromCharCode(c.charCodeAt(0) + 32));
419
+ }
398
420
  function resourceIdentity(tag, props) {
399
- let id = "res:" + tag + ":" + (props.rel || "") + ":" + (props.href || props.src || "");
421
+ const url = String(props.href || props.src || "");
422
+ let id = "res:" + tag + ":" + (props.rel || "") + ":" + url.length + ":" + url;
400
423
  for (let i = 0; i < RESOURCE_QUALIFIERS.length; i++) {
401
424
  const q = RESOURCE_QUALIFIERS[i];
402
- const value = props[q];
403
- if (value != null) id += ":" + q + "=" + (value === true ? "" : value);
425
+ const value = qualifierValue(q, props[q]);
426
+ if (value !== null) id += ":" + q + "=" + value.length + ":" + value;
404
427
  }
405
428
  return id;
406
429
  }
@@ -474,12 +497,20 @@ function resolveAssets(moduleUrl, manifest) {
474
497
  if (e.preloads) {
475
498
  for (let i = 0; i < e.preloads.length; i++) {
476
499
  const link = e.preloads[i];
477
- if (!link || typeof link.href !== "string" || !link.href) continue;
500
+ const href = link && typeof link.href === "string" && link.href;
501
+ const srcset = link && typeof link.imagesrcset === "string" && link.imagesrcset;
502
+ if (!href && !srcset) continue;
478
503
  if (!preloads) preloads = [];
479
- preloads.push({
504
+ if (href) preloads.push({
480
505
  ...link,
481
- href: joinAssetPath(base, link.href)
482
- });
506
+ href: joinAssetPath(base, href)
507
+ });else {
508
+ const {
509
+ href: bad,
510
+ ...rest
511
+ } = link;
512
+ preloads.push(rest);
513
+ }
483
514
  }
484
515
  }
485
516
  if (e.imports) for (let i = 0; i < e.imports.length; i++) walk(e.imports[i]);
@@ -611,9 +642,13 @@ function isCssUrl(url) {
611
642
  const q = url.search(/[?#]/);
612
643
  return (q === -1 ? url : url.slice(0, q)).endsWith(".css");
613
644
  }
614
- const PRELOAD_LINK_ATTRIBUTES = ["type", "crossorigin", "integrity", "referrerpolicy", "fetchpriority", "media"];
645
+ const RESPONSIVE_ATTRIBUTES = ["imagesrcset", "imagesizes"];
646
+ function isSetAttr(value) {
647
+ return value != null && value !== false && value !== "";
648
+ }
649
+ const PRELOAD_LINK_ATTRIBUTES = ["type", "crossorigin", "integrity", "referrerpolicy", "fetchpriority", "media", "imagesrcset", "imagesizes"];
615
650
  function registerPreloadLink(tracking, headRegistry, link, nonce) {
616
- if (!link || typeof link !== "object" || typeof link.href !== "string" || !link.href) {
651
+ if (!link || typeof link !== "object") {
617
652
  return null;
618
653
  }
619
654
  if (typeof link.as !== "string") {
@@ -634,13 +669,35 @@ function registerPreloadLink(tracking, headRegistry, link, nonce) {
634
669
  default:
635
670
  return null;
636
671
  }
672
+ const responsive = as === "image";
673
+ let srcset = null;
674
+ let sizes = null;
675
+ if (responsive) {
676
+ for (const name of RESPONSIVE_ATTRIBUTES) {
677
+ const value = link[name];
678
+ if (!isSetAttr(value)) continue;
679
+ if (typeof value !== "string") {
680
+ continue;
681
+ }
682
+ if (name === "imagesrcset") srcset = value;else sizes = value;
683
+ }
684
+ }
685
+ const href = typeof link.href === "string" && link.href ? link.href : null;
686
+ if (!href && !srcset) {
687
+ return null;
688
+ }
637
689
  const props = {
638
- rel: "preload",
639
- href: link.href,
640
- as
690
+ rel: "preload"
641
691
  };
692
+ if (href) props.href = href;
693
+ props.as = as;
642
694
  for (let i = 0; i < PRELOAD_LINK_ATTRIBUTES.length; i++) {
643
695
  const name = PRELOAD_LINK_ATTRIBUTES[i];
696
+ if (RESPONSIVE_ATTRIBUTES.indexOf(name) !== -1) {
697
+ const value = name === "imagesrcset" ? srcset : sizes;
698
+ if (value !== null) props[name] = value;
699
+ continue;
700
+ }
644
701
  const value = link[name];
645
702
  if (value == null || value === false) continue;
646
703
  props[name] = value === true ? "" : String(value);
@@ -1017,9 +1074,6 @@ function scriptNonce(nonce) {
1017
1074
  function styleNonce(nonce) {
1018
1075
  return destinationNonce(nonce, "style");
1019
1076
  }
1020
- function asciiLowerCase(value) {
1021
- return value.replace(/[A-Z]/g, c => String.fromCharCode(c.charCodeAt(0) + 32));
1022
- }
1023
1077
  function hasNonceProp(props) {
1024
1078
  for (const name in props) if (name.length === 5 && asciiLowerCase(name) === "nonce" && props[name] != null) return true;
1025
1079
  return false;
@@ -1180,6 +1234,7 @@ function renderToStream(code, options = {}) {
1180
1234
  onHead
1181
1235
  } = options;
1182
1236
  const nonce = normalizeNonce(options.nonce);
1237
+ const requestEvent = peekRequestEvent();
1183
1238
  let dispose;
1184
1239
  let dead = false;
1185
1240
  const abandon = () => {
@@ -1281,6 +1336,7 @@ function renderToStream(code, options = {}) {
1281
1336
  };
1282
1337
  const onDone = () => {
1283
1338
  writeTasks();
1339
+ lastBlockingSize = blockingPromises.size;
1284
1340
  doShell();
1285
1341
  onCompleteAll && onCompleteAll({
1286
1342
  write(v) {
@@ -1670,9 +1726,9 @@ function renderToStream(code, options = {}) {
1670
1726
  function doShell() {
1671
1727
  if (shellCompleted) return;
1672
1728
  solidJs.sharedConfig.context = context;
1673
- const blockersBefore = blockingPromises.size;
1729
+ if (blockingPromises.size !== lastBlockingSize) return;
1674
1730
  if (!resolveRootHoles()) return;
1675
- if (blockingPromises.size !== blockersBefore) return;
1731
+ if (blockingPromises.size !== lastBlockingSize) return;
1676
1732
  if (!headShellReady(headRegistry, p => blockingPromises.add(p))) return;
1677
1733
  headStyles = new Set();
1678
1734
  for (const url of tracking.emittedAssets) {
@@ -1700,7 +1756,7 @@ function renderToStream(code, options = {}) {
1700
1756
  let lastBlockingSize = -1;
1701
1757
  let lastRegistrySize = -1;
1702
1758
  let drainTurn = 0;
1703
- const scheduleFlush = fn => {
1759
+ const scheduleFlush = (fn, awaited) => {
1704
1760
  const attempt = () => {
1705
1761
  flushStubBatch();
1706
1762
  if (registry.size !== lastRegistrySize || drainTurn++ < MIN_DRAIN_TURNS) {
@@ -1711,8 +1767,8 @@ function renderToStream(code, options = {}) {
1711
1767
  }
1712
1768
  fn();
1713
1769
  };
1714
- const progressed = blockingPromises.size !== lastBlockingSize;
1715
- lastBlockingSize = blockingPromises.size;
1770
+ const progressed = awaited !== lastBlockingSize;
1771
+ lastBlockingSize = awaited;
1716
1772
  lastRegistrySize = -1;
1717
1773
  drainTurn = 0;
1718
1774
  progressed ? queue(attempt) : setTimeout(attempt);
@@ -1729,7 +1785,7 @@ function renderToStream(code, options = {}) {
1729
1785
  let resolve;
1730
1786
  const p = new Promise(r => resolve = r);
1731
1787
  function flush() {
1732
- allSettled(blockingPromises).then(() => {
1788
+ allSettled(blockingPromises).then(awaited => {
1733
1789
  scheduleFlush(() => {
1734
1790
  if (dead) return resolve();
1735
1791
  try {
@@ -1767,7 +1823,7 @@ function renderToStream(code, options = {}) {
1767
1823
  dispose();
1768
1824
  writable.end();
1769
1825
  } else flushEnd();
1770
- });
1826
+ }, awaited);
1771
1827
  });
1772
1828
  }
1773
1829
  flush();
@@ -1775,8 +1831,12 @@ function renderToStream(code, options = {}) {
1775
1831
  };
1776
1832
  return {
1777
1833
  then(onFulfilled, onRejected) {
1834
+ const freezeHead = () => {
1835
+ if (requestEvent && requestEvent.response) commitResponseStub(requestEvent.response);
1836
+ };
1778
1837
  const p = new Promise(resolve => {
1779
1838
  function complete() {
1839
+ freezeHead();
1780
1840
  dispose();
1781
1841
  resolve(tmp);
1782
1842
  }
@@ -1788,17 +1848,16 @@ function renderToStream(code, options = {}) {
1788
1848
  };
1789
1849
  } else onCompleteAll = complete;
1790
1850
  function flush() {
1791
- allSettled(blockingPromises).then(() => {
1851
+ allSettled(blockingPromises).then(awaited => {
1792
1852
  scheduleFlush(() => {
1793
1853
  try {
1794
- const blockersBefore = blockingPromises.size;
1795
- if (!resolveRootHoles() || blockingPromises.size !== blockersBefore || !headShellReady(headRegistry, p => blockingPromises.add(p))) return flush();
1854
+ if (blockingPromises.size !== lastBlockingSize || !resolveRootHoles() || blockingPromises.size !== lastBlockingSize || !headShellReady(headRegistry, p => blockingPromises.add(p))) return flush();
1796
1855
  } catch (err) {
1797
1856
  failRender(err);
1798
1857
  return resolve(tmp);
1799
1858
  }
1800
1859
  queue(flushEnd);
1801
- });
1860
+ }, awaited);
1802
1861
  });
1803
1862
  }
1804
1863
  flush();
@@ -1808,7 +1867,7 @@ function renderToStream(code, options = {}) {
1808
1867
  pipe(w) {
1809
1868
  claimConsumer("pipe");
1810
1869
  function flush() {
1811
- allSettled(blockingPromises).then(() => {
1870
+ allSettled(blockingPromises).then(awaited => {
1812
1871
  scheduleFlush(() => {
1813
1872
  if (dead) return;
1814
1873
  try {
@@ -1830,7 +1889,7 @@ function renderToStream(code, options = {}) {
1830
1889
  dispose();
1831
1890
  writable.end();
1832
1891
  } else flushEnd();
1833
- });
1892
+ }, awaited);
1834
1893
  });
1835
1894
  }
1836
1895
  flush();
@@ -2501,6 +2560,7 @@ function ssr(t) {
2501
2560
  return result;
2502
2561
  }
2503
2562
  function ssrClassName(value) {
2563
+ if (typeof value === "number") return "" + value;
2504
2564
  if (!value) return "";
2505
2565
  if (typeof value === "string") return escape(value, true);
2506
2566
  value = classListToObject(value);
@@ -2538,17 +2598,22 @@ function ssrStyleProperty(name, value) {
2538
2598
  }
2539
2599
  function ssrElement(tag, props, children, needsId) {
2540
2600
  const hk = needsId ? ssrHydrationKey() : "";
2541
- if (props == null) props = {};else if (typeof props === "function") props = props();
2601
+ if (typeof props === "function") props = props();
2602
+ if (props == null) props = {};
2542
2603
  const skipChildren = VOID_ELEMENTS.test(tag);
2543
2604
  const keys = Object.keys(props);
2544
2605
  let result = `<${tag}${hk} `;
2545
2606
  for (let i = 0; i < keys.length; i++) {
2546
2607
  const prop = keys[i];
2608
+ const value = props[prop];
2609
+ if (tag === "textarea" && (prop === "value" || prop === "defaultValue")) {
2610
+ if (value !== null) children = escape(value);
2611
+ continue;
2612
+ }
2547
2613
  if (ChildProperties.has(prop)) {
2548
2614
  if (children === undefined && !skipChildren) children = tag === "script" || tag === "style" || prop === "innerHTML" ? props[prop] : escape(props[prop]);
2549
2615
  continue;
2550
2616
  }
2551
- const value = props[prop];
2552
2617
  if (prop === "style") {
2553
2618
  result += `style="${ssrStyle(value)}"`;
2554
2619
  } else if (prop === "class") {
@@ -2827,7 +2892,7 @@ function allSettled(promises) {
2827
2892
  let size = promises.size;
2828
2893
  return Promise.allSettled(promises).then(() => {
2829
2894
  if (promises.size !== size) return allSettled(promises);
2830
- return;
2895
+ return size;
2831
2896
  });
2832
2897
  }
2833
2898
  function assembleDocument(html, emittedAssets, preloadLinks, inlineStyles, scripts, nonce, headTags, onHead) {
@@ -2986,7 +3051,8 @@ function classListToObject(classList) {
2986
3051
  function flattenClassList(list, result) {
2987
3052
  for (let i = 0, len = list.length; i < len; i++) {
2988
3053
  const item = list[i];
2989
- if (Array.isArray(item)) flattenClassList(item, result);else if (typeof item === "object" && item != null) Object.assign(result, item);else if (item || item === 0) result[item] = true;
3054
+ if (Array.isArray(item)) flattenClassList(item, result);else if (typeof item === "object" && item != null) Object.assign(result, item);
3055
+ else if (typeof item !== "boolean" && (item || item === 0)) result[item] = true;
2990
3056
  }
2991
3057
  }
2992
3058
  function tryResolveString(node) {
@@ -3095,6 +3161,10 @@ const RequestContext = Symbol.for("solid.RequestContext");
3095
3161
  function getRequestEvent() {
3096
3162
  return globalThis[RequestContext] ? globalThis[RequestContext].getStore() || solidJs.sharedConfig.context && solidJs.sharedConfig.context.event || console.warn("RequestEvent is missing. This is most likely due to accessing `getRequestEvent` non-managed async scope in a partially polyfilled environment. Try moving it above all `await` calls.") : undefined;
3097
3163
  }
3164
+ function peekRequestEvent() {
3165
+ const store = globalThis[RequestContext];
3166
+ return store ? store.getStore() : undefined;
3167
+ }
3098
3168
  function createResponseStub() {
3099
3169
  return {
3100
3170
  status: undefined,
@@ -3156,7 +3226,8 @@ function copyInitHeaders(init) {
3156
3226
  for (const cookie of init.getSetCookie()) headers.append("Set-Cookie", cookie);
3157
3227
  return headers;
3158
3228
  }
3159
- const STUB_GAP_FILL_EXCLUDED = /*#__PURE__*/new Set([ERROR_HEADER, BODY_FORMAT_HEADER, SINGLE_FLIGHT_HEADER, REVALIDATE_HEADER, REDIRECT_HEADER, "Location"].map(header => header.toLowerCase()));
3229
+ const STUB_GAP_FILL_EXCLUDED = /*#__PURE__*/new Set([ERROR_HEADER, BODY_FORMAT_HEADER, SINGLE_FLIGHT_HEADER, REVALIDATE_HEADER, REDIRECT_HEADER, "Location",
3230
+ ...COMPOSED_BODY_FRAMING].map(header => header.toLowerCase()));
3160
3231
  function fillsStubGap(key, headers, response) {
3161
3232
  if (key === "set-cookie" || STUB_GAP_FILL_EXCLUDED.has(key)) return false;
3162
3233
  if (response.body === null && (key === "content-type" || key === "content-length")) return false;
@@ -3185,6 +3256,7 @@ function commitEventResponse(response, event = getRequestEvent()) {
3185
3256
  }
3186
3257
  function deriveHead(stub, responseInit = {}) {
3187
3258
  const headers = mergeStubHeaders(copyInitHeaders(responseInit.headers), stub);
3259
+ for (const header of COMPOSED_BODY_FRAMING) headers.delete(header);
3188
3260
  const status = stub && stub.status || responseInit.status || 200;
3189
3261
  const statusText = stub && stub.statusText || responseInit.statusText || undefined;
3190
3262
  return {
@@ -3268,7 +3340,7 @@ function createSSRResponse(result, event, options = {}) {
3268
3340
  end() {
3269
3341
  if (closed || !controller) return;
3270
3342
  const location = stub && stub.headers.get("Location");
3271
- if (location) {
3343
+ if (location && isHttpNavigationTarget(location)) {
3272
3344
  const attr = nonceAttr(nonce, "script");
3273
3345
  enqueue(`<script${attr}>window.location=${JSON.stringify(location).replace(/</g, "\\u003c")}</script>`);
3274
3346
  }
@@ -3309,13 +3381,25 @@ function notSup() {
3309
3381
  setContainerTraceResolver(solidJs.getProjectionTrace);
3310
3382
  const isServer = true;
3311
3383
  const isDev = false;
3312
- function dynamic(source) {
3384
+ function dynamic(source, options) {
3313
3385
  const cached = solidJs.createMemo(source, {
3314
3386
  serialize: false
3315
3387
  });
3388
+ const deferStream = !!options?.deferStream;
3316
3389
  return props => {
3390
+ const ctx = solidJs.sharedConfig.context;
3391
+ let gated = !deferStream || !ctx?.async;
3317
3392
  return solidJs.createMemo(() => {
3318
- const c = cached();
3393
+ let c;
3394
+ try {
3395
+ c = cached();
3396
+ } catch (err) {
3397
+ if (!gated && err instanceof solidJs.NotReadyError) {
3398
+ gated = true;
3399
+ ctx.block(Promise.resolve(err.source).then(() => {}, () => {}));
3400
+ }
3401
+ throw err;
3402
+ }
3319
3403
  if (c) {
3320
3404
  if (typeof c === "function") return c(props);
3321
3405
  if (typeof c === "string") {