@solidjs/web 2.0.0-beta.26 → 2.0.0-beta.27

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 (39) hide show
  1. package/dist/dev.cjs +3 -1
  2. package/dist/dev.js +3 -2
  3. package/dist/server.cjs +41 -78
  4. package/dist/server.js +42 -80
  5. package/dist/web.cjs +3 -1
  6. package/dist/web.js +3 -2
  7. package/frames/dist/client.cjs +69 -21
  8. package/frames/dist/client.dev.cjs +69 -21
  9. package/frames/dist/client.dev.js +70 -22
  10. package/frames/dist/client.js +70 -22
  11. package/frames/dist/server.cjs +33 -45
  12. package/frames/dist/server.js +33 -45
  13. package/package.json +4 -4
  14. package/serialization/dist/serialization.cjs +6 -3
  15. package/serialization/dist/serialization.js +6 -3
  16. package/serialization/types/index.d.ts +7 -1
  17. package/serialization/types-cjs/index.d.cts +7 -1
  18. package/server-functions/dist/client.cjs +15 -2
  19. package/server-functions/dist/client.js +13 -3
  20. package/server-functions/dist/server.cjs +161 -5
  21. package/server-functions/dist/server.js +155 -6
  22. package/types/client.d.ts +3 -3
  23. package/types/frames/serializer.d.ts +7 -1
  24. package/types/jsx.d.ts +1 -1
  25. package/types/response.d.ts +10 -0
  26. package/types/serializer.d.ts +7 -1
  27. package/types/server-functions/client.d.ts +3 -0
  28. package/types/server-functions/flash.d.ts +38 -0
  29. package/types/server-functions/server.d.ts +79 -4
  30. package/types/server-functions/shared.d.ts +35 -0
  31. package/types-cjs/client.d.cts +3 -3
  32. package/types-cjs/frames/serializer.d.cts +7 -1
  33. package/types-cjs/jsx.d.cts +1 -1
  34. package/types-cjs/response.d.cts +10 -0
  35. package/types-cjs/serializer.d.cts +7 -1
  36. package/types-cjs/server-functions/client.d.cts +3 -0
  37. package/types-cjs/server-functions/flash.d.cts +38 -0
  38. package/types-cjs/server-functions/server.d.cts +79 -4
  39. package/types-cjs/server-functions/shared.d.cts +35 -0
@@ -9,6 +9,7 @@ const runWithHydrationScope = (id, fn) => solidJs.runWithOwner(solidJs.createOwn
9
9
  }), fn);
10
10
 
11
11
  const DEFAULT_DISABLED_FEATURES = seroval.Feature.AggregateError | seroval.Feature.BigIntTypedArray;
12
+ const serializeOnlyDisabledFeatures = () => process.env.NODE_ENV === "development" ? 0 : seroval.Feature.ErrorPrototypeStack;
12
13
  const HYDRATION_GLOBAL = "_$HY.r";
