@solidjs/web 2.0.0-beta.15 → 2.0.0-beta.16

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.
package/dist/server.cjs CHANGED
@@ -60,9 +60,9 @@ const syncOptions = {
60
60
  sync: true
61
61
  };
62
62
  const effect = (fn, effectFn, options) => solidJs.createRenderEffect(fn, effectFn, options ? {
63
- transparent: true,
64
63
  sync: true,
65
- ...options
64
+ ...options,
65
+ transparent: !options.scope
66
66
  } : transparentOptions);
67
67
  const memo = fn => solidJs.createMemo(() => fn(), syncOptions);
68
68
 
@@ -94,9 +94,15 @@ function getLocalHeaderScript(id) {
94
94
  return seroval.getCrossReferenceHeader(id) + ";";
95
95
  }
96
96
 
97
+ function joinAssetPath(base, file) {
98
+ if (/^(?:[a-z][a-z0-9+.-]*:)?\/\//i.test(file)) return file;
99
+ if (typeof base !== "string" || !base) base = "/";
100
+ if (base[base.length - 1] !== "/") base += "/";
101
+ return base + (file[0] === "/" ? file.slice(1) : file);
102
+ }
97
103
  function resolveAssets(moduleUrl, manifest) {
98
104
  if (!manifest) return null;
99
- const base = manifest._base || "/";
105
+ const base = manifest._base;
100
106
  const entry = manifest[moduleUrl];
101
107
  if (!entry) return null;
102
108
  const css = [];
@@ -107,8 +113,8 @@ function resolveAssets(moduleUrl, manifest) {
107
113
  visited.add(key);
108
114
  const e = manifest[key];
109
115
  if (!e) return;
110
- js.push(base + e.file);
111
- if (e.css) for (let i = 0; i < e.css.length; i++) css.push(base + e.css[i]);
116
+ js.push(joinAssetPath(base, e.file));
117
+ if (e.css) for (let i = 0; i < e.css.length; i++) css.push(joinAssetPath(base, e.css[i]));
112
118
  if (e.imports) for (let i = 0; i < e.imports.length; i++) walk(e.imports[i]);
113
119
  };
114
120
  walk(moduleUrl);
@@ -497,38 +503,41 @@ function renderToStream(code, options = {}) {
497
503
  }, {
498
504
  id: renderId
499
505
  });
500
- function doShell() {
501
- if (shellCompleted) return;
502
- if (rootHoles) {
503
- const pending = [];
504
- for (const {
505
- id,
506
- fn
507
- } of rootHoles) {
508
- const marker = `<!--rh${id}-->`;
509
- const res = resolveSSRNode(fn);
510
- if (!res.h.length) {
511
- html = html.replace(marker, res.t[0]);
512
- } else {
513
- let out = res.t[0];
514
- for (let j = 0; j < res.h.length; j++) {
515
- const newId = nextHoleId++;
516
- pending.push({
517
- id: newId,
518
- fn: res.h[j]
519
- });
520
- out += `<!--rh${newId}-->` + res.t[j + 1];
521
- }
522
- html = html.replace(marker, out);
523
- for (const p of res.p) blockingPromises.add(p);
506
+ function resolveRootHoles() {
507
+ if (!rootHoles) return true;
508
+ const pending = [];
509
+ for (const {
510
+ id,
511
+ fn
512
+ } of rootHoles) {
513
+ const marker = `<!--rh${id}-->`;
514
+ const res = resolveSSRNode(fn);
515
+ if (!res.h.length) {
516
+ html = html.replace(marker, res.t[0]);
517
+ } else {
518
+ let out = res.t[0];
519
+ for (let j = 0; j < res.h.length; j++) {
520
+ const newId = nextHoleId++;
521
+ pending.push({
522
+ id: newId,
523
+ fn: res.h[j]
524
+ });
525
+ out += `<!--rh${newId}-->` + res.t[j + 1];
524
526
  }
527
+ html = html.replace(marker, out);
528
+ for (const p of res.p) blockingPromises.add(p);
525
529
  }
526
- if (pending.length) {
527
- rootHoles = pending;
528
- return;
529
- }
530
- rootHoles = null;
531
530
  }
531
+ if (pending.length) {
532
+ rootHoles = pending;
533
+ return false;
534
+ }
535
+ rootHoles = null;
536
+ return true;
537
+ }
538
+ function doShell() {
539
+ if (shellCompleted) return;
540
+ if (!resolveRootHoles()) return;
532
541
  solidJs.sharedConfig.context = context;
533
542
  html = injectAssets(context.assets, html);
534
543
  headStyles = new Set();
@@ -560,7 +569,15 @@ function renderToStream(code, options = {}) {
560
569
  complete();
561
570
  };
562
571
  } else onCompleteAll = complete;
563
- queue(flushEnd);
572
+ function flush() {
573
+ allSettled(blockingPromises).then(() => {
574
+ setTimeout(() => {
575
+ if (!resolveRootHoles()) return flush();
576
+ queue(flushEnd);
577
+ });
578
+ });
579
+ }
580
+ flush();
564
581
  },
565
582
  pipe(w) {
566
583
  function flush() {
@@ -941,29 +958,6 @@ function tryJoinPlainSSRArray(nodes) {
941
958
  }
942
959
  return out;
943
960
  }
944
- function mergeProps(...sources) {
945
- const target = {};
946
- for (let i = 0; i < sources.length; i++) {
947
- let source = sources[i];
948
- if (typeof source === "function") source = source();
949
- if (source) {
950
- const descriptors = Object.getOwnPropertyDescriptors(source);
951
- for (const key in descriptors) {
952
- if (key in target) continue;
953
- Object.defineProperty(target, key, {
954
- enumerable: true,
955
- get() {
956
- for (let i = sources.length - 1; i >= 0; i--) {
957
- const v = (sources[i] || {})[key];
958
- if (v !== undefined) return v;
959
- }
960
- }
961
- });
962
- }
963
- }
964
- }
965
- return target;
966
- }
967
961
  function getHydrationKey() {
968
962
  const hydrate = solidJs.sharedConfig.context;
969
963
  return hydrate && solidJs.sharedConfig.getNextContextId();
@@ -1112,6 +1106,10 @@ function tryResolveString(node) {
1112
1106
  if (node.h && node.h.length > 0) return {
1113
1107
  merge: node
1114
1108
  };
1109
+ if (node.t === undefined) {
1110
+ console.warn(`Unrecognized value. Skipped inserting`, node);
1111
+ return "";
1112
+ }
1115
1113
  return Array.isArray(node.t) ? node.t[0] : node.t;
1116
1114
  }
1117
1115
  if (t === "function") {
@@ -1150,7 +1148,9 @@ function resolveSSRNode(node, result = {
1150
1148
  result.h.push(...node.h);
1151
1149
  result.p.push(...node.p);
1152
1150
  }
1153
- } else result.t[result.t.length - 1] += node.t;
1151
+ } else if (node.t !== undefined) {
1152
+ result.t[result.t.length - 1] += node.t;
1153
+ } else console.warn(`Unrecognized value. Skipped inserting`, node);
1154
1154
  } else if (t === "function") {
1155
1155
  try {
1156
1156
  resolveSSRNode(node(), result);
@@ -1187,15 +1187,38 @@ function dynamic(source) {
1187
1187
  const o = solidJs.getOwner();
1188
1188
  if (o?.id != null) solidJs.getNextChildId(o);
1189
1189
  return props => {
1190
- const memoOwner = solidJs.createOwner();
1191
- return solidJs.runWithOwner(memoOwner, () => {
1192
- const comp = source(),
1193
- t = typeof comp;
1194
- if (comp) {
1195
- if (t === "function") return comp(props);else if (t === "string") {
1196
- return ssrElement(comp, props, undefined, true);
1190
+ const comp = source();
1191
+ let p;
1192
+ let settled = false;
1193
+ let value;
1194
+ let error;
1195
+ if (comp && typeof comp.then === "function") {
1196
+ p = comp;
1197
+ p.then(v => {
1198
+ value = v;
1199
+ settled = true;
1200
+ }, err => {
1201
+ error = err;
1202
+ settled = true;
1203
+ });
1204
+ const ctx = solidJs.sharedConfig.context;
1205
+ if (ctx?.async) ctx.block(p.then(() => {}, () => {}));
1206
+ }
1207
+ return solidJs.createMemo(() => {
1208
+ let c = comp;
1209
+ if (p) {
1210
+ if (!settled) throw new solidJs.NotReadyError(p);
1211
+ if (error) throw error;
1212
+ c = value;
1213
+ }
1214
+ if (c) {
1215
+ if (typeof c === "function") return c(props);
1216
+ if (typeof c === "string") {
1217
+ return ssrElement(c, props, undefined, true);
1197
1218
  }
1198
1219
  }
1220
+ }, {
1221
+ sync: true
1199
1222
  });
1200
1223
  };
1201
1224
  }
@@ -1255,6 +1278,14 @@ Object.defineProperty(exports, "getOwner", {
1255
1278
  enumerable: true,
1256
1279
  get: function () { return solidJs.getOwner; }
1257
1280
  });
1281
+ Object.defineProperty(exports, "mergeProps", {
1282
+ enumerable: true,
1283
+ get: function () { return solidJs.merge; }
1284
+ });
1285
+ Object.defineProperty(exports, "scope", {
1286
+ enumerable: true,
1287
+ get: function () { return solidJs.ssrScope; }
1288
+ });
1258
1289
  Object.defineProperty(exports, "untrack", {
1259
1290
  enumerable: true,
1260
1291
  get: function () { return solidJs.untrack; }
@@ -1295,7 +1326,6 @@ exports.insert = notSup;
1295
1326
  exports.isDev = isDev;
1296
1327
  exports.isServer = isServer;
1297
1328
  exports.memo = memo;
1298
- exports.mergeProps = mergeProps;
1299
1329
  exports.ref = notSup;
1300
1330
  exports.registerDelegatedContainer = notSup;
1301
1331
  exports.registerDelegatedRoot = notSup;
package/dist/server.js CHANGED
@@ -1,5 +1,5 @@
1
- import { createRenderEffect, createMemo, sharedConfig, createRoot, ssrHandleError, getOwner, runWithOwner, createComponent, omit, getNextChildId, createOwner } from 'solid-js';
2
- export { Errored, For, Hydration, Loading, Match, NoHydration, Repeat, Reveal, Show, Switch, createComponent, getOwner, untrack } from 'solid-js';
1
+ import { createRenderEffect, createMemo, sharedConfig, createRoot, ssrHandleError, getOwner, runWithOwner, createComponent, omit, getNextChildId, NotReadyError } from 'solid-js';
2
+ export { Errored, For, Hydration, Loading, Match, NoHydration, Repeat, Reveal, Show, Switch, createComponent, getOwner, merge as mergeProps, ssrScope as scope, untrack } from 'solid-js';
3
3
  import { Serializer, Feature, getCrossReferenceHeader } from 'seroval';
4
4
  import { AbortSignalPlugin, CustomEventPlugin, DOMExceptionPlugin, EventPlugin, FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin } from 'seroval-plugins/web';
5
5
 
@@ -59,9 +59,9 @@ const syncOptions = {
59
59
  sync: true
60
60
  };
61
61
  const effect = (fn, effectFn, options) => createRenderEffect(fn, effectFn, options ? {
62
- transparent: true,
63
62
  sync: true,
64
- ...options
63
+ ...options,
64
+ transparent: !options.scope
65
65
  } : transparentOptions);
66
66
  const memo = fn => createMemo(() => fn(), syncOptions);
67
67
 
@@ -93,9 +93,15 @@ function getLocalHeaderScript(id) {
93
93
  return getCrossReferenceHeader(id) + ";";
94
94
  }
95
95
 
96
+ function joinAssetPath(base, file) {
97
+ if (/^(?:[a-z][a-z0-9+.-]*:)?\/\//i.test(file)) return file;
98
+ if (typeof base !== "string" || !base) base = "/";
99
+ if (base[base.length - 1] !== "/") base += "/";
100
+ return base + (file[0] === "/" ? file.slice(1) : file);
101
+ }
96
102
  function resolveAssets(moduleUrl, manifest) {
97
103
  if (!manifest) return null;
98
- const base = manifest._base || "/";
104
+ const base = manifest._base;
99
105
  const entry = manifest[moduleUrl];
100
106
  if (!entry) return null;
101
107
  const css = [];
@@ -106,8 +112,8 @@ function resolveAssets(moduleUrl, manifest) {
106
112
  visited.add(key);
107
113
  const e = manifest[key];
108
114
  if (!e) return;
109
- js.push(base + e.file);
110
- if (e.css) for (let i = 0; i < e.css.length; i++) css.push(base + e.css[i]);
115
+ js.push(joinAssetPath(base, e.file));
116
+ if (e.css) for (let i = 0; i < e.css.length; i++) css.push(joinAssetPath(base, e.css[i]));
111
117
  if (e.imports) for (let i = 0; i < e.imports.length; i++) walk(e.imports[i]);
112
118
  };
113
119
  walk(moduleUrl);
@@ -496,38 +502,41 @@ function renderToStream(code, options = {}) {
496
502
  }, {
497
503
  id: renderId
498
504
  });
499
- function doShell() {
500
- if (shellCompleted) return;
501
- if (rootHoles) {
502
- const pending = [];
503
- for (const {
504
- id,
505
- fn
506
- } of rootHoles) {
507
- const marker = `<!--rh${id}-->`;
508
- const res = resolveSSRNode(fn);
509
- if (!res.h.length) {
510
- html = html.replace(marker, res.t[0]);
511
- } else {
512
- let out = res.t[0];
513
- for (let j = 0; j < res.h.length; j++) {
514
- const newId = nextHoleId++;
515
- pending.push({
516
- id: newId,
517
- fn: res.h[j]
518
- });
519
- out += `<!--rh${newId}-->` + res.t[j + 1];
520
- }
521
- html = html.replace(marker, out);
522
- for (const p of res.p) blockingPromises.add(p);
505
+ function resolveRootHoles() {
506
+ if (!rootHoles) return true;
507
+ const pending = [];
508
+ for (const {
509
+ id,
510
+ fn
511
+ } of rootHoles) {
512
+ const marker = `<!--rh${id}-->`;
513
+ const res = resolveSSRNode(fn);
514
+ if (!res.h.length) {
515
+ html = html.replace(marker, res.t[0]);
516
+ } else {
517
+ let out = res.t[0];
518
+ for (let j = 0; j < res.h.length; j++) {
519
+ const newId = nextHoleId++;
520
+ pending.push({
521
+ id: newId,
522
+ fn: res.h[j]
523
+ });
524
+ out += `<!--rh${newId}-->` + res.t[j + 1];
523
525
  }
526
+ html = html.replace(marker, out);
527
+ for (const p of res.p) blockingPromises.add(p);
524
528
  }
525
- if (pending.length) {
526
- rootHoles = pending;
527
- return;
528
- }
529
- rootHoles = null;
530
529
  }
530
+ if (pending.length) {
531
+ rootHoles = pending;
532
+ return false;
533
+ }
534
+ rootHoles = null;
535
+ return true;
536
+ }
537
+ function doShell() {
538
+ if (shellCompleted) return;
539
+ if (!resolveRootHoles()) return;
531
540
  sharedConfig.context = context;
532
541
  html = injectAssets(context.assets, html);
533
542
  headStyles = new Set();
@@ -559,7 +568,15 @@ function renderToStream(code, options = {}) {
559
568
  complete();
560
569
  };
561
570
  } else onCompleteAll = complete;
562
- queue(flushEnd);
571
+ function flush() {
572
+ allSettled(blockingPromises).then(() => {
573
+ setTimeout(() => {
574
+ if (!resolveRootHoles()) return flush();
575
+ queue(flushEnd);
576
+ });
577
+ });
578
+ }
579
+ flush();
563
580
  },
564
581
  pipe(w) {
565
582
  function flush() {
@@ -940,29 +957,6 @@ function tryJoinPlainSSRArray(nodes) {
940
957
  }
941
958
  return out;
942
959
  }
943
- function mergeProps(...sources) {
944
- const target = {};
945
- for (let i = 0; i < sources.length; i++) {
946
- let source = sources[i];
947
- if (typeof source === "function") source = source();
948
- if (source) {
949
- const descriptors = Object.getOwnPropertyDescriptors(source);
950
- for (const key in descriptors) {
951
- if (key in target) continue;
952
- Object.defineProperty(target, key, {
953
- enumerable: true,
954
- get() {
955
- for (let i = sources.length - 1; i >= 0; i--) {
956
- const v = (sources[i] || {})[key];
957
- if (v !== undefined) return v;
958
- }
959
- }
960
- });
961
- }
962
- }
963
- }
964
- return target;
965
- }
966
960
  function getHydrationKey() {
967
961
  const hydrate = sharedConfig.context;
968
962
  return hydrate && sharedConfig.getNextContextId();
@@ -1111,6 +1105,10 @@ function tryResolveString(node) {
1111
1105
  if (node.h && node.h.length > 0) return {
1112
1106
  merge: node
1113
1107
  };
1108
+ if (node.t === undefined) {
1109
+ console.warn(`Unrecognized value. Skipped inserting`, node);
1110
+ return "";
1111
+ }
1114
1112
  return Array.isArray(node.t) ? node.t[0] : node.t;
1115
1113
  }
1116
1114
  if (t === "function") {
@@ -1149,7 +1147,9 @@ function resolveSSRNode(node, result = {
1149
1147
  result.h.push(...node.h);
1150
1148
  result.p.push(...node.p);
1151
1149
  }
1152
- } else result.t[result.t.length - 1] += node.t;
1150
+ } else if (node.t !== undefined) {
1151
+ result.t[result.t.length - 1] += node.t;
1152
+ } else console.warn(`Unrecognized value. Skipped inserting`, node);
1153
1153
  } else if (t === "function") {
1154
1154
  try {
1155
1155
  resolveSSRNode(node(), result);
@@ -1186,15 +1186,38 @@ function dynamic(source) {
1186
1186
  const o = getOwner();
1187
1187
  if (o?.id != null) getNextChildId(o);
1188
1188
  return props => {
1189
- const memoOwner = createOwner();
1190
- return runWithOwner(memoOwner, () => {
1191
- const comp = source(),
1192
- t = typeof comp;
1193
- if (comp) {
1194
- if (t === "function") return comp(props);else if (t === "string") {
1195
- return ssrElement(comp, props, undefined, true);
1189
+ const comp = source();
1190
+ let p;
1191
+ let settled = false;
1192
+ let value;
1193
+ let error;
1194
+ if (comp && typeof comp.then === "function") {
1195
+ p = comp;
1196
+ p.then(v => {
1197
+ value = v;
1198
+ settled = true;
1199
+ }, err => {
1200
+ error = err;
1201
+ settled = true;
1202
+ });
1203
+ const ctx = sharedConfig.context;
1204
+ if (ctx?.async) ctx.block(p.then(() => {}, () => {}));
1205
+ }
1206
+ return createMemo(() => {
1207
+ let c = comp;
1208
+ if (p) {
1209
+ if (!settled) throw new NotReadyError(p);
1210
+ if (error) throw error;
1211
+ c = value;
1212
+ }
1213
+ if (c) {
1214
+ if (typeof c === "function") return c(props);
1215
+ if (typeof c === "string") {
1216
+ return ssrElement(c, props, undefined, true);
1196
1217
  }
1197
1218
  }
1219
+ }, {
1220
+ sync: true
1198
1221
  });
1199
1222
  };
1200
1223
  }
@@ -1206,4 +1229,4 @@ function Portal(props) {
1206
1229
  throw new Error("Portal is not supported on the server");
1207
1230
  }
1208
1231
 
1209
- export { Assets, ChildProperties, DOMElements, DOMWithState, DelegatedEvents, Dynamic, HydrationScript, MathMLElements, Namespaces, Portal, RawTextElements, RequestContext, SVGElements, VoidElements, notSup as addEvent, applyRef, notSup as assign, notSup as className, notSup as delegateEvents, dynamic, notSup as dynamicProperty, effect, escape, generateHydrationScript, getAssets, notSup as getDelegatedRoot, getHydrationKey, notSup as getNextElement, notSup as getNextMarker, notSup as getNextMatch, getRequestEvent, notSup as hydrate, notSup as insert, isDev, isServer, memo, mergeProps, notSup as ref, notSup as registerDelegatedContainer, notSup as registerDelegatedRoot, notSup as render, renderToStream, renderToString, renderToStringAsync, notSup as runHydrationEvents, notSup as setAttribute, notSup as setAttributeNS, notSup as setProperty, notSup as setStyleProperty, notSup as spread, ssr, ssrAttribute, ssrClassName, ssrElement, ssrGroup, ssrHydrationKey, ssrStyle, ssrStyleProperty, notSup as style, notSup as template, notSup as unregisterDelegatedContainer, notSup as unregisterDelegatedRoot, useAssets };
1232
+ export { Assets, ChildProperties, DOMElements, DOMWithState, DelegatedEvents, Dynamic, HydrationScript, MathMLElements, Namespaces, Portal, RawTextElements, RequestContext, SVGElements, VoidElements, notSup as addEvent, applyRef, notSup as assign, notSup as className, notSup as delegateEvents, dynamic, notSup as dynamicProperty, effect, escape, generateHydrationScript, getAssets, notSup as getDelegatedRoot, getHydrationKey, notSup as getNextElement, notSup as getNextMarker, notSup as getNextMatch, getRequestEvent, notSup as hydrate, notSup as insert, isDev, isServer, memo, notSup as ref, notSup as registerDelegatedContainer, notSup as registerDelegatedRoot, notSup as render, renderToStream, renderToString, renderToStringAsync, notSup as runHydrationEvents, notSup as setAttribute, notSup as setAttributeNS, notSup as setProperty, notSup as setStyleProperty, notSup as spread, ssr, ssrAttribute, ssrClassName, ssrElement, ssrGroup, ssrHydrationKey, ssrStyle, ssrStyleProperty, notSup as style, notSup as template, notSup as unregisterDelegatedContainer, notSup as unregisterDelegatedRoot, useAssets };