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

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
@@ -72,6 +72,7 @@ function drainHydrationCallbacks() {
72
72
  if (cbs) for (const cb of cbs) cb();
73
73
  setTimeout(() => {
74
74
  if (globalThis._$HY) globalThis._$HY.done = true;
75
+ sharedConfig.registry?.clear();
75
76
  });
76
77
  }
77
78
  function checkHydrationComplete() {
@@ -89,23 +90,10 @@ let _createOptimisticStore;
89
90
  let _createRenderEffect;
90
91
  let _createEffect;
91
92
  class MockPromise {
92
- static all() {
93
- return new MockPromise();
94
- }
95
- static allSettled() {
96
- return new MockPromise();
97
- }
98
- static any() {
99
- return new MockPromise();
100
- }
101
- static race() {
102
- return new MockPromise();
103
- }
104
- static reject() {
105
- return new MockPromise();
106
- }
107
- static resolve() {
108
- return new MockPromise();
93
+ static {
94
+ for (const k of ["all", "allSettled", "any", "race", "reject", "resolve"]) {
95
+ MockPromise[k] = () => new MockPromise();
96
+ }
109
97
  }
110
98
  catch() {
111
99
  return new MockPromise();
@@ -140,6 +128,28 @@ function syncThenable(value) {
140
128
  }
141
129
  };
142
130
  }
131
+ const NO_HYDRATED_VALUE = Symbol("NO_HYDRATED_VALUE");
132
+ function readHydratedValue(initP, refresh) {
133
+ if (initP == null) return NO_HYDRATED_VALUE;
134
+ refresh();
135
+ if (typeof initP === "object" && initP.s === 2) throw initP.v;
136
+ return initP?.v ?? initP;
137
+ }
138
+ function readSerializedOrCompute(compute, prev) {
139
+ if (!sharedConfig.hydrating) return compute(prev);
140
+ const o = signals.getOwner();
141
+ let initP;
142
+ if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
143
+ const init = readHydratedValue(initP, () => subFetch(compute, prev));
144
+ return init !== NO_HYDRATED_VALUE ? init : compute(prev);
145
+ }
146
+ function forwardIteratorReturn(it, value) {
147
+ const returned = it.return?.(value);
148
+ return returned && typeof returned.then === "function" ? returned : syncThenable(returned ?? {
149
+ done: true,
150
+ value
151
+ });
152
+ }
143
153
  function normalizeIterator(it) {
144
154
  let first = true;
145
155
  let buffered = null;
@@ -166,6 +176,10 @@ function normalizeIterator(it) {
166
176
  latest = peek;
167
177
  }
168
178
  return Promise.resolve(latest);
179
+ },
180
+ return(value) {
181
+ buffered = null;
182
+ return forwardIteratorReturn(it, value);
169
183
  }
170
184
  };
171
185
  }
@@ -243,6 +257,9 @@ function wrapFirstYield(iterable, activate) {
243
257
  });
244
258
  }
245
259
  return p;
260
+ },
261
+ return(value) {
262
+ return forwardIteratorReturn(srcIt, value);
246
263
  }
247
264
  };
248
265
  }
@@ -325,6 +342,10 @@ function hydrateStoreFromAsyncIterable(coreFn, initialValue, options) {
325
342
  if (!r.done) result = process(r);
326
343
  }
327
344
  return Promise.resolve(result);
345
+ },
346
+ return(value) {
347
+ buffered = null;
348
+ return forwardIteratorReturn(srcIt, value);
328
349
  }
329
350
  };
330
351
  }
@@ -357,14 +378,7 @@ function hydratedCreateMemo(compute, value, options) {
357
378
  }
358
379
  const aiResult = hydrateSignalFromAsyncIterable(signals.createMemo, compute, value, options);
359
380
  if (aiResult !== null) return aiResult;
360
- return signals.createMemo(prev => {
361
- const o = signals.getOwner();
362
- if (!sharedConfig.hydrating) return compute(prev);
363
- let initP;
364
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
365
- const init = initP?.v ?? initP;
366
- return init != null ? (subFetch(compute, prev), init) : compute(prev);
367
- }, value, options);
381
+ return signals.createMemo(prev => readSerializedOrCompute(compute, prev), value, options);
368
382
  }
