solid-js 2.0.0-beta.5 → 2.0.0-beta.7

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/solid.cjs CHANGED
@@ -20,10 +20,10 @@ function useContext(context) {
20
20
  return signals.getContext(context);
21
21
  }
22
22
  function children(fn) {
23
- const c = signals.createMemo(fn, undefined, {
23
+ const c = signals.createMemo(fn, {
24
24
  lazy: true
25
25
  });
26
- const memo = signals.createMemo(() => signals.flatten(c()), undefined, {
26
+ const memo = signals.createMemo(() => signals.flatten(c()), {
27
27
  lazy: true
28
28
  });
29
29
  memo.toArray = () => {
@@ -265,7 +265,7 @@ function wrapFirstYield(iterable, activate) {
265
265
  }
266
266
  };
267
267
  }
268
- function hydrateSignalFromAsyncIterable(coreFn, compute, value, options) {
268
+ function hydrateSignalFromAsyncIterable(coreFn, compute, options) {
269
269
  const parent = signals.getOwner();
270
270
  const expectedId = signals.peekNextChildId(parent);
271
271
  if (!sharedConfig.has(expectedId)) return null;
@@ -277,7 +277,7 @@ function hydrateSignalFromAsyncIterable(coreFn, compute, value, options) {
277
277
  return it;
278
278
  }
279
279
  };
280
- return coreFn(() => iterable, value, options);
280
+ return coreFn(() => iterable, options);
281
281
  }
282
282
  function hydrateStoreFromAsyncIterable(coreFn, initialValue, options) {
283
283
  const parent = signals.getOwner();
@@ -352,20 +352,20 @@ function hydrateStoreFromAsyncIterable(coreFn, initialValue, options) {
352
352
  };
353
353
  }, initialValue, options);
354
354
  }
355
- function hydratedCreateMemo(compute, value, options) {
355
+ function hydratedCreateMemo(compute, options) {
356
356
  if (!sharedConfig.hydrating || options?.transparent) {
357
- return signals.createMemo(compute, value, options);
357
+ return signals.createMemo(compute, options);
358
358
  }
359
359
  markTopLevelSnapshotScope();
360
360
  const ssrSource = options?.ssrSource;
361
361
  if (ssrSource === "client") {
362
362
  const [hydrated, setHydrated] = signals.createSignal(false, {
363
- pureWrite: true
363
+ ownedWrite: true
364
364
  });
365
365
  const memo = signals.createMemo(prev => {
366
- if (!hydrated()) return prev ?? value;
366
+ if (!hydrated()) return prev;
367
367
  return compute(prev);
368
- }, value, options);
368
+ }, options);
369
369
  setHydrated(true);
370
370
  return memo;
371
371
  }
@@ -373,25 +373,25 @@ function hydratedCreateMemo(compute, value, options) {
373
373
  return signals.createMemo(prev => {
374
374
  if (!sharedConfig.hydrating) return compute(prev);
375
375
  subFetch(compute, prev);
376
- return prev ?? value;
377
- }, value, options);
376
+ return prev;
377
+ }, options);
378
378
  }
379
- const aiResult = hydrateSignalFromAsyncIterable(signals.createMemo, compute, value, options);
379
+ const aiResult = hydrateSignalFromAsyncIterable(signals.createMemo, compute, options);
380
380
  if (aiResult !== null) return aiResult;
381
- return signals.createMemo(prev => readSerializedOrCompute(compute, prev), value, options);
381
+ return signals.createMemo(prev => readSerializedOrCompute(compute, prev), options);
382
382
  }
