solid-js 1.2.3 → 1.3.0-beta.1

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/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
- let isCE, isProp, isChildProp;
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
- if (value === prevProps[prop]) continue;
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
- sharedConfig.resources = globalThis._$HYDRATION.resources;
237
- sharedConfig.completed = globalThis._$HYDRATION.completed;
238
- sharedConfig.events = globalThis._$HYDRATION.events;
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) return current;
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, gatherHydratable, 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 };
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 };
@@ -232,111 +232,160 @@ 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 = Object.assign({
238
+ solidJs.sharedConfig.context = {
237
239
  id: "",
238
240
  count: 0,
239
- assets: []
240
- }, options);
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
- options = {
246
- timeoutMs: 30000,
247
- ...options
248
- };
249
- const context = solidJs.sharedConfig.context = Object.assign({
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
- }, options);
257
- const timeout = new Promise((_, reject) => setTimeout(() => reject("renderToString timed out"), options.timeoutMs));
258
- return Promise.race([solidJs.awaitSuspense(() => escape(code())), timeout]).then(res => {
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 pipeToNodeWritable(code, writable, options = {}) {
271
+ function renderToPipeableStream(code, options) {
264
272
  const {
265
273
  nonce,
266
- onReady = ({
267
- startWriting
268
- }) => startWriting(),
269
- onComplete
274
+ onCompleteShell,
275
+ onCompleteAll
270
276
  } = options;
271
277
  const tmp = [];
272
- let count = 0,
273
- completed = 0,
274
- buffer = {
275
- write(payload) {
276
- tmp.push(payload);
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 result = {
280
- startWriting() {
281
- buffer = writable;
282
- tmp.forEach(chunk => buffer.write(chunk));
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
- const checkEnd = () => {
294
- if (completed === count) {
295
- onComplete && onComplete(result);
296
- writable.end();
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 = Object.assign({
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
- }, options);
306
- solidJs.sharedConfig.context.writeResource = (id, p) => {
307
- count++;
308
- Promise.resolve().then(() => buffer.write(`<script${nonce ? ` nonce="${nonce}"` : ""}>_$HYDRATION.startResource("${id}")</script>`));
309
- p.then(d => {
310
- buffer.write(`<script${nonce ? ` nonce="${nonce}"` : ""}>_$HYDRATION.resolveResource("${id}", ${devalue(d)})</script>`);
311
- ++completed && checkEnd();
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
+ buffer.write(`<div hidden id="${key}">${value}</div><script${nonce ? ` nonce="${nonce}"` : ""}>${!scriptFlushed ? REPLACE_SCRIPT : ""}$df("${key}")</script>`);
337
+ scriptFlushed = true;
338
+ checkEnd();
339
+ };
340
+ }
313
341
  };
314
342
  let html = resolveSSRNode(escape(code()));
315
343
  html = injectAssets(solidJs.sharedConfig.context.assets, html);
316
- buffer.write(html);
317
- onReady(result);
344
+ Promise.resolve().then(() => {
345
+ buffer.write(html + `<script${nonce ? ` nonce="${nonce}"` : ""}>${tasks.length ? tasks.join(";") + ";" : ""}${SYNC_SCRIPT}</script>`);
346
+ tasks.length = 0;
347
+ scheduled = false;
348
+ onCompleteShell && onCompleteShell();
349
+ });
350
+ return {
351
+ pipe(w) {
352
+ buffer = writable = w;
353
+ tmp.forEach(chunk => buffer.write(chunk));
354
+ if (completed) writable.end();else setTimeout(checkEnd);
355
+ }
356
+ };
318
357
  }
319
358
  function pipeToWritable(code, writable, options = {}) {
320
359
  const {
321
360
  nonce,
322
- onReady = ({
361
+ onCompleteShell = ({
323
362
  startWriting
324
363
  }) => startWriting(),
325
- onComplete
364
+ onCompleteAll
326
365
  } = options;
327
366
  const tmp = [];
367
+ const tasks = [];
328
368
  const writer = writable.getWriter();
329
369
  const encoder = new TextEncoder();
330
- solidJs.sharedConfig.context = Object.assign({
331
- id: "",
332
- count: 0,
333
- streaming: true,
334
- suspense: {},
335
- assets: []
336
- }, options);
337
- let count = 0,
338
- completed = 0,
339
- buffer = {
370
+ const registry = new Set();
371
+ const checkEnd = () => {
372
+ if (!registry.size && !completed) {
373
+ onCompleteAll && onCompleteAll(result);
374
+ writable && writable.close();
375
+ completed = true;
376
+ }
377
+ };
378
+ const writeInitialScript = () => {
379
+ if (tasks.length) {
380
+ buffer.write(encoder.encode(`<script${nonce ? ` nonce="${nonce}"` : ""}>${tasks.join(";")}</script>`));
381
+ tasks.length = 0;
382
+ }
383
+ scheduled = false;
384
+ };
385
+ let completed = false;
386
+ let scriptFlushed = false;
387
+ let scheduled = true;
388
+ let buffer = {
340
389
  write(payload) {
341
390
  tmp.push(payload);
342
391
  }
@@ -351,28 +400,60 @@ function pipeToWritable(code, writable, options = {}) {
351
400
  writer.write(encoder.encode(c));
352
401
  },
353
402
  abort() {
354
- completed = count;
403
+ registry.clear();
355
404
  checkEnd();
356
405
  }
357
406
  };
358
- const checkEnd = () => {
359
- if (completed === count) {
360
- onComplete && onComplete(result);
361
- writable.close();
407
+ solidJs.sharedConfig.context = {
408
+ id: "",
409
+ count: 0,
410
+ async: true,
411
+ streaming: true,
412
+ resources: {},
413
+ suspense: {},
414
+ assets: [],
415
+ nonce,
416
+ writeResource(id, p) {
417
+ if (!scheduled) {
418
+ Promise.resolve().then(writeInitialScript);
419
+ scheduled = true;
420
+ }
421
+ tasks.push(`_$HY.init("${id}")`);
422
+ p.then(d => {
423
+ buffer.write(encoder.encode(`<script${nonce ? ` nonce="${nonce}"` : ""}>_$HY.set("${id}", ${devalue(d)})</script>`));
424
+ });
425
+ },
426
+ registerFragment(key) {
427
+ registry.add(key);
428
+ Promise.resolve().then(() => {
429
+ if (registry.has(key)) {
430
+ if (!scheduled) {
431
+ Promise.resolve().then(writeInitialScript);
432
+ scheduled = true;
433
+ }
434
+ tasks.push(`_$HY.init("${key}")`);
435
+ }
436
+ });
437
+ return value => {
438
+ registry.delete(key);
439
+ if (!value) return;
440
+ buffer.write(encoder.encode(`<div hidden id="${key}">${value}</div><script${nonce ? ` nonce="${nonce}"` : ""}>${!scriptFlushed ? REPLACE_SCRIPT : ""}$df("${key}")</script>`));
441
+ scriptFlushed = true;
442
+ checkEnd();
443
+ };
362
444
  }
363
445
  };
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
446
  let html = resolveSSRNode(escape(code()));
373
447
  html = injectAssets(solidJs.sharedConfig.context.assets, html);
374
- buffer.write(encoder.encode(html));
375
- onReady(result);
448
+ Promise.resolve().then(() => {
449
+ buffer.write(encoder.encode(html + `<script${nonce ? ` nonce="${nonce}"` : ""}>${tasks.length ? tasks.join(";") + ";" : ""}${SYNC_SCRIPT}</script>`));
450
+ tasks.length = 0;
451
+ scheduled = false;
452
+ onCompleteShell && onCompleteShell(result);
453
+ });
454
+ }
455
+ function pipeToNodeWritable(code, writable, options = {}) {
456
+ renderToPipeableStream(code, options).pipe(writable);
376
457
  }
377
458
  function Assets(props) {
378
459
  solidJs.sharedConfig.context.assets.push(() => NoHydration({
@@ -382,15 +463,21 @@ function Assets(props) {
382
463
  }));
383
464
  return ssr(`%%$${solidJs.sharedConfig.context.assets.length - 1}%%`);
384
465
  }
385
- function HydrationScript() {
386
- solidJs.sharedConfig.context.assets.push(generateHydrationScript);
466
+ function HydrationScript(props) {
467
+ const {
468
+ nonce
469
+ } = solidJs.sharedConfig.context;
470
+ solidJs.sharedConfig.context.assets.push(() => generateHydrationScript({
471
+ nonce,
472
+ ...props
473
+ }));
387
474
  return ssr(`%%$${solidJs.sharedConfig.context.assets.length - 1}%%`);
388
475
  }
389
476
  function NoHydration(props) {
390
477
  const c = solidJs.sharedConfig.context;
391
- delete solidJs.sharedConfig.context;
478
+ c.noHydrate = true;
392
479
  const children = props.children;
393
- solidJs.sharedConfig.context = c;
480
+ c.noHydrate = false;
394
481
  return children;
395
482
  }
396
483
  function ssr(t, ...nodes) {
@@ -449,6 +536,8 @@ function ssrSpread(props, isSVG, skipChildren) {
449
536
  result += `class="${ssrClassList(value)}"`;
450
537
  } else if (BooleanAttributes.has(prop)) {
451
538
  if (value) result += prop;else continue;
539
+ } else if (prop === "ref" || prop.slice(0, 2) === "on") {
540
+ continue;
452
541
  } else {
453
542
  result += `${Aliases[prop] || prop}="${escape(value, true)}"`;
454
543
  }
@@ -516,26 +605,13 @@ function resolveSSRNode(node) {
516
605
  }
517
606
  function getHydrationKey() {
518
607
  const hydrate = solidJs.sharedConfig.context;
519
- return hydrate && `${hydrate.id}${hydrate.count++}`;
608
+ return hydrate && !hydrate.noHydrate && `${hydrate.id}${hydrate.count++}`;
520
609
  }
521
- function generateHydrationScript() {
522
- const {
523
- nonce,
524
- streaming,
525
- resources,
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>`;
610
+ function generateHydrationScript({
611
+ eventNames = ["click", "input"],
612
+ nonce
613
+ }) {
614
+ 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
615
  }
540
616
  function injectAssets(assets, html) {
541
617
  for (let i = 0; i < assets.length; i++) {
@@ -543,6 +619,33 @@ function injectAssets(assets, html) {
543
619
  }
544
620
  return html;
545
621
  }
622
+ const FRAGMENT_REPLACE = /<!\[([\d.]+)\]>/;
623
+ function asyncWrap(fn) {
624
+ return new Promise(resolve => {
625
+ const registry = new Set();
626
+ const cache = Object.create(null);
627
+ solidJs.sharedConfig.context.registerFragment = register;
628
+ const rendered = fn();
629
+ if (!registry.size) resolve(rendered);
630
+ function register(key) {
631
+ registry.add(key);
632
+ return value => {
633
+ if (value) cache[key] = value;
634
+ registry.delete(key);
635
+ if (!registry.size) Promise.resolve().then(() => {
636
+ let source = resolveSSRNode(rendered);
637
+ let final = "";
638
+ let match;
639
+ while (match = source.match(FRAGMENT_REPLACE)) {
640
+ final += source.substring(0, match.index);
641
+ source = cache[match[1]] + source.substring(match.index + match[0].length);
642
+ }
643
+ resolve(final + source);
644
+ });
645
+ };
646
+ }
647
+ });
648
+ }
546
649
 
547
650
  const isServer = true;
548
651
  function spread() {}
@@ -632,6 +735,7 @@ exports.getHydrationKey = getHydrationKey;
632
735
  exports.isServer = isServer;
633
736
  exports.pipeToNodeWritable = pipeToNodeWritable;
634
737
  exports.pipeToWritable = pipeToWritable;
738
+ exports.renderToPipeableStream = renderToPipeableStream;
635
739
  exports.renderToString = renderToString;
636
740
  exports.renderToStringAsync = renderToStringAsync;
637
741
  exports.resolveSSRNode = resolveSSRNode;