369
383
  function hydratedCreateSignal(fn, second, third) {
370
384
  if (typeof fn !== "function" || !sharedConfig.hydrating) return signals.createSignal(fn, second, third);
@@ -390,14 +404,7 @@ function hydratedCreateSignal(fn, second, third) {
390
404
  }
391
405
  const aiResult = hydrateSignalFromAsyncIterable(signals.createSignal, fn, second, third);
392
406
  if (aiResult !== null) return aiResult;
393
- return signals.createSignal(prev => {
394
- if (!sharedConfig.hydrating) return fn(prev);
395
- const o = signals.getOwner();
396
- let initP;
397
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
398
- const init = initP?.v ?? initP;
399
- return init != null ? (subFetch(fn, prev), init) : fn(prev);
400
- }, second, third);
407
+ return signals.createSignal(prev => readSerializedOrCompute(fn, prev), second, third);
401
408
  }
402
409
  function hydratedCreateErrorBoundary(fn, fallback) {
403
410
  if (!sharedConfig.hydrating) return signals.createErrorBoundary(fn, fallback);
@@ -443,24 +450,10 @@ function hydratedCreateOptimistic(fn, second, third) {
443
450
  }
444
451
  const aiResult = hydrateSignalFromAsyncIterable(signals.createOptimistic, fn, second, third);
445
452
  if (aiResult !== null) return aiResult;
446
- return signals.createOptimistic(prev => {
447
- const o = signals.getOwner();
448
- if (!sharedConfig.hydrating) return fn(prev);
449
- let initP;
450
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
451
- const init = initP?.v ?? initP;
452
- return init != null ? (subFetch(fn, prev), init) : fn(prev);
453
- }, second, third);
453
+ return signals.createOptimistic(prev => readSerializedOrCompute(fn, prev), second, third);
454
454
  }
455
455
  function wrapStoreFn(fn) {
456
- return draft => {
457
- const o = signals.getOwner();
458
- if (!sharedConfig.hydrating) return fn(draft);
459
- let initP;
460
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
461
- const init = initP?.v ?? initP;
462
- return init != null ? (subFetch(fn, draft), init) : fn(draft);
463
- };
456
+ return draft => readSerializedOrCompute(() => fn(draft), draft);
464
457
  }
