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/dev.cjs CHANGED
@@ -35,9 +35,11 @@ function children(fn) {
35
35
  function devComponent(Comp, props) {
36
36
  return signals.createRoot(() => {
37
37
  const owner = signals.getOwner();
38
- owner._props = props;
39
- owner._name = Comp.name;
40
- owner._component = Comp;
38
+ owner._component = {
39
+ fn: Comp,
40
+ props,
41
+ name: Comp.name
42
+ };
41
43
  Object.assign(Comp, {
42
44
  [$DEVCOMP]: true
43
45
  });
@@ -46,12 +48,6 @@ function devComponent(Comp, props) {
46
48
  transparent: true
47
49
  });
48
50
  }
49
- function registerGraph(value) {
50
- const owner = signals.getOwner();
51
- if (!owner) return;
52
- if (owner.sourceMap) owner.sourceMap.push(value);else owner.sourceMap = [value];
53
- value.graph = owner;
54
- }
55
51
 
56
52
  const NoHydrateContext = {
57
53
  id: Symbol("NoHydrateContext"),
@@ -93,6 +89,7 @@ function drainHydrationCallbacks() {
93
89
  setTimeout(() => {
94
90
  if (sharedConfig.verifyHydration) sharedConfig.verifyHydration();
95
91
  if (globalThis._$HY) globalThis._$HY.done = true;
92
+ sharedConfig.registry?.clear();
96
93
  });
97
94
  }
98
95
  function checkHydrationComplete() {
@@ -110,23 +107,10 @@ let _createOptimisticStore;
110
107
  let _createRenderEffect;
111
108
  let _createEffect;
112
109
  class MockPromise {
113
- static all() {
114
- return new MockPromise();
115
- }
116
- static allSettled() {
117
- return new MockPromise();
118
- }
119
- static any() {
120
- return new MockPromise();
121
- }
122
- static race() {
123
- return new MockPromise();
124
- }
125
- static reject() {
126
- return new MockPromise();
127
- }
128
- static resolve() {
129
- return new MockPromise();
110
+ static {
111
+ for (const k of ["all", "allSettled", "any", "race", "reject", "resolve"]) {
112
+ MockPromise[k] = () => new MockPromise();
113
+ }
130
114
  }
131
115
  catch() {
132
116
  return new MockPromise();
@@ -161,6 +145,28 @@ function syncThenable(value) {
161
145
  }
162
146
  };
163
147
  }
148
+ const NO_HYDRATED_VALUE = Symbol("NO_HYDRATED_VALUE");
149
+ function readHydratedValue(initP, refresh) {
150
+ if (initP == null) return NO_HYDRATED_VALUE;
151
+ refresh();
152
+ if (typeof initP === "object" && initP.s === 2) throw initP.v;
153
+ return initP?.v ?? initP;
154
+ }
155
+ function readSerializedOrCompute(compute, prev) {
156
+ if (!sharedConfig.hydrating) return compute(prev);
157
+ const o = signals.getOwner();
158
+ let initP;
159
+ if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
160
+ const init = readHydratedValue(initP, () => subFetch(compute, prev));
161
+ return init !== NO_HYDRATED_VALUE ? init : compute(prev);
162
+ }
163
+ function forwardIteratorReturn(it, value) {
164
+ const returned = it.return?.(value);
165
+ return returned && typeof returned.then === "function" ? returned : syncThenable(returned ?? {
166
+ done: true,
167
+ value
168
+ });
169
+ }
164
170
  function normalizeIterator(it) {
165
171
  let first = true;
166
172
  let buffered = null;
@@ -187,6 +193,10 @@ function normalizeIterator(it) {
187
193
  latest = peek;
188
194
  }
189
195
  return Promise.resolve(latest);
196
+ },
197
+ return(value) {
198
+ buffered = null;
199
+ return forwardIteratorReturn(it, value);
190
200
  }
191
201
  };
192
202
  }
@@ -264,6 +274,9 @@ function wrapFirstYield(iterable, activate) {
264
274
  });
265
275
  }
266
276
  return p;
277
+ },
278
+ return(value) {
279
+ return forwardIteratorReturn(srcIt, value);
267
280
  }
268
281
  };
269
282
  }
@@ -346,6 +359,10 @@ function hydrateStoreFromAsyncIterable(coreFn, initialValue, options) {
346
359
  if (!r.done) result = process(r);
347
360
  }
348
361
  return Promise.resolve(result);
362
+ },
363
+ return(value) {
364
+ buffered = null;
365
+ return forwardIteratorReturn(srcIt, value);
349
366
  }
350
367
  };
351
368
  }
@@ -378,14 +395,7 @@ function hydratedCreateMemo(compute, value, options) {
378
395
  }