383
- function hydratedCreateSignal(fn, second, third) {
384
- if (typeof fn !== "function" || !sharedConfig.hydrating) return signals.createSignal(fn, second, third);
383
+ function hydratedCreateSignal(fn, second) {
384
+ if (typeof fn !== "function" || !sharedConfig.hydrating) return signals.createSignal(fn, second);
385
385
  markTopLevelSnapshotScope();
386
- const ssrSource = third?.ssrSource;
386
+ const ssrSource = second?.ssrSource;
387
387
  if (ssrSource === "client") {
388
388
  const [hydrated, setHydrated] = signals.createSignal(false, {
389
- pureWrite: true
389
+ ownedWrite: true
390
390
  });
391
391
  const sig = signals.createSignal(prev => {
392
- if (!hydrated()) return prev ?? second;
392
+ if (!hydrated()) return prev;
393
393
  return fn(prev);
394
- }, second, third);
394
+ }, second);
395
395
  setHydrated(true);
396
396
  return sig;
397
397
  }
@@ -399,12 +399,12 @@ function hydratedCreateSignal(fn, second, third) {
399
399
  return signals.createSignal(prev => {
400
400
  if (!sharedConfig.hydrating) return fn(prev);
401
401
  subFetch(fn, prev);
402
- return prev ?? second;
403
- }, second, third);
402
+ return prev;
403
+ }, second);
404
404
  }
405
- const aiResult = hydrateSignalFromAsyncIterable(signals.createSignal, fn, second, third);
405
+ const aiResult = hydrateSignalFromAsyncIterable(signals.createSignal, fn, second);
406
406
  if (aiResult !== null) return aiResult;
407
- return signals.createSignal(prev => readSerializedOrCompute(fn, prev), second, third);
407
+ return signals.createSignal(prev => readSerializedOrCompute(fn, prev), second);
408
408
  }
409
409
  function hydratedCreateErrorBoundary(fn, fallback) {
410
410
  if (!sharedConfig.hydrating) return signals.createErrorBoundary(fn, fallback);
@@ -426,18 +426,18 @@ function hydratedCreateErrorBoundary(fn, fallback) {
426
426
  }
427
427
  return signals.createErrorBoundary(fn, fallback);
428
428
  }
429
- function hydratedCreateOptimistic(fn, second, third) {
430
- if (typeof fn !== "function" || !sharedConfig.hydrating) return signals.createOptimistic(fn, second, third);
429
+ function hydratedCreateOptimistic(fn, second) {
430
+ if (typeof fn !== "function" || !sharedConfig.hydrating) return signals.createOptimistic(fn, second);
431
431
  markTopLevelSnapshotScope();
432
- const ssrSource = third?.ssrSource;
432
+ const ssrSource = second?.ssrSource;
433
433
  if (ssrSource === "client") {
434
434
  const [hydrated, setHydrated] = signals.createSignal(false, {
435
- pureWrite: true
435
+ ownedWrite: true
436
436
  });
437
437
  const sig = signals.createOptimistic(prev => {
438
- if (!hydrated()) return prev ?? second;
438
+ if (!hydrated()) return prev;
439
439
  return fn(prev);
440
- }, second, third);
440
+ }, second);
441
441
  setHydrated(true);
442
442
  return sig;
443
443
  }
@@ -445,12 +445,12 @@ function hydratedCreateOptimistic(fn, second, third) {
445
445
  return signals.createOptimistic(prev => {
446
446
  if (!sharedConfig.hydrating) return fn(prev);
447
447
  subFetch(fn, prev);
448
- return prev ?? second;
449
- }, second, third);
448
+ return prev;
449
+ }, second);
450
450
  }
451
- const aiResult = hydrateSignalFromAsyncIterable(signals.createOptimistic, fn, second, third);
451
+ const aiResult = hydrateSignalFromAsyncIterable(signals.createOptimistic, fn, second);
452
452
  if (aiResult !== null) return aiResult;
453
- return signals.createOptimistic(prev => readSerializedOrCompute(fn, prev), second, third);
453
+ return signals.createOptimistic(prev => readSerializedOrCompute(fn, prev), second);
454
454
  }
