solid-js 1.7.0-beta.0 → 1.7.0-beta.2

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.
@@ -1,5 +1,6 @@
1
- import { sharedConfig, splitProps } from 'solid-js';
1
+ import { sharedConfig, createRoot, splitProps } from 'solid-js';
2
2
  export { ErrorBoundary, For, Index, Match, Show, Suspense, SuspenseList, Switch, createComponent, mergeProps } from 'solid-js';
3
+ import { serialize, Feature } from 'seroval';
3
4
 
4
5
  const booleans = ["allowfullscreen", "async", "autofocus", "autoplay", "checked", "controls", "default", "disabled", "formnovalidate", "hidden", "indeterminate", "ismap", "loop", "multiple", "muted", "nomodule", "novalidate", "open", "playsinline", "readonly", "required", "reversed", "seamless", "selected"];
5
6
  const BooleanAttributes = /*#__PURE__*/new Set(booleans);
@@ -10,258 +11,17 @@ const Aliases = /*#__PURE__*/Object.assign(Object.create(null), {
10
11
  htmlFor: "for"
11
12
  });
12
13
 
13
- const {
14
- hasOwnProperty
15
- } = Object.prototype;
16
- const REF_START_CHARS = "hjkmoquxzABCDEFGHIJKLNPQRTUVWXYZ$_";
17
- const REF_START_CHARS_LEN = REF_START_CHARS.length;
18
- const REF_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789$_";
19
- const REF_CHARS_LEN = REF_CHARS.length;
20
- const STACK = [];
21
- const BUFFER = [""];
22
- let ASSIGNMENTS = new Map();
23
- let INDEX_OR_REF = new WeakMap();
24
- let REF_COUNT = 0;
25
- BUFFER.pop();
26
- function stringify(root) {
27
- if (writeProp(root, "")) {
28
- let result = BUFFER[0];
29
- for (let i = 1, len = BUFFER.length; i < len; i++) {
30
- result += BUFFER[i];
31
- }
32
- if (REF_COUNT) {
33
- if (ASSIGNMENTS.size) {
34
- let ref = INDEX_OR_REF.get(root);
35
- if (typeof ref === "number") {
36
- ref = toRefParam(REF_COUNT++);
37
- result = ref + "=" + result;
38
- }
39
- for (const [assignmentRef, assignments] of ASSIGNMENTS) {
40
- result += ";" + assignments + assignmentRef;
41
- }
42
- result += ";return " + ref;
43
- ASSIGNMENTS = new Map();
44
- } else {
45
- result = "return " + result;
46
- }
47
- result = "(function(" + refParamsString() + "){" + result + "}())";
48
- } else if (root && root.constructor === Object) {
49
- result = "(" + result + ")";
50
- }
51
- BUFFER.length = 0;
52
- INDEX_OR_REF = new WeakMap();
53
- return result;
54
- }
55
- return "void 0";
56
- }
57
- function writeProp(cur, accessor) {
58
- switch (typeof cur) {
59
- case "string":
60
- BUFFER.push(quote(cur, 0));
61
- break;
62
- case "number":
63
- BUFFER.push(cur + "");
64
- break;
65
- case "boolean":
66
- BUFFER.push(cur ? "!0" : "!1");
67
- break;
68
- case "object":
69
- if (cur === null) {
70
- BUFFER.push("null");
71
- } else {
72
- const ref = getRef(cur, accessor);
73
- switch (ref) {
74
- case true:
75
- return false;
76
- case false:
77
- switch (cur.constructor) {
78
- case Object:
79
- writeObject(cur);
80
- break;
81
- case Array:
82
- writeArray(cur);
83
- break;
84
- case Date:
85
- BUFFER.push('new Date("' + cur.toISOString() + '")');
86
- break;
87
- case RegExp:
88
- BUFFER.push(cur + "");
89
- break;
90
- case Map:
91
- BUFFER.push("new Map(");
92
- writeArray(Array.from(cur));
93
- BUFFER.push(")");
94
- break;
95
- case Set:
96
- BUFFER.push("new Set(");
97
- writeArray(Array.from(cur));
98
- BUFFER.push(")");
99
- break;
100
- case undefined:
101
- BUFFER.push("Object.assign(Object.create(null),");
102
- writeObject(cur);
103
- BUFFER.push(")");
104
- break;
105
- default:
106
- return false;
107
- }
108
- break;
109
- default:
110
- BUFFER.push(ref);
111
- break;
112
- }
113
- }
114
- break;
115
- default:
116
- return false;
117
- }
118
- return true;
119
- }
120
- function writeObject(obj) {
121
- let sep = "{";
122
- STACK.push(obj);
123
- for (const key in obj) {
124
- if (hasOwnProperty.call(obj, key)) {
125
- const val = obj[key];
126
- const escapedKey = toObjectKey(key);
127
- BUFFER.push(sep + escapedKey + ":");
128
- if (writeProp(val, escapedKey)) {
129
- sep = ",";
130
- } else {
131
- BUFFER.pop();
132
- }
133
- }
134
- }
135
- if (sep === "{") {
136
- BUFFER.push("{}");
137
- } else {
138
- BUFFER.push("}");
139
- }
140
- STACK.pop();
141
- }
142
- function writeArray(arr) {
143
- BUFFER.push("[");
144
- STACK.push(arr);
145
- writeProp(arr[0], 0);
146
- for (let i = 1, len = arr.length; i < len; i++) {
147
- BUFFER.push(",");
148
- writeProp(arr[i], i);
149
- }
150
- STACK.pop();
151
- BUFFER.push("]");
152
- }
153
- function getRef(cur, accessor) {
154
- let ref = INDEX_OR_REF.get(cur);
155
- if (ref === undefined) {
156
- INDEX_OR_REF.set(cur, BUFFER.length);
157
- return false;
158
- }
159
- if (typeof ref === "number") {
160
- ref = insertAndGetRef(cur, ref);
161
- }
162
- if (STACK.includes(cur)) {
163
- const parent = STACK[STACK.length - 1];
164
- let parentRef = INDEX_OR_REF.get(parent);
165
- if (typeof parentRef === "number") {
166
- parentRef = insertAndGetRef(parent, parentRef);
167
- }
168
- ASSIGNMENTS.set(ref, (ASSIGNMENTS.get(ref) || "") + toAssignment(parentRef, accessor) + "=");
169
- return true;
170
- }
171
- return ref;
172
- }
173
- function toObjectKey(name) {
174
- const invalidIdentifierPos = getInvalidIdentifierPos(name);
175
- return invalidIdentifierPos === -1 ? name : quote(name, invalidIdentifierPos);
176
- }
177
- function toAssignment(parent, key) {
178
- return parent + (typeof key === "number" || key[0] === '"' ? "[" + key + "]" : "." + key);
179
- }
180
- function getInvalidIdentifierPos(name) {
181
- let char = name[0];
182
- if (!(char >= "a" && char <= "z" || char >= "A" && char <= "Z" || char === "$" || char === "_")) {
183
- return 0;
184
- }
185
- for (let i = 1, len = name.length; i < len; i++) {
186
- char = name[i];
187
- if (!(char >= "a" && char <= "z" || char >= "A" && char <= "Z" || char >= "0" && char <= "9" || char === "$" || char === "_")) {
188
- return i;
189
- }
190
- }
191
- return -1;
192
- }
193
- function quote(str, startPos) {
194
- let result = "";
195
- let lastPos = 0;
196
- for (let i = startPos, len = str.length; i < len; i++) {
197
- let replacement;
198
- switch (str[i]) {
199
- case '"':
200
- replacement = '\\"';
201
- break;
202
- case "\\":
203
- replacement = "\\\\";
204
- break;
205
- case "<":
206
- replacement = "\\x3C";
207
- break;
208
- case "\n":
209
- replacement = "\\n";
210
- break;
211
- case "\r":
212
- replacement = "\\r";
213
- break;
214
- case "\u2028":
215
- replacement = "\\u2028";
216
- break;
217
- case "\u2029":
218
- replacement = "\\u2029";
219
- break;
220
- default:
221
- continue;
222
- }
223
- result += str.slice(lastPos, i) + replacement;
224
- lastPos = i + 1;
225
- }
226
- if (lastPos === startPos) {
227
- result = str;
228
- } else {
229
- result += str.slice(lastPos);
230
- }
231
- return '"' + result + '"';
232
- }
233
- function insertAndGetRef(obj, pos) {
234
- const ref = toRefParam(REF_COUNT++);
235
- INDEX_OR_REF.set(obj, ref);
236
- if (pos) {
237
- BUFFER[pos - 1] += ref + "=";
238
- } else {
239
- BUFFER[pos] = ref + "=" + BUFFER[pos];
240
- }
241
- return ref;
242
- }
243
- function refParamsString() {
244
- let result = REF_START_CHARS[0];
245
- for (let i = 1; i < REF_COUNT; i++) {
246
- result += "," + toRefParam(i);
247
- }
248
- REF_COUNT = 0;
249
- return result;
250
- }
251
- function toRefParam(index) {
252
- let mod = index % REF_START_CHARS_LEN;
253
- let ref = REF_START_CHARS[mod];
254
- index = (index - mod) / REF_START_CHARS_LEN;
255
- while (index > 0) {
256
- mod = index % REF_CHARS_LEN;
257
- ref += REF_CHARS[mod];
258
- index = (index - mod) / REF_CHARS_LEN;
259
- }
260
- return ref;
14
+ const ES2017FLAG = Feature.AggregateError
15
+ | Feature.BigInt
16
+ | Feature.BigIntTypedArray;
17
+ function stringify(data) {
18
+ return serialize(data, {
19
+ disabledFeatures: ES2017FLAG
20
+ });
261
21
  }
262
22
 
263
23
  const VOID_ELEMENTS = /^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i;
264
- const REPLACE_SCRIPT = `function $df(e,t,n,o,d){if(n=document.getElementById(e),o=document.getElementById("pl-"+e)){for(;o&&8!==o.nodeType&&o.nodeValue!=="pl-"+e;)d=o.nextSibling,o.remove(),o=d;o.replaceWith(n.content)}n.remove(),_$HY.set(e,t),_$HY.fe(e)}`;
24
+ const REPLACE_SCRIPT = `function $df(e,n,t,o,d){if(t=document.getElementById(e),o=document.getElementById("pl-"+e)){for(;o&&8!==o.nodeType&&o.nodeValue!=="pl-"+e;)d=o.nextSibling,o.remove(),o=d;_$HY.done?o.remove():o.replaceWith(t.content)}t.remove(),_$HY.set(e,n),_$HY.fe(e)}`;
265
25
  function renderToString(code, options = {}) {
266
26
  let scripts = "";
267
27
  sharedConfig.context = {
@@ -273,11 +33,14 @@ function renderToString(code, options = {}) {
273
33
  nonce: options.nonce,
274
34
  writeResource(id, p, error) {
275
35
  if (sharedConfig.context.noHydrate) return;
276
- if (error) return scripts += `_$HY.set("${id}", ${serializeError(p)});`;
36
+ if (error) return scripts += `_$HY.set("${id}", ${stringify(p)});`;
277
37
  scripts += `_$HY.set("${id}", ${stringify(p)});`;
278
38
  }
279
39
  };
280
- let html = resolveSSRNode(escape(code()));
40
+ let html = createRoot(d => {
41
+ setTimeout(d);
42
+ return resolveSSRNode(escape(code()));
43
+ });
281
44
  sharedConfig.context.noHydrate = true;
282
45
  html = injectAssets(sharedConfig.context.assets, html);
283
46
  if (scripts.length) html = injectScripts(html, scripts, options.nonce);
@@ -303,6 +66,7 @@ function renderToStream(code, options = {}) {
303
66
  onCompleteAll,
304
67
  renderId
305
68
  } = options;
69
+ let dispose;
306
70
  const blockingResources = [];
307
71
  const registry = new Map();
308
72
  const dedupe = new WeakMap();
@@ -316,6 +80,7 @@ function renderToStream(code, options = {}) {
316
80
  });
317
81
  writable && writable.end();
318
82
  completed = true;
83
+ setTimeout(dispose);
319
84
  }
320
85
  };