379
396
  const aiResult = hydrateSignalFromAsyncIterable(signals.createMemo, compute, value, options);
380
397
  if (aiResult !== null) return aiResult;
381
- return signals.createMemo(prev => {
382
- const o = signals.getOwner();
383
- if (!sharedConfig.hydrating) return compute(prev);
384
- let initP;
385
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
386
- const init = initP?.v ?? initP;
387
- return init != null ? (subFetch(compute, prev), init) : compute(prev);
388
- }, value, options);
398
+ return signals.createMemo(prev => readSerializedOrCompute(compute, prev), value, options);
389
399
  }
390
400
  function hydratedCreateSignal(fn, second, third) {
391
401
  if (typeof fn !== "function" || !sharedConfig.hydrating) return signals.createSignal(fn, second, third);
@@ -411,14 +421,7 @@ function hydratedCreateSignal(fn, second, third) {
411
421
  }
412
422
  const aiResult = hydrateSignalFromAsyncIterable(signals.createSignal, fn, second, third);
413
423
  if (aiResult !== null) return aiResult;
414
- return signals.createSignal(prev => {
415
- if (!sharedConfig.hydrating) return fn(prev);
416
- const o = signals.getOwner();
417
- let initP;
418
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
419
- const init = initP?.v ?? initP;
420
- return init != null ? (subFetch(fn, prev), init) : fn(prev);
421
- }, second, third);
424
+ return signals.createSignal(prev => readSerializedOrCompute(fn, prev), second, third);
422
425
  }
423
426
  function hydratedCreateErrorBoundary(fn, fallback) {
424
427
  if (!sharedConfig.hydrating) return signals.createErrorBoundary(fn, fallback);
@@ -464,24 +467,10 @@ function hydratedCreateOptimistic(fn, second, third) {
464
467
  }
465
468
  const aiResult = hydrateSignalFromAsyncIterable(signals.createOptimistic, fn, second, third);
466
469
  if (aiResult !== null) return aiResult;
467
- return signals.createOptimistic(prev => {
468
- const o = signals.getOwner();
469
- if (!sharedConfig.hydrating) return fn(prev);
470
- let initP;
471
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
472
- const init = initP?.v ?? initP;
473
- return init != null ? (subFetch(fn, prev), init) : fn(prev);
474
- }, second, third);
470
+ return signals.createOptimistic(prev => readSerializedOrCompute(fn, prev), second, third);
475
471
  }
476
472
  function wrapStoreFn(fn) {
477
- return draft => {
478
- const o = signals.getOwner();
479
- if (!sharedConfig.hydrating) return fn(draft);
480
- let initP;
481
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
482
- const init = initP?.v ?? initP;
483
- return init != null ? (subFetch(fn, draft), init) : fn(draft);
484
- };
473
+ return draft => readSerializedOrCompute(() => fn(draft), draft);
485
474
  }
