solid-js 2.0.0-beta.6 → 2.0.0-beta.8

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 CHANGED
@@ -19,10 +19,10 @@ function useContext(context) {
19
19
  return signals.getContext(context);
20
20
  }
21
21
  function children(fn) {
22
- const c = signals.createMemo(fn, undefined, {
22
+ const c = signals.createMemo(fn, {
23
23
  lazy: true
24
24
  });
25
- const memo = signals.createMemo(() => signals.flatten(c()), undefined, {
25
+ const memo = signals.createMemo(() => signals.flatten(c()), {
26
26
  name: "children",
27
27
  lazy: true
28
28
  } );
@@ -282,7 +282,7 @@ function wrapFirstYield(iterable, activate) {
282
282
  }
283
283
  };
284
284
  }
285
- function hydrateSignalFromAsyncIterable(coreFn, compute, value, options) {
285
+ function hydrateSignalFromAsyncIterable(coreFn, compute, options) {
286
286
  const parent = signals.getOwner();
287
287
  const expectedId = signals.peekNextChildId(parent);
288
288
  if (!sharedConfig.has(expectedId)) return null;
@@ -294,9 +294,12 @@ function hydrateSignalFromAsyncIterable(coreFn, compute, value, options) {
294
294
  return it;
295
295
  }
296
296
  };
297
- return coreFn(() => iterable, value, options);
297
+ return coreFn(prev => {
298
+ subFetch(compute, prev);
299
+ return iterable;
300
+ }, options);
298
301
  }
299
- function hydrateStoreFromAsyncIterable(coreFn, initialValue, options) {
302
+ function hydrateStoreFromAsyncIterable(coreFn, fn, initialValue, options) {
300
303
  const parent = signals.getOwner();
301
304
  const expectedId = signals.peekNextChildId(parent);
302
305
  if (!sharedConfig.has(expectedId)) return null;
@@ -306,6 +309,10 @@ function hydrateStoreFromAsyncIterable(coreFn, initialValue, options) {
306
309
  let isFirst = true;
307
310
  let buffered = null;
308
311
  return coreFn(draft => {
312
+ const {
313
+ proxy
314
+ } = createShadowDraft(draft);
315
+ subFetch(fn, proxy);
309
316
  const process = res => {
310
317
  if (res.done) return {
311
318
  done: true,
@@ -313,11 +320,16 @@ function hydrateStoreFromAsyncIterable(coreFn, initialValue, options) {
313
320
  };
314
321
  if (isFirst) {
315
322
  isFirst = false;
316
- if (Array.isArray(res.value)) {
317
- for (let i = 0; i < res.value.length; i++) draft[i] = res.value[i];
318
- draft.length = res.value.length;
319
- } else {
320
- Object.assign(draft, res.value);
323
+ signals.setSnapshotCapture(false);
324
+ try {
325
+ if (Array.isArray(res.value)) {
326
+ for (let i = 0; i < res.value.length; i++) draft[i] = res.value[i];
327
+ draft.length = res.value.length;
328
+ } else {
329
+ Object.assign(draft, res.value);
330
+ }
331
+ } finally {
332
+ signals.setSnapshotCapture(true);
321
333
  }
322
334
  } else {
323
335
  applyPatches(draft, res.value);
@@ -369,59 +381,45 @@ function hydrateStoreFromAsyncIterable(coreFn, initialValue, options) {
369
381
  };
370
382
  }, initialValue, options);
371
383
  }
372
- function hydratedCreateMemo(compute, value, options) {
384
+ function hydratedCreateMemo(compute, options) {
373
385
  if (!sharedConfig.hydrating || options?.transparent) {
374
- return signals.createMemo(compute, value, options);
386
+ return signals.createMemo(compute, options);
375
387
  }
376
388
  markTopLevelSnapshotScope();
377
389
  const ssrSource = options?.ssrSource;
378
390
  if (ssrSource === "client") {
379
391
  const [hydrated, setHydrated] = signals.createSignal(false, {
380
- pureWrite: true
392
+ ownedWrite: true
381
393
  });
382
394
  const memo = signals.createMemo(prev => {
383
- if (!hydrated()) return prev ?? value;
395
+ if (!hydrated()) return prev;
384
396
  return compute(prev);
385
- }, value, options);
397
+ }, options);
386
398
  setHydrated(true);
387
399
  return memo;
388
400
  }
389
- if (ssrSource === "initial") {
390
- return signals.createMemo(prev => {
391
- if (!sharedConfig.hydrating) return compute(prev);
392
- subFetch(compute, prev);
393
- return prev ?? value;
394
- }, value, options);
395
- }
396
- const aiResult = hydrateSignalFromAsyncIterable(signals.createMemo, compute, value, options);
401
+ const aiResult = hydrateSignalFromAsyncIterable(signals.createMemo, compute, options);
397
402
  if (aiResult !== null) return aiResult;
398
- return signals.createMemo(prev => readSerializedOrCompute(compute, prev), value, options);
403
+ return signals.createMemo(prev => readSerializedOrCompute(compute, prev), options);
399
404
  }
400
- function hydratedCreateSignal(fn, second, third) {
401
- if (typeof fn !== "function" || !sharedConfig.hydrating) return signals.createSignal(fn, second, third);
405
+ function hydratedCreateSignal(fn, second) {
406
+ if (typeof fn !== "function" || !sharedConfig.hydrating) return signals.createSignal(fn, second);
402
407
  markTopLevelSnapshotScope();
403
- const ssrSource = third?.ssrSource;
408
+ const ssrSource = second?.ssrSource;
404
409
  if (ssrSource === "client") {
405
410
  const [hydrated, setHydrated] = signals.createSignal(false, {
406
- pureWrite: true
411
+ ownedWrite: true
407
412
  });
408
413
  const sig = signals.createSignal(prev => {
409
- if (!hydrated()) return prev ?? second;
414
+ if (!hydrated()) return prev;
410
415
  return fn(prev);
411
- }, second, third);
416
+ }, second);
412
417
  setHydrated(true);
413
418
  return sig;
414
419
  }
415
- if (ssrSource === "initial") {
416
- return signals.createSignal(prev => {
417
- if (!sharedConfig.hydrating) return fn(prev);
418
- subFetch(fn, prev);
419
- return prev ?? second;
420
- }, second, third);
421
- }
422
- const aiResult = hydrateSignalFromAsyncIterable(signals.createSignal, fn, second, third);
420
+ const aiResult = hydrateSignalFromAsyncIterable(signals.createSignal, fn, second);
423
421
  if (aiResult !== null) return aiResult;
424
- return signals.createSignal(prev => readSerializedOrCompute(fn, prev), second, third);
422
+ return signals.createSignal(prev => readSerializedOrCompute(fn, prev), second);
425
423
  }
426
424
  function hydratedCreateErrorBoundary(fn, fallback) {
427
425
  if (!sharedConfig.hydrating) return signals.createErrorBoundary(fn, fallback);
@@ -443,31 +441,24 @@ function hydratedCreateErrorBoundary(fn, fallback) {
443
441
  }
444
442
  return signals.createErrorBoundary(fn, fallback);
445
443
  }
446
- function hydratedCreateOptimistic(fn, second, third) {
447
- if (typeof fn !== "function" || !sharedConfig.hydrating) return signals.createOptimistic(fn, second, third);
444
+ function hydratedCreateOptimistic(fn, second) {
445
+ if (typeof fn !== "function" || !sharedConfig.hydrating) return signals.createOptimistic(fn, second);
448
446
  markTopLevelSnapshotScope();
449
- const ssrSource = third?.ssrSource;
447
+ const ssrSource = second?.ssrSource;
450
448
  if (ssrSource === "client") {
451
449
  const [hydrated, setHydrated] = signals.createSignal(false, {
452
- pureWrite: true
450
+ ownedWrite: true
453
451
  });
454
452
  const sig = signals.createOptimistic(prev => {
455
- if (!hydrated()) return prev ?? second;
453
+ if (!hydrated()) return prev;
456
454
  return fn(prev);
457
- }, second, third);
455
+ }, second);
458
456
  setHydrated(true);
459
457
  return sig;
460
458
  }
461
- if (ssrSource === "initial") {
462
- return signals.createOptimistic(prev => {
463
- if (!sharedConfig.hydrating) return fn(prev);
464
- subFetch(fn, prev);
465
- return prev ?? second;
466
- }, second, third);
467
- }
468
- const aiResult = hydrateSignalFromAsyncIterable(signals.createOptimistic, fn, second, third);
459
+ const aiResult = hydrateSignalFromAsyncIterable(signals.createOptimistic, fn, second);
469
460
  if (aiResult !== null) return aiResult;
470
- return signals.createOptimistic(prev => readSerializedOrCompute(fn, prev), second, third);
461
+ return signals.createOptimistic(prev => readSerializedOrCompute(fn, prev), second);
471
462
  }
472
463
  function wrapStoreFn(fn) {
473
464
  return draft => readSerializedOrCompute(() => fn(draft), draft);
@@ -475,7 +466,7 @@ function wrapStoreFn(fn) {
475
466
  function hydrateStoreLikeFn(coreFn, fn, initialValue, options, ssrSource) {
476
467
  if (ssrSource === "client") {
477
468
  const [hydrated, setHydrated] = signals.createSignal(false, {
478
- pureWrite: true
469
+ ownedWrite: true
479
470
  });
480
471
  const result = coreFn(draft => {
481
472
  if (!hydrated()) return;
@@ -486,7 +477,7 @@ function hydrateStoreLikeFn(coreFn, fn, initialValue, options, ssrSource) {
486
477
  }
487
478
  if (ssrSource === "hybrid") {
488
479
  const [hydrated, setHydrated] = signals.createSignal(false, {
489
- pureWrite: true
480
+ ownedWrite: true
490
481
  });
491
482
  const result = coreFn(draft => {
492
483
  const o = signals.getOwner();
@@ -508,7 +499,7 @@ function hydrateStoreLikeFn(coreFn, fn, initialValue, options, ssrSource) {
508
499
  setHydrated(true);
509
500
  return result;
510
501
  }
511
- const aiResult = hydrateStoreFromAsyncIterable(coreFn, initialValue, options);
502
+ const aiResult = hydrateStoreFromAsyncIterable(coreFn, fn, initialValue, options);
512
503
  if (aiResult !== null) return aiResult;
513
504
  return coreFn(wrapStoreFn(fn), initialValue, options);
514
505
  }
@@ -516,58 +507,47 @@ function hydratedCreateStore(first, second, third) {
516
507
  if (typeof first !== "function" || !sharedConfig.hydrating) return signals.createStore(first, second, third);
517
508
  markTopLevelSnapshotScope();
518
509
  const ssrSource = third?.ssrSource;
519
- if (ssrSource === "initial") return signals.createStore(second ?? {}, undefined, third);
520
510
  return hydrateStoreLikeFn(signals.createStore, first, second ?? {}, third, ssrSource);
521
511
  }
522
512
  function hydratedCreateOptimisticStore(first, second, third) {
523
513
  if (typeof first !== "function" || !sharedConfig.hydrating) return signals.createOptimisticStore(first, second, third);
524
514
  markTopLevelSnapshotScope();
525
515
  const ssrSource = third?.ssrSource;
526
- if (ssrSource === "initial") return signals.createOptimisticStore(second ?? {}, undefined, third);
527
516
  return hydrateStoreLikeFn(signals.createOptimisticStore, first, second ?? {}, third, ssrSource);
528
517
  }
529
518
  function hydratedCreateProjection(fn, initialValue, options) {
530
519
  if (!sharedConfig.hydrating) return signals.createProjection(fn, initialValue, options);
531
520
  markTopLevelSnapshotScope();
532
521
  const ssrSource = options?.ssrSource;
533
- if (ssrSource === "initial") return signals.createProjection(draft => draft, initialValue, options);
534
522
  return hydrateStoreLikeFn(signals.createProjection, fn, initialValue, options, ssrSource);
535
523
  }
536
- function hydratedEffect(coreFn, compute, effectFn, value, options) {
537
- if (!sharedConfig.hydrating) return coreFn(compute, effectFn, value, options);
524
+ function hydratedEffect(coreFn, compute, effectFn, options) {
525
+ if (!sharedConfig.hydrating || options?.transparent) return coreFn(compute, effectFn, options);
538
526
  const ssrSource = options?.ssrSource;
539
527
  if (ssrSource === "client") {
540
528
  const [hydrated, setHydrated] = signals.createSignal(false, {
541
- pureWrite: true
529
+ ownedWrite: true
542
530
  });
543
531
  let active = false;
544
532
  coreFn(prev => {
545
- if (!hydrated()) return value;
533
+ if (!hydrated()) return prev;
546
534
  active = true;
547
535
  return compute(prev);
548
536
  }, (next, prev) => {
549
537
  if (!active) return;
550
538
  return effectFn(next, prev);
551
- }, value, options);
539
+ }, options);
552
540
  setHydrated(true);
553
541
  return;
554
542
  }
555
- if (ssrSource === "initial") {
556
- coreFn(prev => {
557
- if (!sharedConfig.hydrating) return compute(prev);
558
- subFetch(compute, prev);
559
- return prev ?? value;
560
- }, effectFn, value, options);
561
- return;
562
- }
563
543
  markTopLevelSnapshotScope();
564
- coreFn(prev => readSerializedOrCompute(compute, prev), effectFn, value, options);
544
+ coreFn(prev => readSerializedOrCompute(compute, prev), effectFn, options);
565
545
  }
566
- function hydratedCreateRenderEffect(compute, effectFn, value, options) {
567
- return hydratedEffect(signals.createRenderEffect, compute, effectFn, value, options);
546
+ function hydratedCreateRenderEffect(compute, effectFn, options) {
547
+ return hydratedEffect(signals.createRenderEffect, compute, effectFn, options);
568
548
  }
569
- function hydratedCreateEffect(compute, effectFn, value, options) {
570
- return hydratedEffect(signals.createEffect, compute, effectFn, value, options);
549
+ function hydratedCreateEffect(compute, effectFn, options) {
550
+ return hydratedEffect(signals.createEffect, compute, effectFn, options);
571
551
  }
572
552
  function enableHydration() {
573
553
  _createMemo = hydratedCreateMemo;
@@ -626,24 +606,6 @@ const createStore = (...args) => (_createStore || signals.createStore)(...args);
626
606
  const createOptimisticStore = (...args) => (_createOptimisticStore || signals.createOptimisticStore)(...args);
627
607
  const createRenderEffect = (...args) => (_createRenderEffect || signals.createRenderEffect)(...args);
628
608
  const createEffect = (...args) => (_createEffect || signals.createEffect)(...args);
629
- function loadModuleAssets(mapping) {
630
- const hy = globalThis._$HY;
631
- if (!hy) return;
632
- if (!hy.modules) hy.modules = {};
633
- if (!hy.loading) hy.loading = {};
634
- const pending = [];
635
- for (const moduleUrl in mapping) {
636
- if (hy.modules[moduleUrl]) continue;
637
- const entryUrl = mapping[moduleUrl];
638
- if (!hy.loading[moduleUrl]) {
639
- hy.loading[moduleUrl] = import(entryUrl).then(mod => {
640
- hy.modules[moduleUrl] = mod;
641
- });
642
- }
643
- pending.push(hy.loading[moduleUrl]);
644
- }
645
- return pending.length ? Promise.all(pending).then(() => {}) : undefined;
646
- }
647
609
  function createBoundaryTrigger() {
648
610
  signals.setSnapshotCapture(false);
649
611
  const [s, set] = signals.createSignal(undefined, {
@@ -712,7 +674,7 @@ function createLoadingBoundary(fn, fallback, options) {
712
674
  let assetPromise;
713
675
  if (sharedConfig.hydrating && sharedConfig.has(id + "_assets")) {
714
676
  const mapping = sharedConfig.load(id + "_assets");
715
- if (mapping && typeof mapping === "object") assetPromise = loadModuleAssets(mapping);
677
+ if (mapping && typeof mapping === "object") assetPromise = sharedConfig.loadModuleAssets?.(mapping);
716
678
  }
717
679
  if (sharedConfig.hydrating && sharedConfig.has(id)) {
718
680
  const ref = sharedConfig.load(id);
@@ -831,10 +793,10 @@ function Repeat(props) {
831
793
  }
832
794
  function Show(props) {
833
795
  const keyed = props.keyed;
834
- const conditionValue = signals.createMemo(() => props.when, undefined, {
796
+ const conditionValue = signals.createMemo(() => props.when, {
835
797
  name: "condition value"
836
798
  } );
837
- const condition = keyed ? conditionValue : signals.createMemo(conditionValue, undefined, {
799
+ const condition = keyed ? conditionValue : signals.createMemo(conditionValue, {
838
800
  equals: (a, b) => !a === !b,
839
801
  name: "condition"
840
802
  } );
@@ -849,7 +811,7 @@ function Show(props) {
849
811
  }), "<Show>") : child;
850
812
  }
851
813
  return props.fallback;
852
- }, undefined, {
814
+ }, {
853
815
  name: "value"
854
816
  } );
855
817
  }
@@ -862,10 +824,10 @@ function Switch(props) {
862
824
  const index = i;
863
825
  const mp = mps[i];
864
826
  const prevFunc = func;
865
- const conditionValue = signals.createMemo(() => prevFunc() ? undefined : mp.when, undefined, {
827
+ const conditionValue = signals.createMemo(() => prevFunc() ? undefined : mp.when, {
866
828
  name: "condition value"
867
829
  } );
868
- const condition = mp.keyed ? conditionValue : signals.createMemo(conditionValue, undefined, {
830
+ const condition = mp.keyed ? conditionValue : signals.createMemo(conditionValue, {
869
831
  equals: (a, b) => !a === !b,
870
832
  name: "condition"
871
833
  } );
@@ -883,7 +845,7 @@ function Switch(props) {
883
845
  if (signals.untrack(switchFunc)()?.[0] !== index) throw narrowedError("Match");
884
846
  return conditionValue();
885
847
  }), "<Match>") : child;
886
- }, undefined, {
848
+ }, {
887
849
  name: "eval conditions"
888
850
  } );
889
851
  }
@@ -905,7 +867,7 @@ function Loading(props) {
905
867
  }
906
868
  function Reveal(props) {
907
869
  return signals.createRevealOrder(() => props.children, {
908
- together: () => !!props.together,
870
+ order: () => props.order ?? "sequential",
909
871
  collapsed: () => !!props.collapsed
910
872
  });
911
873
  }