465
458
  function hydrateStoreLikeFn(coreFn, fn, initialValue, options, ssrSource) {
466
459
  if (ssrSource === "client") {
@@ -483,11 +476,8 @@ function hydrateStoreLikeFn(coreFn, fn, initialValue, options, ssrSource) {
483
476
  if (!hydrated()) {
484
477
  if (sharedConfig.has(o.id)) {
485
478
  const initP = sharedConfig.load(o.id);
486
- const init = initP?.v ?? initP;
487
- if (init != null) {
488
- subFetch(fn, draft);
489
- return init;
490
- }
479
+ const init = readHydratedValue(initP, () => subFetch(fn, draft));
480
+ if (init !== NO_HYDRATED_VALUE) return init;
491
481
  }
492
482
  return fn(draft);
493
483
  }
@@ -554,14 +544,7 @@ function hydratedEffect(coreFn, compute, effectFn, value, options) {
554
544
  return;
555
545
  }
556
546
  markTopLevelSnapshotScope();
557
- coreFn(prev => {
558
- const o = signals.getOwner();
559
- if (!sharedConfig.hydrating) return compute(prev);
560
- let initP;
561
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
562
- const init = initP?.v ?? initP;
563
- return init != null ? (subFetch(compute, prev), init) : compute(prev);
564
- }, effectFn, value, options);
547
+ coreFn(prev => readSerializedOrCompute(compute, prev), effectFn, value, options);
565
548
  }
566
549
  function hydratedCreateRenderEffect(compute, effectFn, value, options) {
567
550
  return hydratedEffect(signals.createRenderEffect, compute, effectFn, value, options);
@@ -659,7 +642,7 @@ function resumeBoundaryHydration(o, id, set) {
659
642
  checkHydrationComplete();
660
643
  return;
661
644
  }
662
- sharedConfig.gather(id);
645
+ sharedConfig.gather?.(id);
663
646
  _hydratingValue = true;
664
647
  signals.markSnapshotScope(o);
665
648
  _snapshotRootOwner = o;
@@ -671,11 +654,41 @@ function resumeBoundaryHydration(o, id, set) {
671
654
  signals.flush();
672
655
  checkHydrationComplete();
673
656
  }
674
- function Loading(props) {
675
- const onOpt = props.on ? {
676
- on: () => props.on()
677
- } : undefined;
678
- if (!sharedConfig.hydrating) return signals.createLoadingBoundary(() => props.children, () => props.fallback, onOpt);
657
+ function initBoundaryResume(o, id) {
658
+ _pendingBoundaries++;
659
+ signals.onCleanup(() => {
660
+ if (!signals.isDisposed(o)) return;
661
+ sharedConfig.cleanupFragment?.(id);
662
+ });
663
+ const set = createBoundaryTrigger();
664
+ return [set, () => resumeBoundaryHydration(o, id, set)];
665
+ }
666
+ function waitAndResume(p, resume, assetPromise) {
667
+ const waitFor = assetPromise ? Promise.all([p, assetPromise]) : p;
668
+ waitFor.then(() => {
669
+ if (p && typeof p === "object") p.s = 1;
670
+ resume();
671
+ }, err => {
672
+ if (p && typeof p === "object") {
673
+ p.s = 2;
674
+ p.v = err;
675
+ }
676
+ resume();
677
+ });
678
+ }
679
+ function scheduleResumeAfterAssets(id, resume, assetPromise) {
680
+ sharedConfig.gather?.(id);
681
+ const doResume = () => queueMicrotask(resume);
682
+ if (assetPromise) {
683
+ assetPromise.then(doResume);
684
+ return true;
685
+ }
686
+ doResume();
687
+ return false;
688
+ }
689
+ function createLoadingBoundary(fn, fallback, options) {
690
+ if (!sharedConfig.hydrating) return signals.createLoadingBoundary(fn, fallback, options);
691
+ let settledSerializationResumeQueued = false;
679
692
  return signals.createMemo(() => {
680
693
  const o = signals.getOwner();
681
694
  const id = o.id;
@@ -685,27 +698,21 @@ function Loading(props) {
685
698
  if (mapping && typeof mapping === "object") assetPromise = loadModuleAssets(mapping);
686
699
  }
687
700
  if (sharedConfig.hydrating && sharedConfig.has(id)) {
688
- let ref = sharedConfig.load(id);
701
+ const ref = sharedConfig.load(id);
689
702
  let p;
690
703
  if (ref) {
691
- if (typeof ref !== "object" || ref.s !== 1) p = ref;else sharedConfig.gather(id);
704
+ if (typeof ref !== "object" || ref.s == null) p = ref;else if (ref.s === 1 || ref.s === 2) sharedConfig.gather?.(id);else p = ref;
705
+ }
706
+ if (ref && typeof ref === "object" && ref.s === 1 && p == null && !settledSerializationResumeQueued) {
707
+ settledSerializationResumeQueued = true;
708
+ const [, resume] = initBoundaryResume(o, id);
709
+ if (scheduleResumeAfterAssets(id, resume, assetPromise)) return undefined;
710
+ return fallback();
692
711
  }
693
712
  if (p) {
694
- _pendingBoundaries++;
695
- signals.onCleanup(() => {
696
- if (!signals.isDisposed(o)) return;
697
- sharedConfig.cleanupFragment?.(id);
698
- });
699
- const set = createBoundaryTrigger();
713
+ const [set, resume] = initBoundaryResume(o, id);
700
714
  if (p !== "$$f") {
701
- const waitFor = assetPromise ? Promise.all([p, assetPromise]) : p;
702
- waitFor.then(() => resumeBoundaryHydration(o, id, set), err => {
703
- _pendingBoundaries--;
704
- checkHydrationComplete();
705
- signals.runWithOwner(o, () => {
706
- throw err;
707
- });
708
- });
715
+ waitAndResume(p, resume, assetPromise);
709
716
  } else {
710
717
  const afterAssets = () => {
711
718
  _pendingBoundaries--;
@@ -714,17 +721,26 @@ function Loading(props) {
714
721
  };
715
722
  if (assetPromise) assetPromise.then(() => queueMicrotask(afterAssets));else queueMicrotask(afterAssets);
716
723
  }
717
- return props.fallback;
724
+ return fallback();
725
+ }
726
+ }
727
+ if (sharedConfig.hydrating && sharedConfig.has(id + "_fr") && !settledSerializationResumeQueued) {
728
+ settledSerializationResumeQueued = true;
729
+ const fr = sharedConfig.load(id + "_fr");
730
+ const [, resume] = initBoundaryResume(o, id);
731
+ if (fr && typeof fr === "object" && (fr.s === 1 || fr.s === 2)) {
732
+ if (scheduleResumeAfterAssets(id, resume, assetPromise)) return undefined;
733
+ return fallback();
718
734
  }
735
+ waitAndResume(fr, resume, assetPromise);
736
+ return fallback();
719
737
  }
720
- if (assetPromise) {
721
- _pendingBoundaries++;
722
- const set = createBoundaryTrigger();
723
- assetPromise.then(() => resumeBoundaryHydration(o, id, set));
738
+ if (assetPromise && !sharedConfig.has(id)) {
739
+ const [, resume] = initBoundaryResume(o, id);
740
+ assetPromise.then(resume);
724
741
  return undefined;
725
742
  }
726
- const boundary = signals.createLoadingBoundary(() => props.children, () => props.fallback, onOpt);
727
- return boundary;
743
+ return signals.createLoadingBoundary(fn, fallback, options);
728
744
  });
729
745
  }
730
746
  function NoHydration(props) {
@@ -848,6 +864,18 @@ function Errored(props) {
848
864
  return typeof f === "function" && f.length ? f(err, reset) : f;
849
865
  });
850
866
  }
867
+ function Loading(props) {
868
+ const onOpt = "on" in props ? {
869
+ on: () => props.on
870
+ } : undefined;
871
+ return createLoadingBoundary(() => props.children, () => props.fallback, onOpt);
872
+ }
873
+ function Reveal(props) {
874
+ return signals.createRevealOrder(() => props.children, {
875
+ together: () => !!props.together,
876
+ collapsed: () => !!props.collapsed
877
+ });
878
+ }
851
879
 
852
880
  function ssrHandleError() {}
853
881
  function ssrRunInScope() {}
@@ -873,14 +901,6 @@ Object.defineProperty(exports, "action", {
873
901
  enumerable: true,
874
902
  get: function () { return signals.action; }
875
903
  });
876
- Object.defineProperty(exports, "createErrorBoundary", {
877
- enumerable: true,
878
- get: function () { return signals.createErrorBoundary; }
879
- });
880
- Object.defineProperty(exports, "createLoadingBoundary", {
881
- enumerable: true,
882
- get: function () { return signals.createLoadingBoundary; }
883
- });
884
904
  Object.defineProperty(exports, "createOwner", {
885
905
  enumerable: true,
886
906
  get: function () { return signals.createOwner; }
@@ -889,6 +909,10 @@ Object.defineProperty(exports, "createReaction", {
889
909
  enumerable: true,
890
910
  get: function () { return signals.createReaction; }
891
911
  });
912
+ Object.defineProperty(exports, "createRevealOrder", {
913
+ enumerable: true,
914
+ get: function () { return signals.createRevealOrder; }
915
+ });
892
916
  Object.defineProperty(exports, "createRoot", {
893
917
  enumerable: true,
894
918
  get: function () { return signals.createRoot; }
@@ -929,6 +953,10 @@ Object.defineProperty(exports, "getOwner", {
929
953
  enumerable: true,
930
954
  get: function () { return signals.getOwner; }
931
955
  });
956
+ Object.defineProperty(exports, "isDisposed", {
957
+ enumerable: true,
958
+ get: function () { return signals.isDisposed; }
959
+ });
932
960
  Object.defineProperty(exports, "isEqual", {
933
961
  enumerable: true,
934
962
  get: function () { return signals.isEqual; }
@@ -1011,12 +1039,15 @@ exports.Match = Match;
1011
1039
  exports.NoHydrateContext = NoHydrateContext;
1012
1040
  exports.NoHydration = NoHydration;
1013
1041
  exports.Repeat = Repeat;
1042
+ exports.Reveal = Reveal;
1014
1043
  exports.Show = Show;
1015
1044
  exports.Switch = Switch;
1016
1045
  exports.children = children;
1017
1046
  exports.createComponent = createComponent;
1018
1047
  exports.createContext = createContext;
1019
1048
  exports.createEffect = createEffect;
1049
+ exports.createErrorBoundary = createErrorBoundary;
1050
+ exports.createLoadingBoundary = createLoadingBoundary;
1020
1051
  exports.createMemo = createMemo;
1021
1052
  exports.createOptimistic = createOptimistic;
1022
1053
  exports.createOptimisticStore = createOptimisticStore;