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.js CHANGED
@@ -1,5 +1,5 @@
1
- import { getContext, createMemo as createMemo$1, flatten, getOwner, createRoot, setContext, untrack, createLoadingBoundary, onCleanup, isDisposed, runWithOwner, createOwner, createEffect as createEffect$1, createOptimistic as createOptimistic$1, createOptimisticStore as createOptimisticStore$1, createProjection as createProjection$1, createRenderEffect as createRenderEffect$1, createSignal as createSignal$1, createStore as createStore$1, setSnapshotCapture, releaseSnapshotScope, getNextChildId, createErrorBoundary as createErrorBoundary$1, markSnapshotScope, flush, clearSnapshots, peekNextChildId, mapArray, repeat } from '@solidjs/signals';
2
- export { $PROXY, $REFRESH, $TRACK, NotReadyError, action, createErrorBoundary, createLoadingBoundary, createOwner, createReaction, createRoot, createTrackedEffect, deep, enableExternalSource, enforceLoadingBoundary, flatten, flush, getNextChildId, getObserver, getOwner, isEqual, isPending, isRefreshing, isWrappable, latest, mapArray, merge, omit, onCleanup, onSettled, reconcile, refresh, repeat, resolve, runWithOwner, snapshot, storePath, untrack } from '@solidjs/signals';
1
+ import { getContext, createMemo as createMemo$1, flatten, createRoot, setContext, getOwner, untrack, createOwner, runWithOwner, createEffect as createEffect$1, createErrorBoundary as createErrorBoundary$1, createLoadingBoundary as createLoadingBoundary$1, createOptimistic as createOptimistic$1, createOptimisticStore as createOptimisticStore$1, createProjection as createProjection$1, createRenderEffect as createRenderEffect$1, createSignal as createSignal$1, createStore as createStore$1, setSnapshotCapture, releaseSnapshotScope, getNextChildId, onCleanup, isDisposed, peekNextChildId, clearSnapshots, flush, markSnapshotScope, mapArray, repeat, createRevealOrder, DEV as DEV$1 } from '@solidjs/signals';
2
+ export { $PROXY, $REFRESH, $TRACK, NotReadyError, action, createOwner, createReaction, createRevealOrder, createRoot, createTrackedEffect, deep, enableExternalSource, enforceLoadingBoundary, flatten, flush, getNextChildId, getObserver, getOwner, isDisposed, isEqual, isPending, isRefreshing, isWrappable, latest, mapArray, merge, omit, onCleanup, onSettled, reconcile, refresh, repeat, resolve, runWithOwner, snapshot, storePath, untrack } from '@solidjs/signals';
3
3
 
4
4
  const $DEVCOMP = Symbol("COMPONENT_DEV" );
