solid-js 1.2.5 → 1.3.0-beta.10
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/README.md +3 -1
- package/dist/dev.cjs +137 -46
- package/dist/dev.js +135 -46
- package/dist/server.cjs +70 -60
- package/dist/server.js +70 -60
- package/dist/solid.cjs +137 -46
- package/dist/solid.js +135 -46
- package/package.json +27 -15
- package/types/index.d.ts +2 -3
- package/types/reactive/signal.d.ts +98 -82
- package/types/render/component.d.ts +4 -1
- package/types/render/hydration.d.ts +3 -2
- package/types/server/index.d.ts +2 -2
- package/types/server/reactive.d.ts +2 -2
- package/types/server/rendering.d.ts +7 -5
- package/web/dist/dev.cjs +32 -24
- package/web/dist/dev.js +33 -23
- package/web/dist/server.cjs +219 -135
- package/web/dist/server.js +220 -137
- package/web/dist/web.cjs +32 -24
- package/web/dist/web.js +33 -23
- package/web/types/client.d.ts +11 -3
- package/web/types/core.d.ts +2 -2
- package/web/types/index.d.ts +2 -0
- package/web/types/server-mock.d.ts +33 -20
package/web/dist/server.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { sharedConfig,
|
|
1
|
+
import { sharedConfig, splitProps } from 'solid-js';
|
|
2
2
|
export { ErrorBoundary, For, Index, Match, Show, Suspense, SuspenseList, Switch, createComponent, mergeProps } from 'solid-js';
|
|
3
3
|
|
|
4
4
|
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"];
|
|
@@ -229,147 +229,191 @@ function stringifyString(str) {
|
|
|
229
229
|
return result;
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
+
const REPLACE_SCRIPT = `function $df(e,y,t){t=document.getElementById(e),document.getElementById("pl"+e).replaceWith(...t.childNodes),_$HY.set(e,y)}`;
|
|
233
|
+
const FRAGMENT_REPLACE = /<!\[([\d.]+)\]>/;
|
|
232
234
|
function renderToString(code, options = {}) {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
+
let scripts = "";
|
|
236
|
+
sharedConfig.context = {
|
|
237
|
+
id: options.renderId || "",
|
|
235
238
|
count: 0,
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
239
|
+
suspense: {},
|
|
240
|
+
assets: [],
|
|
241
|
+
nonce: options.nonce,
|
|
242
|
+
writeResource(id, p, error) {
|
|
243
|
+
if (error) return scripts += `_$HY.set("${id}", ${serializeError(p)});`;
|
|
244
|
+
scripts += `_$HY.set("${id}", ${devalue(p)});`;
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
let html = injectAssets(sharedConfig.context.assets, resolveSSRNode(escape(code())));
|
|
248
|
+
if (scripts.length) html = injectScripts(html, scripts, options.nonce);
|
|
249
|
+
return html;
|
|
240
250
|
}
|
|
241
251
|
function renderToStringAsync(code, options = {}) {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
252
|
+
let scripts = "";
|
|
253
|
+
const {
|
|
254
|
+
nonce,
|
|
255
|
+
renderId,
|
|
256
|
+
timeoutMs = 30000
|
|
257
|
+
} = options;
|
|
258
|
+
const context = sharedConfig.context = {
|
|
259
|
+
id: renderId || "",
|
|
248
260
|
count: 0,
|
|
249
261
|
resources: {},
|
|
250
262
|
suspense: {},
|
|
251
263
|
assets: [],
|
|
252
|
-
async: true
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
264
|
+
async: true,
|
|
265
|
+
nonce,
|
|
266
|
+
writeResource(id, p, error) {
|
|
267
|
+
if (error) return scripts += `_$HY.set("${id}", ${serializeError(p)});`;
|
|
268
|
+
if (typeof p !== "object" || !("then" in p)) return scripts += `_$HY.set("${id}", ${devalue(p)});`;
|
|
269
|
+
p.then(d => scripts += `_$HY.set("${id}", ${devalue(d)});`).catch(() => scripts += `_$HY.set("${id}", null);`);
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
const timeout = new Promise((_, reject) => setTimeout(() => reject("renderToString timed out"), timeoutMs));
|
|
273
|
+
function asyncWrap(fn) {
|
|
274
|
+
return new Promise(resolve => {
|
|
275
|
+
const registry = new Set();
|
|
276
|
+
const cache = Object.create(null);
|
|
277
|
+
sharedConfig.context.registerFragment = register;
|
|
278
|
+
const rendered = fn();
|
|
279
|
+
if (!registry.size) resolve(rendered);
|
|
280
|
+
function register(key) {
|
|
281
|
+
registry.add(key);
|
|
282
|
+
return (value = "", error) => {
|
|
283
|
+
cache[key] = value;
|
|
284
|
+
registry.delete(key);
|
|
285
|
+
if (error) return scripts += `_$HY.set("${key}", Promise.resolve(${serializeError(error)}));`;
|
|
286
|
+
scripts += `_$HY.set("${key}", true);`;
|
|
287
|
+
if (!registry.size) Promise.resolve().then(() => {
|
|
288
|
+
let source = resolveSSRNode(rendered);
|
|
289
|
+
let final = "";
|
|
290
|
+
let match;
|
|
291
|
+
while (match = source.match(FRAGMENT_REPLACE)) {
|
|
292
|
+
final += source.substring(0, match.index);
|
|
293
|
+
source = cache[match[1]] + source.substring(match.index + match[0].length);
|
|
294
|
+
}
|
|
295
|
+
resolve(final + source);
|
|
296
|
+
});
|
|
297
|
+
return true;
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
return Promise.race([asyncWrap(() => escape(code())), timeout]).then(res => {
|
|
303
|
+
let html = injectAssets(context.assets, resolveSSRNode(res));
|
|
304
|
+
if (scripts.length) html = injectScripts(html, scripts, nonce);
|
|
305
|
+
return html;
|
|
258
306
|
});
|
|
259
307
|
}
|
|
260
|
-
function
|
|
308
|
+
function renderToStream(code, options = {}) {
|
|
261
309
|
const {
|
|
262
310
|
nonce,
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
onComplete
|
|
311
|
+
onCompleteShell,
|
|
312
|
+
onCompleteAll,
|
|
313
|
+
renderId
|
|
267
314
|
} = options;
|
|
268
315
|
const tmp = [];
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
316
|
+
const tasks = [];
|
|
317
|
+
const registry = new Map();
|
|
318
|
+
const checkEnd = () => {
|
|
319
|
+
if (!registry.size && !completed) {
|
|
320
|
+
onCompleteAll && onCompleteAll(result);
|
|
321
|
+
writable && writable.end();
|
|
322
|
+
completed = true;
|
|
274
323
|
}
|
|
275
324
|
};
|
|
276
|
-
const
|
|
277
|
-
|
|
278
|
-
buffer =
|
|
279
|
-
|
|
280
|
-
setTimeout(checkEnd);
|
|
281
|
-
},
|
|
282
|
-
write(c) {
|
|
283
|
-
writable.write(c);
|
|
284
|
-
},
|
|
285
|
-
abort() {
|
|
286
|
-
completed = count;
|
|
287
|
-
checkEnd();
|
|
325
|
+
const writeInitialScript = () => {
|
|
326
|
+
if (tasks.length && !completed) {
|
|
327
|
+
buffer.write(`<script${nonce ? ` nonce="${nonce}"` : ""}>${tasks.join(";")}</script>`);
|
|
328
|
+
tasks.length = 0;
|
|
288
329
|
}
|
|
330
|
+
scheduled = false;
|
|
289
331
|
};
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
332
|
+
let writable;
|
|
333
|
+
let completed = false;
|
|
334
|
+
let scriptFlushed = false;
|
|
335
|
+
let scheduled = true;
|
|
336
|
+
let buffer = {
|
|
337
|
+
write(payload) {
|
|
338
|
+
tmp.push(payload);
|
|
294
339
|
}
|
|
295
340
|
};
|
|
296
|
-
sharedConfig.context =
|
|
297
|
-
id: "",
|
|
341
|
+
sharedConfig.context = {
|
|
342
|
+
id: renderId || "",
|
|
298
343
|
count: 0,
|
|
344
|
+
async: true,
|
|
299
345
|
streaming: true,
|
|
346
|
+
resources: {},
|
|
300
347
|
suspense: {},
|
|
301
|
-
assets: []
|
|
302
|
-
}, options);
|
|
303
|
-
sharedConfig.context.writeResource = (id, p) => {
|
|
304
|
-
count++;
|
|
305
|
-
Promise.resolve().then(() => buffer.write(`<script${nonce ? ` nonce="${nonce}"` : ""}>_$HYDRATION.startResource("${id}")</script>`));
|
|
306
|
-
p.then(d => {
|
|
307
|
-
buffer.write(`<script${nonce ? ` nonce="${nonce}"` : ""}>_$HYDRATION.resolveResource("${id}", ${devalue(d)})</script>`);
|
|
308
|
-
++completed && checkEnd();
|
|
309
|
-
});
|
|
310
|
-
};
|
|
311
|
-
let html = resolveSSRNode(escape(code()));
|
|
312
|
-
html = injectAssets(sharedConfig.context.assets, html);
|
|
313
|
-
buffer.write(html);
|
|
314
|
-
onReady(result);
|
|
315
|
-
}
|
|
316
|
-
function pipeToWritable(code, writable, options = {}) {
|
|
317
|
-
const {
|
|
348
|
+
assets: [],
|
|
318
349
|
nonce,
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
assets: []
|
|
333
|
-
}, options);
|
|
334
|
-
let count = 0,
|
|
335
|
-
completed = 0,
|
|
336
|
-
buffer = {
|
|
337
|
-
write(payload) {
|
|
338
|
-
tmp.push(payload);
|
|
339
|
-
}
|
|
340
|
-
};
|
|
341
|
-
const result = {
|
|
342
|
-
startWriting() {
|
|
343
|
-
buffer = writer;
|
|
344
|
-
tmp.forEach(chunk => writer.write(chunk));
|
|
345
|
-
setTimeout(checkEnd);
|
|
346
|
-
},
|
|
347
|
-
write(c) {
|
|
348
|
-
writer.write(encoder.encode(c));
|
|
350
|
+
writeResource(id, p, error) {
|
|
351
|
+
if (!scheduled) {
|
|
352
|
+
Promise.resolve().then(writeInitialScript);
|
|
353
|
+
scheduled = true;
|
|
354
|
+
}
|
|
355
|
+
if (error) return tasks.push(`_$HY.set("${id}", ${serializeError(p)})`);
|
|
356
|
+
if (typeof p !== "object" || !("then" in p)) return tasks.push(`_$HY.set("${id}", ${devalue(p)})`);
|
|
357
|
+
tasks.push(`_$HY.init("${id}")`);
|
|
358
|
+
p.then(d => {
|
|
359
|
+
!completed && buffer.write(`<script${nonce ? ` nonce="${nonce}"` : ""}>_$HY.set("${id}", ${devalue(d)})</script>`);
|
|
360
|
+
}).catch(err => {
|
|
361
|
+
!completed && buffer.write(`<script${nonce ? ` nonce="${nonce}"` : ""}>_$HY.set("${id}", null, ${serializeError(err)})</script>`);
|
|
362
|
+
});
|
|
349
363
|
},
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
364
|
+
registerFragment(key) {
|
|
365
|
+
registry.set(key, []);
|
|
366
|
+
if (!scheduled) {
|
|
367
|
+
Promise.resolve().then(writeInitialScript);
|
|
368
|
+
scheduled = true;
|
|
369
|
+
}
|
|
370
|
+
tasks.push(`_$HY.init("${key}")`);
|
|
371
|
+
return (value, error) => {
|
|
372
|
+
const keys = registry.get(key);
|
|
373
|
+
registry.delete(key);
|
|
374
|
+
if (waitForFragments(registry, key)) return;
|
|
375
|
+
if ((value !== undefined || error) && !completed) {
|
|
376
|
+
buffer.write(`<div hidden id="${key}">${value !== undefined ? value : " "}</div><script${nonce ? ` nonce="${nonce}"` : ""}>${!scriptFlushed ? REPLACE_SCRIPT : ""}${keys.length ? keys.map(k => `_$HY.unset("${k}");`) : ""}$df("${key}"${error ? "," + serializeError(error) : ""})</script>`);
|
|
377
|
+
scriptFlushed = true;
|
|
378
|
+
}
|
|
379
|
+
checkEnd();
|
|
380
|
+
return true;
|
|
381
|
+
};
|
|
359
382
|
}
|
|
360
383
|
};
|
|
361
|
-
sharedConfig.context.writeResource = (id, p) => {
|
|
362
|
-
count++;
|
|
363
|
-
Promise.resolve().then(() => buffer.write(encoder.encode(`<script${nonce ? ` nonce="${nonce}"` : ""}>_$HYDRATION.startResource("${id}")</script>`)));
|
|
364
|
-
p.then(d => {
|
|
365
|
-
buffer.write(encoder.encode(`<script${nonce ? ` nonce="${nonce}"` : ""}>_$HYDRATION.resolveResource("${id}", ${devalue(d)})</script>`));
|
|
366
|
-
++completed && checkEnd();
|
|
367
|
-
});
|
|
368
|
-
};
|
|
369
384
|
let html = resolveSSRNode(escape(code()));
|
|
370
385
|
html = injectAssets(sharedConfig.context.assets, html);
|
|
371
|
-
|
|
372
|
-
|
|
386
|
+
Promise.resolve().then(() => {
|
|
387
|
+
if (tasks.length) html = injectScripts(html, tasks.join(";"), nonce);
|
|
388
|
+
buffer.write(html);
|
|
389
|
+
tasks.length = 0;
|
|
390
|
+
scheduled = false;
|
|
391
|
+
onCompleteShell && onCompleteShell();
|
|
392
|
+
});
|
|
393
|
+
return {
|
|
394
|
+
pipe(w) {
|
|
395
|
+
buffer = writable = w;
|
|
396
|
+
tmp.forEach(chunk => buffer.write(chunk));
|
|
397
|
+
if (completed) writable.end();else setTimeout(checkEnd);
|
|
398
|
+
},
|
|
399
|
+
pipeTo(w) {
|
|
400
|
+
const encoder = new TextEncoder();
|
|
401
|
+
const writer = w.getWriter();
|
|
402
|
+
writable = {
|
|
403
|
+
end() {
|
|
404
|
+
writer.releaseLock();
|
|
405
|
+
w.close();
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
buffer = {
|
|
409
|
+
write(payload) {
|
|
410
|
+
writer.write(encoder.encode(payload));
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
tmp.forEach(chunk => buffer.write(chunk));
|
|
414
|
+
if (completed) writable.end();else setTimeout(checkEnd);
|
|
415
|
+
}
|
|
416
|
+
};
|
|
373
417
|
}
|
|
374
418
|
function Assets(props) {
|
|
375
419
|
sharedConfig.context.assets.push(() => NoHydration({
|
|
@@ -379,15 +423,21 @@ function Assets(props) {
|
|
|
379
423
|
}));
|
|
380
424
|
return ssr(`%%$${sharedConfig.context.assets.length - 1}%%`);
|
|
381
425
|
}
|
|
382
|
-
function HydrationScript() {
|
|
383
|
-
|
|
426
|
+
function HydrationScript(props) {
|
|
427
|
+
const {
|
|
428
|
+
nonce
|
|
429
|
+
} = sharedConfig.context;
|
|
430
|
+
sharedConfig.context.assets.push(() => generateHydrationScript({
|
|
431
|
+
nonce,
|
|
432
|
+
...props
|
|
433
|
+
}));
|
|
384
434
|
return ssr(`%%$${sharedConfig.context.assets.length - 1}%%`);
|
|
385
435
|
}
|
|
386
436
|
function NoHydration(props) {
|
|
387
437
|
const c = sharedConfig.context;
|
|
388
|
-
|
|
438
|
+
c.noHydrate = true;
|
|
389
439
|
const children = props.children;
|
|
390
|
-
|
|
440
|
+
c.noHydrate = false;
|
|
391
441
|
return children;
|
|
392
442
|
}
|
|
393
443
|
function ssr(t, ...nodes) {
|
|
@@ -515,26 +565,13 @@ function resolveSSRNode(node) {
|
|
|
515
565
|
}
|
|
516
566
|
function getHydrationKey() {
|
|
517
567
|
const hydrate = sharedConfig.context;
|
|
518
|
-
return hydrate && `${hydrate.id}${hydrate.count++}`;
|
|
568
|
+
return hydrate && !hydrate.noHydrate && `${hydrate.id}${hydrate.count++}`;
|
|
519
569
|
}
|
|
520
|
-
function generateHydrationScript(
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
eventNames = ["click", "input"]
|
|
526
|
-
} = sharedConfig.context;
|
|
527
|
-
let s = `<script${nonce ? ` nonce="${nonce}"` : ""}>(()=>{_$HYDRATION={events:[],completed:new WeakSet};const t=e=>e&&e.hasAttribute&&(e.hasAttribute("data-hk")?e:t(e.host&&e.host instanceof Node?e.host:e.parentNode)),e=e=>{let o=e.composedPath&&e.composedPath()[0]||e.target,s=t(o);s&&!_$HYDRATION.completed.has(s)&&_$HYDRATION.events.push([s,e])};["${eventNames.join('","')}"].forEach(t=>document.addEventListener(t,e))})();`;
|
|
528
|
-
if (streaming) {
|
|
529
|
-
s += `(()=>{const e=_$HYDRATION,o={};e.startResource=e=>{let r;o[e]=[new Promise(e=>r=e),r]},e.resolveResource=(e,r)=>{const n=o[e];if(!n)return o[e]=[r];n[1](r)},e.loadResource=e=>{const r=o[e];if(r)return r[0]}})();`;
|
|
530
|
-
}
|
|
531
|
-
if (resources) {
|
|
532
|
-
s += `_$HYDRATION.resources = ${devalue(Object.keys(resources).reduce((r, k) => {
|
|
533
|
-
r[k] = resources[k].data;
|
|
534
|
-
return r;
|
|
535
|
-
}, {}))};`;
|
|
536
|
-
}
|
|
537
|
-
return s + `</script>`;
|
|
570
|
+
function generateHydrationScript({
|
|
571
|
+
eventNames = ["click", "input"],
|
|
572
|
+
nonce
|
|
573
|
+
}) {
|
|
574
|
+
return `<script${nonce ? ` nonce="${nonce}"` : ""}>((e,t,o={})=>{t=e=>e&&e.hasAttribute&&(e.hasAttribute("data-hk")?e:t(e.host&&e.host instanceof Node?e.host:e.parentNode)),["${eventNames.join('","')}"].forEach((o=>document.addEventListener(o,(o=>{let s=o.composedPath&&o.composedPath()[0]||o.target,n=t(s);n&&!e.completed.has(n)&&e.events.push([n,o])})))),e.init=(e,t,s)=>{o[e]=[new Promise(((e,o)=>(t=e,s=o))),t,s]},e.set=(e,t,s,n)=>{(n=o[e])&&(s?n[2](s):n[1](t)),o[e]=[t]},e.unset=e=>{delete o[e]},e.load=(e,t)=>{if(t=o[e])return t[0]}})(window._$HY||(_$HY={events:[],completed:new WeakSet}))</script><!xs>`;
|
|
538
575
|
}
|
|
539
576
|
function injectAssets(assets, html) {
|
|
540
577
|
for (let i = 0; i < assets.length; i++) {
|
|
@@ -542,6 +579,52 @@ function injectAssets(assets, html) {
|
|
|
542
579
|
}
|
|
543
580
|
return html;
|
|
544
581
|
}
|
|
582
|
+
function injectScripts(html, scripts, nonce) {
|
|
583
|
+
const tag = `<script${nonce ? ` nonce="${nonce}"` : ""}>${scripts}</script>`;
|
|
584
|
+
const index = html.indexOf("<!xs>");
|
|
585
|
+
if (index > -1) {
|
|
586
|
+
return html.slice(0, index) + tag + html.slice(index);
|
|
587
|
+
}
|
|
588
|
+
return html + tag;
|
|
589
|
+
}
|
|
590
|
+
function serializeError(error) {
|
|
591
|
+
return error.message ? `new Error(${devalue(error.message)})` : devalue(error);
|
|
592
|
+
}
|
|
593
|
+
function waitForFragments(registry, key) {
|
|
594
|
+
for (const k of [...registry.keys()].reverse()) {
|
|
595
|
+
if (key.startsWith(k)) {
|
|
596
|
+
registry.get(k).push(key);
|
|
597
|
+
return true;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
return false;
|
|
601
|
+
}
|
|
602
|
+
function pipeToNodeWritable(code, writable, options = {}) {
|
|
603
|
+
if (options.onReady) {
|
|
604
|
+
options.onCompleteShell = () => {
|
|
605
|
+
options.onReady({
|
|
606
|
+
startWriting() {
|
|
607
|
+
stream.pipe(writable);
|
|
608
|
+
}
|
|
609
|
+
});
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
const stream = renderToStream(code, options);
|
|
613
|
+
if (!options.onReady) stream.pipe(writable);
|
|
614
|
+
}
|
|
615
|
+
function pipeToWritable(code, writable, options = {}) {
|
|
616
|
+
if (options.onReady) {
|
|
617
|
+
options.onCompleteShell = () => {
|
|
618
|
+
options.onReady({
|
|
619
|
+
startWriting() {
|
|
620
|
+
stream.pipeTo(writable);
|
|
621
|
+
}
|
|
622
|
+
});
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
const stream = renderToStream(code, options);
|
|
626
|
+
if (!options.onReady) stream.pipeTo(writable);
|
|
627
|
+
}
|
|
545
628
|
|
|
546
629
|
const isServer = true;
|
|
547
630
|
function spread() {}
|
|
@@ -560,4 +643,4 @@ function Portal(props) {
|
|
|
560
643
|
return "";
|
|
561
644
|
}
|
|
562
645
|
|
|
563
|
-
export { Assets, Dynamic, HydrationScript, NoHydration, Portal, escape, generateHydrationScript, getHydrationKey, isServer, pipeToNodeWritable, pipeToWritable, renderToString, renderToStringAsync, resolveSSRNode, spread, ssr, ssrBoolean, ssrClassList, ssrHydrationKey, ssrSpread, ssrStyle };
|
|
646
|
+
export { Assets, Dynamic, HydrationScript, NoHydration, Portal, escape, generateHydrationScript, getHydrationKey, isServer, pipeToNodeWritable, pipeToWritable, renderToStream, renderToString, renderToStringAsync, resolveSSRNode, spread, ssr, ssrBoolean, ssrClassList, ssrHydrationKey, ssrSpread, ssrStyle };
|
package/web/dist/web.cjs
CHANGED
|
@@ -98,7 +98,7 @@ function render(code, element, init) {
|
|
|
98
98
|
let disposer;
|
|
99
99
|
solidJs.createRoot(dispose => {
|
|
100
100
|
disposer = dispose;
|
|
101
|
-
insert(element, code(), element.firstChild ? null : undefined, init);
|
|
101
|
+
element === document ? code() : insert(element, code(), element.firstChild ? null : undefined, init);
|
|
102
102
|
});
|
|
103
103
|
return () => {
|
|
104
104
|
disposer();
|
|
@@ -217,28 +217,21 @@ function assign(node, props, isSVG, skipChildren, prevProps = {}) {
|
|
|
217
217
|
prevProps[prop] = assignProp(node, prop, value, prevProps[prop], isSVG);
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
|
-
function hydrate(code, element) {
|
|
221
|
-
solidJs.sharedConfig.
|
|
222
|
-
solidJs.sharedConfig.
|
|
223
|
-
solidJs.sharedConfig.
|
|
220
|
+
function hydrate$1(code, element, options = {}) {
|
|
221
|
+
solidJs.sharedConfig.completed = globalThis._$HY.completed;
|
|
222
|
+
solidJs.sharedConfig.events = globalThis._$HY.events;
|
|
223
|
+
solidJs.sharedConfig.load = globalThis._$HY.load;
|
|
224
|
+
solidJs.sharedConfig.gather = root => gatherHydratable(element, root);
|
|
225
|
+
solidJs.sharedConfig.registry = new Map();
|
|
224
226
|
solidJs.sharedConfig.context = {
|
|
225
|
-
id: "",
|
|
226
|
-
count: 0
|
|
227
|
-
loadResource: globalThis._$HYDRATION.loadResource
|
|
227
|
+
id: options.renderId || "",
|
|
228
|
+
count: 0
|
|
228
229
|
};
|
|
229
|
-
|
|
230
|
-
gatherHydratable(element);
|
|
230
|
+
gatherHydratable(element, options.renderId);
|
|
231
231
|
const dispose = render(code, element, [...element.childNodes]);
|
|
232
232
|
solidJs.sharedConfig.context = null;
|
|
233
233
|
return dispose;
|
|
234
234
|
}
|
|
235
|
-
function gatherHydratable(element) {
|
|
236
|
-
const templates = element.querySelectorAll(`*[data-hk]`);
|
|
237
|
-
for (let i = 0; i < templates.length; i++) {
|
|
238
|
-
const node = templates[i];
|
|
239
|
-
solidJs.sharedConfig.registry.set(node.getAttribute("data-hk"), node);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
235
|
function getNextElement(template) {
|
|
243
236
|
let node, key;
|
|
244
237
|
if (!solidJs.sharedConfig.context || !(node = solidJs.sharedConfig.registry.get(key = getHydrationKey()))) {
|
|
@@ -332,7 +325,7 @@ function eventHandler(e) {
|
|
|
332
325
|
Object.defineProperty(e, "currentTarget", {
|
|
333
326
|
configurable: true,
|
|
334
327
|
get() {
|
|
335
|
-
return node;
|
|
328
|
+
return node || document;
|
|
336
329
|
}
|
|
337
330
|
});
|
|
338
331
|
while (node !== null) {
|
|
@@ -387,7 +380,12 @@ function insertExpression(parent, value, current, marker, unwrapArray) {
|
|
|
387
380
|
solidJs.createRenderEffect(() => current = insertExpression(parent, array, current, marker, true));
|
|
388
381
|
return () => current;
|
|
389
382
|
}
|
|
390
|
-
if (solidJs.sharedConfig.context && current && current.length)
|
|
383
|
+
if (solidJs.sharedConfig.context && current && current.length) {
|
|
384
|
+
for (let i = 0; i < array.length; i++) {
|
|
385
|
+
if (array[i].parentNode) return current = array;
|
|
386
|
+
}
|
|
387
|
+
return current;
|
|
388
|
+
}
|
|
391
389
|
if (array.length === 0) {
|
|
392
390
|
current = cleanChildren(parent, current, marker);
|
|
393
391
|
if (multi) return current;
|
|
@@ -404,6 +402,7 @@ function insertExpression(parent, value, current, marker, unwrapArray) {
|
|
|
404
402
|
}
|
|
405
403
|
current = array;
|
|
406
404
|
} else if (value instanceof Node) {
|
|
405
|
+
if (solidJs.sharedConfig.context) return current = value.parentNode ? value : current;
|
|
407
406
|
if (Array.isArray(current)) {
|
|
408
407
|
if (multi) return current = cleanChildren(parent, current, marker, value);
|
|
409
408
|
cleanChildren(parent, current, null, value);
|
|
@@ -455,6 +454,14 @@ function cleanChildren(parent, current, marker, replacement) {
|
|
|
455
454
|
} else parent.insertBefore(node, marker);
|
|
456
455
|
return [node];
|
|
457
456
|
}
|
|
457
|
+
function gatherHydratable(element, root) {
|
|
458
|
+
const templates = element.querySelectorAll(`*[data-hk]`);
|
|
459
|
+
for (let i = 0; i < templates.length; i++) {
|
|
460
|
+
const node = templates[i];
|
|
461
|
+
const key = node.getAttribute("data-hk");
|
|
462
|
+
if (!root || key.startsWith(root)) solidJs.sharedConfig.registry.set(key, node);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
458
465
|
function getHydrationKey() {
|
|
459
466
|
const hydrate = solidJs.sharedConfig.context;
|
|
460
467
|
return `${hydrate.id}${hydrate.count++}`;
|
|
@@ -468,8 +475,7 @@ function NoHydration(props) {
|
|
|
468
475
|
|
|
469
476
|
function renderToString(fn, options) {}
|
|
470
477
|
function renderToStringAsync(fn, options) {}
|
|
471
|
-
function
|
|
472
|
-
function pipeToWritable(fn, writable, options) {}
|
|
478
|
+
function renderToStream(fn, options) {}
|
|
473
479
|
function ssr(template, ...nodes) {}
|
|
474
480
|
function resolveSSRNode(node) {}
|
|
475
481
|
function ssrClassList(value) {}
|
|
@@ -485,6 +491,10 @@ const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
|
|
|
485
491
|
function createElement(tagName, isSVG = false) {
|
|
486
492
|
return isSVG ? document.createElementNS(SVG_NAMESPACE, tagName) : document.createElement(tagName);
|
|
487
493
|
}
|
|
494
|
+
const hydrate = (...args) => {
|
|
495
|
+
solidJs.enableHydration();
|
|
496
|
+
return hydrate$1(...args);
|
|
497
|
+
};
|
|
488
498
|
function Portal(props) {
|
|
489
499
|
const {
|
|
490
500
|
useShadow
|
|
@@ -629,7 +639,6 @@ exports.clearDelegatedEvents = clearDelegatedEvents;
|
|
|
629
639
|
exports.delegateEvents = delegateEvents;
|
|
630
640
|
exports.dynamicProperty = dynamicProperty;
|
|
631
641
|
exports.escape = escape;
|
|
632
|
-
exports.gatherHydratable = gatherHydratable;
|
|
633
642
|
exports.generateHydrationScript = generateHydrationScript;
|
|
634
643
|
exports.getHydrationKey = getHydrationKey;
|
|
635
644
|
exports.getNextElement = getNextElement;
|
|
@@ -639,9 +648,8 @@ exports.hydrate = hydrate;
|
|
|
639
648
|
exports.insert = insert;
|
|
640
649
|
exports.isServer = isServer;
|
|
641
650
|
exports.memo = memo;
|
|
642
|
-
exports.pipeToNodeWritable = pipeToNodeWritable;
|
|
643
|
-
exports.pipeToWritable = pipeToWritable;
|
|
644
651
|
exports.render = render;
|
|
652
|
+
exports.renderToStream = renderToStream;
|
|
645
653
|
exports.renderToString = renderToString;
|
|
646
654
|
exports.renderToStringAsync = renderToStringAsync;
|
|
647
655
|
exports.resolveSSRNode = resolveSSRNode;
|