486
475
  function hydrateStoreLikeFn(coreFn, fn, initialValue, options, ssrSource) {
487
476
  if (ssrSource === "client") {
@@ -504,11 +493,8 @@ function hydrateStoreLikeFn(coreFn, fn, initialValue, options, ssrSource) {
504
493
  if (!hydrated()) {
505
494
  if (sharedConfig.has(o.id)) {
506
495
  const initP = sharedConfig.load(o.id);
507
- const init = initP?.v ?? initP;
508
- if (init != null) {
509
- subFetch(fn, draft);
510
- return init;
511
- }
496
+ const init = readHydratedValue(initP, () => subFetch(fn, draft));
497
+ if (init !== NO_HYDRATED_VALUE) return init;
512
498
  }
513
499
  return fn(draft);
514
500
  }
@@ -575,14 +561,7 @@ function hydratedEffect(coreFn, compute, effectFn, value, options) {
575
561
  return;
576
562
  }
577
563
  markTopLevelSnapshotScope();
578
- coreFn(prev => {
579
- const o = signals.getOwner();
580
- if (!sharedConfig.hydrating) return compute(prev);
581
- let initP;
582
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
583
- const init = initP?.v ?? initP;
584
- return init != null ? (subFetch(compute, prev), init) : compute(prev);
585
- }, effectFn, value, options);
564
+ coreFn(prev => readSerializedOrCompute(compute, prev), effectFn, value, options);
586
565
  }
587
566
  function hydratedCreateRenderEffect(compute, effectFn, value, options) {
588
567
  return hydratedEffect(signals.createRenderEffect, compute, effectFn, value, options);
@@ -680,7 +659,7 @@ function resumeBoundaryHydration(o, id, set) {
680
659
  checkHydrationComplete();
681
660
  return;
682
661
  }
683
- sharedConfig.gather(id);
662
+ sharedConfig.gather?.(id);
684
663
  _hydratingValue = true;
685
664
  signals.markSnapshotScope(o);
686
665
  _snapshotRootOwner = o;
@@ -692,11 +671,41 @@ function resumeBoundaryHydration(o, id, set) {
692
671
  signals.flush();
693
672
  checkHydrationComplete();
694
673
  }
695
- function Loading(props) {
696
- const onOpt = props.on ? {
697
- on: () => props.on()
698
- } : undefined;
699
- if (!sharedConfig.hydrating) return signals.createLoadingBoundary(() => props.children, () => props.fallback, onOpt);
674
+ function initBoundaryResume(o, id) {
675
+ _pendingBoundaries++;
676
+ signals.onCleanup(() => {
677
+ if (!signals.isDisposed(o)) return;
678
+ sharedConfig.cleanupFragment?.(id);
679
+ });
680
+ const set = createBoundaryTrigger();
681
+ return [set, () => resumeBoundaryHydration(o, id, set)];
682
+ }
683
+ function waitAndResume(p, resume, assetPromise) {
684
+ const waitFor = assetPromise ? Promise.all([p, assetPromise]) : p;
685
+ waitFor.then(() => {
686
+ if (p && typeof p === "object") p.s = 1;
687
+ resume();
688
+ }, err => {
689
+ if (p && typeof p === "object") {
690
+ p.s = 2;
691
+ p.v = err;
692
+ }
693
+ resume();
694
+ });
695
+ }
696
+ function scheduleResumeAfterAssets(id, resume, assetPromise) {
697
+ sharedConfig.gather?.(id);
698
+ const doResume = () => queueMicrotask(resume);
699
+ if (assetPromise) {
700
+ assetPromise.then(doResume);
701
+ return true;
702
+ }
703
+ doResume();
704
+ return false;
705
+ }
706
+ function createLoadingBoundary(fn, fallback, options) {
707
+ if (!sharedConfig.hydrating) return signals.createLoadingBoundary(fn, fallback, options);
708
+ let settledSerializationResumeQueued = false;
700
709
  return signals.createMemo(() => {
701
710
  const o = signals.getOwner();
702
711
  const id = o.id;
@@ -706,27 +715,21 @@ function Loading(props) {
706
715
  if (mapping && typeof mapping === "object") assetPromise = loadModuleAssets(mapping);
707
716
  }
708
717
  if (sharedConfig.hydrating && sharedConfig.has(id)) {
709
- let ref = sharedConfig.load(id);
718
+ const ref = sharedConfig.load(id);
710
719
  let p;
711
720
  if (ref) {
712
- if (typeof ref !== "object" || ref.s !== 1) p = ref;else sharedConfig.gather(id);
721
+ if (typeof ref !== "object" || ref.s == null) p = ref;else if (ref.s === 1 || ref.s === 2) sharedConfig.gather?.(id);else p = ref;
722
+ }
723
+ if (ref && typeof ref === "object" && ref.s === 1 && p == null && !settledSerializationResumeQueued) {
724
+ settledSerializationResumeQueued = true;
725
+ const [, resume] = initBoundaryResume(o, id);
726
+ if (scheduleResumeAfterAssets(id, resume, assetPromise)) return undefined;
727
+ return fallback();
713
728
  }
714
729
  if (p) {
715
- _pendingBoundaries++;
716
- signals.onCleanup(() => {
717
- if (!signals.isDisposed(o)) return;
718
- sharedConfig.cleanupFragment?.(id);
719
- });
720
- const set = createBoundaryTrigger();
730
+ const [set, resume] = initBoundaryResume(o, id);
721
731
  if (p !== "$$f") {
722
- const waitFor = assetPromise ? Promise.all([p, assetPromise]) : p;
723
- waitFor.then(() => resumeBoundaryHydration(o, id, set), err => {
724
- _pendingBoundaries--;
725
- checkHydrationComplete();
726
- signals.runWithOwner(o, () => {
727
- throw err;
728
- });
729
- });
732
+ waitAndResume(p, resume, assetPromise);
730
733
  } else {
731
734
  const afterAssets = () => {
732
735
  _pendingBoundaries--;
@@ -735,17 +738,26 @@ function Loading(props) {
735
738
  };
736
739
  if (assetPromise) assetPromise.then(() => queueMicrotask(afterAssets));else queueMicrotask(afterAssets);
737
740
  }
738
- return props.fallback;
741
+ return fallback();
742
+ }
743
+ }
744
+ if (sharedConfig.hydrating && sharedConfig.has(id + "_fr") && !settledSerializationResumeQueued) {
745
+ settledSerializationResumeQueued = true;
746
+ const fr = sharedConfig.load(id + "_fr");
747
+ const [, resume] = initBoundaryResume(o, id);
748
+ if (fr && typeof fr === "object" && (fr.s === 1 || fr.s === 2)) {
749
+ if (scheduleResumeAfterAssets(id, resume, assetPromise)) return undefined;
750
+ return fallback();
739
751
  }
752
+ waitAndResume(fr, resume, assetPromise);
753
+ return fallback();
740
754
  }
741
- if (assetPromise) {
742
- _pendingBoundaries++;
743
- const set = createBoundaryTrigger();
744
- assetPromise.then(() => resumeBoundaryHydration(o, id, set));
755
+ if (assetPromise && !sharedConfig.has(id)) {
756
+ const [, resume] = initBoundaryResume(o, id);
757
+ assetPromise.then(resume);
745
758
  return undefined;
746
759
  }
747
- const boundary = signals.createLoadingBoundary(() => props.children, () => props.fallback, onOpt);
748
- return boundary;
760
+ return signals.createLoadingBoundary(fn, fallback, options);
749
761
  });
750
762
  }
751
763
  function NoHydration(props) {
@@ -885,14 +897,22 @@ function Errored(props) {
885
897
  return typeof f === "function" && f.length ? f(err, reset) : f;
886
898
  });
887
899
  }
900
+ function Loading(props) {
901
+ const onOpt = "on" in props ? {
902
+ on: () => props.on
903
+ } : undefined;
904
+ return createLoadingBoundary(() => props.children, () => props.fallback, onOpt);
905
+ }
906
+ function Reveal(props) {
907
+ return signals.createRevealOrder(() => props.children, {
908
+ together: () => !!props.together,
909
+ collapsed: () => !!props.collapsed
910
+ });
911
+ }
888
912
 
889
913
  function ssrHandleError() {}
890
914
  function ssrRunInScope() {}
891
- const DevHooks = {};
892
- const DEV = {
893
- hooks: DevHooks,
894
- registerGraph
895
- } ;
915
+ const DEV = signals.DEV ;
896
916
  if (globalThis) {
897
917
  if (!globalThis.Solid$$) globalThis.Solid$$ = true;else console.warn("You appear to have multiple instances of Solid. This can lead to unexpected behavior.");
898
918
  }
@@ -917,14 +937,6 @@ Object.defineProperty(exports, "action", {
917
937
  enumerable: true,
918
938
  get: function () { return signals.action; }
919
939
  });
920
- Object.defineProperty(exports, "createErrorBoundary", {
921
- enumerable: true,
922
- get: function () { return signals.createErrorBoundary; }
923
- });
924
- Object.defineProperty(exports, "createLoadingBoundary", {
925
- enumerable: true,
926
- get: function () { return signals.createLoadingBoundary; }
927
- });
928
940
  Object.defineProperty(exports, "createOwner", {
929
941
  enumerable: true,
930
942
  get: function () { return signals.createOwner; }
@@ -933,6 +945,10 @@ Object.defineProperty(exports, "createReaction", {
933
945
  enumerable: true,
934
946
  get: function () { return signals.createReaction; }
935
947
  });
948
+ Object.defineProperty(exports, "createRevealOrder", {
949
+ enumerable: true,
950
+ get: function () { return signals.createRevealOrder; }
951
+ });
936
952
  Object.defineProperty(exports, "createRoot", {
937
953
  enumerable: true,
938
954
  get: function () { return signals.createRoot; }
@@ -973,6 +989,10 @@ Object.defineProperty(exports, "getOwner", {
973
989
  enumerable: true,
974
990
  get: function () { return signals.getOwner; }
975
991
  });
992
+ Object.defineProperty(exports, "isDisposed", {
993
+ enumerable: true,
994
+ get: function () { return signals.isDisposed; }
995
+ });
976
996
  Object.defineProperty(exports, "isEqual", {
977
997
  enumerable: true,
978
998
  get: function () { return signals.isEqual; }
@@ -1055,12 +1075,15 @@ exports.Match = Match;
1055
1075
  exports.NoHydrateContext = NoHydrateContext;
1056
1076
  exports.NoHydration = NoHydration;
1057
1077
  exports.Repeat = Repeat;
1078
+ exports.Reveal = Reveal;
1058
1079
  exports.Show = Show;
1059
1080
  exports.Switch = Switch;
1060
1081
  exports.children = children;
1061
1082
  exports.createComponent = createComponent;
1062
1083
  exports.createContext = createContext;
1063
1084
  exports.createEffect = createEffect;
1085
+ exports.createErrorBoundary = createErrorBoundary;
1086
+ exports.createLoadingBoundary = createLoadingBoundary;
1064
1087
  exports.createMemo = createMemo;
1065
1088
  exports.createOptimistic = createOptimistic;
1066
1089
  exports.createOptimisticStore = createOptimisticStore;