5
5
  function createContext(defaultValue, options) {
@@ -34,9 +34,11 @@ function children(fn) {
34
34
  function devComponent(Comp, props) {
35
35
  return createRoot(() => {
36
36
  const owner = getOwner();
37
- owner._props = props;
38
- owner._name = Comp.name;
39
- owner._component = Comp;
37
+ owner._component = {
38
+ fn: Comp,
39
+ props,
40
+ name: Comp.name
41
+ };
40
42
  Object.assign(Comp, {
41
43
  [$DEVCOMP]: true
42
44
  });
@@ -45,12 +47,6 @@ function devComponent(Comp, props) {
45
47
  transparent: true
46
48
  });
47
49
  }
48
- function registerGraph(value) {
49
- const owner = getOwner();
50
- if (!owner) return;
51
- if (owner.sourceMap) owner.sourceMap.push(value);else owner.sourceMap = [value];
52
- value.graph = owner;
53
- }
54
50
 
55
51
  const NoHydrateContext = {
56
52
  id: Symbol("NoHydrateContext"),
@@ -92,6 +88,7 @@ function drainHydrationCallbacks() {
92
88
  setTimeout(() => {
93
89
  if (sharedConfig.verifyHydration) sharedConfig.verifyHydration();
94
90
  if (globalThis._$HY) globalThis._$HY.done = true;
91
+ sharedConfig.registry?.clear();
95
92
  });
96
93
  }
97
94
  function checkHydrationComplete() {
@@ -109,23 +106,10 @@ let _createOptimisticStore;
109
106
  let _createRenderEffect;
110
107
  let _createEffect;
111
108
  class MockPromise {
112
- static all() {
113
- return new MockPromise();
114
- }
115
- static allSettled() {
116
- return new MockPromise();
117
- }
118
- static any() {
119
- return new MockPromise();
120
- }
121
- static race() {
122
- return new MockPromise();
123
- }
124
- static reject() {
125
- return new MockPromise();
126
- }
127
- static resolve() {
128
- return new MockPromise();
109
+ static {
110
+ for (const k of ["all", "allSettled", "any", "race", "reject", "resolve"]) {
111
+ MockPromise[k] = () => new MockPromise();
112
+ }
129
113
  }
130
114
  catch() {
131
115
  return new MockPromise();
@@ -160,6 +144,28 @@ function syncThenable(value) {
160
144
  }
161
145
  };
162
146
  }
147
+ const NO_HYDRATED_VALUE = Symbol("NO_HYDRATED_VALUE");
148
+ function readHydratedValue(initP, refresh) {
149
+ if (initP == null) return NO_HYDRATED_VALUE;
150
+ refresh();
151
+ if (typeof initP === "object" && initP.s === 2) throw initP.v;
152
+ return initP?.v ?? initP;
153
+ }
154
+ function readSerializedOrCompute(compute, prev) {
155
+ if (!sharedConfig.hydrating) return compute(prev);
156
+ const o = getOwner();
157
+ let initP;
158
+ if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
159
+ const init = readHydratedValue(initP, () => subFetch(compute, prev));
160
+ return init !== NO_HYDRATED_VALUE ? init : compute(prev);
161
+ }
162
+ function forwardIteratorReturn(it, value) {
163
+ const returned = it.return?.(value);
164
+ return returned && typeof returned.then === "function" ? returned : syncThenable(returned ?? {
165
+ done: true,
166
+ value
167
+ });
168
+ }
163
169
  function normalizeIterator(it) {
164
170
  let first = true;
165
171
  let buffered = null;
@@ -186,6 +192,10 @@ function normalizeIterator(it) {
186
192
  latest = peek;
187
193
  }
188
194
  return Promise.resolve(latest);
195
+ },
196
+ return(value) {
197
+ buffered = null;
198
+ return forwardIteratorReturn(it, value);
189
199
  }
190
200
  };
191
201
  }
@@ -263,6 +273,9 @@ function wrapFirstYield(iterable, activate) {
263
273
  });
264
274
  }
265
275
  return p;
276
+ },
277
+ return(value) {
278
+ return forwardIteratorReturn(srcIt, value);
266
279
  }
267
280
  };
268
281
  }
@@ -345,6 +358,10 @@ function hydrateStoreFromAsyncIterable(coreFn, initialValue, options) {
345
358
  if (!r.done) result = process(r);
346
359
  }
347
360
  return Promise.resolve(result);
361
+ },
362
+ return(value) {
363
+ buffered = null;
364
+ return forwardIteratorReturn(srcIt, value);
348
365
  }
349
366
  };
350
367
  }
@@ -377,14 +394,7 @@ function hydratedCreateMemo(compute, value, options) {
377
394
  }
378
395
  const aiResult = hydrateSignalFromAsyncIterable(createMemo$1, compute, value, options);
379
396
  if (aiResult !== null) return aiResult;
380
- return createMemo$1(prev => {
381
- const o = getOwner();
382
- if (!sharedConfig.hydrating) return compute(prev);
383
- let initP;
384
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
385
- const init = initP?.v ?? initP;
386
- return init != null ? (subFetch(compute, prev), init) : compute(prev);
387
- }, value, options);
397
+ return createMemo$1(prev => readSerializedOrCompute(compute, prev), value, options);
388
398
  }
