solid-js 1.2.5 → 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.
@@ -1,13 +1,14 @@
1
- declare type HydrationContext = {
1
+ export declare type HydrationContext = {
2
2
  id: string;
3
3
  count: number;
4
- loadResource?: (id: string) => Promise<any>;
5
4
  };
6
5
  declare type SharedConfig = {
7
6
  context?: HydrationContext;
8
7
  resources?: {
9
8
  [key: string]: any;
10
9
  };
10
+ load?: (id: string) => Promise<any> | undefined;
11
+ gather?: (key: string) => void;
11
12
  registry?: Map<string, Element>;
12
13
  };
13
14
  export declare const sharedConfig: SharedConfig;
@@ -1,3 +1,3 @@
1
1
  export { createRoot, createSignal, createComputed, createRenderEffect, createEffect, createDeferred, createSelector, createMemo, getListener, onMount, onCleanup, onError, untrack, batch, on, children, createContext, useContext, getOwner, runWithOwner, equalFn, requestCallback, mapArray, observable, from, $PROXY, DEV } from "./reactive";
2
- export { awaitSuspense, mergeProps, splitProps, createComponent, For, Index, Show, Switch, Match, ErrorBoundary, Suspense, SuspenseList, createResource, enableScheduling, startTransition, useTransition, createUniqueId, lazy, sharedConfig } from "./rendering";
2
+ export { mergeProps, splitProps, createComponent, For, Index, Show, Switch, Match, ErrorBoundary, Suspense, SuspenseList, createResource, enableScheduling, startTransition, useTransition, createUniqueId, lazy, sharedConfig } from "./rendering";
3
3
  export type { Component, Resource } from "./rendering";
@@ -1,9 +1,8 @@
1
+ import type { Accessor, Setter } from "../reactive/signal";
1
2
  export declare const equalFn: <T>(a: T, b: T) => boolean;
2
3
  export declare const $PROXY: unique symbol;
3
4
  export declare const DEV: {};
4
5
  export declare let Owner: Owner | null;
5
- export declare type Accessor<T> = () => T;
6
- export declare type Setter<T> = undefined extends T ? <U extends T>(v?: (U extends Function ? never : U) | ((prev?: U) => U)) => U : <U extends T>(v: (U extends Function ? never : U) | ((prev: U) => U)) => U;
7
6
  interface Owner {
8
7
  owner: Owner | null;
9
8
  context: any | null;
@@ -94,8 +94,10 @@ declare type HydrationContext = {
94
94
  writeResource?: (id: string, v: Promise<any>) => void;
95
95
  resources: Record<string, any>;
96
96
  suspense: Record<string, SuspenseContextType>;
97
+ registerFragment: (v: string) => (v?: string) => void;
97
98
  async?: boolean;
98
99
  streaming?: boolean;
100
+ noHydrate: boolean;
99
101
  };
100
102
  export declare function SuspenseList(props: {
101
103
  children: string;
@@ -106,5 +108,4 @@ export declare function Suspense(props: {
106
108
  fallback: string;
107
109
  children: string;
108
110
  }): any;
109
- export declare function awaitSuspense(fn: () => any): Promise<unknown>;
110
111
  export {};
package/web/dist/dev.cjs CHANGED
@@ -219,27 +219,25 @@ function assign(node, props, isSVG, skipChildren, prevProps = {}) {
219
219
  }
220
220
  }
221
221
  function hydrate(code, element) {
222
- solidJs.sharedConfig.resources = globalThis._$HYDRATION.resources;
223
- solidJs.sharedConfig.completed = globalThis._$HYDRATION.completed;
224
- solidJs.sharedConfig.events = globalThis._$HYDRATION.events;
222
+ if (!globalThis._$HY.sync) {
223
+ let dispose;
224
+ globalThis._$HY.queue.push(() => dispose = hydrate(code, element));
225
+ return () => dispose();
226
+ }
227
+ solidJs.sharedConfig.completed = globalThis._$HY.completed;
228
+ solidJs.sharedConfig.events = globalThis._$HY.events;
229
+ solidJs.sharedConfig.load = globalThis._$HY.load;
230
+ solidJs.sharedConfig.gather = root => gatherHydratable(element, root);
231
+ solidJs.sharedConfig.registry = new Map();
225
232
  solidJs.sharedConfig.context = {
226
233
  id: "",
227
- count: 0,
228
- loadResource: globalThis._$HYDRATION.loadResource
234
+ count: 0
229
235
  };
230
- solidJs.sharedConfig.registry = new Map();
231
236
  gatherHydratable(element);
232
237
  const dispose = render(code, element, [...element.childNodes]);
233
238
  solidJs.sharedConfig.context = null;
234
239
  return dispose;
235
240
  }
236
- function gatherHydratable(element) {
237
- const templates = element.querySelectorAll(`*[data-hk]`);
238
- for (let i = 0; i < templates.length; i++) {
239
- const node = templates[i];
240
- solidJs.sharedConfig.registry.set(node.getAttribute("data-hk"), node);
241
- }
242
- }
243
241
  function getNextElement(template) {
244
242
  let node, key;
245
243
  if (!solidJs.sharedConfig.context || !(node = solidJs.sharedConfig.registry.get(key = getHydrationKey()))) {
@@ -333,7 +331,7 @@ function eventHandler(e) {
333
331
  Object.defineProperty(e, "currentTarget", {
334
332
  configurable: true,
335
333
  get() {
336
- return node;
334
+ return node || document;
337
335
  }
338
336
  });
339
337
  while (node !== null) {
@@ -388,7 +386,12 @@ function insertExpression(parent, value, current, marker, unwrapArray) {
388
386
  solidJs.createRenderEffect(() => current = insertExpression(parent, array, current, marker, true));
389
387
  return () => current;
390
388
  }
391
- if (solidJs.sharedConfig.context && current && current.length) return current;
389
+ if (solidJs.sharedConfig.context && current && current.length) {
390
+ for (let i; i < array.length; i++) {
391
+ if (array[i].parentNode) return array;
392
+ }
393
+ return current;
394
+ }
392
395
  if (array.length === 0) {
393
396
  current = cleanChildren(parent, current, marker);
394
397
  if (multi) return current;
@@ -456,6 +459,14 @@ function cleanChildren(parent, current, marker, replacement) {
456
459
  } else parent.insertBefore(node, marker);
457
460
  return [node];
458
461
  }
462
+ function gatherHydratable(element, root) {
463
+ const templates = element.querySelectorAll(`*[data-hk]`);
464
+ for (let i = 0; i < templates.length; i++) {
465
+ const node = templates[i];
466
+ const key = node.getAttribute("data-hk");
467
+ if (!root || key.startsWith(root)) solidJs.sharedConfig.registry.set(key, node);
468
+ }
469
+ }
459
470
  function getHydrationKey() {
460
471
  const hydrate = solidJs.sharedConfig.context;
461
472
  return `${hydrate.id}${hydrate.count++}`;
@@ -630,7 +641,6 @@ exports.clearDelegatedEvents = clearDelegatedEvents;
630
641
  exports.delegateEvents = delegateEvents;
631
642
  exports.dynamicProperty = dynamicProperty;
632
643
  exports.escape = escape;
633
- exports.gatherHydratable = gatherHydratable;
634
644
  exports.generateHydrationScript = generateHydrationScript;
635
645
  exports.getHydrationKey = getHydrationKey;
636
646
  exports.getNextElement = getNextElement;
package/web/dist/dev.js CHANGED
@@ -216,27 +216,25 @@ function assign(node, props, isSVG, skipChildren, prevProps = {}) {
216
216
  }
217
217
  }
218
218
  function hydrate(code, element) {
219
- sharedConfig.resources = globalThis._$HYDRATION.resources;
220
- sharedConfig.completed = globalThis._$HYDRATION.completed;
221
- 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();
222
229
  sharedConfig.context = {
223
230
  id: "",
224
- count: 0,
225
- loadResource: globalThis._$HYDRATION.loadResource
231
+ count: 0
226
232
  };
227
- sharedConfig.registry = new Map();
228
233
  gatherHydratable(element);
229
234
  const dispose = render(code, element, [...element.childNodes]);
230
235
  sharedConfig.context = null;
231
236
  return dispose;
232
237
  }
233
- function gatherHydratable(element) {
234
- const templates = element.querySelectorAll(`*[data-hk]`);
235
- for (let i = 0; i < templates.length; i++) {
236
- const node = templates[i];
237
- sharedConfig.registry.set(node.getAttribute("data-hk"), node);
238
- }
239
- }
240
238
  function getNextElement(template) {
241
239
  let node, key;
242
240
  if (!sharedConfig.context || !(node = sharedConfig.registry.get(key = getHydrationKey()))) {
@@ -330,7 +328,7 @@ function eventHandler(e) {
330
328
  Object.defineProperty(e, "currentTarget", {
331
329
  configurable: true,
332
330
  get() {
333
- return node;
331
+ return node || document;
334
332
  }
335
333
  });
336
334
  while (node !== null) {
@@ -385,7 +383,12 @@ function insertExpression(parent, value, current, marker, unwrapArray) {
385
383
  createRenderEffect(() => current = insertExpression(parent, array, current, marker, true));
386
384
  return () => current;
387
385
  }
388
- 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
+ }
389
392
  if (array.length === 0) {
390
393
  current = cleanChildren(parent, current, marker);
391
394
  if (multi) return current;
@@ -453,6 +456,14 @@ function cleanChildren(parent, current, marker, replacement) {
453
456
  } else parent.insertBefore(node, marker);
454
457
  return [node];
455
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
+ }
456
467
  function getHydrationKey() {
457
468
  const hydrate = sharedConfig.context;
458
469
  return `${hydrate.id}${hydrate.count++}`;
@@ -536,4 +547,4 @@ function Dynamic(props) {
536
547
  });
537
548
  }
538
549
 
539
- 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,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 = 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
+ 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
- onReady(result);
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
- onReady = ({
363
+ onCompleteShell = ({
323
364
  startWriting
324
365
  }) => startWriting(),
325
- onComplete
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
- 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 = {
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
- completed = count;
405
+ registry.clear();
355
406
  checkEnd();
356
407
  }
357
408
  };
358
- const checkEnd = () => {
359
- if (completed === count) {
360
- onComplete && onComplete(result);
361
- writable.close();
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
- onReady(result);
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
- solidJs.sharedConfig.context.assets.push(generateHydrationScript);
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
- delete solidJs.sharedConfig.context;
482
+ c.noHydrate = true;
392
483
  const children = props.children;
393
- solidJs.sharedConfig.context = c;
484
+ c.noHydrate = false;
394
485
  return children;
395
486
  }
396
487
  function ssr(t, ...nodes) {
@@ -518,26 +609,13 @@ function resolveSSRNode(node) {
518
609
  }
519
610
  function getHydrationKey() {
520
611
  const hydrate = solidJs.sharedConfig.context;
521
- return hydrate && `${hydrate.id}${hydrate.count++}`;
612
+ return hydrate && !hydrate.noHydrate && `${hydrate.id}${hydrate.count++}`;
522
613
  }
523
- function generateHydrationScript() {
524
- const {
525
- nonce,
526
- streaming,
527
- resources,
528
- eventNames = ["click", "input"]
529
- } = solidJs.sharedConfig.context;
530
- 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))})();`;
531
- if (streaming) {
532
- 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]}})();`;
533
- }
534
- if (resources) {
535
- s += `_$HYDRATION.resources = ${devalue(Object.keys(resources).reduce((r, k) => {
536
- r[k] = resources[k].data;
537
- return r;
538
- }, {}))};`;
539
- }
540
- 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>`;
541
619
  }
542
620
  function injectAssets(assets, html) {
543
621
  for (let i = 0; i < assets.length; i++) {
@@ -545,6 +623,33 @@ function injectAssets(assets, html) {
545
623
  }
546
624
  return html;
547
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
+ }
548
653
 
549
654
  const isServer = true;
550
655
  function spread() {}
@@ -634,6 +739,7 @@ exports.getHydrationKey = getHydrationKey;
634
739
  exports.isServer = isServer;
635
740
  exports.pipeToNodeWritable = pipeToNodeWritable;
636
741
  exports.pipeToWritable = pipeToWritable;
742
+ exports.renderToPipeableStream = renderToPipeableStream;
637
743
  exports.renderToString = renderToString;
638
744
  exports.renderToStringAsync = renderToStringAsync;
639
745
  exports.resolveSSRNode = resolveSSRNode;