13
14
  const DEFAULT_WEB_PLUGINS = Object.freeze([web.AbortSignalPlugin,
14
15
  web.CustomEventPlugin, web.DOMExceptionPlugin, web.EventPlugin,
@@ -20,7 +21,7 @@ function createSerializer(options) {
20
21
  return new seroval.Serializer({
21
22
  ...options,
22
23
  plugins: resolveSerializerPlugins(options.plugins),
23
- disabledFeatures: options.disabledFeatures === undefined ? DEFAULT_DISABLED_FEATURES : options.disabledFeatures
24
+ disabledFeatures: (options.disabledFeatures === undefined ? DEFAULT_DISABLED_FEATURES : options.disabledFeatures) | serializeOnlyDisabledFeatures()
24
25
  });
25
26
  }
26
27
  function createHydrationSerializer({
@@ -88,7 +89,7 @@ function createJSONSerializer({
88
89
  const stream = seroval.toCrossJSONStream(value, {
89
90
  refs,
90
91
  plugins: resolved.plugins,
91
- disabledFeatures: resolved.disabledFeatures,
92
+ disabledFeatures: resolved.disabledFeatures | serializeOnlyDisabledFeatures(),
92
93
  onParse(node, initial) {
93
94
  onData({
94
95
  key,
@@ -245,7 +246,7 @@ function applyAssetTracking(context, tracking, manifest) {
245
246
  context.resolveAssetsSync = resolve;
246
247
  }
247
248
  }
248
- const REPLACE_SCRIPT = `function $df(e,n,o,t){if(!(n=document.getElementById(e)))return 0;if(!(o=document.getElementById("pl-"+e)))return(_$HY.dq=_$HY.dq||{})[e]=1,0;for(;o&&(8!==o.nodeType||o.nodeValue!=="pl-"+e);)t=o.nextSibling,o.remove(),o=t;_$HY.done?o.remove():o.replaceWith(n.content),n.remove(),_$HY.fe(e),$dfd();return 1}function $dfl(e,o,n){if(!(o=document.getElementById("pl-"+e)))return(_$HY.dlq=_$HY.dlq||{})[e]=1,0;if(o._$fl)return 1;for(n=o.nextSibling;n;){if(8===n.nodeType&&n.nodeValue==="pl-"+e){o.parentNode&&o.parentNode.insertBefore(o.content.cloneNode(!0),n),o._$fl=1,$dfd();return 1}n=n.nextSibling}return 0}function $dflj(e,i){for(i=0;i<e.length;i++)$dfl(e[i])}function $dfd(e,i){if(e=_$HY.dq){_$HY.dq=0;for(i in e)$df(i)}if(e=_$HY.dlq){_$HY.dlq=0;for(i in e)$dfl(i)}}function $dfs(e,c,d){(_$HY.sc=_$HY.sc||{})[e]=c,d&&((_$HY.sd=_$HY.sd||{})[e]=1)}function $dfg(e,g,i,k){if(!(g=_$HY.sg&&_$HY.sg[e]))return;for(i=0;i<g.length;i++)if(_$HY.sc&&_$HY.sc[g[i]]>0)return;for(i=0;i<g.length;i++)k=g[i],delete _$HY.sg[k],$df(k)}function $dfc(e){if(--_$HY.sc[e]<=0){delete _$HY.sc[e],_$HY.sg&&_$HY.sg[e]?$dfg(e):!(_$HY.sd&&_$HY.sd[e])&&$df(e);_$HY.sd&&delete _$HY.sd[e]}}function $dfj(e,i,n){for(i=0;i<e.length;i++)if(_$HY.sc&&_$HY.sc[e[i]]>0){for(n=0;n<e.length;n++)(_$HY.sg=_$HY.sg||{})[e[n]]=e;return}for(i=0;i<e.length;i++)$df(e[i])}`;
249
+ const REPLACE_SCRIPT = `function $df(e,n,o,t){if(!(n=document.getElementById(e)))return 0;if(!(o=document.getElementById("pl-"+e)))return(_$HY.dq=_$HY.dq||{})[e]=1,0;for(;o&&(8!==o.nodeType||o.nodeValue!=="pl-"+e);)t=o.nextSibling,o.remove(),o=t;t=o.parentNode,_$HY.done?o.remove():o.replaceWith(n.content),n.remove(),_$HY.fe(e,t),$dfd();return 1}function $dfl(e,o,n){if(!(o=document.getElementById("pl-"+e)))return(_$HY.dlq=_$HY.dlq||{})[e]=1,0;if(o._$fl)return 1;for(n=o.nextSibling;n;){if(8===n.nodeType&&n.nodeValue==="pl-"+e){o.parentNode&&o.parentNode.insertBefore(o.content.cloneNode(!0),n),o._$fl=1,$dfd();return 1}n=n.nextSibling}return 0}function $dflj(e,i){for(i=0;i<e.length;i++)$dfl(e[i])}function $dfd(e,i){if(e=_$HY.dq){_$HY.dq=0;for(i in e)$df(i)}if(e=_$HY.dlq){_$HY.dlq=0;for(i in e)$dfl(i)}}function $dfs(e,c,d){(_$HY.sc=_$HY.sc||{})[e]=c,d&&((_$HY.sd=_$HY.sd||{})[e]=1)}function $dfg(e,g,i,k){if(!(g=_$HY.sg&&_$HY.sg[e]))return;for(i=0;i<g.length;i++)if(_$HY.sc&&_$HY.sc[g[i]]>0)return;for(i=0;i<g.length;i++)k=g[i],delete _$HY.sg[k],$df(k)}function $dfc(e){if(--_$HY.sc[e]<=0){delete _$HY.sc[e],_$HY.sg&&_$HY.sg[e]?$dfg(e):!(_$HY.sd&&_$HY.sd[e])&&$df(e);_$HY.sd&&delete _$HY.sd[e]}}function $dfj(e,i,n){for(i=0;i<e.length;i++)if(_$HY.sc&&_$HY.sc[e[i]]>0){for(n=0;n<e.length;n++)(_$HY.sg=_$HY.sg||{})[e[n]]=e;return}for(i=0;i<e.length;i++)$df(e[i])}`;
249
250
  function renderToStream(code, options = {}) {
250
251
  let {
251
252
  nonce,
@@ -317,11 +318,7 @@ function renderToStream(code, options = {}) {
317
318
  }
318
319
  },
319
320
  shell(shellHtml, meta) {
320
- shellHtml = injectBeforeHead(shellHtml, meta.assets);
321
- shellHtml = injectPreloadLinks(meta.preloads, shellHtml);
322
- shellHtml = injectInlineStyles(meta.inlineStyles, shellHtml, nonce);
323
- if (meta.tasks.length) shellHtml = injectScripts(shellHtml, meta.tasks, nonce);
324
- buffer.write(shellHtml);
321
+ buffer.write(assembleDocument(shellHtml, meta.assets, meta.preloads, meta.inlineStyles, meta.tasks.length ? meta.tasks : "", nonce));
325
322
  },
326
323
  ...options.sink
327
324
  };
@@ -952,25 +949,36 @@ function resolveAssetsHtml(assets) {
952
949
  for (let i = 0, len = assets.length; i < len; i++) out += assets[i]();
953
950
  return out;
954
951
  }
955
- function injectBeforeHead(html, content) {
956
- if (!content) return html;
957
- const index = html.indexOf("</head>");
958
- if (index === -1) return html;
959
- return html.slice(0, index) + content + html.slice(index);
960
- }
961
- function injectPreloadLinks(emittedAssets, html, nonce) {
962
- if (!emittedAssets.size) return html;
963
- let links = "";
964
- for (const url of emittedAssets) {
965
- if (url.endsWith(".css")) {
966
- links += `<link rel="stylesheet" href="${url}">`;
967
- } else {
968
- links += `<link rel="modulepreload" href="${url}">`;
952
+ function assembleDocument(html, assetsHtml, emittedAssets, inlineStyles, scripts, nonce) {
953
+ const scriptTag = scripts ? `<script${nonce ? ` nonce="${nonce}"` : ""}>${scripts}</script>` : "";
954
+ if (!assetsHtml && !(emittedAssets && emittedAssets.size) && !(inlineStyles && inlineStyles.size)) {
955
+ if (!scriptTag) return html;
956
+ const xs = html.indexOf("<!--xs-->");
957
+ return xs === -1 ? html + scriptTag : html.slice(0, xs) + scriptTag + html.slice(xs);
958
+ }
959
+ const headIdx = html.indexOf("</head>");
960
+ if (headIdx === -1) {
961
+ if (!scriptTag) return html;
962
+ const xs = html.indexOf("<!--xs-->");
963
+ return xs === -1 ? html + scriptTag : html.slice(0, xs) + scriptTag + html.slice(xs);
964
+ }
965
+ let head = assetsHtml || "";
966
+ if (emittedAssets && emittedAssets.size) {
967
+ for (const url of emittedAssets) {
968
+ head += url.endsWith(".css") ? `<link rel="stylesheet" href="${url}">` : `<link rel="modulepreload" href="${url}">`;
969
+ }
970
+ }
971
+ if (inlineStyles && inlineStyles.size) {
972
+ for (const entry of inlineStyles.values()) {
973
+ if (entry.emitted) continue;
974
+ entry.emitted = true;
975
+ head += renderInlineStyle(entry, nonce);
969
976
  }
970
977
  }
971
- const index = html.indexOf("</head>");
972
- if (index === -1) return html;
973
- return html.slice(0, index) + links + html.slice(index);
978
+ if (!scriptTag) return html.slice(0, headIdx) + head + html.slice(headIdx);
979
+ const xsIdx = html.indexOf("<!--xs-->");
980
+ if (xsIdx === -1) return html.slice(0, headIdx) + head + html.slice(headIdx) + scriptTag;
981
+ 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);
974
982
  }
975
983
  function serializeFragmentAssets(key, boundaryModules, context) {
976
984
  const map = boundaryModules.get(key);
@@ -1022,26 +1030,6 @@ function renderInlineStyle(entry, nonce) {
1022
1030
  }
1023
1031
  return `<style${nonce ? ` nonce="${nonce}"` : ""} data-asset="${escape(entry.id, true)}"${attrs}>${escapeStyleContent(entry.content)}</style>`;
1024
1032
  }
1025
- function injectInlineStyles(inlineStyles, html, nonce) {
1026
- if (!inlineStyles.size) return html;
1027
- const index = html.indexOf("</head>");
1028
- if (index === -1) return html;
1029
- let out = "";
1030
- for (const entry of inlineStyles.values()) {
1031
- if (entry.emitted) continue;
1032
- entry.emitted = true;
1033
- out += renderInlineStyle(entry, nonce);
1034
- }
1035
- return out ? html.slice(0, index) + out + html.slice(index) : html;
1036
- }
1037
- function injectScripts(html, scripts, nonce) {
1038
- const tag = `<script${nonce ? ` nonce="${nonce}"` : ""}>${scripts}</script>`;
1039
- const index = html.indexOf("<!--xs-->");
1040
- if (index > -1) {
1041
- return html.slice(0, index) + tag + html.slice(index);
1042
- }
1043
- return html + tag;
1044
- }
1045
1033
  function waitForFragments(registry, key) {
1046
1034
  for (const k of [...registry.keys()].reverse()) {
1047
1035
  if (key.startsWith(k)) return k;
@@ -7,6 +7,7 @@ const runWithHydrationScope = (id, fn) => runWithOwner(createOwner({
7
7
  }), fn);
8
8
 
9
9
  const DEFAULT_DISABLED_FEATURES = Feature.AggregateError | Feature.BigIntTypedArray;
10
+ const serializeOnlyDisabledFeatures = () => process.env.NODE_ENV === "development" ? 0 : Feature.ErrorPrototypeStack;
10
11
  const HYDRATION_GLOBAL = "_$HY.r";
11
12
  const DEFAULT_WEB_PLUGINS = Object.freeze([AbortSignalPlugin,
12
13
  CustomEventPlugin, DOMExceptionPlugin, EventPlugin,
@@ -18,7 +19,7 @@ function createSerializer(options) {
18
19
  return new Serializer({
19
20
  ...options,
20
21
  plugins: resolveSerializerPlugins(options.plugins),
21
- disabledFeatures: options.disabledFeatures === undefined ? DEFAULT_DISABLED_FEATURES : options.disabledFeatures
22
+ disabledFeatures: (options.disabledFeatures === undefined ? DEFAULT_DISABLED_FEATURES : options.disabledFeatures) | serializeOnlyDisabledFeatures()
22
23
  });
23
24
  }
24
25
  function createHydrationSerializer({
@@ -86,7 +87,7 @@ function createJSONSerializer({
86
87
  const stream = toCrossJSONStream(value, {
87
88
  refs,
88
89
  plugins: resolved.plugins,
89
- disabledFeatures: resolved.disabledFeatures,
90
+ disabledFeatures: resolved.disabledFeatures | serializeOnlyDisabledFeatures(),
90
91
  onParse(node, initial) {
91
92
  onData({
92
93
  key,
@@ -243,7 +244,7 @@ function applyAssetTracking(context, tracking, manifest) {
243
244
  context.resolveAssetsSync = resolve;
244
245
  }
245
246
  }
246
- const REPLACE_SCRIPT = `function $df(e,n,o,t){if(!(n=document.getElementById(e)))return 0;if(!(o=document.getElementById("pl-"+e)))return(_$HY.dq=_$HY.dq||{})[e]=1,0;for(;o&&(8!==o.nodeType||o.nodeValue!=="pl-"+e);)t=o.nextSibling,o.remove(),o=t;_$HY.done?o.remove():o.replaceWith(n.content),n.remove(),_$HY.fe(e),$dfd();return 1}function $dfl(e,o,n){if(!(o=document.getElementById("pl-"+e)))return(_$HY.dlq=_$HY.dlq||{})[e]=1,0;if(o._$fl)return 1;for(n=o.nextSibling;n;){if(8===n.nodeType&&n.nodeValue==="pl-"+e){o.parentNode&&o.parentNode.insertBefore(o.content.cloneNode(!0),n),o._$fl=1,$dfd();return 1}n=n.nextSibling}return 0}function $dflj(e,i){for(i=0;i<e.length;i++)$dfl(e[i])}function $dfd(e,i){if(e=_$HY.dq){_$HY.dq=0;for(i in e)$df(i)}if(e=_$HY.dlq){_$HY.dlq=0;for(i in e)$dfl(i)}}function $dfs(e,c,d){(_$HY.sc=_$HY.sc||{})[e]=c,d&&((_$HY.sd=_$HY.sd||{})[e]=1)}function $dfg(e,g,i,k){if(!(g=_$HY.sg&&_$HY.sg[e]))return;for(i=0;i<g.length;i++)if(_$HY.sc&&_$HY.sc[g[i]]>0)return;for(i=0;i<g.length;i++)k=g[i],delete _$HY.sg[k],$df(k)}function $dfc(e){if(--_$HY.sc[e]<=0){delete _$HY.sc[e],_$HY.sg&&_$HY.sg[e]?$dfg(e):!(_$HY.sd&&_$HY.sd[e])&&$df(e);_$HY.sd&&delete _$HY.sd[e]}}function $dfj(e,i,n){for(i=0;i<e.length;i++)if(_$HY.sc&&_$HY.sc[e[i]]>0){for(n=0;n<e.length;n++)(_$HY.sg=_$HY.sg||{})[e[n]]=e;return}for(i=0;i<e.length;i++)$df(e[i])}`;
247
+ const REPLACE_SCRIPT = `function $df(e,n,o,t){if(!(n=document.getElementById(e)))return 0;if(!(o=document.getElementById("pl-"+e)))return(_$HY.dq=_$HY.dq||{})[e]=1,0;for(;o&&(8!==o.nodeType||o.nodeValue!=="pl-"+e);)t=o.nextSibling,o.remove(),o=t;t=o.parentNode,_$HY.done?o.remove():o.replaceWith(n.content),n.remove(),_$HY.fe(e,t),$dfd();return 1}function $dfl(e,o,n){if(!(o=document.getElementById("pl-"+e)))return(_$HY.dlq=_$HY.dlq||{})[e]=1,0;if(o._$fl)return 1;for(n=o.nextSibling;n;){if(8===n.nodeType&&n.nodeValue==="pl-"+e){o.parentNode&&o.parentNode.insertBefore(o.content.cloneNode(!0),n),o._$fl=1,$dfd();return 1}n=n.nextSibling}return 0}function $dflj(e,i){for(i=0;i<e.length;i++)$dfl(e[i])}function $dfd(e,i){if(e=_$HY.dq){_$HY.dq=0;for(i in e)$df(i)}if(e=_$HY.dlq){_$HY.dlq=0;for(i in e)$dfl(i)}}function $dfs(e,c,d){(_$HY.sc=_$HY.sc||{})[e]=c,d&&((_$HY.sd=_$HY.sd||{})[e]=1)}function $dfg(e,g,i,k){if(!(g=_$HY.sg&&_$HY.sg[e]))return;for(i=0;i<g.length;i++)if(_$HY.sc&&_$HY.sc[g[i]]>0)return;for(i=0;i<g.length;i++)k=g[i],delete _$HY.sg[k],$df(k)}function $dfc(e){if(--_$HY.sc[e]<=0){delete _$HY.sc[e],_$HY.sg&&_$HY.sg[e]?$dfg(e):!(_$HY.sd&&_$HY.sd[e])&&$df(e);_$HY.sd&&delete _$HY.sd[e]}}function $dfj(e,i,n){for(i=0;i<e.length;i++)if(_$HY.sc&&_$HY.sc[e[i]]>0){for(n=0;n<e.length;n++)(_$HY.sg=_$HY.sg||{})[e[n]]=e;return}for(i=0;i<e.length;i++)$df(e[i])}`;
247
248
  function renderToStream(code, options = {}) {
248
249
  let {
249
250
  nonce,
@@ -315,11 +316,7 @@ function renderToStream(code, options = {}) {
315
316
  }
316
317
  },
317
318
  shell(shellHtml, meta) {
318
- shellHtml = injectBeforeHead(shellHtml, meta.assets);
319
- shellHtml = injectPreloadLinks(meta.preloads, shellHtml);
320
- shellHtml = injectInlineStyles(meta.inlineStyles, shellHtml, nonce);
321
- if (meta.tasks.length) shellHtml = injectScripts(shellHtml, meta.tasks, nonce);
322
- buffer.write(shellHtml);
319
+ buffer.write(assembleDocument(shellHtml, meta.assets, meta.preloads, meta.inlineStyles, meta.tasks.length ? meta.tasks : "", nonce));
323
320
  },
324
321
  ...options.sink
325
322
  };
@@ -950,25 +947,36 @@ function resolveAssetsHtml(assets) {
950
947
  for (let i = 0, len = assets.length; i < len; i++) out += assets[i]();
951
948
  return out;
952
949
  }
953
- function injectBeforeHead(html, content) {
954
- if (!content) return html;
955
- const index = html.indexOf("</head>");
956
- if (index === -1) return html;
957
- return html.slice(0, index) + content + html.slice(index);
958
- }
959
- function injectPreloadLinks(emittedAssets, html, nonce) {
960
- if (!emittedAssets.size) return html;
961
- let links = "";
962
- for (const url of emittedAssets) {
963
- if (url.endsWith(".css")) {
964
- links += `<link rel="stylesheet" href="${url}">`;
965
- } else {
966
- links += `<link rel="modulepreload" href="${url}">`;
950
+ function assembleDocument(html, assetsHtml, emittedAssets, inlineStyles, scripts, nonce) {
951
+ const scriptTag = scripts ? `<script${nonce ? ` nonce="${nonce}"` : ""}>${scripts}</script>` : "";
952
+ if (!assetsHtml && !(emittedAssets && emittedAssets.size) && !(inlineStyles && inlineStyles.size)) {
953
+ if (!scriptTag) return html;
954
+ const xs = html.indexOf("<!--xs-->");
955
+ return xs === -1 ? html + scriptTag : html.slice(0, xs) + scriptTag + html.slice(xs);
956
+ }
957
+ const headIdx = html.indexOf("</head>");
958
+ if (headIdx === -1) {
959
+ if (!scriptTag) return html;
960
+ const xs = html.indexOf("<!--xs-->");
961
+ return xs === -1 ? html + scriptTag : html.slice(0, xs) + scriptTag + html.slice(xs);
962
+ }
963
+ let head = assetsHtml || "";
964
+ if (emittedAssets && emittedAssets.size) {
965
+ for (const url of emittedAssets) {
966
+ head += url.endsWith(".css") ? `<link rel="stylesheet" href="${url}">` : `<link rel="modulepreload" href="${url}">`;
967
+ }
968
+ }
969
+ if (inlineStyles && inlineStyles.size) {
970
+ for (const entry of inlineStyles.values()) {
971
+ if (entry.emitted) continue;
972
+ entry.emitted = true;
973
+ head += renderInlineStyle(entry, nonce);
967
974
  }
968
975
  }
969
- const index = html.indexOf("</head>");
970
- if (index === -1) return html;
971
- return html.slice(0, index) + links + html.slice(index);
976
+ if (!scriptTag) return html.slice(0, headIdx) + head + html.slice(headIdx);
977
+ const xsIdx = html.indexOf("<!--xs-->");
978
+ if (xsIdx === -1) return html.slice(0, headIdx) + head + html.slice(headIdx) + scriptTag;
979
+ 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);
972
980
  }
973
981
  function serializeFragmentAssets(key, boundaryModules, context) {
974
982
  const map = boundaryModules.get(key);
@@ -1020,26 +1028,6 @@ function renderInlineStyle(entry, nonce) {
1020
1028
  }
1021
1029
  return `<style${nonce ? ` nonce="${nonce}"` : ""} data-asset="${escape(entry.id, true)}"${attrs}>${escapeStyleContent(entry.content)}</style>`;
1022
1030
  }
1023
- function injectInlineStyles(inlineStyles, html, nonce) {
1024
- if (!inlineStyles.size) return html;
1025
- const index = html.indexOf("</head>");
1026
- if (index === -1) return html;
1027
- let out = "";
1028
- for (const entry of inlineStyles.values()) {
1029
- if (entry.emitted) continue;
1030
- entry.emitted = true;
1031
- out += renderInlineStyle(entry, nonce);
1032
- }
1033
- return out ? html.slice(0, index) + out + html.slice(index) : html;
1034
- }
1035
- function injectScripts(html, scripts, nonce) {
1036
- const tag = `<script${nonce ? ` nonce="${nonce}"` : ""}>${scripts}</script>`;
1037
- const index = html.indexOf("<!--xs-->");
1038
- if (index > -1) {
1039
- return html.slice(0, index) + tag + html.slice(index);
1040
- }
1041
- return html + tag;
1042
- }
1043
1031
  function waitForFragments(registry, key) {
1044
1032
  for (const k of [...registry.keys()].reverse()) {
1045
1033
  if (key.startsWith(k)) return k;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@solidjs/web",
3
3
  "description": "Solid's web runtime: client rendering, hydration, SSR, and DOM-specific control flow (Portal, Dynamic).",
4
- "version": "2.0.0-beta.26",
4
+ "version": "2.0.0-beta.27",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",
7
7
  "homepage": "https://solidjs.com",
@@ -316,10 +316,10 @@
316
316
  "seroval-plugins": "~1.5.4"
317
317
  },
318
318
  "peerDependencies": {
319
- "solid-js": "^2.0.0-beta.26"
319
+ "solid-js": "^2.0.0-beta.27"
320
320
  },
321
321
  "devDependencies": {
322
- "solid-js": "2.0.0-beta.26"
322
+ "solid-js": "2.0.0-beta.27"
323
323
  },
324
324
  "scripts": {
325
325
  "build": "npm-run-all -nl build:clean types:copy-jsx build:js",
@@ -334,7 +334,7 @@
334
334
  "types:web-storage": "tsc --project ./storage/tsconfig.build.json",
335
335
  "types:web-frames": "tsc --project ./frames/tsconfig.build.json",
336
336
  "types:copy-serialization": "node -e \"fs.mkdirSync('./serialization/types', { recursive: true }); fs.copyFileSync('../../node_modules/@dom-expressions/runtime/src/serializer.d.ts', './serialization/types/index.d.ts');\"",
337
- "types:copy-server-functions": "node -e \"fs.mkdirSync('./types/server-functions', { recursive: true }); for (const f of ['shared', 'client', 'server']) fs.copyFileSync('../../node_modules/@dom-expressions/runtime/src/server-functions/' + f + '.d.ts', './types/server-functions/' + f + '.d.ts');\"",
337
+ "types:copy-server-functions": "node -e \"fs.mkdirSync('./types/server-functions', { recursive: true }); for (const f of ['shared', 'flash', 'client', 'server']) fs.copyFileSync('../../node_modules/@dom-expressions/runtime/src/server-functions/' + f + '.d.ts', './types/server-functions/' + f + '.d.ts');\"",
338
338
  "types:copy-frames": "node -e \"fs.mkdirSync('./types/frames', { recursive: true }); for (const f of ['frame-client', 'frame-transport', 'frame-sink', 'serializer']) fs.copyFileSync('../../node_modules/@dom-expressions/runtime/src/' + f + '.d.ts', './types/frames/' + f + '.d.ts'); for (const f of ['client', 'server']) fs.writeFileSync('./types/frames/' + f + '.d.ts', fs.readFileSync('./frames/types/' + f + '.d.ts', 'utf8').replaceAll('@dom-expressions/runtime/src/', './'));\"",
339
339
  "types:cjs": "node ../../scripts/sync-dual-types.mjs ./types ./types-cjs ./storage/types ./storage/types-cjs ./serialization/types ./serialization/types-cjs",
340
340
  "test": "vitest run && vitest run --config vite.config.server.mjs && vitest run --config vite.config.hydrate.mjs",
@@ -4,6 +4,7 @@ var seroval = require('seroval');
4
4
  var web = require('seroval-plugins/web');
5
5
 
6
6
  const DEFAULT_DISABLED_FEATURES = seroval.Feature.AggregateError | seroval.Feature.BigIntTypedArray;
7
+ const serializeOnlyDisabledFeatures = () => process.env.NODE_ENV === "development" ? 0 : seroval.Feature.ErrorPrototypeStack;
7
8
  const HYDRATION_GLOBAL = "_$HY.r";
8
9
  const DEFAULT_WEB_PLUGINS = Object.freeze([web.AbortSignalPlugin,
9
10
  web.CustomEventPlugin, web.DOMExceptionPlugin, web.EventPlugin,
@@ -15,7 +16,7 @@ function createSerializer(options) {
15
16
  return new seroval.Serializer({
16
17
  ...options,
17
18
  plugins: resolveSerializerPlugins(options.plugins),
18
- disabledFeatures: options.disabledFeatures === undefined ? DEFAULT_DISABLED_FEATURES : options.disabledFeatures
19
+ disabledFeatures: (options.disabledFeatures === undefined ? DEFAULT_DISABLED_FEATURES : options.disabledFeatures) | serializeOnlyDisabledFeatures()
19
20
  });
20
21
  }
21
22
  function createHydrationSerializer({
@@ -56,11 +57,13 @@ function serializeJSON(value, {
56
57
  onError,
57
58
  ...codecOptions
58
59
  }) {
60
+ const resolved = resolveCodecOptions(codecOptions);
59
61
  return seroval.toCrossJSONStream(value, {
60
62
  onParse,
61
63
  onDone,
62
64
  onError,
63
- ...resolveCodecOptions(codecOptions)
65
+ ...resolved,
66
+ disabledFeatures: resolved.disabledFeatures | serializeOnlyDisabledFeatures()
64
67
  });
65
68
  }
66
69
  function createJSONDeserializer(options) {
@@ -106,7 +109,7 @@ function createJSONSerializer({
106
109
  const stream = seroval.toCrossJSONStream(value, {
107
110
  refs,
108
111
  plugins: resolved.plugins,
109
- disabledFeatures: resolved.disabledFeatures,
112
+ disabledFeatures: resolved.disabledFeatures | serializeOnlyDisabledFeatures(),
110
113
  onParse(node, initial) {
111
114
  onData({
112
115
  key,
@@ -2,6 +2,7 @@ import { Feature, Serializer, getCrossReferenceHeader, toCrossJSONStream, fromCr
2
2
  import { AbortSignalPlugin, CustomEventPlugin, DOMExceptionPlugin, EventPlugin, FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin } from 'seroval-plugins/web';
3
3
 
4
4
  const DEFAULT_DISABLED_FEATURES = Feature.AggregateError | Feature.BigIntTypedArray;
5
+ const serializeOnlyDisabledFeatures = () => process.env.NODE_ENV === "development" ? 0 : Feature.ErrorPrototypeStack;
5
6
  const HYDRATION_GLOBAL = "_$HY.r";
6
7
  const DEFAULT_WEB_PLUGINS = Object.freeze([AbortSignalPlugin,
7
8
  CustomEventPlugin, DOMExceptionPlugin, EventPlugin,
@@ -13,7 +14,7 @@ function createSerializer(options) {
13
14
  return new Serializer({
14
15
  ...options,
15
16
  plugins: resolveSerializerPlugins(options.plugins),
16
- disabledFeatures: options.disabledFeatures === undefined ? DEFAULT_DISABLED_FEATURES : options.disabledFeatures
17
+ disabledFeatures: (options.disabledFeatures === undefined ? DEFAULT_DISABLED_FEATURES : options.disabledFeatures) | serializeOnlyDisabledFeatures()
17
18
  });
18
19
  }
19
20
  function createHydrationSerializer({
@@ -54,11 +55,13 @@ function serializeJSON(value, {
54
55
  onError,
55
56
  ...codecOptions
56
57
  }) {
58
+ const resolved = resolveCodecOptions(codecOptions);
57
59
  return toCrossJSONStream(value, {
58
60
  onParse,
59
61
  onDone,
60
62
  onError,
61
- ...resolveCodecOptions(codecOptions)
63
+ ...resolved,
64
+ disabledFeatures: resolved.disabledFeatures | serializeOnlyDisabledFeatures()
62
65
  });
63
66
  }
64
67
  function createJSONDeserializer(options) {
@@ -104,7 +107,7 @@ function createJSONSerializer({
104
107
  const stream = toCrossJSONStream(value, {
105
108
  refs,
106
109
  plugins: resolved.plugins,
107
- disabledFeatures: resolved.disabledFeatures,
110
+ disabledFeatures: resolved.disabledFeatures | serializeOnlyDisabledFeatures(),
108
111
  onParse(node, initial) {
109
112
  onData({
110
113
  key,
@@ -37,7 +37,9 @@ export interface WebSerializerOptions {
37
37
  scopeId?: string;
38
38
  /**
39
39
  * Seroval feature bitflags to exclude from output. Defaults to disabling
40
- * post-ES2017 features (AggregateError, BigInt typed arrays).
40
+ * post-ES2017 features (AggregateError, BigInt typed arrays). Outside
41
+ * development, `Error.prototype.stack` is additionally stripped on top of
42
+ * any override — serialized stacks leak server paths to the client.
41
43
  */
42
44
  disabledFeatures?: number;
43
45
  /** Extra plugins, composed ahead of `DEFAULT_WEB_PLUGINS`. */
@@ -101,6 +103,10 @@ export interface JSONCodecOptions {
101
103
  /**
102
104
  * Seroval feature bitflags to exclude. Defaults to disabling `RegExp`
103
105
  * (payloads may come from an untrusted peer). Must match on both peers.
106
+ * Outside development, the encoding side additionally strips
107
+ * `Error.prototype.stack` on top of any override — serialized stacks leak
108
+ * server paths to the client. Decoding stays permissive, so payloads from
109
+ * a development peer still round-trip.
104
110
  */
105
111
  disabledFeatures?: number;
106
112
  /** Maximum parse/deserialize depth. Defaults to 64. Must match on both peers. */
@@ -37,7 +37,9 @@ export interface WebSerializerOptions {
37
37
  scopeId?: string;
38
38
  /**
39
39
  * Seroval feature bitflags to exclude from output. Defaults to disabling
40
- * post-ES2017 features (AggregateError, BigInt typed arrays).
40
+ * post-ES2017 features (AggregateError, BigInt typed arrays). Outside
41
+ * development, `Error.prototype.stack` is additionally stripped on top of
42
+ * any override — serialized stacks leak server paths to the client.
41
43
  */
42
44
  disabledFeatures?: number;
43
45
  /** Extra plugins, composed ahead of `DEFAULT_WEB_PLUGINS`. */
@@ -101,6 +103,10 @@ export interface JSONCodecOptions {
101
103
  /**
102
104
  * Seroval feature bitflags to exclude. Defaults to disabling `RegExp`
103
105
  * (payloads may come from an untrusted peer). Must match on both peers.
106
+ * Outside development, the encoding side additionally strips
107
+ * `Error.prototype.stack` on top of any override — serialized stacks leak
108
+ * server paths to the client. Decoding stays permissive, so payloads from
109
+ * a development peer still round-trip.
104
110
  */
105
111
  disabledFeatures?: number;
106
112
  /** Maximum parse/deserialize depth. Defaults to 64. Must match on both peers. */
@@ -3,6 +3,8 @@
3
3
  var seroval = require('seroval');
4
4
  var web = require('seroval-plugins/web');
5
5
 
6
+ const REVALIDATE_HEADER = "X-Revalidate";
7
+
6
8
  seroval.Feature.AggregateError | seroval.Feature.BigIntTypedArray;
7
9
  const DEFAULT_WEB_PLUGINS = Object.freeze([web.AbortSignalPlugin,
8
10
  web.CustomEventPlugin, web.DOMExceptionPlugin, web.EventPlugin,
@@ -98,6 +100,14 @@ const INSTANCE_HEADER = "X-Server-Function-Instance";
98
100
  const BODY_FORMAT_HEADER = "X-Server-Function-Format";
99
101
  const SINGLE_FLIGHT_HEADER = "X-Single-Flight";
100
102
  const FILE_FORM_KEY = "__server_function_file__";
103
+ const FLASH_COOKIE = "flash";
104
+ const FLASH_MATCHER = new RegExp(`(?:^|;\\s*)${FLASH_COOKIE}=([^;]+)`);
105
+ function hasFlashCookie(cookieHeader) {
106
+ return !!cookieHeader && FLASH_MATCHER.test(cookieHeader);
107
+ }
108
+ function clearFlashCookie() {
109
+ return `${FLASH_COOKIE}=; Max-Age=0; Path=/`;
110
+ }
101
111
  const BodyFormat = {
102
112
  Serialized: "0",
103
113
  String: "1",
@@ -403,13 +413,13 @@ async function fetchServerFunction(base, id, options, args, meta) {
403
413
  await consumer(payload.data, {
404
414
  response
405
415
  });
406
- if (response.headers.has(ERROR_HEADER) && !response.headers.has("Location") && !response.headers.has("X-Revalidate")) {
416
+ if (response.headers.has(ERROR_HEADER) && !response.headers.has("Location") && !response.headers.has(REVALIDATE_HEADER)) {
407
417
  throw payload.value;
408
418
  }
409
419
  return payload.value;
410
420
  }
411
421
  }
412
- if (response.headers.has("Location") || response.headers.has("X-Revalidate") || response.headers.has(SINGLE_FLIGHT_HEADER)) {
422
+ if (response.headers.has("Location") || response.headers.has(REVALIDATE_HEADER) || response.headers.has(SINGLE_FLIGHT_HEADER)) {
413
423
  return response;
414
424
  }
415
425
  const result = await decodeResponse(response.clone());
@@ -487,16 +497,19 @@ function registerServerReference() {
487
497
  }
488
498
 
489
499
  exports.ERROR_HEADER = ERROR_HEADER;
500
+ exports.FLASH_COOKIE = FLASH_COOKIE;
490
501
  exports.FUNCTION_HEADER = FUNCTION_HEADER;
491
502
  exports.GET = GET;
492
503
  exports.INSTANCE_HEADER = INSTANCE_HEADER;
493
504
  exports.SINGLE_FLIGHT_HEADER = SINGLE_FLIGHT_HEADER;
505
+ exports.clearFlashCookie = clearFlashCookie;
494
506
  exports.configureServerFunctionsClient = configureServerFunctionsClient;
495
507
  exports.createServerReference = createServerReference;
496
508
  exports.decodeErrorHeaderValue = decodeErrorHeaderValue;
497
509
  exports.decodeResponse = decodeResponse;
498
510
  exports.encodeErrorHeaderValue = encodeErrorHeaderValue;
499
511
  exports.getServerFunctionMetadata = getServerFunctionMetadata;
512
+ exports.hasFlashCookie = hasFlashCookie;
500
513
  exports.isServerFunction = isServerFunction;
501
514
  exports.registerServerReference = registerServerReference;
502
515
  exports.subscribeFlightData = subscribeFlightData;
@@ -1,6 +1,8 @@
1
1
  import { fromCrossJSON, Feature } from 'seroval';
2
2
  import { AbortSignalPlugin, CustomEventPlugin, DOMExceptionPlugin, EventPlugin, FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin } from 'seroval-plugins/web';
3
3
 
4
+ const REVALIDATE_HEADER = "X-Revalidate";
5
+
4
6
  Feature.AggregateError | Feature.BigIntTypedArray;
5
7
  const DEFAULT_WEB_PLUGINS = Object.freeze([AbortSignalPlugin,
6
8
  CustomEventPlugin, DOMExceptionPlugin, EventPlugin,
@@ -96,6 +98,14 @@ const INSTANCE_HEADER = "X-Server-Function-Instance";
96
98
  const BODY_FORMAT_HEADER = "X-Server-Function-Format";
97
99
  const SINGLE_FLIGHT_HEADER = "X-Single-Flight";
98
100
  const FILE_FORM_KEY = "__server_function_file__";
101
+ const FLASH_COOKIE = "flash";
102
+ const FLASH_MATCHER = new RegExp(`(?:^|;\\s*)${FLASH_COOKIE}=([^;]+)`);
103
+ function hasFlashCookie(cookieHeader) {
104
+ return !!cookieHeader && FLASH_MATCHER.test(cookieHeader);
105
+ }
106
+ function clearFlashCookie() {
107
+ return `${FLASH_COOKIE}=; Max-Age=0; Path=/`;
108
+ }
99
109
  const BodyFormat = {
100
110
  Serialized: "0",
101
111
  String: "1",
@@ -401,13 +411,13 @@ async function fetchServerFunction(base, id, options, args, meta) {
401
411
  await consumer(payload.data, {
402
412
  response
403
413
  });
404
- if (response.headers.has(ERROR_HEADER) && !response.headers.has("Location") && !response.headers.has("X-Revalidate")) {
414
+ if (response.headers.has(ERROR_HEADER) && !response.headers.has("Location") && !response.headers.has(REVALIDATE_HEADER)) {
405
415
  throw payload.value;
406
416
  }
407
417
  return payload.value;
408
418
  }
409
419
  }
410
- if (response.headers.has("Location") || response.headers.has("X-Revalidate") || response.headers.has(SINGLE_FLIGHT_HEADER)) {
420
+ if (response.headers.has("Location") || response.headers.has(REVALIDATE_HEADER) || response.headers.has(SINGLE_FLIGHT_HEADER)) {
411
421
  return response;
412
422
  }
413
423
  const result = await decodeResponse(response.clone());
@@ -484,4 +494,4 @@ function registerServerReference() {
484
494
  throw new Error("registerServerReference must not be called in the client build");
485
495
  }
486
496
 
487
- export { ERROR_HEADER, FUNCTION_HEADER, GET, INSTANCE_HEADER, SINGLE_FLIGHT_HEADER, configureServerFunctionsClient, createServerReference, decodeErrorHeaderValue, decodeResponse, encodeErrorHeaderValue, getServerFunctionMetadata, isServerFunction, registerServerReference, subscribeFlightData, withMeta };
497
+ export { ERROR_HEADER, FLASH_COOKIE, FUNCTION_HEADER, GET, INSTANCE_HEADER, SINGLE_FLIGHT_HEADER, clearFlashCookie, configureServerFunctionsClient, createServerReference, decodeErrorHeaderValue, decodeResponse, encodeErrorHeaderValue, getServerFunctionMetadata, hasFlashCookie, isServerFunction, registerServerReference, subscribeFlightData, withMeta };