solid-js 1.3.0-beta.1 → 1.3.0-beta.5

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.
@@ -56,9 +56,9 @@ declare type MatchProps<T> = {
56
56
  };
57
57
  export declare function Match<T>(props: MatchProps<T>): MatchProps<T>;
58
58
  export declare function ErrorBoundary(props: {
59
- fallback: string | ((err: any) => string);
59
+ fallback: string | ((err: any, reset: () => void) => string);
60
60
  children: string;
61
- }): string;
61
+ }): any;
62
62
  export interface Resource<T> {
63
63
  (): T | undefined;
64
64
  loading: boolean;
@@ -91,12 +91,13 @@ export declare function useTransition(): [() => boolean, (fn: () => any) => void
91
91
  declare type HydrationContext = {
92
92
  id: string;
93
93
  count: number;
94
- writeResource?: (id: string, v: Promise<any>) => void;
94
+ writeResource?: (id: string, v: Promise<any> | any, error?: boolean) => void;
95
95
  resources: Record<string, any>;
96
96
  suspense: Record<string, SuspenseContextType>;
97
- registerFragment: (v: string) => (v?: string) => void;
97
+ registerFragment: (v: string) => (v?: string, err?: any) => boolean;
98
98
  async?: boolean;
99
99
  streaming?: boolean;
100
+ dataOnly?: boolean;
100
101
  noHydrate: boolean;
101
102
  };
102
103
  export declare function SuspenseList(props: {
@@ -105,7 +106,7 @@ export declare function SuspenseList(props: {
105
106
  tail?: "collapsed" | "hidden";
106
107
  }): string;
107
108
  export declare function Suspense(props: {
108
- fallback: string;
109
+ fallback?: string;
109
110
  children: string;
110
111
  }): any;
111
112
  export {};
package/web/dist/dev.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();
@@ -218,22 +218,17 @@ function assign(node, props, isSVG, skipChildren, prevProps = {}) {
218
218
  prevProps[prop] = assignProp(node, prop, value, prevProps[prop], isSVG);
219
219
  }
220
220
  }
221
- function hydrate(code, element) {
222
- if (!globalThis._$HY.sync) {
223
- let dispose;
224
- globalThis._$HY.queue.push(() => dispose = hydrate(code, element));
225
- return () => dispose();
226
- }
221
+ function hydrate$1(code, element, options = {}) {
227
222
  solidJs.sharedConfig.completed = globalThis._$HY.completed;
228
223
  solidJs.sharedConfig.events = globalThis._$HY.events;
229
224
  solidJs.sharedConfig.load = globalThis._$HY.load;
230
225
  solidJs.sharedConfig.gather = root => gatherHydratable(element, root);
231
226
  solidJs.sharedConfig.registry = new Map();
232
227
  solidJs.sharedConfig.context = {
233
- id: "",
228
+ id: options.renderId || "",
234
229
  count: 0
235
230
  };
236
- gatherHydratable(element);
231
+ gatherHydratable(element, options.renderId);
237
232
  const dispose = render(code, element, [...element.childNodes]);
238
233
  solidJs.sharedConfig.context = null;
239
234
  return dispose;
@@ -387,8 +382,8 @@ function insertExpression(parent, value, current, marker, unwrapArray) {
387
382
  return () => current;
388
383
  }
389
384
  if (solidJs.sharedConfig.context && current && current.length) {
390
- for (let i; i < array.length; i++) {
391
- if (array[i].parentNode) return array;
385
+ for (let i = 0; i < array.length; i++) {
386
+ if (array[i].parentNode) return current = array;
392
387
  }
393
388
  return current;
394
389
  }
@@ -480,8 +475,7 @@ function NoHydration(props) {
480
475
 
481
476
  function renderToString(fn, options) {}
482
477
  function renderToStringAsync(fn, options) {}
483
- function pipeToNodeWritable(fn, writable, options) {}
484
- function pipeToWritable(fn, writable, options) {}
478
+ function renderToStream(fn, options) {}
485
479
  function ssr(template, ...nodes) {}
486
480
  function resolveSSRNode(node) {}
487
481
  function ssrClassList(value) {}
@@ -497,6 +491,10 @@ const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
497
491
  function createElement(tagName, isSVG = false) {
498
492
  return isSVG ? document.createElementNS(SVG_NAMESPACE, tagName) : document.createElement(tagName);
499
493
  }
494
+ const hydrate = (...args) => {
495
+ solidJs.enableHydration();
496
+ return hydrate$1(...args);
497
+ };
500
498
  function Portal(props) {
501
499
  const {
502
500
  useShadow
@@ -650,9 +648,8 @@ exports.hydrate = hydrate;
650
648
  exports.insert = insert;
651
649
  exports.isServer = isServer;
652
650
  exports.memo = memo;
653
- exports.pipeToNodeWritable = pipeToNodeWritable;
654
- exports.pipeToWritable = pipeToWritable;
655
651
  exports.render = render;
652
+ exports.renderToStream = renderToStream;
656
653
  exports.renderToString = renderToString;
657
654
  exports.renderToStringAsync = renderToStringAsync;
658
655
  exports.resolveSSRNode = resolveSSRNode;
package/web/dist/dev.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createMemo, createRoot, createRenderEffect, sharedConfig, createSignal, onCleanup, splitProps, untrack } from 'solid-js';
1
+ import { createMemo, createRoot, createRenderEffect, sharedConfig, enableHydration, createSignal, onCleanup, splitProps, untrack } from 'solid-js';
2
2
  export { ErrorBoundary, For, Index, Match, Show, Suspense, SuspenseList, Switch, createComponent, createRenderEffect as effect, getOwner, 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"];
@@ -95,7 +95,7 @@ function render(code, element, init) {
95
95
  let disposer;
96
96
  createRoot(dispose => {
97
97
  disposer = dispose;
98
- insert(element, code(), element.firstChild ? null : undefined, init);
98
+ element === document ? code() : insert(element, code(), element.firstChild ? null : undefined, init);
99
99
  });
100
100
  return () => {
101
101
  disposer();
@@ -215,22 +215,17 @@ function assign(node, props, isSVG, skipChildren, prevProps = {}) {
215
215
  prevProps[prop] = assignProp(node, prop, value, prevProps[prop], isSVG);
216
216
  }
217
217
  }
218
- function hydrate(code, element) {
219
- if (!globalThis._$HY.sync) {
220
- let dispose;
221
- globalThis._$HY.queue.push(() => dispose = hydrate(code, element));
222
- return () => dispose();
223
- }
218
+ function hydrate$1(code, element, options = {}) {
224
219
  sharedConfig.completed = globalThis._$HY.completed;
225
220
  sharedConfig.events = globalThis._$HY.events;
226
221
  sharedConfig.load = globalThis._$HY.load;
227
222
  sharedConfig.gather = root => gatherHydratable(element, root);
228
223
  sharedConfig.registry = new Map();
229
224
  sharedConfig.context = {
230
- id: "",
225
+ id: options.renderId || "",
231
226
  count: 0
232
227
  };
233
- gatherHydratable(element);
228
+ gatherHydratable(element, options.renderId);
234
229
  const dispose = render(code, element, [...element.childNodes]);
235
230
  sharedConfig.context = null;
236
231
  return dispose;
@@ -384,8 +379,8 @@ function insertExpression(parent, value, current, marker, unwrapArray) {
384
379
  return () => current;
385
380
  }
386
381
  if (sharedConfig.context && current && current.length) {
387
- for (let i; i < array.length; i++) {
388
- if (array[i].parentNode) return array;
382
+ for (let i = 0; i < array.length; i++) {
383
+ if (array[i].parentNode) return current = array;
389
384
  }
390
385
  return current;
391
386
  }
@@ -477,8 +472,7 @@ function NoHydration(props) {
477
472
 
478
473
  function renderToString(fn, options) {}
479
474
  function renderToStringAsync(fn, options) {}
480
- function pipeToNodeWritable(fn, writable, options) {}
481
- function pipeToWritable(fn, writable, options) {}
475
+ function renderToStream(fn, options) {}
482
476
  function ssr(template, ...nodes) {}
483
477
  function resolveSSRNode(node) {}
484
478
  function ssrClassList(value) {}
@@ -494,6 +488,10 @@ const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
494
488
  function createElement(tagName, isSVG = false) {
495
489
  return isSVG ? document.createElementNS(SVG_NAMESPACE, tagName) : document.createElement(tagName);
496
490
  }
491
+ const hydrate = (...args) => {
492
+ enableHydration();
493
+ return hydrate$1(...args);
494
+ };
497
495
  function Portal(props) {
498
496
  const {
499
497
  useShadow
@@ -547,4 +545,4 @@ function Dynamic(props) {
547
545
  });
548
546
  }
549
547
 
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 };
548
+ 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, render, renderToStream, renderToString, renderToStringAsync, resolveSSRNode, runHydrationEvents, setAttribute, setAttributeNS, spread, ssr, ssrBoolean, ssrClassList, ssrHydrationKey, ssrSpread, ssrStyle, style, template };
@@ -232,26 +232,32 @@ 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
+ const REPLACE_SCRIPT = `function $df(e,y,t){t=document.getElementById(e),document.getElementById("pl"+e).replaceWith(...t.childNodes),_$HY.set(e,y)}`;
236
+ const FRAGMENT_REPLACE = /<!\[([\d.]+)\]>/;
237
237
  function renderToString(code, options = {}) {
238
+ let scripts = "";
238
239
  solidJs.sharedConfig.context = {
239
- id: "",
240
+ id: options.renderId || "",
240
241
  count: 0,
241
242
  suspense: {},
242
243
  assets: [],
243
- nonce: options.nonce
244
+ nonce: options.nonce,
245
+ writeResource(id, p, error) {
246
+ if (error) scripts += `_$HY.set("${id}", ${serializeError(p)});`;
247
+ }
244
248
  };
245
- let html = resolveSSRNode(escape(code()));
246
- return injectAssets(solidJs.sharedConfig.context.assets, html) + `<script${options.nonce ? ` nonce="${options.nonce}"` : ""}>${SYNC_SCRIPT}</script>`;
249
+ let html = injectAssets(solidJs.sharedConfig.context.assets, resolveSSRNode(escape(code())));
250
+ if (scripts.length) html = injectScripts(html, scripts, options.nonce);
251
+ return html;
247
252
  }
248
253
  function renderToStringAsync(code, options = {}) {
249
254
  const {
250
255
  nonce,
256
+ renderId,
251
257
  timeoutMs = 30000
252
258
  } = options;
253
259
  const context = solidJs.sharedConfig.context = {
254
- id: "",
260
+ id: renderId || "",
255
261
  count: 0,
256
262
  resources: {},
257
263
  suspense: {},
@@ -260,23 +266,56 @@ function renderToStringAsync(code, options = {}) {
260
266
  nonce
261
267
  };
262
268
  let scripts = "";
263
- solidJs.sharedConfig.context.writeResource = (id, p) => p.then(d => scripts += `_$HY.set("${id}", ${devalue(d)});`);
269
+ solidJs.sharedConfig.context.writeResource = (id, p, error) => {
270
+ if (error) return scripts += `_$HY.set("${id}", ${serializeError(p)});`;
271
+ p.then(d => scripts += `_$HY.set("${id}", ${devalue(d)});`).catch(() => scripts += `_$HY.set("${id}", null);`);
272
+ };
264
273
  const timeout = new Promise((_, reject) => setTimeout(() => reject("renderToString timed out"), timeoutMs));
274
+ function asyncWrap(fn) {
275
+ return new Promise(resolve => {
276
+ const registry = new Set();
277
+ const cache = Object.create(null);
278
+ solidJs.sharedConfig.context.registerFragment = register;
279
+ const rendered = fn();
280
+ if (!registry.size) resolve(rendered);
281
+ function register(key) {
282
+ registry.add(key);
283
+ return (value = "", error) => {
284
+ cache[key] = value;
285
+ registry.delete(key);
286
+ if (error) return scripts += `_$HY.set("${key}", Promise.resolve(${serializeError(error)}));`;
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
+ }
265
302
  return Promise.race([asyncWrap(() => escape(code())), timeout]).then(res => {
266
- let html = resolveSSRNode(res);
267
- html += `<script${nonce ? ` nonce="${nonce}"` : ""}>${scripts.length ? scripts + ";" : ""}${SYNC_SCRIPT}</script>`;
268
- return injectAssets(context.assets, html);
303
+ let html = injectAssets(context.assets, resolveSSRNode(res));
304
+ if (scripts.length) html = injectScripts(html, scripts, nonce);
305
+ return html;
269
306
  });
270
307
  }
271
- function renderToPipeableStream(code, options) {
308
+ function renderToStream(code, options = {}) {
272
309
  const {
273
310
  nonce,
274
311
  onCompleteShell,
275
- onCompleteAll
312
+ onCompleteAll,
313
+ dataOnly,
314
+ renderId
276
315
  } = options;
277
316
  const tmp = [];
278
317
  const tasks = [];
279
- const registry = new Set();
318
+ const registry = new Map();
280
319
  const checkEnd = () => {
281
320
  if (!registry.size && !completed) {
282
321
  onCompleteAll && onCompleteAll(result);
@@ -285,7 +324,7 @@ function renderToPipeableStream(code, options) {
285
324
  }
286
325
  };
287
326
  const writeInitialScript = () => {
288
- if (tasks.length) {
327
+ if (tasks.length && !completed) {
289
328
  buffer.write(`<script${nonce ? ` nonce="${nonce}"` : ""}>${tasks.join(";")}</script>`);
290
329
  tasks.length = 0;
291
330
  }
@@ -301,48 +340,55 @@ function renderToPipeableStream(code, options) {
301
340
  }
302
341
  };
303
342
  solidJs.sharedConfig.context = {
304
- id: "",
343
+ id: renderId || "",
305
344
  count: 0,
306
345
  async: true,
307
346
  streaming: true,
347
+ dataOnly,
308
348
  resources: {},
309
349
  suspense: {},
310
350
  assets: [],
311
351
  nonce,
312
- writeResource(id, p) {
352
+ writeResource(id, p, error) {
313
353
  if (!scheduled) {
314
354
  Promise.resolve().then(writeInitialScript);
315
355
  scheduled = true;
316
356
  }
357
+ if (error) return tasks.push(`_$HY.set("${id}", ${serializeError(p)})`);
317
358
  tasks.push(`_$HY.init("${id}")`);
318
359
  p.then(d => {
319
- buffer.write(`<script${nonce ? ` nonce="${nonce}"` : ""}>_$HY.set("${id}", ${devalue(d)})</script>`);
360
+ !completed && buffer.write(`<script${nonce ? ` nonce="${nonce}"` : ""}>_$HY.set("${id}", ${devalue(d)})</script>`);
361
+ }).catch(() => {
362
+ !completed && buffer.write(`<script${nonce ? ` nonce="${nonce}"` : ""}>_$HY.set("${id}", null)</script>`);
320
363
  });
321
364
  },
322
365
  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}")`);
366
+ registry.set(key, []);
367
+ if (!dataOnly) {
368
+ if (!scheduled) {
369
+ Promise.resolve().then(writeInitialScript);
370
+ scheduled = true;
331
371
  }
332
- });
333
- return value => {
372
+ tasks.push(`_$HY.init("${key}")`);
373
+ }
374
+ return (value, error) => {
375
+ const keys = registry.get(key);
334
376
  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;
377
+ if (waitForFragments(registry, key)) return;
378
+ if ((value !== undefined || error) && !completed) {
379
+ 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>`);
380
+ scriptFlushed = true;
381
+ }
338
382
  checkEnd();
383
+ return true;
339
384
  };
340
385
  }
341
386
  };
342
387
  let html = resolveSSRNode(escape(code()));
343
388
  html = injectAssets(solidJs.sharedConfig.context.assets, html);
344
389
  Promise.resolve().then(() => {
345
- buffer.write(html + `<script${nonce ? ` nonce="${nonce}"` : ""}>${tasks.length ? tasks.join(";") + ";" : ""}${SYNC_SCRIPT}</script>`);
390
+ if (tasks.length) html = injectScripts(html, tasks.join(";"), nonce);
391
+ buffer.write(html);
346
392
  tasks.length = 0;
347
393
  scheduled = false;
348
394
  onCompleteShell && onCompleteShell();
@@ -352,108 +398,24 @@ function renderToPipeableStream(code, options) {
352
398
  buffer = writable = w;
353
399
  tmp.forEach(chunk => buffer.write(chunk));
354
400
  if (completed) writable.end();else setTimeout(checkEnd);
355
- }
356
- };
357
- }
358
- function pipeToWritable(code, writable, options = {}) {
359
- const {
360
- nonce,
361
- onCompleteShell = ({
362
- startWriting
363
- }) => startWriting(),
364
- onCompleteAll
365
- } = options;
366
- const tmp = [];
367
- const tasks = [];
368
- const writer = writable.getWriter();
369
- const encoder = new TextEncoder();
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 = {
389
- write(payload) {
390
- tmp.push(payload);
391
- }
392
- };
393
- const result = {
394
- startWriting() {
395
- buffer = writer;
396
- tmp.forEach(chunk => writer.write(chunk));
397
- setTimeout(checkEnd);
398
- },
399
- write(c) {
400
- writer.write(encoder.encode(c));
401
- },
402
- abort() {
403
- registry.clear();
404
- checkEnd();
405
- }
406
- };
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
401
  },
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}")`);
402
+ pipeTo(w) {
403
+ const encoder = new TextEncoder();
404
+ const writer = w.getWriter();
405
+ writable = {
406
+ end() {
407
+ w.close();
408
+ }
409
+ };
410
+ buffer = {
411
+ write(payload) {
412
+ writer.write(encoder.encode(payload));
435
413
  }
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
414
  };
415
+ tmp.forEach(chunk => buffer.write(chunk));
416
+ if (completed) writable.end();else setTimeout(checkEnd);
444
417
  }
445
418
  };
446
- let html = resolveSSRNode(escape(code()));
447
- html = injectAssets(solidJs.sharedConfig.context.assets, html);
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);
457
419
  }
458
420
  function Assets(props) {
459
421
  solidJs.sharedConfig.context.assets.push(() => NoHydration({
@@ -611,7 +573,7 @@ function generateHydrationScript({
611
573
  eventNames = ["click", "input"],
612
574
  nonce
613
575
  }) {
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>`;
576
+ 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.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>`;
615
577
  }
616
578
  function injectAssets(assets, html) {
617
579
  for (let i = 0; i < assets.length; i++) {
@@ -619,32 +581,51 @@ function injectAssets(assets, html) {
619
581
  }
620
582
  return html;
621
583
  }
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
- };
584
+ function injectScripts(html, scripts, nonce) {
585
+ const tag = `<script${nonce ? ` nonce="${nonce}"` : ""}>${scripts}</script>`;
586
+ const index = html.indexOf("<!xs>");
587
+ if (index > -1) {
588
+ return html.slice(0, index) + tag + html.slice(index);
589
+ }
590
+ return html + tag;
591
+ }
592
+ function serializeError(error) {
593
+ return error.message ? `new Error(${devalue(error.message)})` : devalue(error);
594
+ }
595
+ function waitForFragments(registry, key) {
596
+ for (const k of [...registry.keys()].reverse()) {
597
+ if (key.startsWith(k)) {
598
+ registry.get(k).push(key);
599
+ return true;
646
600
  }
647
- });
601
+ }
602
+ return false;
603
+ }
604
+ function pipeToNodeWritable(code, writable, options = {}) {
605
+ if (options.onReady) {
606
+ options.onCompleteShell = () => {
607
+ options.onReady({
608
+ startWriting() {
609
+ stream.pipe(writable);
610
+ }
611
+ });
612
+ };
613
+ }
614
+ const stream = renderToStream(code, options);
615
+ if (!options.onReady) stream.pipe(writable);
616
+ }
617
+ function pipeToWritable(code, writable, options = {}) {
618
+ if (options.onReady) {
619
+ options.onCompleteShell = () => {
620
+ options.onReady({
621
+ startWriting() {
622
+ stream.pipeTo(writable);
623
+ }
624
+ });
625
+ };
626
+ }
627
+ const stream = renderToStream(code, options);
628
+ if (!options.onReady) stream.pipeTo(writable);
648
629
  }
649
630
 
650
631
  const isServer = true;
@@ -735,7 +716,7 @@ exports.getHydrationKey = getHydrationKey;
735
716
  exports.isServer = isServer;
736
717
  exports.pipeToNodeWritable = pipeToNodeWritable;
737
718
  exports.pipeToWritable = pipeToWritable;
738
- exports.renderToPipeableStream = renderToPipeableStream;
719
+ exports.renderToStream = renderToStream;
739
720
  exports.renderToString = renderToString;
740
721
  exports.renderToStringAsync = renderToStringAsync;
741
722
  exports.resolveSSRNode = resolveSSRNode;