455
455
  function wrapStoreFn(fn) {
456
456
  return draft => readSerializedOrCompute(() => fn(draft), draft);
@@ -458,7 +458,7 @@ function wrapStoreFn(fn) {
458
458
  function hydrateStoreLikeFn(coreFn, fn, initialValue, options, ssrSource) {
459
459
  if (ssrSource === "client") {
460
460
  const [hydrated, setHydrated] = signals.createSignal(false, {
461
- pureWrite: true
461
+ ownedWrite: true
462
462
  });
463
463
  const result = coreFn(draft => {
464
464
  if (!hydrated()) return;
@@ -469,7 +469,7 @@ function hydrateStoreLikeFn(coreFn, fn, initialValue, options, ssrSource) {
469
469
  }
470
470
  if (ssrSource === "hybrid") {
471
471
  const [hydrated, setHydrated] = signals.createSignal(false, {
472
- pureWrite: true
472
+ ownedWrite: true
473
473
  });
474
474
  const result = coreFn(draft => {
475
475
  const o = signals.getOwner();
@@ -499,14 +499,14 @@ function hydratedCreateStore(first, second, third) {
499
499
  if (typeof first !== "function" || !sharedConfig.hydrating) return signals.createStore(first, second, third);
500
500
  markTopLevelSnapshotScope();
501
501
  const ssrSource = third?.ssrSource;
502
- if (ssrSource === "initial") return signals.createStore(second ?? {}, undefined, third);
502
+ if (ssrSource === "initial") return signals.createStore(second ?? {});
503
503
  return hydrateStoreLikeFn(signals.createStore, first, second ?? {}, third, ssrSource);
504
504
  }
505
505
  function hydratedCreateOptimisticStore(first, second, third) {
506
506
  if (typeof first !== "function" || !sharedConfig.hydrating) return signals.createOptimisticStore(first, second, third);
507
507
  markTopLevelSnapshotScope();
508
508
  const ssrSource = third?.ssrSource;
509
- if (ssrSource === "initial") return signals.createOptimisticStore(second ?? {}, undefined, third);
509
+ if (ssrSource === "initial") return signals.createOptimisticStore(second ?? {});
510
510
  return hydrateStoreLikeFn(signals.createOptimisticStore, first, second ?? {}, third, ssrSource);
511
511
  }
512
512
  function hydratedCreateProjection(fn, initialValue, options) {
@@ -516,22 +516,22 @@ function hydratedCreateProjection(fn, initialValue, options) {
516
516
  if (ssrSource === "initial") return signals.createProjection(draft => draft, initialValue, options);
517
517
  return hydrateStoreLikeFn(signals.createProjection, fn, initialValue, options, ssrSource);
518
518
  }
519
- function hydratedEffect(coreFn, compute, effectFn, value, options) {
520
- if (!sharedConfig.hydrating) return coreFn(compute, effectFn, value, options);
519
+ function hydratedEffect(coreFn, compute, effectFn, options) {
520
+ if (!sharedConfig.hydrating || options?.transparent) return coreFn(compute, effectFn, options);
521
521
  const ssrSource = options?.ssrSource;
522
522
  if (ssrSource === "client") {
523
523
  const [hydrated, setHydrated] = signals.createSignal(false, {
524
- pureWrite: true
524
+ ownedWrite: true
525
525
  });
526
526
  let active = false;
527
527
  coreFn(prev => {
528
- if (!hydrated()) return value;
528
+ if (!hydrated()) return prev;
529
529
  active = true;
530
530
  return compute(prev);
531
531
  }, (next, prev) => {
532
532
  if (!active) return;
533
533
  return effectFn(next, prev);
534
- }, value, options);
534
+ }, options);
535
535
  setHydrated(true);
536
536
  return;
537
537
  }
@@ -539,18 +539,18 @@ function hydratedEffect(coreFn, compute, effectFn, value, options) {
539
539
  coreFn(prev => {
540
540
  if (!sharedConfig.hydrating) return compute(prev);
541
541
  subFetch(compute, prev);
542
- return prev ?? value;
543
- }, effectFn, value, options);
542
+ return prev;
543
+ }, effectFn, options);
544
544
  return;
545
545
  }
546
546
  markTopLevelSnapshotScope();
547
- coreFn(prev => readSerializedOrCompute(compute, prev), effectFn, value, options);
547
+ coreFn(prev => readSerializedOrCompute(compute, prev), effectFn, options);
548
548
  }
549
- function hydratedCreateRenderEffect(compute, effectFn, value, options) {
550
- return hydratedEffect(signals.createRenderEffect, compute, effectFn, value, options);
549
+ function hydratedCreateRenderEffect(compute, effectFn, options) {
550
+ return hydratedEffect(signals.createRenderEffect, compute, effectFn, options);
551
551
  }
552
- function hydratedCreateEffect(compute, effectFn, value, options) {
553
- return hydratedEffect(signals.createEffect, compute, effectFn, value, options);
552
+ function hydratedCreateEffect(compute, effectFn, options) {
553
+ return hydratedEffect(signals.createEffect, compute, effectFn, options);
554
554
  }
555
555
  function enableHydration() {
556
556
  _createMemo = hydratedCreateMemo;
@@ -609,24 +609,6 @@ const createStore = (...args) => (_createStore || signals.createStore)(...args);
609
609
  const createOptimisticStore = (...args) => (_createOptimisticStore || signals.createOptimisticStore)(...args);
610
610
  const createRenderEffect = (...args) => (_createRenderEffect || signals.createRenderEffect)(...args);
611
611
  const createEffect = (...args) => (_createEffect || signals.createEffect)(...args);
612
- function loadModuleAssets(mapping) {
613
- const hy = globalThis._$HY;
614
- if (!hy) return;
615
- if (!hy.modules) hy.modules = {};
616
- if (!hy.loading) hy.loading = {};
617
- const pending = [];
618
- for (const moduleUrl in mapping) {
619
- if (hy.modules[moduleUrl]) continue;
620
- const entryUrl = mapping[moduleUrl];
621
- if (!hy.loading[moduleUrl]) {
622
- hy.loading[moduleUrl] = import(entryUrl).then(mod => {
623
- hy.modules[moduleUrl] = mod;
624
- });
625
- }
626
- pending.push(hy.loading[moduleUrl]);
627
- }
628
- return pending.length ? Promise.all(pending).then(() => {}) : undefined;
629
- }
630
612
  function createBoundaryTrigger() {
631
613
  signals.setSnapshotCapture(false);
632
614
  const [s, set] = signals.createSignal(undefined, {
@@ -654,6 +636,38 @@ function resumeBoundaryHydration(o, id, set) {
654
636
  signals.flush();
655
637
  checkHydrationComplete();
656
638
  }
639
+ function initBoundaryResume(o, id) {
640
+ _pendingBoundaries++;
641
+ signals.onCleanup(() => {
642
+ if (!signals.isDisposed(o)) return;
643
+ sharedConfig.cleanupFragment?.(id);
644
+ });
645
+ const set = createBoundaryTrigger();
646
+ return [set, () => resumeBoundaryHydration(o, id, set)];
647
+ }
648
+ function waitAndResume(p, resume, assetPromise) {
649
+ const waitFor = assetPromise ? Promise.all([p, assetPromise]) : p;
650
+ waitFor.then(() => {
651
+ if (p && typeof p === "object") p.s = 1;
652
+ resume();
653
+ }, err => {
654
+ if (p && typeof p === "object") {
655
+ p.s = 2;
656
+ p.v = err;
657
+ }
658
+ resume();
659
+ });
660
+ }
661
+ function scheduleResumeAfterAssets(id, resume, assetPromise) {
662
+ sharedConfig.gather?.(id);
663
+ const doResume = () => queueMicrotask(resume);
664
+ if (assetPromise) {
665
+ assetPromise.then(doResume);
666
+ return true;
667
+ }
668
+ doResume();
669
+ return false;
670
+ }
657
671
  function createLoadingBoundary(fn, fallback, options) {
658
672
  if (!sharedConfig.hydrating) return signals.createLoadingBoundary(fn, fallback, options);
659
673
  let settledSerializationResumeQueued = false;
@@ -663,7 +677,7 @@ function createLoadingBoundary(fn, fallback, options) {
663
677
  let assetPromise;
664
678
  if (sharedConfig.hydrating && sharedConfig.has(id + "_assets")) {
665
679
  const mapping = sharedConfig.load(id + "_assets");
666
- if (mapping && typeof mapping === "object") assetPromise = loadModuleAssets(mapping);
680
+ if (mapping && typeof mapping === "object") assetPromise = sharedConfig.loadModuleAssets?.(mapping);
667
681
  }
668
682
  if (sharedConfig.hydrating && sharedConfig.has(id)) {
669
683
  const ref = sharedConfig.load(id);
@@ -673,41 +687,14 @@ function createLoadingBoundary(fn, fallback, options) {
673
687
  }
674
688
  if (ref && typeof ref === "object" && ref.s === 1 && p == null && !settledSerializationResumeQueued) {
675
689
  settledSerializationResumeQueued = true;
676
- _pendingBoundaries++;
677
- signals.onCleanup(() => {
678
- if (!signals.isDisposed(o)) return;
679
- sharedConfig.cleanupFragment?.(id);
680
- });
681
- const set = createBoundaryTrigger();
682
- const scheduleResume = () => queueMicrotask(() => resumeBoundaryHydration(o, id, set));
683
- if (assetPromise) {
684
- assetPromise.then(scheduleResume);
685
- return undefined;
686
- }
687
- scheduleResume();
690
+ const [, resume] = initBoundaryResume(o, id);
691
+ if (scheduleResumeAfterAssets(id, resume, assetPromise)) return undefined;
688
692
  return fallback();
689
693
  }
690
694
  if (p) {
691
- _pendingBoundaries++;
692
- signals.onCleanup(() => {
693
- if (!signals.isDisposed(o)) return;
694
- sharedConfig.cleanupFragment?.(id);
695
- });
696
- const set = createBoundaryTrigger();
695
+ const [set, resume] = initBoundaryResume(o, id);
697
696
  if (p !== "$$f") {
698
- const waitFor = assetPromise ? Promise.all([p, assetPromise]) : p;
699
- waitFor.then(() => {
700
- if (p && typeof p === "object") {
701
- p.s = 1;
702
- }
703
- resumeBoundaryHydration(o, id, set);
704
- }, err => {
705
- if (p && typeof p === "object") {
706
- p.s = 2;
707
- p.v = err;
708
- }
709
- resumeBoundaryHydration(o, id, set);
710
- });
697
+ waitAndResume(p, resume, assetPromise);
711
698
  } else {
712
699
  const afterAssets = () => {
713
700
  _pendingBoundaries--;
@@ -719,10 +706,20 @@ function createLoadingBoundary(fn, fallback, options) {
719
706
  return fallback();
720
707
  }
721
708
  }
709
+ if (sharedConfig.hydrating && sharedConfig.has(id + "_fr") && !settledSerializationResumeQueued) {
710
+ settledSerializationResumeQueued = true;
711
+ const fr = sharedConfig.load(id + "_fr");
712
+ const [, resume] = initBoundaryResume(o, id);
713
+ if (fr && typeof fr === "object" && (fr.s === 1 || fr.s === 2)) {
714
+ if (scheduleResumeAfterAssets(id, resume, assetPromise)) return undefined;
715
+ return fallback();
716
+ }
717
+ waitAndResume(fr, resume, assetPromise);
718
+ return fallback();
719
+ }
722
720
  if (assetPromise && !sharedConfig.has(id)) {
723
- _pendingBoundaries++;
724
- const set = createBoundaryTrigger();
725
- assetPromise.then(() => resumeBoundaryHydration(o, id, set));
721
+ const [, resume] = initBoundaryResume(o, id);
722
+ assetPromise.then(resume);
726
723
  return undefined;
727
724
  }
728
725
  return signals.createLoadingBoundary(fn, fallback, options);
@@ -794,8 +791,8 @@ function Repeat(props) {
794
791
  }
795
792
  function Show(props) {
796
793
  const keyed = props.keyed;
797
- const conditionValue = signals.createMemo(() => props.when, undefined, undefined);
798
- const condition = keyed ? conditionValue : signals.createMemo(conditionValue, undefined, {
794
+ const conditionValue = signals.createMemo(() => props.when, undefined);
795
+ const condition = keyed ? conditionValue : signals.createMemo(conditionValue, {
799
796
  equals: (a, b) => !a === !b
800
797
  });
801
798
  return signals.createMemo(() => {
@@ -809,7 +806,7 @@ function Show(props) {
809
806
  }), IS_DEV) : child;
810
807
  }
811
808
  return props.fallback;
812
- }, undefined, undefined);
809
+ }, undefined);
813
810
  }
814
811
  function Switch(props) {
815
812
  const chs = children(() => props.children);
@@ -820,8 +817,8 @@ function Switch(props) {
820
817
  const index = i;
821
818
  const mp = mps[i];
822
819
  const prevFunc = func;
823
- const conditionValue = signals.createMemo(() => prevFunc() ? undefined : mp.when, undefined, undefined);
824
- const condition = mp.keyed ? conditionValue : signals.createMemo(conditionValue, undefined, {
820
+ const conditionValue = signals.createMemo(() => prevFunc() ? undefined : mp.when, undefined);
821
+ const condition = mp.keyed ? conditionValue : signals.createMemo(conditionValue, {
825
822
  equals: (a, b) => !a === !b
826
823
  });
827
824
  func = () => prevFunc() || (condition() ? [index, conditionValue, mp] : undefined);
@@ -838,7 +835,7 @@ function Switch(props) {
838
835
  if (signals.untrack(switchFunc)()?.[0] !== index) throw narrowedError("Match");
839
836
  return conditionValue();
840
837
  }), IS_DEV) : child;
841
- }, undefined, undefined);
838
+ }, undefined);
842
839
  }
843
840
  function Match(props) {
844
841
  return props;
@@ -855,6 +852,12 @@ function Loading(props) {
855
852
  } : undefined;
856
853
  return createLoadingBoundary(() => props.children, () => props.fallback, onOpt);
857
854
  }
855
+ function Reveal(props) {
856
+ return signals.createRevealOrder(() => props.children, {
857
+ together: () => !!props.together,
858
+ collapsed: () => !!props.collapsed
859
+ });
860
+ }
858
861
 
859
862
  function ssrHandleError() {}
860
863
  function ssrRunInScope() {}
@@ -888,6 +891,10 @@ Object.defineProperty(exports, "createReaction", {
888
891
  enumerable: true,
889
892
  get: function () { return signals.createReaction; }
890
893
  });
894
+ Object.defineProperty(exports, "createRevealOrder", {
895
+ enumerable: true,
896
+ get: function () { return signals.createRevealOrder; }
897
+ });
891
898
  Object.defineProperty(exports, "createRoot", {
892
899
  enumerable: true,
893
900
  get: function () { return signals.createRoot; }
@@ -928,6 +935,10 @@ Object.defineProperty(exports, "getOwner", {
928
935
  enumerable: true,
929
936
  get: function () { return signals.getOwner; }
930
937
  });
938
+ Object.defineProperty(exports, "isDisposed", {
939
+ enumerable: true,
940
+ get: function () { return signals.isDisposed; }
941
+ });
931
942
  Object.defineProperty(exports, "isEqual", {
932
943
  enumerable: true,
933
944
  get: function () { return signals.isEqual; }
@@ -1010,6 +1021,7 @@ exports.Match = Match;
1010
1021
  exports.NoHydrateContext = NoHydrateContext;
1011
1022
  exports.NoHydration = NoHydration;
1012
1023
  exports.Repeat = Repeat;
1024
+ exports.Reveal = Reveal;
1013
1025
  exports.Show = Show;
1014
1026
  exports.Switch = Switch;
1015
1027
  exports.children = children;