321
86
  const pushTask = task => {
@@ -367,7 +132,7 @@ function renderToStream(code, options = {}) {
367
132
  },
368
133
  writeResource(id, p, error, wait) {
369
134
  const serverOnly = sharedConfig.context.noHydrate;
370
- if (error) return !serverOnly && pushTask(serializeSet(dedupe, id, p, serializeError));
135
+ if (error) return !serverOnly && pushTask(serializeSet(dedupe, id, p));
371
136
  if (!p || typeof p !== "object" || !("then" in p)) return !serverOnly && pushTask(serializeSet(dedupe, id, p));
372
137
  if (!firstFlushed) wait && blockingResources.push(p);else !serverOnly && pushTask(`_$HY.init("${id}")`);
373
138
  if (serverOnly) return;
@@ -390,10 +155,10 @@ function renderToStream(code, options = {}) {
390
155
  if ((value !== undefined || error) && !completed) {
391
156
  if (!firstFlushed) {
392
157
  Promise.resolve().then(() => html = replacePlaceholder(html, key, value !== undefined ? value : ""));
393
- error && pushTask(serializeSet(dedupe, key, error, serializeError));
158
+ error && pushTask(serializeSet(dedupe, key, error));
394
159
  } else {
395
160
  buffer.write(`<template id="${key}">${value !== undefined ? value : " "}</template>`);
396
- pushTask(`${keys.length ? keys.map(k => `_$HY.unset("${k}")`).join(";") + ";" : ""}$df("${key}"${error ? "," + serializeError(error) : ""})${!scriptFlushed ? ";" + REPLACE_SCRIPT : ""}`);
161
+ pushTask(`${keys.length ? keys.map(k => `_$HY.unset("${k}")`).join(";") + ";" : ""}$df("${key}"${error ? "," + stringify(error) : ""})${!scriptFlushed ? ";" + REPLACE_SCRIPT : ""}`);
397
162
  scriptFlushed = true;
398
163
  }
399
164
  }
@@ -403,7 +168,10 @@ function renderToStream(code, options = {}) {
403
168
  };
404
169
  }
405
170
  };
406
- let html = resolveSSRNode(escape(code()));
171
+ let html = createRoot(d => {
172
+ dispose = d;
173
+ return resolveSSRNode(escape(code()));
174
+ });
407
175
  function doShell() {
408
176
  sharedConfig.context = context;
409
177
  context.noHydrate = true;
@@ -501,7 +269,7 @@ function ssrClassList(value) {
501
269
  classValue = !!value[key];
502
270
  if (!key || key === "undefined" || !classValue) continue;
503
271
  i && (result += " ");
504
- result += key;
272
+ result += escape(key);
505
273
  }
506
274
  return result;
507
275
  }
@@ -538,7 +306,7 @@ function ssrElement(tag, props, children, needsId) {
538
306
  } else if (prop === "class" || prop === "className" || prop === "classList") {
539
307
  if (classResolved) continue;
540
308
  let n;
541
- result += `class="${(n = props.class) ? n + " " : ""}${(n = props.className) ? n + " " : ""}${ssrClassList(props.classList)}"`;
309
+ result += `class="${escape(((n = props.class) ? n + " " : "") + ((n = props.className) ? n + " " : ""), true) + ssrClassList(props.classList)}"`;
542
310
  classResolved = true;
543
311
  } else if (BooleanAttributes.has(prop)) {
544
312
  if (value) result += prop;else continue;
@@ -551,7 +319,7 @@ function ssrElement(tag, props, children, needsId) {
551
319
  }
552
320
  if (skipChildren) {
553
321
  return {
554
- t: result + '/>'
322
+ t: result + "/>"
555
323
  };
556
324
  }
557
325
  return {
@@ -568,13 +336,10 @@ function ssrHydrationKey() {
568
336
  function escape(s, attr) {
569
337
  const t = typeof s;
570
338
  if (t !== "string") {
571
- if (!attr && t === "function") return escape(s(), attr);
339
+ if (!attr && t === "function") return escape(s());
572
340
  if (!attr && Array.isArray(s)) {
573
- let r = "";
574
- for (let i = 0; i < s.length; i++) r += resolveSSRNode(escape(s[i], attr));
575
- return {
576
- t: r
577
- };
341
+ for (let i = 0; i < s.length; i++) s[i] = escape(s[i]);
342
+ return s;
578
343
  }
579
344
  if (attr && t === "boolean") return String(s);
580
345
  return s;
@@ -619,8 +384,12 @@ function resolveSSRNode(node) {
619
384
  if (t === "string") return node;
620
385
  if (node == null || t === "boolean") return "";
621
386
  if (Array.isArray(node)) {
387
+ let prev = {};
622
388
  let mapped = "";
623
- for (let i = 0, len = node.length; i < len; i++) mapped += resolveSSRNode(node[i]);
389
+ for (let i = 0, len = node.length; i < len; i++) {
390
+ if (typeof prev !== "object" && typeof node[i] !== "object") mapped += `<!--!-->`;
391
+ mapped += resolveSSRNode(prev = node[i]);
392
+ }
624
393
  return mapped;
625
394
  }
626
395
  if (t === "object") return node.t;
@@ -677,21 +446,6 @@ function injectScripts(html, scripts, nonce) {
677
446
  }
678
447
  return html + tag;
679
448
  }
680
- function serializeError(error) {
681
- if (error.message) {
682
- const fields = {};
683
- const keys = Object.getOwnPropertyNames(error);
684
- for (let i = 0; i < keys.length; i++) {
685
- const key = keys[i];
686
- const value = error[key];
687
- if (!value || key !== "message" && typeof value !== "function") {
688
- fields[key] = value;
689
- }
690
- }
691
- return `Object.assign(new Error(${stringify(error.message)}), ${stringify(fields)})`;
692
- }
693
- return stringify(error);
694
- }
695
449
  function waitForFragments(registry, key) {
696
450
  for (const k of [...registry.keys()].reverse()) {
697
451
  if (key.startsWith(k)) {
@@ -701,11 +455,11 @@ function waitForFragments(registry, key) {
701
455
  }
702
456
  return false;
703
457
  }
704
- function serializeSet(registry, key, value, serializer = stringify) {
458
+ function serializeSet(registry, key, value) {
705
459
  const exist = registry.get(value);
706
460
  if (exist) return `_$HY.set("${key}", _$HY.r["${exist}"][0])`;
707
461
  value !== null && typeof value === "object" && registry.set(value, key);
708
- return `_$HY.set("${key}", ${serializer(value)})`;
462
+ return `_$HY.set("${key}", ${stringify(value)})`;
709
463
  }
710
464
  function replacePlaceholder(html, key, value) {
711
465
  const marker = `<template id="pl-${key}">`;
@@ -772,9 +526,10 @@ function ssrSpread(props, isSVG, skipChildren) {
772
526
  classResolved = true;
773
527
  } else if (BooleanAttributes.has(prop)) {
774
528
  if (value) result += prop;else continue;
775
- } else if (value == undefined || prop === "ref" || prop.slice(0, 2) === "on") {
529
+ } else if (value == undefined || prop === "ref" || prop.slice(0, 2) === "on" || prop.slice(0, 5) === "prop:") {
776
530
  continue;
777
531
  } else {
532
+ if (prop.slice(0, 5) === "attr:") prop = prop.slice(5);
778
533
  result += `${Aliases[prop] || prop}="${escape(value, true)}"`;
779
534
  }
780
535
  if (i !== keys.length - 1) result += " ";
@@ -783,6 +538,7 @@ function ssrSpread(props, isSVG, skipChildren) {
783
538
  }
784
539
 
785
540
  const isServer = true;
541
+ const isDev = false;
786
542
  function render() {}
787
543
  function hydrate() {}
788
544
  function insert() {}
@@ -803,4 +559,4 @@ function Portal(props) {
803
559
  return "";
804
560
  }
805
561
 
806
- export { Assets, Dynamic, Hydration, HydrationScript, NoHydration, Portal, addEventListener, delegateEvents, escape, generateHydrationScript, getAssets, getHydrationKey, hydrate, insert, isServer, pipeToNodeWritable, pipeToWritable, render, renderToStream, renderToString, renderToStringAsync, resolveSSRNode, spread, ssr, ssrAttribute, ssrClassList, ssrElement, ssrHydrationKey, ssrSpread, ssrStyle, stringify, useAssets };
562
+ export { Assets, Dynamic, Hydration, HydrationScript, NoHydration, Portal, addEventListener, delegateEvents, escape, generateHydrationScript, getAssets, getHydrationKey, hydrate, insert, isDev, isServer, pipeToNodeWritable, pipeToWritable, render, renderToStream, renderToString, renderToStringAsync, resolveSSRNode, spread, ssr, ssrAttribute, ssrClassList, ssrElement, ssrHydrationKey, ssrSpread, ssrStyle, stringify, useAssets };