solid-js 1.2.2 → 1.3.0-beta.0
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 +67 -28
- package/dist/dev.js +68 -28
- package/dist/server.cjs +20 -51
- package/dist/server.js +21 -51
- package/dist/solid.cjs +67 -28
- package/dist/solid.js +68 -28
- package/html/dist/html.cjs +3 -2
- package/html/dist/html.js +3 -2
- package/package.json +2 -2
- package/store/dist/dev.cjs +2 -2
- package/store/dist/dev.js +3 -3
- package/store/dist/store.cjs +2 -2
- package/store/dist/store.js +2 -2
- package/store/types/store.d.ts +1 -1
- package/types/index.d.ts +0 -1
- package/types/jsx.d.ts +2 -0
- package/types/reactive/signal.d.ts +76 -78
- package/types/render/hydration.d.ts +3 -2
- package/types/server/index.d.ts +1 -1
- package/types/server/reactive.d.ts +1 -2
- package/types/server/rendering.d.ts +2 -1
- package/web/dist/dev.cjs +57 -40
- package/web/dist/dev.js +58 -40
- package/web/dist/server.cjs +207 -99
- package/web/dist/server.js +208 -101
- package/web/dist/web.cjs +57 -40
- package/web/dist/web.js +58 -40
- package/web/types/client.d.ts +0 -1
- package/web/types/core.d.ts +2 -2
package/web/dist/dev.js
CHANGED
|
@@ -200,60 +200,41 @@ function insert(parent, accessor, marker, initial) {
|
|
|
200
200
|
createRenderEffect(current => insertExpression(parent, accessor(), current, marker), initial);
|
|
201
201
|
}
|
|
202
202
|
function assign(node, props, isSVG, skipChildren, prevProps = {}) {
|
|
203
|
-
|
|
203
|
+
for (const prop in prevProps) {
|
|
204
|
+
if (!(prop in props)) {
|
|
205
|
+
if (prop === "children") continue;
|
|
206
|
+
assignProp(node, prop, null, prevProps[prop], isSVG);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
204
209
|
for (const prop in props) {
|
|
205
210
|
if (prop === "children") {
|
|
206
211
|
if (!skipChildren) insertExpression(node, props.children);
|
|
207
212
|
continue;
|
|
208
213
|
}
|
|
209
214
|
const value = props[prop];
|
|
210
|
-
|
|
211
|
-
if (prop === "style") {
|
|
212
|
-
style(node, value, prevProps[prop]);
|
|
213
|
-
} else if (prop === "classList") {
|
|
214
|
-
classList(node, value, prevProps[prop]);
|
|
215
|
-
} else if (prop === "ref") {
|
|
216
|
-
value(node);
|
|
217
|
-
} else if (prop.slice(0, 3) === "on:") {
|
|
218
|
-
node.addEventListener(prop.slice(3), value);
|
|
219
|
-
} else if (prop.slice(0, 10) === "oncapture:") {
|
|
220
|
-
node.addEventListener(prop.slice(10), value, true);
|
|
221
|
-
} else if (prop.slice(0, 2) === "on") {
|
|
222
|
-
const name = prop.slice(2).toLowerCase();
|
|
223
|
-
const delegate = DelegatedEvents.has(name);
|
|
224
|
-
addEventListener(node, name, value, delegate);
|
|
225
|
-
delegate && delegateEvents([name]);
|
|
226
|
-
} else if ((isChildProp = ChildProperties.has(prop)) || !isSVG && (PropAliases[prop] || (isProp = Properties.has(prop))) || (isCE = node.nodeName.includes("-"))) {
|
|
227
|
-
if (isCE && !isProp && !isChildProp) node[toPropertyName(prop)] = value;else node[PropAliases[prop] || prop] = value;
|
|
228
|
-
} else {
|
|
229
|
-
const ns = isSVG && prop.indexOf(":") > -1 && SVGNamespace[prop.split(":")[0]];
|
|
230
|
-
if (ns) setAttributeNS(node, ns, prop, value);else setAttribute(node, Aliases[prop] || prop, value);
|
|
231
|
-
}
|
|
232
|
-
prevProps[prop] = value;
|
|
215
|
+
prevProps[prop] = assignProp(node, prop, value, prevProps[prop], isSVG);
|
|
233
216
|
}
|
|
234
217
|
}
|
|
235
218
|
function hydrate(code, element) {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
219
|
+
if (!globalThis._$HY.sync) {
|
|
220
|
+
let dispose;
|
|
221
|
+
globalThis._$HY.queue.push(() => dispose = hydrate(code, element));
|
|
222
|
+
return () => dispose();
|
|
223
|
+
}
|
|
224
|
+
sharedConfig.completed = globalThis._$HY.completed;
|
|
225
|
+
sharedConfig.events = globalThis._$HY.events;
|
|
226
|
+
sharedConfig.load = globalThis._$HY.load;
|
|
227
|
+
sharedConfig.gather = root => gatherHydratable(element, root);
|
|
228
|
+
sharedConfig.registry = new Map();
|
|
239
229
|
sharedConfig.context = {
|
|
240
230
|
id: "",
|
|
241
|
-
count: 0
|
|
242
|
-
loadResource: globalThis._$HYDRATION.loadResource
|
|
231
|
+
count: 0
|
|
243
232
|
};
|
|
244
|
-
sharedConfig.registry = new Map();
|
|
245
233
|
gatherHydratable(element);
|
|
246
234
|
const dispose = render(code, element, [...element.childNodes]);
|
|
247
235
|
sharedConfig.context = null;
|
|
248
236
|
return dispose;
|
|
249
237
|
}
|
|
250
|
-
function gatherHydratable(element) {
|
|
251
|
-
const templates = element.querySelectorAll(`*[data-hk]`);
|
|
252
|
-
for (let i = 0; i < templates.length; i++) {
|
|
253
|
-
const node = templates[i];
|
|
254
|
-
sharedConfig.registry.set(node.getAttribute("data-hk"), node);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
238
|
function getNextElement(template) {
|
|
258
239
|
let node, key;
|
|
259
240
|
if (!sharedConfig.context || !(node = sharedConfig.registry.get(key = getHydrationKey()))) {
|
|
@@ -311,6 +292,30 @@ function toggleClassKey(node, key, value) {
|
|
|
311
292
|
const classNames = key.trim().split(/\s+/);
|
|
312
293
|
for (let i = 0, nameLen = classNames.length; i < nameLen; i++) node.classList.toggle(classNames[i], value);
|
|
313
294
|
}
|
|
295
|
+
function assignProp(node, prop, value, prev, isSVG) {
|
|
296
|
+
let isCE, isProp, isChildProp;
|
|
297
|
+
if (prop === "style") return style(node, value, prev);
|
|
298
|
+
if (prop === "classList") return classList(node, value, prev);
|
|
299
|
+
if (value === prev) return prev;
|
|
300
|
+
if (prop === "ref") {
|
|
301
|
+
value(node);
|
|
302
|
+
} else if (prop.slice(0, 3) === "on:") {
|
|
303
|
+
node.addEventListener(prop.slice(3), value);
|
|
304
|
+
} else if (prop.slice(0, 10) === "oncapture:") {
|
|
305
|
+
node.addEventListener(prop.slice(10), value, true);
|
|
306
|
+
} else if (prop.slice(0, 2) === "on") {
|
|
307
|
+
const name = prop.slice(2).toLowerCase();
|
|
308
|
+
const delegate = DelegatedEvents.has(name);
|
|
309
|
+
addEventListener(node, name, value, delegate);
|
|
310
|
+
delegate && delegateEvents([name]);
|
|
311
|
+
} else if ((isChildProp = ChildProperties.has(prop)) || !isSVG && (PropAliases[prop] || (isProp = Properties.has(prop))) || (isCE = node.nodeName.includes("-"))) {
|
|
312
|
+
if (isCE && !isProp && !isChildProp) node[toPropertyName(prop)] = value;else node[PropAliases[prop] || prop] = value;
|
|
313
|
+
} else {
|
|
314
|
+
const ns = isSVG && prop.indexOf(":") > -1 && SVGNamespace[prop.split(":")[0]];
|
|
315
|
+
if (ns) setAttributeNS(node, ns, prop, value);else setAttribute(node, Aliases[prop] || prop, value);
|
|
316
|
+
}
|
|
317
|
+
return value;
|
|
318
|
+
}
|
|
314
319
|
function eventHandler(e) {
|
|
315
320
|
const key = `$$${e.type}`;
|
|
316
321
|
let node = e.composedPath && e.composedPath()[0] || e.target;
|
|
@@ -323,7 +328,7 @@ function eventHandler(e) {
|
|
|
323
328
|
Object.defineProperty(e, "currentTarget", {
|
|
324
329
|
configurable: true,
|
|
325
330
|
get() {
|
|
326
|
-
return node;
|
|
331
|
+
return node || document;
|
|
327
332
|
}
|
|
328
333
|
});
|
|
329
334
|
while (node !== null) {
|
|
@@ -378,7 +383,12 @@ function insertExpression(parent, value, current, marker, unwrapArray) {
|
|
|
378
383
|
createRenderEffect(() => current = insertExpression(parent, array, current, marker, true));
|
|
379
384
|
return () => current;
|
|
380
385
|
}
|
|
381
|
-
if (sharedConfig.context && current && current.length)
|
|
386
|
+
if (sharedConfig.context && current && current.length) {
|
|
387
|
+
for (let i; i < array.length; i++) {
|
|
388
|
+
if (array[i].parentNode) return array;
|
|
389
|
+
}
|
|
390
|
+
return current;
|
|
391
|
+
}
|
|
382
392
|
if (array.length === 0) {
|
|
383
393
|
current = cleanChildren(parent, current, marker);
|
|
384
394
|
if (multi) return current;
|
|
@@ -446,6 +456,14 @@ function cleanChildren(parent, current, marker, replacement) {
|
|
|
446
456
|
} else parent.insertBefore(node, marker);
|
|
447
457
|
return [node];
|
|
448
458
|
}
|
|
459
|
+
function gatherHydratable(element, root) {
|
|
460
|
+
const templates = element.querySelectorAll(`*[data-hk]`);
|
|
461
|
+
for (let i = 0; i < templates.length; i++) {
|
|
462
|
+
const node = templates[i];
|
|
463
|
+
const key = node.getAttribute("data-hk");
|
|
464
|
+
if (!root || key.startsWith(root)) sharedConfig.registry.set(key, node);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
449
467
|
function getHydrationKey() {
|
|
450
468
|
const hydrate = sharedConfig.context;
|
|
451
469
|
return `${hydrate.id}${hydrate.count++}`;
|
|
@@ -529,4 +547,4 @@ function Dynamic(props) {
|
|
|
529
547
|
});
|
|
530
548
|
}
|
|
531
549
|
|
|
532
|
-
export { Aliases, Assets, ChildProperties, DelegatedEvents, Dynamic, Assets as HydrationScript, NoHydration, Portal, PropAliases, Properties, SVGElements, SVGNamespace, addEventListener, assign, classList, clearDelegatedEvents, delegateEvents, dynamicProperty, escape,
|
|
550
|
+
export { Aliases, Assets, ChildProperties, DelegatedEvents, Dynamic, Assets as HydrationScript, NoHydration, Portal, PropAliases, Properties, SVGElements, SVGNamespace, addEventListener, assign, classList, clearDelegatedEvents, delegateEvents, dynamicProperty, escape, generateHydrationScript, getHydrationKey, getNextElement, getNextMarker, getNextMatch, hydrate, insert, isServer, memo, pipeToNodeWritable, pipeToWritable, render, renderToString, renderToStringAsync, resolveSSRNode, runHydrationEvents, setAttribute, setAttributeNS, spread, ssr, ssrBoolean, ssrClassList, ssrHydrationKey, ssrSpread, ssrStyle, style, template };
|
package/web/dist/server.cjs
CHANGED
|
@@ -232,111 +232,162 @@ function stringifyString(str) {
|
|
|
232
232
|
return result;
|
|
233
233
|
}
|
|
234
234
|
|
|
235
|
+
const REPLACE_SCRIPT = `function $df(e,t){t=document.getElementById(e),document.getElementById("pl"+e).replaceWith(...t.childNodes),_$HY.set(e)}`;
|
|
236
|
+
const SYNC_SCRIPT = `_$HY.sync=!0;for(let e=0;e<_$HY.queue.length;e++)_$HY.queue[e]()`;
|
|
235
237
|
function renderToString(code, options = {}) {
|
|
236
|
-
solidJs.sharedConfig.context =
|
|
238
|
+
solidJs.sharedConfig.context = {
|
|
237
239
|
id: "",
|
|
238
240
|
count: 0,
|
|
239
|
-
|
|
240
|
-
|
|
241
|
+
suspense: {},
|
|
242
|
+
assets: [],
|
|
243
|
+
nonce: options.nonce
|
|
244
|
+
};
|
|
241
245
|
let html = resolveSSRNode(escape(code()));
|
|
242
|
-
return injectAssets(solidJs.sharedConfig.context.assets, html)
|
|
246
|
+
return injectAssets(solidJs.sharedConfig.context.assets, html) + `<script${options.nonce ? ` nonce="${options.nonce}"` : ""}>${SYNC_SCRIPT}</script>`;
|
|
243
247
|
}
|
|
244
248
|
function renderToStringAsync(code, options = {}) {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
};
|
|
249
|
-
const context = solidJs.sharedConfig.context =
|
|
249
|
+
const {
|
|
250
|
+
nonce,
|
|
251
|
+
timeoutMs = 30000
|
|
252
|
+
} = options;
|
|
253
|
+
const context = solidJs.sharedConfig.context = {
|
|
250
254
|
id: "",
|
|
251
255
|
count: 0,
|
|
252
256
|
resources: {},
|
|
253
257
|
suspense: {},
|
|
254
258
|
assets: [],
|
|
255
|
-
async: true
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
+
async: true,
|
|
260
|
+
nonce
|
|
261
|
+
};
|
|
262
|
+
let scripts = "";
|
|
263
|
+
solidJs.sharedConfig.context.writeResource = (id, p) => p.then(d => scripts += `_$HY.set("${id}", ${devalue(d)});`);
|
|
264
|
+
const timeout = new Promise((_, reject) => setTimeout(() => reject("renderToString timed out"), timeoutMs));
|
|
265
|
+
return Promise.race([asyncWrap(() => escape(code())), timeout]).then(res => {
|
|
259
266
|
let html = resolveSSRNode(res);
|
|
267
|
+
html += `<script${nonce ? ` nonce="${nonce}"` : ""}>${scripts.length ? scripts + ";" : ""}${SYNC_SCRIPT}</script>`;
|
|
260
268
|
return injectAssets(context.assets, html);
|
|
261
269
|
});
|
|
262
270
|
}
|
|
263
|
-
function
|
|
271
|
+
function renderToPipeableStream(code, options) {
|
|
264
272
|
const {
|
|
265
273
|
nonce,
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
}) => startWriting(),
|
|
269
|
-
onComplete
|
|
274
|
+
onCompleteShell,
|
|
275
|
+
onCompleteAll
|
|
270
276
|
} = options;
|
|
271
277
|
const tmp = [];
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
278
|
+
const tasks = [];
|
|
279
|
+
const registry = new Set();
|
|
280
|
+
const checkEnd = () => {
|
|
281
|
+
if (!registry.size && !completed) {
|
|
282
|
+
onCompleteAll && onCompleteAll(result);
|
|
283
|
+
writable && writable.end();
|
|
284
|
+
completed = true;
|
|
277
285
|
}
|
|
278
286
|
};
|
|
279
|
-
const
|
|
280
|
-
|
|
281
|
-
buffer =
|
|
282
|
-
|
|
283
|
-
setTimeout(checkEnd);
|
|
284
|
-
},
|
|
285
|
-
write(c) {
|
|
286
|
-
writable.write(c);
|
|
287
|
-
},
|
|
288
|
-
abort() {
|
|
289
|
-
completed = count;
|
|
290
|
-
checkEnd();
|
|
287
|
+
const writeInitialScript = () => {
|
|
288
|
+
if (tasks.length) {
|
|
289
|
+
buffer.write(`<script${nonce ? ` nonce="${nonce}"` : ""}>${tasks.join(";")}</script>`);
|
|
290
|
+
tasks.length = 0;
|
|
291
291
|
}
|
|
292
|
+
scheduled = false;
|
|
292
293
|
};
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
294
|
+
let writable;
|
|
295
|
+
let completed = false;
|
|
296
|
+
let scriptFlushed = false;
|
|
297
|
+
let scheduled = true;
|
|
298
|
+
let buffer = {
|
|
299
|
+
write(payload) {
|
|
300
|
+
tmp.push(payload);
|
|
297
301
|
}
|
|
298
302
|
};
|
|
299
|
-
solidJs.sharedConfig.context =
|
|
303
|
+
solidJs.sharedConfig.context = {
|
|
300
304
|
id: "",
|
|
301
305
|
count: 0,
|
|
306
|
+
async: true,
|
|
302
307
|
streaming: true,
|
|
308
|
+
resources: {},
|
|
303
309
|
suspense: {},
|
|
304
|
-
assets: []
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
310
|
+
assets: [],
|
|
311
|
+
nonce,
|
|
312
|
+
writeResource(id, p) {
|
|
313
|
+
if (!scheduled) {
|
|
314
|
+
Promise.resolve().then(writeInitialScript);
|
|
315
|
+
scheduled = true;
|
|
316
|
+
}
|
|
317
|
+
tasks.push(`_$HY.init("${id}")`);
|
|
318
|
+
p.then(d => {
|
|
319
|
+
buffer.write(`<script${nonce ? ` nonce="${nonce}"` : ""}>_$HY.set("${id}", ${devalue(d)})</script>`);
|
|
320
|
+
});
|
|
321
|
+
},
|
|
322
|
+
registerFragment(key) {
|
|
323
|
+
registry.add(key);
|
|
324
|
+
Promise.resolve().then(() => {
|
|
325
|
+
if (registry.has(key)) {
|
|
326
|
+
if (!scheduled) {
|
|
327
|
+
Promise.resolve().then(writeInitialScript);
|
|
328
|
+
scheduled = true;
|
|
329
|
+
}
|
|
330
|
+
tasks.push(`_$HY.init("${key}")`);
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
return value => {
|
|
334
|
+
registry.delete(key);
|
|
335
|
+
if (!value) return;
|
|
336
|
+
Promise.resolve().then(() => {
|
|
337
|
+
buffer.write(`<div hidden id="${key}">${value}</div><script${nonce ? ` nonce="${nonce}"` : ""}>${!scriptFlushed ? REPLACE_SCRIPT : ""}$df("${key}")</script>`);
|
|
338
|
+
scriptFlushed = true;
|
|
339
|
+
checkEnd();
|
|
340
|
+
});
|
|
341
|
+
};
|
|
342
|
+
}
|
|
313
343
|
};
|
|
314
344
|
let html = resolveSSRNode(escape(code()));
|
|
315
345
|
html = injectAssets(solidJs.sharedConfig.context.assets, html);
|
|
316
346
|
buffer.write(html);
|
|
317
|
-
|
|
347
|
+
Promise.resolve().then(() => {
|
|
348
|
+
writeInitialScript();
|
|
349
|
+
buffer.write(`<script${nonce ? ` nonce="${nonce}"` : ""}>${SYNC_SCRIPT}</script>`);
|
|
350
|
+
onCompleteShell && onCompleteShell();
|
|
351
|
+
});
|
|
352
|
+
return {
|
|
353
|
+
pipe(w) {
|
|
354
|
+
buffer = writable = w;
|
|
355
|
+
tmp.forEach(chunk => buffer.write(chunk));
|
|
356
|
+
if (completed) writable.end();else setTimeout(checkEnd);
|
|
357
|
+
}
|
|
358
|
+
};
|
|
318
359
|
}
|
|
319
360
|
function pipeToWritable(code, writable, options = {}) {
|
|
320
361
|
const {
|
|
321
362
|
nonce,
|
|
322
|
-
|
|
363
|
+
onCompleteShell = ({
|
|
323
364
|
startWriting
|
|
324
365
|
}) => startWriting(),
|
|
325
|
-
|
|
366
|
+
onCompleteAll
|
|
326
367
|
} = options;
|
|
327
368
|
const tmp = [];
|
|
369
|
+
const tasks = [];
|
|
328
370
|
const writer = writable.getWriter();
|
|
329
371
|
const encoder = new TextEncoder();
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
372
|
+
const registry = new Set();
|
|
373
|
+
const checkEnd = () => {
|
|
374
|
+
if (!registry.size && !completed) {
|
|
375
|
+
onCompleteAll && onCompleteAll(result);
|
|
376
|
+
writable && writable.close();
|
|
377
|
+
completed = true;
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
const writeInitialScript = () => {
|
|
381
|
+
if (tasks.length) {
|
|
382
|
+
buffer.write(encoder.encode(`<script${nonce ? ` nonce="${nonce}"` : ""}>${tasks.join(";")}</script>`));
|
|
383
|
+
tasks.length = 0;
|
|
384
|
+
}
|
|
385
|
+
scheduled = false;
|
|
386
|
+
};
|
|
387
|
+
let completed = false;
|
|
388
|
+
let scriptFlushed = false;
|
|
389
|
+
let scheduled = true;
|
|
390
|
+
let buffer = {
|
|
340
391
|
write(payload) {
|
|
341
392
|
tmp.push(payload);
|
|
342
393
|
}
|
|
@@ -351,28 +402,62 @@ function pipeToWritable(code, writable, options = {}) {
|
|
|
351
402
|
writer.write(encoder.encode(c));
|
|
352
403
|
},
|
|
353
404
|
abort() {
|
|
354
|
-
|
|
405
|
+
registry.clear();
|
|
355
406
|
checkEnd();
|
|
356
407
|
}
|
|
357
408
|
};
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
409
|
+
solidJs.sharedConfig.context = {
|
|
410
|
+
id: "",
|
|
411
|
+
count: 0,
|
|
412
|
+
async: true,
|
|
413
|
+
streaming: true,
|
|
414
|
+
resources: {},
|
|
415
|
+
suspense: {},
|
|
416
|
+
assets: [],
|
|
417
|
+
nonce,
|
|
418
|
+
writeResource(id, p) {
|
|
419
|
+
if (!scheduled) {
|
|
420
|
+
Promise.resolve().then(writeInitialScript);
|
|
421
|
+
scheduled = true;
|
|
422
|
+
}
|
|
423
|
+
tasks.push(`_$HY.init("${id}")`);
|
|
424
|
+
p.then(d => {
|
|
425
|
+
buffer.write(encoder.encode(`<script${nonce ? ` nonce="${nonce}"` : ""}>_$HY.set("${id}", ${devalue(d)})</script>`));
|
|
426
|
+
});
|
|
427
|
+
},
|
|
428
|
+
registerFragment(key) {
|
|
429
|
+
registry.add(key);
|
|
430
|
+
Promise.resolve().then(() => {
|
|
431
|
+
if (registry.has(key)) {
|
|
432
|
+
if (!scheduled) {
|
|
433
|
+
Promise.resolve().then(writeInitialScript);
|
|
434
|
+
scheduled = true;
|
|
435
|
+
}
|
|
436
|
+
tasks.push(`_$HY.init("${key}")`);
|
|
437
|
+
}
|
|
438
|
+
});
|
|
439
|
+
return value => {
|
|
440
|
+
registry.delete(key);
|
|
441
|
+
if (!value) return;
|
|
442
|
+
Promise.resolve().then(() => {
|
|
443
|
+
buffer.write(encoder.encode(`<div hidden id="${key}">${value}</div><script${nonce ? ` nonce="${nonce}"` : ""}>${!scriptFlushed ? REPLACE_SCRIPT : ""}$df("${key}")</script>`));
|
|
444
|
+
scriptFlushed = true;
|
|
445
|
+
checkEnd();
|
|
446
|
+
});
|
|
447
|
+
};
|
|
362
448
|
}
|
|
363
449
|
};
|
|
364
|
-
solidJs.sharedConfig.context.writeResource = (id, p) => {
|
|
365
|
-
count++;
|
|
366
|
-
Promise.resolve().then(() => buffer.write(encoder.encode(`<script${nonce ? ` nonce="${nonce}"` : ""}>_$HYDRATION.startResource("${id}")</script>`)));
|
|
367
|
-
p.then(d => {
|
|
368
|
-
buffer.write(encoder.encode(`<script${nonce ? ` nonce="${nonce}"` : ""}>_$HYDRATION.resolveResource("${id}", ${devalue(d)})</script>`));
|
|
369
|
-
++completed && checkEnd();
|
|
370
|
-
});
|
|
371
|
-
};
|
|
372
450
|
let html = resolveSSRNode(escape(code()));
|
|
373
451
|
html = injectAssets(solidJs.sharedConfig.context.assets, html);
|
|
374
452
|
buffer.write(encoder.encode(html));
|
|
375
|
-
|
|
453
|
+
Promise.resolve().then(() => {
|
|
454
|
+
writeInitialScript();
|
|
455
|
+
buffer.write(encoder.encode(`<script${nonce ? ` nonce="${nonce}"` : ""}>${SYNC_SCRIPT}</script>`));
|
|
456
|
+
onCompleteShell && onCompleteShell(result);
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
function pipeToNodeWritable(code, writable, options = {}) {
|
|
460
|
+
renderToPipeableStream(code, options).pipe(writable);
|
|
376
461
|
}
|
|
377
462
|
function Assets(props) {
|
|
378
463
|
solidJs.sharedConfig.context.assets.push(() => NoHydration({
|
|
@@ -382,15 +467,21 @@ function Assets(props) {
|
|
|
382
467
|
}));
|
|
383
468
|
return ssr(`%%$${solidJs.sharedConfig.context.assets.length - 1}%%`);
|
|
384
469
|
}
|
|
385
|
-
function HydrationScript() {
|
|
386
|
-
|
|
470
|
+
function HydrationScript(props) {
|
|
471
|
+
const {
|
|
472
|
+
nonce
|
|
473
|
+
} = solidJs.sharedConfig.context;
|
|
474
|
+
solidJs.sharedConfig.context.assets.push(() => generateHydrationScript({
|
|
475
|
+
nonce,
|
|
476
|
+
...props
|
|
477
|
+
}));
|
|
387
478
|
return ssr(`%%$${solidJs.sharedConfig.context.assets.length - 1}%%`);
|
|
388
479
|
}
|
|
389
480
|
function NoHydration(props) {
|
|
390
481
|
const c = solidJs.sharedConfig.context;
|
|
391
|
-
|
|
482
|
+
c.noHydrate = true;
|
|
392
483
|
const children = props.children;
|
|
393
|
-
|
|
484
|
+
c.noHydrate = false;
|
|
394
485
|
return children;
|
|
395
486
|
}
|
|
396
487
|
function ssr(t, ...nodes) {
|
|
@@ -449,6 +540,8 @@ function ssrSpread(props, isSVG, skipChildren) {
|
|
|
449
540
|
result += `class="${ssrClassList(value)}"`;
|
|
450
541
|
} else if (BooleanAttributes.has(prop)) {
|
|
451
542
|
if (value) result += prop;else continue;
|
|
543
|
+
} else if (prop === "ref" || prop.slice(0, 2) === "on") {
|
|
544
|
+
continue;
|
|
452
545
|
} else {
|
|
453
546
|
result += `${Aliases[prop] || prop}="${escape(value, true)}"`;
|
|
454
547
|
}
|
|
@@ -516,26 +609,13 @@ function resolveSSRNode(node) {
|
|
|
516
609
|
}
|
|
517
610
|
function getHydrationKey() {
|
|
518
611
|
const hydrate = solidJs.sharedConfig.context;
|
|
519
|
-
return hydrate && `${hydrate.id}${hydrate.count++}`;
|
|
612
|
+
return hydrate && !hydrate.noHydrate && `${hydrate.id}${hydrate.count++}`;
|
|
520
613
|
}
|
|
521
|
-
function generateHydrationScript(
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
eventNames = ["click", "input"]
|
|
527
|
-
} = solidJs.sharedConfig.context;
|
|
528
|
-
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))})();`;
|
|
529
|
-
if (streaming) {
|
|
530
|
-
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]}})();`;
|
|
531
|
-
}
|
|
532
|
-
if (resources) {
|
|
533
|
-
s += `_$HYDRATION.resources = ${devalue(Object.keys(resources).reduce((r, k) => {
|
|
534
|
-
r[k] = resources[k].data;
|
|
535
|
-
return r;
|
|
536
|
-
}, {}))};`;
|
|
537
|
-
}
|
|
538
|
-
return s + `</script>`;
|
|
614
|
+
function generateHydrationScript({
|
|
615
|
+
eventNames = ["click", "input"],
|
|
616
|
+
nonce
|
|
617
|
+
}) {
|
|
618
|
+
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 n=o.composedPath&&o.composedPath()[0]||o.target,s=t(n);s&&!e.completed.has(s)&&e.events.push([s,o])})))),e.init=(e,t)=>{o[e]=[new Promise((e=>t=e)),t]},e.set=(e,t,n)=>{if(!(n=o[e]))return o[e]=[t];n[1](t)},e.load=(e,t)=>{if(t=o[e])return t[0]}})(window._$HY||(_$HY={events:[],completed:new WeakSet,queue:[]}));</script>`;
|
|
539
619
|
}
|
|
540
620
|
function injectAssets(assets, html) {
|
|
541
621
|
for (let i = 0; i < assets.length; i++) {
|
|
@@ -543,6 +623,33 @@ function injectAssets(assets, html) {
|
|
|
543
623
|
}
|
|
544
624
|
return html;
|
|
545
625
|
}
|
|
626
|
+
const FRAGMENT_REPLACE = /<!\[([\d.]+)\]>/;
|
|
627
|
+
function asyncWrap(fn) {
|
|
628
|
+
return new Promise(resolve => {
|
|
629
|
+
const registry = new Set();
|
|
630
|
+
const cache = Object.create(null);
|
|
631
|
+
solidJs.sharedConfig.context.registerFragment = register;
|
|
632
|
+
const rendered = fn();
|
|
633
|
+
if (!registry.size) resolve(rendered);
|
|
634
|
+
function register(key) {
|
|
635
|
+
registry.add(key);
|
|
636
|
+
return value => {
|
|
637
|
+
if (value) cache[key] = value;
|
|
638
|
+
registry.delete(key);
|
|
639
|
+
if (!registry.size) Promise.resolve().then(() => {
|
|
640
|
+
let source = resolveSSRNode(rendered);
|
|
641
|
+
let final = "";
|
|
642
|
+
let match;
|
|
643
|
+
while (match = source.match(FRAGMENT_REPLACE)) {
|
|
644
|
+
final += source.substring(0, match.index);
|
|
645
|
+
source = cache[match[1]] + source.substring(match.index + match[0].length);
|
|
646
|
+
}
|
|
647
|
+
resolve(final + source);
|
|
648
|
+
});
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
});
|
|
652
|
+
}
|
|
546
653
|
|
|
547
654
|
const isServer = true;
|
|
548
655
|
function spread() {}
|
|
@@ -632,6 +739,7 @@ exports.getHydrationKey = getHydrationKey;
|
|
|
632
739
|
exports.isServer = isServer;
|
|
633
740
|
exports.pipeToNodeWritable = pipeToNodeWritable;
|
|
634
741
|
exports.pipeToWritable = pipeToWritable;
|
|
742
|
+
exports.renderToPipeableStream = renderToPipeableStream;
|
|
635
743
|
exports.renderToString = renderToString;
|
|
636
744
|
exports.renderToStringAsync = renderToStringAsync;
|
|
637
745
|
exports.resolveSSRNode = resolveSSRNode;
|