solid-js 2.0.0-beta.10 → 2.0.0-beta.12

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/server.cjs CHANGED
@@ -8,13 +8,154 @@ const NoHydrateContext = {
8
8
  };
9
9
  const sharedConfig = {
10
10
  getNextContextId() {
11
- const o = signals.getOwner();
11
+ const o = getOwner();
12
12
  if (!o) throw new Error(`getNextContextId cannot be used under non-hydrating context`);
13
- if (signals.getContext(NoHydrateContext)) return undefined;
14
- return signals.getNextChildId(o);
13
+ if (getContext(NoHydrateContext)) return undefined;
14
+ return getNextChildId(o);
15
15
  }
16
16
  };
17
17
 
18
+ const defaultSSRContext = {};
19
+ let currentOwner = null;
20
+ const OWNER_POOL_MAX = 4096;
21
+ const ownerPool = [];
22
+ function formatChildId(prefix, id) {
23
+ const num = id.toString(36);
24
+ const len = num.length - 1;
25
+ return prefix + (len ? String.fromCharCode(64 + len) : "") + num;
26
+ }
27
+ function nextChildIdFor(owner, consume) {
28
+ let counter = owner;
29
+ while (counter._transparent && counter._parent) counter = counter._parent;
30
+ if (counter.id != null) {
31
+ return formatChildId(counter.id, counter._childCount++ );
32
+ }
33
+ throw new Error("Cannot get child id from owner without an id");
34
+ }
35
+ function consumeClientComputedSlot(owner) {
36
+ if (owner?.id != null) nextChildIdFor(owner);
37
+ }
38
+ function getNextChildId(owner) {
39
+ return nextChildIdFor(owner);
40
+ }
41
+ function createOwner(options) {
42
+ const parent = currentOwner;
43
+ const transparent = options?.transparent ?? false;
44
+ const id = options?.id ?? (transparent ? parent?.id : parent?.id != null ? nextChildIdFor(parent) : undefined);
45
+ const ctx = parent?._context ?? defaultSSRContext;
46
+ let owner;
47
+ if (ownerPool.length) {
48
+ owner = ownerPool.pop();
49
+ owner.id = id;
50
+ owner._transparent = transparent;
51
+ owner._disposal = null;
52
+ owner._parent = parent;
53
+ owner._context = ctx;
54
+ owner._childCount = 0;
55
+ owner._firstChild = null;
56
+ owner._nextSibling = null;
57
+ owner._disposed = false;
58
+ } else {
59
+ owner = {
60
+ id,
61
+ _transparent: transparent,
62
+ _disposal: null,
63
+ _parent: parent,
64
+ _context: ctx,
65
+ _childCount: 0,
66
+ _firstChild: null,
67
+ _nextSibling: null,
68
+ _disposed: false
69
+ };
70
+ }
71
+ if (parent) {
72
+ const lastChild = parent._firstChild;
73
+ if (lastChild) owner._nextSibling = lastChild;
74
+ parent._firstChild = owner;
75
+ }
76
+ return owner;
77
+ }
78
+ function runWithOwner(owner, fn) {
79
+ const prev = currentOwner;
80
+ currentOwner = owner;
81
+ try {
82
+ return fn();
83
+ } finally {
84
+ currentOwner = prev;
85
+ }
86
+ }
87
+ function getOwner() {
88
+ return currentOwner;
89
+ }
90
+ function isDisposed(owner) {
91
+ return owner._disposed;
92
+ }
93
+ function onCleanup(fn) {
94
+ const o = currentOwner;
95
+ if (!o) return fn;
96
+ if (!o._disposal) o._disposal = fn;else if (Array.isArray(o._disposal)) o._disposal.push(fn);else o._disposal = [o._disposal, fn];
97
+ return fn;
98
+ }
99
+ function getContext(context, owner = currentOwner) {
100
+ if (!owner) throw new signals.NoOwnerError();
101
+ const map = owner._context;
102
+ const stored = map[context.id];
103
+ const value = stored !== undefined ? stored : context.defaultValue;
104
+ if (value === undefined) throw new signals.ContextNotFoundError();
105
+ return value;
106
+ }
107
+ function setContext(context, value, owner = currentOwner) {
108
+ if (!owner) throw new signals.NoOwnerError();
109
+ const o = owner;
110
+ o._context = {
111
+ ...o._context,
112
+ [context.id]: value === undefined ? context.defaultValue : value
113
+ };
114
+ }
115
+ function disposeOwner(owner, self = true) {
116
+ const node = owner;
117
+ if (node._disposed) return;
118
+ if (!node._firstChild && !node._disposal) {
119
+ if (self) {
120
+ node._disposed = true;
121
+ if (ownerPool.length < OWNER_POOL_MAX) {
122
+ node.id = undefined;
123
+ node._parent = null;
124
+ node._nextSibling = null;
125
+ ownerPool.push(node);
126
+ }
127
+ }
128
+ return;
129
+ }
130
+ if (self) node._disposed = true;
131
+ let child = node._firstChild;
132
+ while (child) {
133
+ const next = child._nextSibling;
134
+ disposeOwner(child, true);
135
+ child = next;
136
+ }
137
+ node._firstChild = null;
138
+ node._childCount = 0;
139
+ const d = node._disposal;
140
+ if (d) {
141
+ if (Array.isArray(d)) {
142
+ for (let i = 0, len = d.length; i < len; i++) d[i]();
143
+ } else {
144
+ d();
145
+ }
146
+ node._disposal = null;
147
+ }
148
+ if (self && ownerPool.length < OWNER_POOL_MAX) {
149
+ node.id = undefined;
150
+ node._parent = null;
151
+ node._nextSibling = null;
152
+ ownerPool.push(node);
153
+ }
154
+ }
155
+ function createRoot(init, options) {
156
+ const owner = createOwner(options);
157
+ return runWithOwner(owner, () => init(() => disposeOwner(owner)));
158
+ }
18
159
  let Observer = null;