389
399
  function hydratedCreateSignal(fn, second, third) {
390
400
  if (typeof fn !== "function" || !sharedConfig.hydrating) return createSignal$1(fn, second, third);
@@ -410,14 +420,7 @@ function hydratedCreateSignal(fn, second, third) {
410
420
  }
411
421
  const aiResult = hydrateSignalFromAsyncIterable(createSignal$1, fn, second, third);
412
422
  if (aiResult !== null) return aiResult;
413
- return createSignal$1(prev => {
414
- if (!sharedConfig.hydrating) return fn(prev);
415
- const o = getOwner();
416
- let initP;
417
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
418
- const init = initP?.v ?? initP;
419
- return init != null ? (subFetch(fn, prev), init) : fn(prev);
420
- }, second, third);
423
+ return createSignal$1(prev => readSerializedOrCompute(fn, prev), second, third);
421
424
  }
422
425
  function hydratedCreateErrorBoundary(fn, fallback) {
423
426
  if (!sharedConfig.hydrating) return createErrorBoundary$1(fn, fallback);
@@ -463,24 +466,10 @@ function hydratedCreateOptimistic(fn, second, third) {
463
466
  }
464
467
  const aiResult = hydrateSignalFromAsyncIterable(createOptimistic$1, fn, second, third);
465
468
  if (aiResult !== null) return aiResult;
466
- return createOptimistic$1(prev => {
467
- const o = getOwner();
468
- if (!sharedConfig.hydrating) return fn(prev);
469
- let initP;
470
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
471
- const init = initP?.v ?? initP;
472
- return init != null ? (subFetch(fn, prev), init) : fn(prev);
473
- }, second, third);
469
+ return createOptimistic$1(prev => readSerializedOrCompute(fn, prev), second, third);
474
470
  }
475
471
  function wrapStoreFn(fn) {
476
- return draft => {
477
- const o = getOwner();
478
- if (!sharedConfig.hydrating) return fn(draft);
479
- let initP;
480
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
481
- const init = initP?.v ?? initP;
482
- return init != null ? (subFetch(fn, draft), init) : fn(draft);
483
- };
472
+ return draft => readSerializedOrCompute(() => fn(draft), draft);
484
473
  }
