@solidjs/web 2.0.0-beta.16 → 2.0.0-beta.18
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/dev.cjs +153 -14
- package/dist/dev.js +154 -16
- package/dist/server.cjs +140 -40
- package/dist/server.js +141 -42
- package/dist/web.cjs +153 -14
- package/dist/web.js +154 -16
- package/package.json +25 -10
- package/serialization/dist/serialization.cjs +83 -0
- package/serialization/dist/serialization.js +75 -0
- package/serialization/package.json +20 -0
- package/serialization/types/index.d.ts +97 -0
- package/serialization/types-cjs/index.d.cts +97 -0
- package/serialization/types-cjs/package.json +3 -0
- package/types/client.d.ts +13 -0
- package/types/index.d.ts +7 -1
- package/types/serializer.d.ts +97 -0
- package/types/server.d.ts +54 -15
- package/types-cjs/client.d.cts +13 -0
- package/types-cjs/index.d.cts +7 -1
- package/types-cjs/serializer.d.cts +97 -0
- package/types-cjs/server.d.cts +54 -15
- package/storage/types/src/client.d.ts +0 -1
- package/storage/types/src/index.d.ts +0 -171
- package/storage/types/src/jsx.d.ts +0 -29
- package/storage/types/src/server-mock.d.ts +0 -161
- package/storage/types/storage/src/index.d.ts +0 -2
- package/storage/types-cjs/src/client.d.cts +0 -1
- package/storage/types-cjs/src/index.d.cts +0 -171
- package/storage/types-cjs/src/jsx.d.cts +0 -29
- package/storage/types-cjs/src/server-mock.d.cts +0 -161
- package/storage/types-cjs/storage/src/index.d.cts +0 -2
package/dist/server.cjs
CHANGED
|
@@ -66,25 +66,32 @@ const effect = (fn, effectFn, options) => solidJs.createRenderEffect(fn, effectF
|
|
|
66
66
|
} : transparentOptions);
|
|
67
67
|
const memo = fn => solidJs.createMemo(() => fn(), syncOptions);
|
|
68
68
|
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
|
|
69
|
+
const DEFAULT_DISABLED_FEATURES = seroval.Feature.AggregateError | seroval.Feature.BigIntTypedArray;
|
|
70
|
+
const HYDRATION_GLOBAL = "_$HY.r";
|
|
71
|
+
const DEFAULT_WEB_PLUGINS = Object.freeze([web.AbortSignalPlugin,
|
|
72
|
+
web.CustomEventPlugin, web.DOMExceptionPlugin, web.EventPlugin,
|
|
73
|
+
web.FormDataPlugin, web.HeadersPlugin, web.ReadableStreamPlugin, web.RequestPlugin, web.ResponsePlugin, web.URLSearchParamsPlugin, web.URLPlugin]);
|
|
74
|
+
function resolveSerializerPlugins(customPlugins) {
|
|
75
|
+
return customPlugins ? [...customPlugins, ...DEFAULT_WEB_PLUGINS] : [...DEFAULT_WEB_PLUGINS];
|
|
76
|
+
}
|
|
77
|
+
function createSerializer(options) {
|
|
78
|
+
return new seroval.Serializer({
|
|
79
|
+
...options,
|
|
80
|
+
plugins: resolveSerializerPlugins(options.plugins),
|
|
81
|
+
disabledFeatures: options.disabledFeatures === undefined ? DEFAULT_DISABLED_FEATURES : options.disabledFeatures
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
function createHydrationSerializer({
|
|
73
85
|
onData,
|
|
74
86
|
onDone,
|
|
75
87
|
scopeId,
|
|
76
88
|
onError,
|
|
77
|
-
plugins
|
|
89
|
+
plugins
|
|
78
90
|
}) {
|
|
79
|
-
|
|
80
|
-
web.CustomEventPlugin, web.DOMExceptionPlugin, web.EventPlugin,
|
|
81
|
-
web.FormDataPlugin, web.HeadersPlugin, web.ReadableStreamPlugin, web.RequestPlugin, web.ResponsePlugin, web.URLSearchParamsPlugin, web.URLPlugin];
|
|
82
|
-
const allPlugins = customPlugins ? [...customPlugins, ...defaultPlugins] : defaultPlugins;
|
|
83
|
-
return new seroval.Serializer({
|
|
91
|
+
return createSerializer({
|
|
84
92
|
scopeId,
|
|
85
|
-
plugins
|
|
86
|
-
globalIdentifier:
|
|
87
|
-
disabledFeatures: ES2017FLAG,
|
|
93
|
+
plugins,
|
|
94
|
+
globalIdentifier: HYDRATION_GLOBAL,
|
|
88
95
|
onData,
|
|
89
96
|
onDone,
|
|
90
97
|
onError
|
|
@@ -93,6 +100,7 @@ function createSerializer({
|
|
|
93
100
|
function getLocalHeaderScript(id) {
|
|
94
101
|
return seroval.getCrossReferenceHeader(id) + ";";
|
|
95
102
|
}
|
|
103
|
+
seroval.Feature.RegExp;
|
|
96
104
|
|
|
97
105
|
function joinAssetPath(base, file) {
|
|
98
106
|
if (/^(?:[a-z][a-z0-9+.-]*:)?\/\//i.test(file)) return file;
|
|
@@ -124,7 +132,7 @@ function resolveAssets(moduleUrl, manifest) {
|
|
|
124
132
|
};
|
|
125
133
|
}
|
|
126
134
|
function registerEntryAssets(manifest) {
|
|
127
|
-
if (!manifest) return;
|
|
135
|
+
if (!manifest || typeof manifest === "function" || typeof manifest.resolve === "function") return;
|
|
128
136
|
const ctx = solidJs.sharedConfig.context;
|
|
129
137
|
if (!ctx?.registerAsset) return;
|
|
130
138
|
for (const key in manifest) {
|
|
@@ -141,25 +149,48 @@ function createAssetTracking() {
|
|
|
141
149
|
const boundaryModules = new Map();
|
|
142
150
|
const boundaryStyles = new Map();
|
|
143
151
|
const emittedAssets = new Set();
|
|
152
|
+
const inlineStyles = new Map();
|
|
144
153
|
let currentBoundaryId = null;
|
|
145
154
|
return {
|
|
146
155
|
boundaryModules,
|
|
147
156
|
boundaryStyles,
|
|
148
157
|
emittedAssets,
|
|
158
|
+
inlineStyles,
|
|
159
|
+
registerInlineStyle(desc) {
|
|
160
|
+
let entry = inlineStyles.get(desc.id);
|
|
161
|
+
if (!entry) {
|
|
162
|
+
entry = {
|
|
163
|
+
id: desc.id,
|
|
164
|
+
content: desc.content || "",
|
|
165
|
+
attrs: desc.attrs,
|
|
166
|
+
emitted: false
|
|
167
|
+
};
|
|
168
|
+
inlineStyles.set(desc.id, entry);
|
|
169
|
+
}
|
|
170
|
+
if (currentBoundaryId) {
|
|
171
|
+
let styles = boundaryStyles.get(currentBoundaryId);
|
|
172
|
+
if (!styles) {
|
|
173
|
+
styles = new Set();
|
|
174
|
+
boundaryStyles.set(currentBoundaryId, styles);
|
|
175
|
+
}
|
|
176
|
+
styles.add(entry);
|
|
177
|
+
}
|
|
178
|
+
return entry;
|
|
179
|
+
},
|
|
149
180
|
get currentBoundaryId() {
|
|
150
181
|
return currentBoundaryId;
|
|
151
182
|
},
|
|
152
183
|
set currentBoundaryId(v) {
|
|
153
184
|
currentBoundaryId = v;
|
|
154
185
|
},
|
|
155
|
-
registerModule(
|
|
186
|
+
registerModule(key, entryUrl) {
|
|
156
187
|
const id = currentBoundaryId || "";
|
|
157
188
|
let map = boundaryModules.get(id);
|
|
158
189
|
if (!map) {
|
|
159
190
|
map = {};
|
|
160
191
|
boundaryModules.set(id, map);
|
|
161
192
|
}
|
|
162
|
-
map[
|
|
193
|
+
map[key] = entryUrl;
|
|
163
194
|
},
|
|
164
195
|
getBoundaryModules(id) {
|
|
165
196
|
return boundaryModules.get(id) || null;
|
|
@@ -182,10 +213,21 @@ function applyAssetTracking(context, tracking, manifest) {
|
|
|
182
213
|
});
|
|
183
214
|
context.registerModule = tracking.registerModule;
|
|
184
215
|
context.getBoundaryModules = tracking.getBoundaryModules;
|
|
185
|
-
if (manifest
|
|
216
|
+
if (typeof manifest === "function") {
|
|
217
|
+
context.resolveAssets = manifest;
|
|
218
|
+
} else if (manifest && typeof manifest.resolve === "function") {
|
|
219
|
+
context.resolveAssets = key => manifest.resolve(key);
|
|
220
|
+
if (typeof manifest.resolveSync === "function") {
|
|
221
|
+
context.resolveAssetsSync = key => manifest.resolveSync(key);
|
|
222
|
+
}
|
|
223
|
+
} else if (manifest) {
|
|
224
|
+
const resolve = moduleUrl => resolveAssets(moduleUrl, manifest);
|
|
225
|
+
context.resolveAssets = resolve;
|
|
226
|
+
context.resolveAssetsSync = resolve;
|
|
227
|
+
}
|
|
186
228
|
}
|
|
187
229
|
const VOID_ELEMENTS = /^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i;
|
|
188
|
-
const REPLACE_SCRIPT = `function $df(e,n,o,t){if(!(n=document.getElementById(e))
|
|
230
|
+
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])}`;
|
|
189
231
|
function renderToString(code, options = {}) {
|
|
190
232
|
const {
|
|
191
233
|
renderId = "",
|
|
@@ -194,7 +236,7 @@ function renderToString(code, options = {}) {
|
|
|
194
236
|
manifest
|
|
195
237
|
} = options;
|
|
196
238
|
let scripts = "";
|
|
197
|
-
const serializer =
|
|
239
|
+
const serializer = createHydrationSerializer({
|
|
198
240
|
scopeId: renderId,
|
|
199
241
|
plugins: options.plugins,
|
|
200
242
|
onData(script) {
|
|
@@ -220,16 +262,20 @@ function renderToString(code, options = {}) {
|
|
|
220
262
|
}
|
|
221
263
|
serializer.write(id, p);
|
|
222
264
|
},
|
|
223
|
-
registerAsset(type,
|
|
265
|
+
registerAsset(type, value) {
|
|
266
|
+
if (type === "inline-style") {
|
|
267
|
+
tracking.registerInlineStyle(value);
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
224
270
|
if (tracking.currentBoundaryId && type === "style") {
|
|
225
271
|
let styles = tracking.boundaryStyles.get(tracking.currentBoundaryId);
|
|
226
272
|
if (!styles) {
|
|
227
273
|
styles = new Set();
|
|
228
274
|
tracking.boundaryStyles.set(tracking.currentBoundaryId, styles);
|
|
229
275
|
}
|
|
230
|
-
styles.add(
|
|
276
|
+
styles.add(value);
|
|
231
277
|
}
|
|
232
|
-
tracking.emittedAssets.add(
|
|
278
|
+
tracking.emittedAssets.add(value);
|
|
233
279
|
}
|
|
234
280
|
};
|
|
235
281
|
applyAssetTracking(solidJs.sharedConfig.context, tracking, manifest);
|
|
@@ -245,6 +291,7 @@ function renderToString(code, options = {}) {
|
|
|
245
291
|
serializer.close();
|
|
246
292
|
html = injectAssets(solidJs.sharedConfig.context.assets, html);
|
|
247
293
|
html = injectPreloadLinks(tracking.emittedAssets, html);
|
|
294
|
+
html = injectInlineStyles(tracking.inlineStyles, html, nonce);
|
|
248
295
|
if (scripts.length) html = injectScripts(html, scripts, options.nonce);
|
|
249
296
|
return html;
|
|
250
297
|
}
|
|
@@ -283,7 +330,7 @@ function renderToStream(code, options = {}) {
|
|
|
283
330
|
completed = true;
|
|
284
331
|
if (firstFlushed) dispose();
|
|
285
332
|
};
|
|
286
|
-
const serializer =
|
|
333
|
+
const serializer = createHydrationSerializer({
|
|
287
334
|
scopeId: options.renderId,
|
|
288
335
|
plugins: options.plugins,
|
|
289
336
|
onData: pushTask,
|
|
@@ -355,19 +402,27 @@ function renderToStream(code, options = {}) {
|
|
|
355
402
|
async: true,
|
|
356
403
|
assets: [],
|
|
357
404
|
nonce,
|
|
358
|
-
registerAsset(type,
|
|
405
|
+
registerAsset(type, value) {
|
|
406
|
+
if (type === "inline-style") {
|
|
407
|
+
const entry = tracking.registerInlineStyle(value);
|
|
408
|
+
if (firstFlushed && !tracking.currentBoundaryId && !entry.emitted) {
|
|
409
|
+
entry.emitted = true;
|
|
410
|
+
buffer.write(renderInlineStyle(entry, nonce));
|
|
411
|
+
}
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
359
414
|
if (tracking.currentBoundaryId && type === "style") {
|
|
360
415
|
let styles = tracking.boundaryStyles.get(tracking.currentBoundaryId);
|
|
361
416
|
if (!styles) {
|
|
362
417
|
styles = new Set();
|
|
363
418
|
tracking.boundaryStyles.set(tracking.currentBoundaryId, styles);
|
|
364
419
|
}
|
|
365
|
-
styles.add(
|
|
420
|
+
styles.add(value);
|
|
366
421
|
}
|
|
367
|
-
if (!tracking.emittedAssets.has(
|
|
368
|
-
tracking.emittedAssets.add(
|
|
422
|
+
if (!tracking.emittedAssets.has(value)) {
|
|
423
|
+
tracking.emittedAssets.add(value);
|
|
369
424
|
if (firstFlushed && type === "module") {
|
|
370
|
-
buffer.write(`<link rel="modulepreload" href="${
|
|
425
|
+
buffer.write(`<link rel="modulepreload" href="${value}">`);
|
|
371
426
|
}
|
|
372
427
|
}
|
|
373
428
|
},
|
|
@@ -451,10 +506,13 @@ function renderToStream(code, options = {}) {
|
|
|
451
506
|
serializeFragmentAssets(key, tracking.boundaryModules, context);
|
|
452
507
|
const styles = collectStreamStyles(key, tracking, headStyles);
|
|
453
508
|
const deferActivation = !!revealGroup;
|
|
454
|
-
|
|
455
|
-
|
|
509
|
+
for (let i = 0; i < styles.inline.length; i++) {
|
|
510
|
+
buffer.write(renderInlineStyle(styles.inline[i], nonce));
|
|
511
|
+
}
|
|
512
|
+
if (styles.links.length) {
|
|
513
|
+
emitTask(`$dfs("${key}",${styles.links.length},${deferActivation ? 1 : 0})`);
|
|
456
514
|
writeTasks();
|
|
457
|
-
for (const url of styles) {
|
|
515
|
+
for (const url of styles.links) {
|
|
458
516
|
buffer.write(`<link rel="stylesheet" href="${url}" onload="$dfc('${key}')" onerror="$dfc('${key}')">`);
|
|
459
517
|
}
|
|
460
518
|
buffer.write(`<template id="${key}">${value !== undefined ? value : " "}</template>`);
|
|
@@ -545,6 +603,7 @@ function renderToStream(code, options = {}) {
|
|
|
545
603
|
if (url.endsWith(".css")) headStyles.add(url);
|
|
546
604
|
}
|
|
547
605
|
html = injectPreloadLinks(tracking.emittedAssets, html);
|
|
606
|
+
html = injectInlineStyles(tracking.inlineStyles, html, nonce);
|
|
548
607
|
serializeRootAssets();
|
|
549
608
|
if (tasks.length) html = injectScripts(html, tasks, nonce);
|
|
550
609
|
buffer.write(html);
|
|
@@ -850,10 +909,11 @@ function ssrStyleProperty(name, value) {
|
|
|
850
909
|
return value != null ? name + value : "";
|
|
851
910
|
}
|
|
852
911
|
function ssrElement(tag, props, children, needsId) {
|
|
912
|
+
const hk = needsId ? ssrHydrationKey() : "";
|
|
853
913
|
if (props == null) props = {};else if (typeof props === "function") props = props();
|
|
854
914
|
const skipChildren = VOID_ELEMENTS.test(tag);
|
|
855
915
|
const keys = Object.keys(props);
|
|
856
|
-
let result = `<${tag}${
|
|
916
|
+
let result = `<${tag}${hk} `;
|
|
857
917
|
for (let i = 0; i < keys.length; i++) {
|
|
858
918
|
const prop = keys[i];
|
|
859
919
|
if (ChildProperties.has(prop)) {
|
|
@@ -898,7 +958,10 @@ function escape(s, attr) {
|
|
|
898
958
|
for (let i = 0; i < s.length; i++) s[i] = escape(s[i]);
|
|
899
959
|
return s;
|
|
900
960
|
}
|
|
901
|
-
if (attr
|
|
961
|
+
if (attr) {
|
|
962
|
+
if (s == null || t === "boolean" || t === "number") return s;
|
|
963
|
+
return escape(String(s), attr);
|
|
964
|
+
}
|
|
902
965
|
return s;
|
|
903
966
|
}
|
|
904
967
|
const delimCode = attr ? 34 : 60;
|
|
@@ -1034,14 +1097,48 @@ function propagateBoundaryStyles(childKey, parentKey, tracking) {
|
|
|
1034
1097
|
}
|
|
1035
1098
|
function collectStreamStyles(key, tracking, headStyles) {
|
|
1036
1099
|
const styles = tracking.getBoundaryStyles(key);
|
|
1037
|
-
|
|
1038
|
-
const
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1100
|
+
const links = [];
|
|
1101
|
+
const inline = [];
|
|
1102
|
+
if (!styles) return {
|
|
1103
|
+
links,
|
|
1104
|
+
inline
|
|
1105
|
+
};
|
|
1106
|
+
for (const entry of styles) {
|
|
1107
|
+
if (typeof entry === "string") {
|
|
1108
|
+
if (!headStyles || !headStyles.has(entry)) links.push(entry);
|
|
1109
|
+
} else if (!entry.emitted) {
|
|
1110
|
+
entry.emitted = true;
|
|
1111
|
+
inline.push(entry);
|
|
1042
1112
|
}
|
|
1043
1113
|
}
|
|
1044
|
-
return
|
|
1114
|
+
return {
|
|
1115
|
+
links,
|
|
1116
|
+
inline
|
|
1117
|
+
};
|
|
1118
|
+
}
|
|
1119
|
+
function escapeStyleContent(content) {
|
|
1120
|
+
return content.replace(/<\/(style)/gi, "<\\/$1");
|
|
1121
|
+
}
|
|
1122
|
+
function renderInlineStyle(entry, nonce) {
|
|
1123
|
+
let attrs = "";
|
|
1124
|
+
if (entry.attrs) {
|
|
1125
|
+
for (const name in entry.attrs) {
|
|
1126
|
+
attrs += ` ${name}="${escape(String(entry.attrs[name]), true)}"`;
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
return `<style${nonce ? ` nonce="${nonce}"` : ""} data-asset="${escape(entry.id, true)}"${attrs}>${escapeStyleContent(entry.content)}</style>`;
|
|
1130
|
+
}
|
|
1131
|
+
function injectInlineStyles(inlineStyles, html, nonce) {
|
|
1132
|
+
if (!inlineStyles.size) return html;
|
|
1133
|
+
const index = html.indexOf("</head>");
|
|
1134
|
+
if (index === -1) return html;
|
|
1135
|
+
let out = "";
|
|
1136
|
+
for (const entry of inlineStyles.values()) {
|
|
1137
|
+
if (entry.emitted) continue;
|
|
1138
|
+
entry.emitted = true;
|
|
1139
|
+
out += renderInlineStyle(entry, nonce);
|
|
1140
|
+
}
|
|
1141
|
+
return out ? html.slice(0, index) + out + html.slice(index) : html;
|
|
1045
1142
|
}
|
|
1046
1143
|
function injectScripts(html, scripts, nonce) {
|
|
1047
1144
|
const tag = `<script${nonce ? ` nonce="${nonce}"` : ""}>${scripts}</script>`;
|
|
@@ -1227,7 +1324,9 @@ function Dynamic(props) {
|
|
|
1227
1324
|
return solidJs.createComponent(Comp, solidJs.omit(props, "component"));
|
|
1228
1325
|
}
|
|
1229
1326
|
function Portal(props) {
|
|
1230
|
-
|
|
1327
|
+
const o = solidJs.getOwner();
|
|
1328
|
+
if (o?.id != null) solidJs.getNextChildId(o);
|
|
1329
|
+
return undefined;
|
|
1231
1330
|
}
|
|
1232
1331
|
|
|
1233
1332
|
Object.defineProperty(exports, "Errored", {
|
|
@@ -1304,6 +1403,7 @@ exports.RawTextElements = RawTextElements;
|
|
|
1304
1403
|
exports.RequestContext = RequestContext;
|
|
1305
1404
|
exports.SVGElements = SVGElements;
|
|
1306
1405
|
exports.VoidElements = VoidElements;
|
|
1406
|
+
exports.acquireAsset = notSup;
|
|
1307
1407
|
exports.addEvent = notSup;
|
|
1308
1408
|
exports.applyRef = applyRef;
|
|
1309
1409
|
exports.assign = notSup;
|