19
160
  function runWithObserver(comp, fn) {
20
161
  const prev = Observer;
@@ -99,8 +240,11 @@ function createSignal(first, second) {
99
240
  }];
100
241
  }
101
242
  function createMemo(compute, options) {
243
+ if (options?.sync) {
244
+ return createSyncMemo(compute, options);
245
+ }
102
246
  const ctx = sharedConfig.context;
103
- const owner = signals.createOwner();
247
+ const owner = createOwner();
104
248
  const comp = {
105
249
  owner,
106
250
  value: undefined,
@@ -109,12 +253,12 @@ function createMemo(compute, options) {
109
253
  computed: false,
110
254
  disposed: false
111
255
  };
112
- signals.runWithOwner(owner, () => signals.onCleanup(() => {
256
+ runWithOwner(owner, () => onCleanup(() => {
113
257
  comp.disposed = true;
114
258
  }));
115
259
  function update() {
116
260
  if (comp.disposed) return;
117
- const run = () => signals.runWithOwner(owner, () => runWithObserver(comp, () => comp.compute(comp.value)));
261
+ const run = () => runWithOwner(owner, () => runWithObserver(comp, () => comp.compute(comp.value)));
118
262
  try {
119
263
  comp.error = undefined;
120
264
  const result = run();
@@ -134,7 +278,7 @@ function createMemo(compute, options) {
134
278
  } else if (!options?.lazy) {
135
279
  update();
136
280
  }
137
- return () => {
281
+ const read = () => {
138
282
  if (!comp.computed) {
139
283
  update();
140
284
  }
@@ -143,6 +287,44 @@ function createMemo(compute, options) {
143
287
  }
144
288
  return comp.value;
145
289
  };
290
+ read[signals.$REFRESH] = comp;
291
+ return read;
292
+ }
293
+ function createSyncMemo(compute, options) {
294
+ const owner = createOwner();
295
+ let value;
296
+ let error;
297
+ let cached = false;
298
+ function pull() {
299
+ const prev = currentOwner;
300
+ currentOwner = owner;
301
+ try {
302
+ value = compute(value);
303
+ error = undefined;
304
+ cached = true;
305
+ return value;
306
+ } catch (err) {
307
+ if (err instanceof signals.NotReadyError) throw err;
308
+ error = err;
309
+ cached = true;
310
+ throw err;
311
+ } finally {
312
+ currentOwner = prev;
313
+ }
314
+ }
315
+ if (!options?.lazy) {
316
+ try {
317
+ pull();
318
+ } catch {
319
+ }
320
+ }
321
+ return () => {
322
+ if (cached) {
323
+ if (error !== undefined) throw error;
324
+ return value;
325
+ }
326
+ return pull();
327
+ };
146
328
  }
147
329
  function createDeepProxy(target, patches, basePath = []) {
148
330
  const childProxies = new Map();
@@ -207,7 +389,7 @@ function createDeepProxy(target, patches, basePath = []) {
207
389
  function processResult(comp, result, owner, ctx, deferStream, ssrSource, rerun) {
208
390
  if (comp.disposed) return;
209
391
  const id = owner.id;
210
- const noHydrate = signals.getContext(NoHydrateContext, owner);
392
+ const noHydrate = getContext(NoHydrateContext, owner);
211
393
  if (result instanceof Promise) {
212
394
  if (result.s === 1) {
213
395
  comp.value = result.v;
@@ -326,11 +508,11 @@ function closeAsyncIterator(iter, value) {
326
508
  function serverEffect(compute, effectFn, options) {
327
509
  const ssrSource = options?.ssrSource;
328
510
  if (ssrSource === "client") {
329
- signals.createOwner();
511
+ createOwner();
330
512
  return;
331
513
  }
332
514
  const ctx = sharedConfig.context;
333
- const owner = signals.createOwner();
515
+ const owner = createOwner();
334
516
  const comp = {
335
517
  owner,
336
518
  value: undefined,
@@ -340,12 +522,12 @@ function serverEffect(compute, effectFn, options) {
340
522
  disposed: false
341
523
  };
342
524
  if (ssrSource) {
343
- signals.runWithOwner(owner, () => signals.onCleanup(() => {
525
+ runWithOwner(owner, () => onCleanup(() => {
344
526
  comp.disposed = true;
345
527
  }));
346
528
  }
347
529
  try {
348
- const result = signals.runWithOwner(owner, () => runWithObserver(comp, () => compute(undefined)));
530
+ const result = runWithOwner(owner, () => runWithObserver(comp, () => compute(undefined)));
349
531
  if (ssrSource) {
350
532
  processResult(comp, result, owner, ctx, options?.deferStream, ssrSource);
351
533
  }
@@ -360,8 +542,8 @@ function createRenderEffect(compute, effectFn, options) {
360
542
  serverEffect(compute, effectFn, options);
361
543
  }
362
544
  function createTrackedEffect(compute, options) {
363
- const o = signals.getOwner();
364
- if (o?.id != null) signals.getNextChildId(o);
545
+ const o = getOwner();
546
+ if (o?.id != null) getNextChildId(o);
365
547
  }
366
548
  function createReaction(effectFn, options) {
367
549
  return tracking => {
@@ -404,20 +586,20 @@ function createPendingProxy(state, source) {
404
586
  }
405
587
  function createProjection(fn, initialValue, options) {
406
588
  const ctx = sharedConfig.context;
407
- const owner = signals.createOwner();
589
+ const owner = createOwner();
408
590
  const [state] = createStore(initialValue);
409
591
  if (options?.ssrSource === "client") {
410
592
  return state;
411
593
  }
412
594
  let disposed = false;
413
- signals.runWithOwner(owner, () => signals.onCleanup(() => {
595
+ runWithOwner(owner, () => onCleanup(() => {
414
596
  disposed = true;
415
597
  }));
416
598
  const ssrSource = options?.ssrSource;
417
599
  const useProxy = ssrSource !== "hybrid";
418
600
  const patches = [];
419
601
  const draft = useProxy ? createDeepProxy(state, patches) : state;
420
- const runProjection = () => signals.runWithOwner(owner, () => fn(draft));
602
+ const runProjection = () => runWithOwner(owner, () => fn(draft));
421
603
  const result = runProjection();
422
604
  const iteratorFn = result?.[Symbol.asyncIterator];
423
605
  if (typeof iteratorFn === "function") {
@@ -448,7 +630,7 @@ function createProjection(fn, initialValue, options) {
448
630
  }, error => {
449
631
  markReady();
450
632
  }, () => disposed);
451
- if (ctx?.async && !signals.getContext(NoHydrateContext) && owner.id) ctx.serialize(owner.id, deferred.promise, options?.deferStream);
633
+ if (ctx?.async && !getContext(NoHydrateContext) && owner.id) ctx.serialize(owner.id, deferred.promise, options?.deferStream);
452
634
  return pending;
453
635
  } else {
454
636
  let currentResult = result;
@@ -480,7 +662,7 @@ function createProjection(fn, initialValue, options) {
480
662
  }, error => {
481
663
  markReady();
482
664
  }, () => disposed);
483
- if (ctx?.async && !signals.getContext(NoHydrateContext) && owner.id) {
665
+ if (ctx?.async && !getContext(NoHydrateContext) && owner.id) {
484
666
  let tappedFirst = true;
485
667
  const tapped = {
486
668
  [Symbol.asyncIterator]: () => ({
@@ -541,7 +723,7 @@ function createProjection(fn, initialValue, options) {
541
723
  }, error => {
542
724
  markReady();
543
725
  }, () => disposed);
544
- if (ctx?.async && !signals.getContext(NoHydrateContext) && owner.id) ctx.serialize(owner.id, deferred.promise, options?.deferStream);
726
+ if (ctx?.async && !getContext(NoHydrateContext) && owner.id) ctx.serialize(owner.id, deferred.promise, options?.deferStream);
545
727
  return pending;
546
728
  }
547
729
  if (result !== undefined && result !== state && result !== draft) {
@@ -567,46 +749,104 @@ function reconcile(value) {
567
749
  function deep(store) {
568
750
  return store;
569
751
  }
752
+ function proxySource(read) {
753
+ return new Proxy({}, {
754
+ get(_, property, receiver) {
755
+ if (property === signals.$PROXY) return receiver;
756
+ const source = read() || {};
757
+ return source[property];
758
+ },
759
+ has(_, property) {
760
+ if (property === signals.$PROXY) return true;
761
+ return property in (read() || {});
762
+ },
763
+ ownKeys() {
764
+ return Object.keys(read() || {});
765
+ },
766
+ getOwnPropertyDescriptor(_, property) {
767
+ return {
768
+ configurable: true,
769
+ enumerable: true,
770
+ get() {
771
+ return (read() || {})[property];
772
+ }
773
+ };
774
+ }
775
+ });
776
+ }
777
+ function merge(...sources) {
778
+ for (let i = 0; i < sources.length; i++) {
779
+ if (typeof sources[i] === "function") {
780
+ sources[i] = proxySource(createMemo(sources[i]));
781
+ }
782
+ }
783
+ return signals.merge(...sources);
784
+ }
570
785
  function mapArray(list, mapFn, options = {}) {
571
- const parent = signals.createOwner();
572
- return createMemo(() => {
786
+ const indexes = mapFn.length > 1;
787
+ const parent = currentOwner;
788
+ const read = createMemo(() => {
573
789
  const items = list();
574
- let s = [];
790
+ const s = [];
575
791
  if (items && items.length) {
576
- signals.runWithOwner(parent, () => {
792
+ const parent = currentOwner;
793
+ const origId = parent.id;
794
+ const origChildCount = parent._childCount;
795
+ try {
577
796
  for (let i = 0, len = items.length; i < len; i++) {
578
- const o = signals.createOwner();
579
- s.push(signals.runWithOwner(o, () => mapFn(() => items[i], () => i)));
797
+ if (origId !== undefined) {
798
+ parent.id = formatChildId(origId, origChildCount + i);
799
+ }
800
+ parent._childCount = 0;
801
+ s.push(options.keyed === false ? indexes ? mapFn(() => items[i], i) : mapFn(() => items[i]) : typeof options.keyed === "function" ? indexes ? mapFn(() => items[i], () => i) : mapFn(() => items[i]) : indexes ? mapFn(items[i], () => i) : mapFn(items[i]));
580
802
  }
581
- });
803
+ } finally {
804
+ parent.id = origId;
805
+ parent._childCount = origChildCount + items.length;
806
+ }
582
807
  } else if (options.fallback) {
583
- s = [signals.runWithOwner(parent, () => {
584
- const fo = signals.createOwner();
585
- return signals.runWithOwner(fo, () => options.fallback());
586
- })];
808
+ const fo = createOwner();
809
+ s.push(runWithOwner(fo, () => options.fallback()));
587
810
  }
588
811
  return s;
812
+ }, {
813
+ sync: true
589
814
  });
815
+ consumeClientComputedSlot(parent);
816
+ return read;
590
817
  }
591
818
  function repeat(count, mapFn, options = {}) {
592
- const owner = signals.createOwner();
593
- return createMemo(() => {
819
+ const parent = currentOwner;
820
+ const read = createMemo(() => {
594
821
  const len = count();
595
822
  const offset = options.from?.() || 0;
596
823
  if (!len) {
597
824
  if (!options.fallback) return [];
598
- return [signals.runWithOwner(owner, () => {
599
- const fallbackOwner = signals.createOwner();
600
- return signals.runWithOwner(fallbackOwner, () => options.fallback());
601
- })];
825
+ const fo = createOwner();
826
+ return [runWithOwner(fo, () => options.fallback())];
602
827
  }
603
- return signals.runWithOwner(owner, () => Array.from({
604
- length: len
605
- }, (_, i) => {
606
- const itemOwner = signals.createOwner();
607
- return signals.runWithOwner(itemOwner, () => mapFn(i + offset));
608
- }));
828
+ const out = new Array(len);
829
+ const parent = currentOwner;
830
+ const origId = parent.id;
831
+ const origChildCount = parent._childCount;
832
+ try {
833
+ for (let i = 0; i < len; i++) {
834
+ if (origId !== undefined) {
835
+ parent.id = formatChildId(origId, origChildCount + i);
836
+ }
837
+ parent._childCount = 0;
838
+ out[i] = mapFn(i + offset);
839
+ }
840
+ } finally {
841
+ parent.id = origId;
842
+ parent._childCount = origChildCount + len;
843
+ }
844
+ return out;
845
+ }, {
846
+ sync: true
609
847
  });
848
+ consumeClientComputedSlot(parent);
849
+ return read;
610
850
  }
611
851
  const ErrorContext = {
612
852
  id: Symbol("ErrorContext"),
@@ -620,9 +860,9 @@ function runWithBoundaryErrorContext(owner, render, onError, context, boundaryId
620
860
  if (boundaryId !== undefined) context._currentBoundaryId = boundaryId;
621
861
  }
622
862
  try {
623
- return signals.runWithOwner(owner, () => {
624
- const parentHandler = signals.getContext(ErrorContext);
625
- signals.setContext(ErrorContext, err => onError(err, parentHandler));
863
+ return runWithOwner(owner, () => {
864
+ const parentHandler = getContext(ErrorContext);
865
+ setContext(ErrorContext, err => onError(err, parentHandler));
626
866
  return render();
627
867
  });
628
868
  } finally {
@@ -634,19 +874,19 @@ function runWithBoundaryErrorContext(owner, render, onError, context, boundaryId
634
874
  }
635
875
  function createErrorBoundary(fn, fallback) {
636
876
  const ctx = sharedConfig.context;
637
- const parent = signals.getOwner();
638
- const owner = signals.createOwner();
877
+ const parent = getOwner();
878
+ const owner = createOwner();
639
879
  const resolve = () => {
640
- const resolved = ctx.resolve(signals.runWithOwner(signals.createOwner(), fn));
880
+ const resolved = ctx.resolve(runWithOwner(createOwner(), fn));
641
881
  if (resolved?.p?.length) throw new signals.NotReadyError(Promise.all(resolved.p));
642
882
  return resolved;
643
883
  };
644
- const renderFallback = err => ctx ? signals.runWithOwner(parent, () => {
645
- const fallbackOwner = signals.createOwner();
646
- return signals.runWithOwner(fallbackOwner, () => fallback(err, () => {}));
884
+ const renderFallback = err => ctx ? runWithOwner(parent, () => {
885
+ const fallbackOwner = createOwner();
886
+ return runWithOwner(fallbackOwner, () => fallback(err, () => {}));
647
887
  }) : fallback(err, () => {});
648
888
  const serializeError = err => {
649
- if (ctx && owner.id && !signals.runWithOwner(owner, () => signals.getContext(NoHydrateContext))) {
889
+ if (ctx && owner.id && !runWithOwner(owner, () => getContext(NoHydrateContext))) {
650
890
  ctx.serialize(owner.id, err);
651
891
  }
652
892
  };
@@ -657,14 +897,14 @@ function createErrorBoundary(fn, fallback) {
657
897
  return () => {
658
898
  let result;
659
899
  let handled = false;
660
- if (ctx) owner.dispose(false);
900
+ if (ctx) disposeOwner(owner, false);
661
901
  try {
662
902
  result = ctx ? runWithBoundaryErrorContext(owner, resolve, err => {
663
903
  if (err instanceof signals.NotReadyError) throw err;
664
904
  handled = true;
665
905
  result = handleError(err);
666
906
  throw err;
667
- }) : signals.runWithOwner(owner, fn);
907
+ }) : runWithOwner(owner, fn);
668
908
  } catch (err) {
669
909
  if (err instanceof signals.NotReadyError) throw err;
670
910
  result = handled ? result : handleError(err);
@@ -684,8 +924,8 @@ function createLoadingBoundary$1(fn, fallback, options) {
684
924
  }
685
925
  }
686
926
  function createRevealOrder(fn, _options) {
687
- const o = signals.createOwner();
688
- return signals.runWithOwner(o, fn);
927
+ const o = createOwner();
928
+ return runWithOwner(o, fn);
689
929
  }
690
930
  function untrack(fn) {
691
931
  return fn();
@@ -711,23 +951,23 @@ function latest(fn) {
711
951
  function isRefreshing() {
712
952
  return false;
713
953
  }
714
- function refresh(fn) {
715
- return fn();
954
+ function refresh(_target) {
955
+ return undefined;
716
956
  }
717
957
  function action(fn) {
718
958
  return fn;
719
959
  }
720
960
  function onSettled(callback) {
721
- const o = signals.getOwner();
722
- if (o?.id != null) signals.getNextChildId(o);
961
+ const o = getOwner();
962
+ if (o?.id != null) getNextChildId(o);
723
963
  }
724
964
 
725
965
  const $DEVCOMP = Symbol("solid-dev-component");
726
966
  function createContext(defaultValue, options) {
727
967
  const id = Symbol(options && options.name || "");
728
968
  function provider(props) {
729
- return signals.createRoot(() => {
730
- signals.setContext(provider, props.value);
969
+ return createRoot(() => {
970
+ setContext(provider, props.value);
731
971
  return children(() => props.children);
732
972
  });
733
973
  }
@@ -736,14 +976,15 @@ function createContext(defaultValue, options) {
736
976
  return provider;
737
977
  }
738
978
  function useContext(context) {
739
- return signals.getContext(context);
979
+ return getContext(context);
740
980
  }
741
981
  function children(fn) {
742
982
  const c = createMemo(fn, {
743
983
  lazy: true
744
984
  });
745
985
  const memo = createMemo(() => signals.flatten(c()), {
746
- lazy: true
986
+ lazy: true,
987
+ sync: true
747
988
  });
748
989
  memo.toArray = () => {
749
990
  const v = memo();
@@ -751,11 +992,6 @@ function children(fn) {
751
992
  };
752
993
  return memo;
753
994
  }
754
- function ssrRunInScope(fn) {
755
- const owner = signals.getOwner();
756
- if (!owner) return fn;
757
- return Array.isArray(fn) ? fn.map(hole => () => signals.runWithOwner(owner, hole)) : () => signals.runWithOwner(owner, fn);
758
- }
759
995
 
760
996
  function enableHydration() {}
761
997
  function createComponent(Comp, props) {
@@ -773,7 +1009,7 @@ function lazy(fn, moduleUrl) {
773
1009
  return p;
774
1010
  };
775
1011
  const wrap = props => {
776
- const noHydrate = signals.getContext(NoHydrateContext);
1012
+ const noHydrate = getContext(NoHydrateContext);
777
1013
  if (!noHydrate && !moduleUrl) {
778
1014
  throw new Error("lazy() used in SSR without a moduleUrl. " + "All lazy() components require a moduleUrl for correct hydration. " + "This is typically injected by the bundler plugin.");
779
1015
  }
@@ -799,6 +1035,8 @@ function lazy(fn, moduleUrl) {
799
1035
  return createMemo(() => {
800
1036
  if (!p.v) throw new signals.NotReadyError(p);
801
1037
  return p.v(props);
1038
+ }, {
1039
+ sync: true
802
1040
  });
803
1041
  };
804
1042
  wrap.preload = load;
@@ -806,9 +1044,9 @@ function lazy(fn, moduleUrl) {
806
1044
  return wrap;
807
1045
  }
808
1046
  function createUniqueId() {
809
- const o = signals.getOwner();
1047
+ const o = getOwner();
810
1048
  if (!o) throw new Error(`createUniqueId cannot be used outside of a reactive context`);
811
- return signals.getNextChildId(o);
1049
+ return getNextChildId(o);
812
1050
  }
813
1051
 
814
1052
  const RevealGroupContext = {
@@ -819,7 +1057,7 @@ function ssrHandleError(err) {
819
1057
  if (err instanceof signals.NotReadyError) {
820
1058
  return err.source;
821
1059
  }
822
- const handler = signals.getContext(ErrorContext);
1060
+ const handler = getContext(ErrorContext);
823
1061
  if (handler) {
824
1062
  handler(err);
825
1063
  return;
@@ -832,10 +1070,10 @@ function createLoadingBoundary(fn, fallback, options) {
832
1070
  return createLoadingBoundary$1(fn, fallback);
833
1071
  }
834
1072
  const ctx = currentCtx;
835
- const parent = signals.getOwner();
836
- const parentHandler = parent && signals.runWithOwner(parent, () => signals.getContext(ErrorContext));
837
- const revealGroup = parent && signals.runWithOwner(parent, () => signals.getContext(RevealGroupContext));
838
- const o = signals.createOwner();
1073
+ const parent = getOwner();
1074
+ const parentHandler = parent && runWithOwner(parent, () => getContext(ErrorContext));
1075
+ const revealGroup = parent && runWithOwner(parent, () => getContext(RevealGroupContext));
1076
+ const o = createOwner();
839
1077
  const id = o.id;
840
1078
  o.id = id + "00";
841
1079
  let done;
@@ -876,13 +1114,13 @@ function createLoadingBoundary(fn, fallback, options) {
876
1114
  if (done?.(undefined, err)) return;
877
1115
  if (!parentHandler) throw err;
878
1116
  try {
879
- signals.runWithOwner(parent, () => parentHandler(err));
1117
+ runWithOwner(parent, () => parentHandler(err));
880
1118
  } catch (caught) {
881
1119
  if (caught !== err) throw caught;
882
1120
  }
883
1121
  }
884
1122
  function runDiscovery() {
885
- o.dispose(false);
1123
+ disposeOwner(o, false);
886
1124
  serializeBuffer = [];
887
1125
  retryPromise = undefined;
888
1126
  return runLoadingPhase(() => {
@@ -909,10 +1147,10 @@ function createLoadingBoundary(fn, fallback, options) {
909
1147
  ctx.serialize(id, "$$f");
910
1148
  return () => undefined;
911
1149
  }
912
- const fallbackOwner = signals.createOwner({
1150
+ const fallbackOwner = createOwner({
913
1151
  id
914
1152
  });
915
- const fallbackResult = signals.runWithOwner(fallbackOwner, () => {
1153
+ const fallbackResult = runWithOwner(fallbackOwner, () => {
916
1154
  if (!ctx.async) return fallback();
917
1155
  const tpl = collapseFallback ? [`<template id="pl-${id}">`, `</template><!--pl-${id}-->`] : [`<template id="pl-${id}"></template>`, `<!--pl-${id}-->`];
918
1156
  return ctx.ssr(tpl, ctx.escape(fallback()));
@@ -929,12 +1167,13 @@ function createLoadingBoundary(fn, fallback, options) {
929
1167
  ret = runDiscovery();
930
1168
  }
931
1169
  commitBoundaryState();
932
- while (ret.p.length) {
933
- await Promise.all(ret.p).catch(() => {});
934
- ret = runLoadingPhase(() => ctx.ssr(ret.t, ...ret.h));
1170
+ while (ret && ret.p && ret.p.length) {
1171
+ const pending = ret;
1172
+ await Promise.all(pending.p).catch(() => {});
1173
+ ret = runLoadingPhase(() => ctx.ssr(pending.t, ...pending.h));
935
1174
  }
936
1175
  flushSerializeBuffer();
937
- done(ret.t[0]);
1176
+ done(ret && Array.isArray(ret.t) ? ret.t[0] : ret && ret.t);
938
1177
  if (revealGroup) revealGroup.onResolved(id);
939
1178
  } catch (err) {
940
1179
  finalizeError(err);
@@ -947,19 +1186,19 @@ function createLoadingBoundary(fn, fallback, options) {
947
1186
  return () => fallbackResult;
948
1187
  }
949
1188
  function NoHydration(props) {
950
- const o = signals.createOwner();
951
- return signals.runWithOwner(o, () => {
952
- signals.setContext(NoHydrateContext, true);
1189
+ const o = createOwner();
1190
+ return runWithOwner(o, () => {
1191
+ setContext(NoHydrateContext, true);
953
1192
  return props.children;
954
1193
  });
955
1194
  }
956
1195
  function Hydration(props) {
957
- if (!signals.getContext(NoHydrateContext)) return props.children;
958
- const o = signals.createOwner({
1196
+ if (!getContext(NoHydrateContext)) return props.children;
1197
+ const o = createOwner({
959
1198
  id: props.id ?? ""
960
1199
  });
961
- return signals.runWithOwner(o, () => {
962
- signals.setContext(NoHydrateContext, false);
1200
+ return runWithOwner(o, () => {
1201
+ setContext(NoHydrateContext, false);
963
1202
  return props.children;
964
1203
  });
965
1204
  }
@@ -981,27 +1220,29 @@ function Repeat(props) {
981
1220
  return repeat(() => props.count, index => typeof props.children === "function" ? props.children(index) : props.children, options);
982
1221
  }
983
1222
  function Show(props) {
984
- const o = signals.getOwner();
1223
+ const o = getOwner();
985
1224
  if (o?.id != null) {
986
- signals.getNextChildId(o);
987
- if (!props.keyed) signals.getNextChildId(o);
1225
+ getNextChildId(o);
1226
+ if (!props.keyed) getNextChildId(o);
988
1227
  }
989
1228
  return createMemo(() => {
990
1229
  const when = props.when;
991
1230
  if (when) {
992
1231
  const child = props.children;
993
1232
  if (typeof child === "function" && child.length > 0) {
994
- return child(() => when);
1233
+ return props.keyed ? child(when) : child(() => when);
995
1234
  }
996
1235
  return child;
997
1236
  }
998
1237
  return props.fallback;
1238
+ }, {
1239
+ sync: true
999
1240
  });
1000
1241
  }
1001
1242
  function Switch(props) {
1002
1243
  const chs = children(() => props.children);
1003
- const o = signals.getOwner();
1004
- if (o?.id != null) signals.getNextChildId(o);
1244
+ const o = getOwner();
1245
+ if (o?.id != null) getNextChildId(o);
1005
1246
  return createMemo(() => {
1006
1247
  let conds = chs();
1007
1248
  if (!Array.isArray(conds)) conds = [conds];
@@ -1009,10 +1250,12 @@ function Switch(props) {
1009
1250
  const w = conds[i].when;
1010
1251
  if (w) {
1011
1252
  const c = conds[i].children;
1012
- return typeof c === "function" && c.length > 0 ? c(() => w) : c;
1253
+ return typeof c === "function" && c.length > 0 ? conds[i].keyed ? c(w) : c(() => w) : c;
1013
1254
  }
1014
1255
  }
1015
1256
  return props.fallback;
1257
+ }, {
1258
+ sync: true
1016
1259
  });
1017
1260
  }
1018
1261
  function Match(props) {
@@ -1028,13 +1271,13 @@ function Loading(props) {
1028
1271
  return createLoadingBoundary(() => props.children, () => props.fallback);
1029
1272
  }
1030
1273
  function Reveal(props) {
1031
- const o = signals.createOwner();
1274
+ const o = createOwner();
1032
1275
  const id = o.id;
1033
1276
  const order = props.order ?? "sequential";
1034
1277
  const collapsed = order === "sequential" && !!props.collapsed;
1035
1278
  if (!sharedConfig.context?.async) {
1036
- const parent = signals.getOwner();
1037
- const parentGroup = parent ? signals.runWithOwner(parent, () => signals.getContext(RevealGroupContext)) : null;
1279
+ const parent = getOwner();
1280
+ const parentGroup = parent ? runWithOwner(parent, () => getContext(RevealGroupContext)) : null;
1038
1281
  let collapsedByParent = false;
1039
1282
  if (parentGroup) {
1040
1283
  const reg = parentGroup.register(id);
@@ -1042,8 +1285,8 @@ function Reveal(props) {
1042
1285
  if (order === "together" || collapsed) console.warn("Nested <Reveal> with collapsed/together won't coordinate correctly with renderToString. Use renderToStream for full support.");
1043
1286
  }
1044
1287
  let count = 0;
1045
- return signals.runWithOwner(o, () => {
1046
- signals.setContext(RevealGroupContext, {
1288
+ return runWithOwner(o, () => {
1289
+ setContext(RevealGroupContext, {
1047
1290
  id,
1048
1291
  register(_key) {
1049
1292
  count++;
@@ -1071,8 +1314,8 @@ function Reveal(props) {
1071
1314
  let collapsedByParent = false;
1072
1315
  let selfMinimallyResolved = false;
1073
1316
  let notifiedParentDone = false;
1074
- const parent = signals.getOwner();
1075
- const parentGroup = parent ? signals.runWithOwner(parent, () => signals.getContext(RevealGroupContext)) : null;
1317
+ const parent = getOwner();
1318
+ const parentGroup = parent ? runWithOwner(parent, () => getContext(RevealGroupContext)) : null;
1076
1319
  if (parentGroup) {
1077
1320
  const reg = parentGroup.register(id, {
1078
1321
  onActivate: () => {
@@ -1140,8 +1383,8 @@ function Reveal(props) {
1140
1383
  composites.forEach((_, key) => activateComposite(key));
1141
1384
  notifyParentIfDone();
1142
1385
  }
1143
- return signals.runWithOwner(o, () => {
1144
- signals.setContext(RevealGroupContext, {
1386
+ return runWithOwner(o, () => {
1387
+ setContext(RevealGroupContext, {
1145
1388
  id,
1146
1389
  register(key, options) {
1147
1390
  keys.push(key);
@@ -1218,14 +1461,6 @@ Object.defineProperty(exports, "NotReadyError", {
1218
1461
  enumerable: true,
1219
1462
  get: function () { return signals.NotReadyError; }
1220
1463
  });
1221
- Object.defineProperty(exports, "createOwner", {
1222
- enumerable: true,
1223
- get: function () { return signals.createOwner; }
1224
- });
1225
- Object.defineProperty(exports, "createRoot", {
1226
- enumerable: true,
1227
- get: function () { return signals.createRoot; }
1228
- });
1229
1464
  Object.defineProperty(exports, "enableExternalSource", {
1230
1465
  enumerable: true,
1231
1466
  get: function () { return signals.enableExternalSource; }
@@ -1238,18 +1473,6 @@ Object.defineProperty(exports, "flatten", {
1238
1473
  enumerable: true,
1239
1474
  get: function () { return signals.flatten; }
1240
1475
  });
1241
- Object.defineProperty(exports, "getNextChildId", {
1242
- enumerable: true,
1243
- get: function () { return signals.getNextChildId; }
1244
- });
1245
- Object.defineProperty(exports, "getOwner", {
1246
- enumerable: true,
1247
- get: function () { return signals.getOwner; }
1248
- });
1249
- Object.defineProperty(exports, "isDisposed", {
1250
- enumerable: true,
1251
- get: function () { return signals.isDisposed; }
1252
- });
1253
1476
  Object.defineProperty(exports, "isEqual", {
1254
1477
  enumerable: true,
1255
1478
  get: function () { return signals.isEqual; }
@@ -1258,22 +1481,10 @@ Object.defineProperty(exports, "isWrappable", {
1258
1481
  enumerable: true,
1259
1482
  get: function () { return signals.isWrappable; }
1260
1483
  });
1261
- Object.defineProperty(exports, "merge", {
1262
- enumerable: true,
1263
- get: function () { return signals.merge; }
1264
- });
1265
1484
  Object.defineProperty(exports, "omit", {
1266
1485
  enumerable: true,
1267
1486
  get: function () { return signals.omit; }
1268
1487
  });
1269
- Object.defineProperty(exports, "onCleanup", {
1270
- enumerable: true,
1271
- get: function () { return signals.onCleanup; }
1272
- });
1273
- Object.defineProperty(exports, "runWithOwner", {
1274
- enumerable: true,
1275
- get: function () { return signals.runWithOwner; }
1276
- });
1277
1488
  Object.defineProperty(exports, "snapshot", {
1278
1489
  enumerable: true,
1279
1490
  get: function () { return signals.snapshot; }
@@ -1306,10 +1517,12 @@ exports.createLoadingBoundary = createLoadingBoundary;
1306
1517
  exports.createMemo = createMemo;
1307
1518
  exports.createOptimistic = createOptimistic;
1308
1519
  exports.createOptimisticStore = createOptimisticStore;
1520
+ exports.createOwner = createOwner;
1309
1521
  exports.createProjection = createProjection;
1310
1522
  exports.createReaction = createReaction;
1311
1523
  exports.createRenderEffect = createRenderEffect;
1312
1524
  exports.createRevealOrder = createRevealOrder;
1525
+ exports.createRoot = createRoot;
1313
1526
  exports.createSignal = createSignal;
1314
1527
  exports.createStore = createStore;
1315
1528
  exports.createTrackedEffect = createTrackedEffect;
@@ -1317,19 +1530,24 @@ exports.createUniqueId = createUniqueId;
1317
1530
  exports.deep = deep;
1318
1531
  exports.enableHydration = enableHydration;
1319
1532
  exports.flush = flush;
1533
+ exports.getNextChildId = getNextChildId;
1320
1534
  exports.getObserver = getObserver;
1535
+ exports.getOwner = getOwner;
1536
+ exports.isDisposed = isDisposed;
1321
1537
  exports.isPending = isPending;
1322
1538
  exports.isRefreshing = isRefreshing;
1323
1539
  exports.latest = latest;
1324
1540
  exports.lazy = lazy;
1325
1541
  exports.mapArray = mapArray;
1542
+ exports.merge = merge;
1543
+ exports.onCleanup = onCleanup;
1326
1544
  exports.onSettled = onSettled;
1327
1545
  exports.reconcile = reconcile;
1328
1546
  exports.refresh = refresh;
1329
1547
  exports.repeat = repeat;
1330
1548
  exports.resolve = resolve;
1549
+ exports.runWithOwner = runWithOwner;
1331
1550
  exports.sharedConfig = sharedConfig;
1332
1551
  exports.ssrHandleError = ssrHandleError;
1333
- exports.ssrRunInScope = ssrRunInScope;
1334
1552
  exports.untrack = untrack;
1335
1553
  exports.useContext = useContext;