485
474
  function hydrateStoreLikeFn(coreFn, fn, initialValue, options, ssrSource) {
486
475
  if (ssrSource === "client") {
@@ -503,11 +492,8 @@ function hydrateStoreLikeFn(coreFn, fn, initialValue, options, ssrSource) {
503
492
  if (!hydrated()) {
504
493
  if (sharedConfig.has(o.id)) {
505
494
  const initP = sharedConfig.load(o.id);
506
- const init = initP?.v ?? initP;
507
- if (init != null) {
508
- subFetch(fn, draft);
509
- return init;
510
- }
495
+ const init = readHydratedValue(initP, () => subFetch(fn, draft));
496
+ if (init !== NO_HYDRATED_VALUE) return init;
511
497
  }
512
498
  return fn(draft);
513
499
  }
@@ -574,14 +560,7 @@ function hydratedEffect(coreFn, compute, effectFn, value, options) {
574
560
  return;
575
561
  }
576
562
  markTopLevelSnapshotScope();
577
- coreFn(prev => {
578
- const o = getOwner();
579
- if (!sharedConfig.hydrating) return compute(prev);
580
- let initP;
581
- if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
582
- const init = initP?.v ?? initP;
583
- return init != null ? (subFetch(compute, prev), init) : compute(prev);
584
- }, effectFn, value, options);
563
+ coreFn(prev => readSerializedOrCompute(compute, prev), effectFn, value, options);
585
564
  }
586
565
  function hydratedCreateRenderEffect(compute, effectFn, value, options) {
587
566
  return hydratedEffect(createRenderEffect$1, compute, effectFn, value, options);
@@ -679,7 +658,7 @@ function resumeBoundaryHydration(o, id, set) {
679
658
  checkHydrationComplete();
680
659
  return;
681
660
  }
682
- sharedConfig.gather(id);
661
+ sharedConfig.gather?.(id);
683
662
  _hydratingValue = true;
684
663
  markSnapshotScope(o);
685
664
  _snapshotRootOwner = o;
@@ -691,11 +670,41 @@ function resumeBoundaryHydration(o, id, set) {
691
670
  flush();
692
671
  checkHydrationComplete();
693
672
  }
694
- function Loading(props) {
695
- const onOpt = props.on ? {
696
- on: () => props.on()
697
- } : undefined;
698
- if (!sharedConfig.hydrating) return createLoadingBoundary(() => props.children, () => props.fallback, onOpt);
673
+ function initBoundaryResume(o, id) {
674
+ _pendingBoundaries++;
675
+ onCleanup(() => {
676
+ if (!isDisposed(o)) return;
677
+ sharedConfig.cleanupFragment?.(id);
678
+ });
679
+ const set = createBoundaryTrigger();
680
+ return [set, () => resumeBoundaryHydration(o, id, set)];
681
+ }
682
+ function waitAndResume(p, resume, assetPromise) {
683
+ const waitFor = assetPromise ? Promise.all([p, assetPromise]) : p;
684
+ waitFor.then(() => {
685
+ if (p && typeof p === "object") p.s = 1;
686
+ resume();
687
+ }, err => {
688
+ if (p && typeof p === "object") {
689
+ p.s = 2;
690
+ p.v = err;
691
+ }
692
+ resume();
693
+ });
694
+ }
695
+ function scheduleResumeAfterAssets(id, resume, assetPromise) {
696
+ sharedConfig.gather?.(id);
697
+ const doResume = () => queueMicrotask(resume);
698
+ if (assetPromise) {
699
+ assetPromise.then(doResume);
700
+ return true;
701
+ }
702
+ doResume();
703
+ return false;
704
+ }
705
+ function createLoadingBoundary(fn, fallback, options) {
706
+ if (!sharedConfig.hydrating) return createLoadingBoundary$1(fn, fallback, options);
707
+ let settledSerializationResumeQueued = false;
699
708
  return createMemo$1(() => {
700
709
  const o = getOwner();
701
710
  const id = o.id;
@@ -705,27 +714,21 @@ function Loading(props) {
705
714
  if (mapping && typeof mapping === "object") assetPromise = loadModuleAssets(mapping);
706
715
  }
707
716
  if (sharedConfig.hydrating && sharedConfig.has(id)) {
708
- let ref = sharedConfig.load(id);
717
+ const ref = sharedConfig.load(id);
709
718
  let p;
710
719
  if (ref) {
711
- if (typeof ref !== "object" || ref.s !== 1) p = ref;else sharedConfig.gather(id);
720
+ if (typeof ref !== "object" || ref.s == null) p = ref;else if (ref.s === 1 || ref.s === 2) sharedConfig.gather?.(id);else p = ref;
721
+ }
722
+ if (ref && typeof ref === "object" && ref.s === 1 && p == null && !settledSerializationResumeQueued) {
723
+ settledSerializationResumeQueued = true;
724
+ const [, resume] = initBoundaryResume(o, id);
725
+ if (scheduleResumeAfterAssets(id, resume, assetPromise)) return undefined;
726
+ return fallback();
712
727
  }
713
728
  if (p) {
714
- _pendingBoundaries++;
715
- onCleanup(() => {
716
- if (!isDisposed(o)) return;
717
- sharedConfig.cleanupFragment?.(id);
718
- });
719
- const set = createBoundaryTrigger();
729
+ const [set, resume] = initBoundaryResume(o, id);
720
730
  if (p !== "$$f") {
721
- const waitFor = assetPromise ? Promise.all([p, assetPromise]) : p;
722
- waitFor.then(() => resumeBoundaryHydration(o, id, set), err => {
723
- _pendingBoundaries--;
724
- checkHydrationComplete();
725
- runWithOwner(o, () => {
726
- throw err;
727
- });
728
- });
731
+ waitAndResume(p, resume, assetPromise);
729
732
  } else {
730
733
  const afterAssets = () => {
731
734
  _pendingBoundaries--;
@@ -734,17 +737,26 @@ function Loading(props) {
734
737
  };
735
738
  if (assetPromise) assetPromise.then(() => queueMicrotask(afterAssets));else queueMicrotask(afterAssets);
736
739
  }
737
- return props.fallback;
740
+ return fallback();
741
+ }
742
+ }
743
+ if (sharedConfig.hydrating && sharedConfig.has(id + "_fr") && !settledSerializationResumeQueued) {
744
+ settledSerializationResumeQueued = true;
745
+ const fr = sharedConfig.load(id + "_fr");
746
+ const [, resume] = initBoundaryResume(o, id);
747
+ if (fr && typeof fr === "object" && (fr.s === 1 || fr.s === 2)) {
748
+ if (scheduleResumeAfterAssets(id, resume, assetPromise)) return undefined;
749
+ return fallback();
738
750
  }
751
+ waitAndResume(fr, resume, assetPromise);
752
+ return fallback();
739
753
  }
740
- if (assetPromise) {
741
- _pendingBoundaries++;
742
- const set = createBoundaryTrigger();
743
- assetPromise.then(() => resumeBoundaryHydration(o, id, set));
754
+ if (assetPromise && !sharedConfig.has(id)) {
755
+ const [, resume] = initBoundaryResume(o, id);
756
+ assetPromise.then(resume);
744
757
  return undefined;
745
758
  }
746
- const boundary = createLoadingBoundary(() => props.children, () => props.fallback, onOpt);
747
- return boundary;
759
+ return createLoadingBoundary$1(fn, fallback, options);
748
760
  });
749
761
  }
750
762
  function NoHydration(props) {
@@ -884,16 +896,24 @@ function Errored(props) {
884
896
  return typeof f === "function" && f.length ? f(err, reset) : f;
885
897
  });
886
898
  }
899
+ function Loading(props) {
900
+ const onOpt = "on" in props ? {
901
+ on: () => props.on
902
+ } : undefined;
903
+ return createLoadingBoundary(() => props.children, () => props.fallback, onOpt);
904
+ }
905
+ function Reveal(props) {
906
+ return createRevealOrder(() => props.children, {
907
+ together: () => !!props.together,
908
+ collapsed: () => !!props.collapsed
909
+ });
910
+ }
887
911
 
888
912
  function ssrHandleError() {}
889
913
  function ssrRunInScope() {}
890
- const DevHooks = {};
891
- const DEV = {
892
- hooks: DevHooks,
893
- registerGraph
894
- } ;
914
+ const DEV = DEV$1 ;
895
915
  if (globalThis) {
896
916
  if (!globalThis.Solid$$) globalThis.Solid$$ = true;else console.warn("You appear to have multiple instances of Solid. This can lead to unexpected behavior.");
897
917
  }
898
918
 
899
- export { $DEVCOMP, DEV, Errored, For, Hydration, Loading, Match, NoHydrateContext, NoHydration, Repeat, Show, Switch, children, createComponent, createContext, createEffect, createMemo, createOptimistic, createOptimisticStore, createProjection, createRenderEffect, createSignal, createStore, createUniqueId, enableHydration, lazy, sharedConfig, ssrHandleError, ssrRunInScope, useContext };
919
+ export { $DEVCOMP, DEV, Errored, For, Hydration, Loading, Match, NoHydrateContext, NoHydration, Repeat, Reveal, Show, Switch, children, createComponent, createContext, createEffect, createErrorBoundary, createLoadingBoundary, createMemo, createOptimistic, createOptimisticStore, createProjection, createRenderEffect, createSignal, createStore, createUniqueId, enableHydration, lazy, sharedConfig, ssrHandleError, ssrRunInScope, useContext };