@solidjs/signals 2.0.0-beta.9 → 2.0.0-rc.0

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.
Files changed (91) hide show
  1. package/README.md +13 -9
  2. package/dist/dev.js +5971 -1426
  3. package/dist/node.cjs +7681 -3293
  4. package/dist/prod/affects.js +126 -0
  5. package/dist/prod/boundaries.js +572 -0
  6. package/dist/prod/core/action.js +139 -0
  7. package/dist/prod/core/async.js +553 -0
  8. package/dist/prod/core/constants.js +92 -0
  9. package/dist/prod/core/context.js +67 -0
  10. package/dist/prod/core/core.js +817 -0
  11. package/dist/prod/core/dev.js +3 -0
  12. package/dist/prod/core/effect.js +145 -0
  13. package/dist/prod/core/error.js +68 -0
  14. package/dist/prod/core/external.js +98 -0
  15. package/dist/prod/core/graph.js +104 -0
  16. package/dist/prod/core/heap.js +140 -0
  17. package/dist/prod/core/invariants.js +42 -0
  18. package/dist/prod/core/lanes.js +140 -0
  19. package/dist/prod/core/optimistic.js +245 -0
  20. package/dist/prod/core/owner.js +302 -0
  21. package/dist/prod/core/scheduler.js +749 -0
  22. package/dist/prod/core/verdict.js +369 -0
  23. package/dist/prod/index.js +45 -0
  24. package/dist/prod/map.js +317 -0
  25. package/dist/prod/signals.js +375 -0
  26. package/dist/prod/store/optimistic.js +217 -0
  27. package/dist/prod/store/projection.js +231 -0
  28. package/dist/prod/store/reconcile.js +707 -0
  29. package/dist/prod/store/store.js +1081 -0
  30. package/dist/prod/store/storePath.js +103 -0
  31. package/dist/prod/store/utils.js +328 -0
  32. package/dist/types/affects.d.ts +47 -0
  33. package/dist/types/boundaries.d.ts +60 -13
  34. package/dist/types/core/action.d.ts +35 -6
  35. package/dist/types/core/async.d.ts +16 -1
  36. package/dist/types/core/constants.d.ts +35 -6
  37. package/dist/types/core/context.d.ts +10 -2
  38. package/dist/types/core/core.d.ts +58 -63
  39. package/dist/types/core/dev.d.ts +17 -2
  40. package/dist/types/core/effect.d.ts +1 -2
  41. package/dist/types/core/error.d.ts +33 -0
  42. package/dist/types/core/external.d.ts +0 -11
  43. package/dist/types/core/graph.d.ts +2 -1
  44. package/dist/types/core/heap.d.ts +8 -0
  45. package/dist/types/core/index.d.ts +3 -2
  46. package/dist/types/core/invariants.d.ts +59 -0
  47. package/dist/types/core/lanes.d.ts +2 -0
  48. package/dist/types/core/optimistic.d.ts +6 -0
  49. package/dist/types/core/owner.d.ts +50 -3
  50. package/dist/types/core/scheduler.d.ts +82 -10
  51. package/dist/types/core/types.d.ts +66 -1
  52. package/dist/types/core/verdict.d.ts +2 -0
  53. package/dist/types/index.d.ts +3 -2
  54. package/dist/types/map.d.ts +21 -5
  55. package/dist/types/signals.d.ts +164 -12
  56. package/dist/types/store/index.d.ts +1 -1
  57. package/dist/types/store/optimistic.d.ts +3 -3
  58. package/dist/types/store/projection.d.ts +10 -6
  59. package/dist/types/store/reconcile.d.ts +31 -8
  60. package/dist/types/store/store.d.ts +101 -6
  61. package/dist/types-cjs/affects.d.cts +47 -0
  62. package/dist/types-cjs/boundaries.d.cts +60 -13
  63. package/dist/types-cjs/core/action.d.cts +35 -6
  64. package/dist/types-cjs/core/async.d.cts +16 -1
  65. package/dist/types-cjs/core/constants.d.cts +35 -6
  66. package/dist/types-cjs/core/context.d.cts +10 -2
  67. package/dist/types-cjs/core/core.d.cts +58 -63
  68. package/dist/types-cjs/core/dev.d.cts +17 -2
  69. package/dist/types-cjs/core/effect.d.cts +1 -2
  70. package/dist/types-cjs/core/error.d.cts +33 -0
  71. package/dist/types-cjs/core/external.d.cts +0 -11
  72. package/dist/types-cjs/core/graph.d.cts +2 -1
  73. package/dist/types-cjs/core/heap.d.cts +8 -0
  74. package/dist/types-cjs/core/index.d.cts +3 -2
  75. package/dist/types-cjs/core/invariants.d.cts +59 -0
  76. package/dist/types-cjs/core/lanes.d.cts +2 -0
  77. package/dist/types-cjs/core/optimistic.d.cts +6 -0
  78. package/dist/types-cjs/core/owner.d.cts +50 -3
  79. package/dist/types-cjs/core/scheduler.d.cts +82 -10
  80. package/dist/types-cjs/core/types.d.cts +66 -1
  81. package/dist/types-cjs/core/verdict.d.cts +2 -0
  82. package/dist/types-cjs/index.d.cts +3 -2
  83. package/dist/types-cjs/map.d.cts +21 -5
  84. package/dist/types-cjs/signals.d.cts +164 -12
  85. package/dist/types-cjs/store/index.d.cts +1 -1
  86. package/dist/types-cjs/store/optimistic.d.cts +3 -3
  87. package/dist/types-cjs/store/projection.d.cts +10 -6
  88. package/dist/types-cjs/store/reconcile.d.cts +31 -8
  89. package/dist/types-cjs/store/store.d.cts +101 -6
  90. package/package.json +11 -9
  91. package/dist/prod.js +0 -3627
@@ -0,0 +1,126 @@
1
+ import { forEachDependent } from "./core/async.js";
2
+
3
+ import { $REFRESH, STATUS_PENDING } from "./core/constants.js";
4
+
5
+ import { NotReadyError } from "./core/error.js";
6
+
7
+ import "./core/core.js";
8
+
9
+ import { GlobalQueue, globalQueue, schedule, shiftAffectsMarks } from "./core/scheduler.js";
10
+
11
+ import "./core/verdict.js";
12
+
13
+ import "./core/effect.js";
14
+
15
+ import "./core/invariants.js";
16
+
17
+ import { $TARGET, getStoreAffectsNodes } from "./store/store.js";
18
+
19
+ /**
20
+ * The counting half of a mark, shared by direct registration and store-scope
21
+ * inheritance (a node created inside a live keyless mark's identity scope).
22
+ * A mark is ONLY this count: coverage of everything derived from the node is
23
+ * pull-derived by the verdict layer's `markWalk` (dep-graph reachability), so
24
+ * nothing is stored downstream and nothing can be stranded or stripped by
25
+ * mid-window recomputes.
26
+ */ function markAffects(e) {
27
+ e.t = (e.t || 0) + 1;
28
+ shiftAffectsMarks(1);
29
+ }
30
+
31
+ /**
32
+ * Boundary visual channel: within a transaction, a live mark holds Loading
33
+ * fallbacks / reveal ordering the way real in-flight async would — but the
34
+ * notification is tagged visibility-only at the source (`_markVisual`), so
35
+ * the root queue never registers reporters from it: marks are invisible to
36
+ * ALL completion and settlement accounting by construction. Boundaries hold
37
+ * the marked node in `_sources` while `_affectsCount` is live; the release
38
+ * sweep (finalizePureQueue re-checks boundary children after mark release)
39
+ * is the display-state update point. Ambient marks release inside the same
40
+ * flush that would surface them, before effects run — verdict-only, netting
41
+ * no visual change.
42
+ */ function notifyMarkBoundaries(e) {
43
+ if (!e.o && !e.u) return;
44
+ const r = new NotReadyError(e);
45
+ r.l = true;
46
+ const t = new Set;
47
+ const visit = e => {
48
+ if (t.has(e)) return;
49
+ t.add(e);
50
+ // Display consumers (render effects, boundary computeds) act on the
51
+ // notification; descent stops there, exactly like the status rails.
52
+ if (e.i) {
53
+ e.i(STATUS_PENDING, r);
54
+ return;
55
+ }
56
+ forEachDependent(e, visit);
57
+ };
58
+ forEachDependent(e, visit);
59
+ }
60
+
61
+ /**
62
+ * Registers one `affects()` mark on a node: counts it, records the
63
+ * registration with the current transaction (after initTransition the queue's
64
+ * batch IS the active transition, mirroring `_optimisticNodes`), re-derives
65
+ * every downstream verdict companion (the mark channel's only push — verdict
66
+ * pokes, not state), and notifies boundary display state. Both walks run on
67
+ * every registration (not just the first): subscribers gained since an
68
+ * earlier overlapping registration get covered, and dedup stops re-descent.
69
+ */ function registerAffectsMark(e) {
70
+ markAffects(e);
71
+ globalQueue.m.A.push(e);
72
+ // Companions only exist once the verdict layer (isPending/latest) loaded;
73
+ // without them there is no materialized verdict to poke.
74
+ GlobalQueue.k !== null && GlobalQueue.k(e);
75
+ notifyMarkBoundaries(e);
76
+ schedule();
77
+ }
78
+
79
+ /**
80
+ * Releases one registration. When the node's last mark drops, re-derives
81
+ * every downstream verdict through the settlement snap (committed, not
82
+ * transition-scoped — release runs inside queue finalization, where a
83
+ * setSignal would open a fresh override window that nothing settles).
84
+ */ function releaseAffectsMark(e) {
85
+ shiftAffectsMarks(-1);
86
+ e.t--;
87
+ if (!e.t) {
88
+ GlobalQueue.k !== null && GlobalQueue.k(e, true);
89
+ GlobalQueue.p?.(e);
90
+ }
91
+ }
92
+
93
+ /**
94
+ * Releases one batch of affects marks (a settling transaction's, or the
95
+ * ambient batch at a plain flush end).
96
+ */ function releaseAffectsMarks(e) {
97
+ for (let r = 0; r < e.length; r++) releaseAffectsMark(e[r]);
98
+ e.length = 0;
99
+ }
100
+
101
+ // Late installation (same pattern as `GlobalQueue._update`): the mark engine
102
+ // lives with the feature so graphs that never declare a mark never ship it.
103
+ // Each call site is gated by state only this module creates (a non-empty
104
+ // `_affectsNodes` batch, a live scope in the store's `affectsScopes`), so the
105
+ // hooks are installed before the first time any of them can fire.
106
+ GlobalQueue.G = releaseAffectsMarks;
107
+
108
+ GlobalQueue.M = markAffects;
109
+
110
+ GlobalQueue.h = releaseAffectsMark;
111
+
112
+ function affects(e, r) {
113
+ const t = e?.[$TARGET];
114
+ if (t) {
115
+ const e = getStoreAffectsNodes(t, r);
116
+ for (let r = 0; r < e.length; r++) registerAffectsMark(e[r]);
117
+ return;
118
+ }
119
+ const o = e?.[$REFRESH];
120
+ if (o) {
121
+ registerAffectsMark(o);
122
+ return;
123
+ }
124
+ }
125
+
126
+ export { affects };
@@ -0,0 +1,572 @@
1
+ import { runWithOwner, signal, untrack, read, computed, setSignal, recompute } from "./core/core.js";
2
+
3
+ import { NotReadyError, unwrapStatusError } from "./core/error.js";
4
+
5
+ import { createOwner, cleanup } from "./core/owner.js";
6
+
7
+ import { Queue, haltReactivity, schedule } from "./core/scheduler.js";
8
+
9
+ import { getContext, setContext, createContext } from "./core/context.js";
10
+
11
+ import { STATUS_PENDING, STATUS_ERROR, REACTIVE_DISPOSED, CONFIG_AUTO_DISPOSE } from "./core/constants.js";
12
+
13
+ import "./core/invariants.js";
14
+
15
+ import "./core/verdict.js";
16
+
17
+ import "./core/effect.js";
18
+
19
+ import { accessor } from "./signals.js";
20
+
21
+ function boundaryComputed(e, t) {
22
+ const r = computed(e, {
23
+ lazy: true
24
+ });
25
+ r.i = (e, t) => {
26
+ // Use passed values if provided, otherwise read from node
27
+ const n = e !== undefined ? e : r.S;
28
+ const s = t !== undefined ? t : r._;
29
+ // Notify both status dimensions like a render effect does; the queue chain
30
+ // consumes this boundary's own type and forwards the remainder upward until
31
+ // a boundary that handles it is found.
32
+ r.S &= ~r.R;
33
+ const i = r.C.notify(r, STATUS_PENDING | STATUS_ERROR, n, s);
34
+ // The queue is the only propagation channel: a foreign status must not stay
35
+ // reader-visible on the tree, or reads re-throw it across the boundary and
36
+ // link unrelated ambient contexts (the #2809 nested-boundary loop). Deps are
37
+ // untouched, so the tree still recomputes when the foreign source settles.
38
+ const o = n & ~r.R & (STATUS_PENDING | STATUS_ERROR);
39
+ if (o) {
40
+ r.S &= ~o;
41
+ if (r._ === s && !(r.S & (STATUS_PENDING | STATUS_ERROR))) r._ = undefined;
42
+ }
43
+ // An ERROR the chain could not deliver to any boundary is uncaught. The
44
+ // scrub above already removed it from reader-visible state, so without
45
+ // escalation here it would vanish entirely (#2884) — halt-and-throw,
46
+ // exactly like an unhandled effect error.
47
+ if (!i && n & STATUS_ERROR) {
48
+ haltReactivity(unwrapStatusError(s));
49
+ throw s;
50
+ }
51
+ };
52
+ r.R = t;
53
+ r.T &= ~CONFIG_AUTO_DISPOSE;
54
+ recompute(r, true);
55
+ return r;
56
+ }
57
+
58
+ function createBoundChildren(e, t, r, n) {
59
+ const s = e.C;
60
+ s.addChild(e.C = r);
61
+ cleanup(() => s.removeChild(e.C));
62
+ return runWithOwner(e, () => {
63
+ const e = computed(t);
64
+ return boundaryComputed(() => flatten(read(e)), n);
65
+ });
66
+ }
67
+
68
+ const ON_INIT = Symbol();
69
+
70
+ const RevealControllerContext = /* @__PURE__ */ createContext(null);
71
+
72
+ let _revealUsed = false;
73
+
74
+ const FALSE_ACCESSOR = () => false;
75
+
76
+ const SEQUENTIAL_ACCESSOR = () => "sequential";
77
+
78
+ function isRevealController(e) {
79
+ return e instanceof RevealController;
80
+ }
81
+
82
+ function isSlotReady(e) {
83
+ return isRevealController(e) ? e.O() : e.v.size === 0 && !e.N;
84
+ }
85
+
86
+ function isSlotMinimallyReady(e) {
87
+ return isRevealController(e) ? e.U() : isSlotReady(e);
88
+ }
89
+
90
+ function setSlotState(e, t, r, n) {
91
+ setSignal(e.I, r);
92
+ setSignal(e.D, n);
93
+ if (isRevealController(e)) {
94
+ if (!r && e.P === t) e.P = undefined;
95
+ return e.j(r, n);
96
+ }
97
+ if (!r && e.B === t && e.W) e.B = undefined;
98
+ }
99
+
100
+ class RevealController {
101
+ L;
102
+ F;
103
+ q=[];
104
+ P;
105
+ I=signal(false, {
106
+ ownedWrite: true,
107
+ V: true
108
+ });
109
+ D=signal(false, {
110
+ ownedWrite: true,
111
+ V: true
112
+ });
113
+ H=true;
114
+ J=true;
115
+ K=false;
116
+ constructor(e, t) {
117
+ this.L = e;
118
+ this.F = t;
119
+ }
120
+ X(e) {
121
+ for (let t = 0; t < this.q.length; t++) {
122
+ const r = this.q[t];
123
+ if ((isRevealController(r) ? r.P : r.B) !== this) continue;
124
+ if (e(r) === false) return false;
125
+ }
126
+ return true;
127
+ }
128
+ O() {
129
+ return this.X(isSlotReady);
130
+ }
131
+ /**
132
+ * "Minimally ready" = this group has something visible to show under its own policy.
133
+ * Used by an enclosing `together` group to decide when it can release.
134
+ * - `together`: every direct slot is minimally ready.
135
+ * - `sequential`: the first owned slot is minimally ready (frontier can advance).
136
+ * - `natural`: any owned slot is minimally ready.
137
+ */ U() {
138
+ const e = untrack(this.L);
139
+ if (e === "together") return this.X(isSlotMinimallyReady);
140
+ if (e === "natural") {
141
+ let e = false;
142
+ let t = false;
143
+ this.X(r => {
144
+ e = true;
145
+ if (isSlotMinimallyReady(r)) {
146
+ t = true;
147
+ return false;
148
+ }
149
+ });
150
+ return !e || t;
151
+ }
152
+ // sequential: only the first owned slot matters.
153
+ let t = true;
154
+ this.X(e => {
155
+ t = isSlotMinimallyReady(e);
156
+ return false;
157
+ });
158
+ return t;
159
+ }
160
+ Y(e) {
161
+ if (this.q.includes(e)) return;
162
+ this.q.push(e);
163
+ const t = untrack(this.L);
164
+ setSignal(e.I, true), setSignal(e.D, t === "sequential" ? !!untrack(this.F) : false);
165
+ untrack(() => this.j());
166
+ }
167
+ Z(e) {
168
+ const t = this.q.indexOf(e);
169
+ if (t >= 0) this.q.splice(t, 1);
170
+ untrack(() => this.j());
171
+ }
172
+ j(e, t) {
173
+ if (this.K) return;
174
+ this.K = true;
175
+ const r = this.H;
176
+ const n = this.J;
177
+ try {
178
+ const r = e ?? read(this.I), n = untrack(this.L), s = n === "sequential" && !!untrack(this.F), i = t ?? s;
179
+ if (r) {
180
+ // Held by an outer group. Propagate the hold (and whatever collapsed policy
181
+ // the outer asked for) down the whole subtree. Inner order is ignored while
182
+ // held; it resumes once the outer releases us.
183
+ this.X(e => setSlotState(e, this, true, i));
184
+ } else if (n === "natural") {
185
+ // Each child reveals based on its own readiness. A nested controller slot
186
+ // is released to run its own order locally — we bypass setSlotState for it
187
+ // so the parent backpointer survives for upward readiness notifications.
188
+ this.X(e => {
189
+ if (isRevealController(e)) {
190
+ setSignal(e.D, false);
191
+ setSignal(e.I, false);
192
+ e.j(false, false);
193
+ } else {
194
+ setSlotState(e, this, !isSlotReady(e), false);
195
+ }
196
+ });
197
+ } else if (n === "together") {
198
+ // Release when every direct slot is minimally ready (has something to show
199
+ // under its own order). A fully-ready inner together is minimally ready;
200
+ // sequential's first slot being ready is minimally ready; natural having any
201
+ // ready child is minimally ready. This lets `together` guarantee a single
202
+ // cohesive reveal without waiting for every grandchild.
203
+ const e = this.X(isSlotMinimallyReady);
204
+ this.X(t => setSlotState(t, this, !e, false));
205
+ } else {
206
+ let e = false;
207
+ this.X(t => {
208
+ if (e) return setSlotState(t, this, true, s);
209
+ if (isSlotReady(t)) return setSlotState(t, this, false, false);
210
+ e = true;
211
+ // Frontier slot. For a leaf, holding `_disabled=true` is what keeps its
212
+ // fallback visible. For a composite, we instead release it so it runs
213
+ // its own order locally — its leaves will each show their own fallback
214
+ // until their data lands. Outer still waits on full readiness before
215
+ // advancing past this slot, and we bypass setSlotState so the parent
216
+ // backpointer survives for upward readiness notifications.
217
+ if (isRevealController(t)) {
218
+ setSignal(t.D, false);
219
+ setSignal(t.I, false);
220
+ t.j(false, false);
221
+ } else {
222
+ setSlotState(t, this, true, false);
223
+ }
224
+ });
225
+ }
226
+ } finally {
227
+ this.H = this.O();
228
+ this.J = this.U();
229
+ this.K = false;
230
+ }
231
+ if (this.P && (r !== this.H || n !== this.J)) this.P.j();
232
+ }
233
+ }
234
+
235
+ class CollectionQueue extends Queue {
236
+ $;
237
+ v=new Set;
238
+ ee;
239
+ N=true;
240
+ I=signal(false, {
241
+ ownedWrite: true,
242
+ V: true
243
+ });
244
+ _;
245
+ D=signal(false, {
246
+ ownedWrite: true,
247
+ V: true
248
+ });
249
+ B;
250
+ W=false;
251
+ te;
252
+ re=ON_INIT;
253
+ constructor(e) {
254
+ super();
255
+ this.$ = e;
256
+ }
257
+ run(e) {
258
+ if (!e || read(this.I) && (!_revealUsed || read(this.D))) return;
259
+ return super.run(e);
260
+ }
261
+ notify(e, t, r, n) {
262
+ if (!(t & this.$)) return super.notify(e, t, r, n);
263
+ if (this.W && this.te) {
264
+ const e = untrack(() => {
265
+ try {
266
+ return this.te();
267
+ } catch {
268
+ return ON_INIT;
269
+ }
270
+ });
271
+ if (e !== this.re) {
272
+ this.re = e;
273
+ this.W = false;
274
+ this.v.clear();
275
+ }
276
+ }
277
+ // Routing is dimension-independent: each boundary consumes only its own
278
+ // status dimension from the mask (`type &= ~collectionType` below) and
279
+ // forwards the remainder up the queue chain. An error inside a `Loading`
280
+ // needs no special rule — the ERROR dimension survives consumption here and
281
+ // reaches the `Errored` that catches it natively, and `flags & collectionType`
282
+ // keeps this boundary from collecting a node that isn't actually pending.
283
+ // Symmetrically, a pending inside an `Errored` forwards on the PENDING
284
+ // dimension, while a status already caught by an inner boundary arrives with
285
+ // its dimension consumed from the mask and is correctly not re-routed
286
+ // (the Loading > Errored > content composition escape, #2856).
287
+ if (this.$ & STATUS_PENDING && this.W) return super.notify(e, t, r, n);
288
+ if (r & this.$) {
289
+ this.N = true;
290
+ const t = n?.source || e._?.source;
291
+ if (t) {
292
+ const e = this.v.size === 0;
293
+ this.v.add(t);
294
+ if (e) setSignal(this.I, true);
295
+ if (this.$ & STATUS_ERROR) {
296
+ setSignal(this._, unwrapStatusError(t._));
297
+ }
298
+ }
299
+ }
300
+ t &= ~this.$;
301
+ return t ? super.notify(e, t, r, n) : true;
302
+ }
303
+ ne() {
304
+ for (const e of this.v) {
305
+ // A source with a live affects() mark holds display state for the
306
+ // mark's lifetime (the visual channel): the marked node carries no
307
+ // status of its own, so the count is the liveness test. The release
308
+ // sweep (finalizePureQueue after mark release) re-runs this check.
309
+ if (e.se & REACTIVE_DISPOSED || !e.t && !(e.S & this.$) && !(this.$ & STATUS_ERROR && e.S & STATUS_PENDING)) this.v.delete(e);
310
+ }
311
+ if (!this.v.size) {
312
+ if (this.$ & STATUS_PENDING && this.N && !this.W && this.ee) {
313
+ this.N = !!(this.ee.S & this.$);
314
+ } else {
315
+ this.N = false;
316
+ }
317
+ if (!this.N) {
318
+ setSignal(this.I, false);
319
+ if (this.te) {
320
+ try {
321
+ this.re = untrack(() => this.te());
322
+ } catch {
323
+ /* value not yet committed — _prevOn stays stale, next notify will reset */}
324
+ }
325
+ }
326
+ }
327
+ if (_revealUsed) this.B?.j();
328
+ }
329
+ }
330
+
331
+ function createCollectionBoundary(e, t, r, n) {
332
+ const s = createOwner();
333
+ if (_revealUsed) setContext(RevealControllerContext, null, s);
334
+ const i = new CollectionQueue(e);
335
+ if (e === STATUS_ERROR) i._ = signal(undefined, {
336
+ ownedWrite: true,
337
+ V: true
338
+ });
339
+ if (n) i.te = n;
340
+ const o = i.ee = createBoundChildren(s, t, i, e);
341
+ // Prime source tracking so reveal registration sees pending sources.
342
+ untrack(() => {
343
+ let t = false;
344
+ try {
345
+ read(o);
346
+ } catch (e) {
347
+ if (e instanceof NotReadyError) t = true; else throw e;
348
+ }
349
+ i.N = t || !!(o.S & e) || o._ instanceof NotReadyError;
350
+ });
351
+ const l = _revealUsed && e === STATUS_PENDING ? getContext(RevealControllerContext) : null;
352
+ if (l) {
353
+ i.B = l;
354
+ l.Y(i);
355
+ cleanup(() => l.Z(i));
356
+ }
357
+ return accessor(computed(() => {
358
+ if (!read(i.I)) {
359
+ const e = read(o);
360
+ if (!untrack(() => read(i.I))) return i.W = true, e;
361
+ }
362
+ // Collapsed reveal slots suppress their own output entirely; the
363
+ // renderer treats the hole as empty, so the cast never leaks to users
364
+ // outside a `createRevealOrder` scope.
365
+ if (_revealUsed && read(i.D)) return undefined;
366
+ return r(i);
367
+ },
368
+ // Boundary structure, not a user source: its value is fallback-or-content and
369
+ // legitimately swaps mid-hydration (reveal/resume), so it must never be frozen
370
+ // by snapshot capture. The tree no longer carries foreign status flags, so
371
+ // capture can't rely on PENDING to skip this node the way it used to.
372
+ {
373
+ V: true
374
+ }));
375
+ }
376
+
377
+ /**
378
+ * Lower-level primitive that backs the `<Loading>` flow control. Catches
379
+ * pending async reads inside `fn` and renders `fallback` until they settle.
380
+ *
381
+ * App code should use `<Loading fallback={...}>` instead — reach for this only
382
+ * when authoring custom boundary components.
383
+ *
384
+ * @param fn the tracked subtree
385
+ * @param fallback the fallback shown while async reads in `fn` are unresolved
386
+ * @param options `on` — accessor whose value scopes the boundary; when set,
387
+ * transitions caused by writes to other reactive sources are *not* caught
388
+ *
389
+ * @example
390
+ * ```tsx
391
+ * // Custom boundary component built on top of the primitive.
392
+ * function MyLoading(props: { fallback: JSX.Element; children: JSX.Element }) {
393
+ * return createLoadingBoundary(
394
+ * () => props.children,
395
+ * () => props.fallback
396
+ * ) as unknown as JSX.Element;
397
+ * }
398
+ * ```
399
+ */ function createLoadingBoundary(e, t, r) {
400
+ return createCollectionBoundary(STATUS_PENDING, e, () => t(), r?.on);
401
+ }
402
+
403
+ /**
404
+ * Lower-level primitive that backs the `<Errored>` flow control. Catches
405
+ * thrown errors inside `fn` and invokes `fallback(error, reset)` instead.
406
+ * `error` is an accessor for the latest captured error; `reset()` recomputes
407
+ * the failing sources so the boundary can attempt to recover.
408
+ *
409
+ * App code should use `<Errored fallback={...}>` instead — reach for this only
410
+ * when authoring custom boundary components.
411
+ *
412
+ * @example
413
+ * ```tsx
414
+ * // Custom boundary that wraps the primitive and adds telemetry.
415
+ * function TracedErrored(props: { fallback: (e: () => unknown) => JSX.Element; children: JSX.Element }) {
416
+ * return createErrorBoundary(
417
+ * () => props.children,
418
+ * (err, reset) => {
419
+ * reportError(err());
420
+ * return props.fallback(err);
421
+ * }
422
+ * ) as unknown as JSX.Element;
423
+ * }
424
+ * ```
425
+ */ function createErrorBoundary(e, t) {
426
+ return createCollectionBoundary(STATUS_ERROR, e, e => t(accessor(e._), () => {
427
+ for (const t of e.v) recompute(t);
428
+ schedule();
429
+ }));
430
+ }
431
+
432
+ /**
433
+ * Coordinate the reveal timing of sibling loading boundaries.
434
+ *
435
+ * Accepts reactive accessors:
436
+ * - `order`: `"sequential"` (default) | `"together"` | `"natural"`.
437
+ * - `"sequential"` — classic frontier reveal: siblings reveal in registration order
438
+ * as each resolves; later siblings stay hidden until earlier ones complete.
439
+ * - `"together"` — every direct slot stays on its fallback until the whole group
440
+ * is "minimally ready" (each direct slot has produced its own first visible
441
+ * content under its own order), then the whole group releases at once.
442
+ * - `"natural"` — children reveal independently (as each resolves). At the top
443
+ * level this is a no-op compared to not using `createRevealOrder`; the mode
444
+ * exists for nesting, where the group registers as a single composite slot to
445
+ * any enclosing `createRevealOrder`.
446
+ * - `collapsed`: only meaningful when `order === "sequential"`. When set, tail siblings
447
+ * past the frontier suppress their own fallback output. Ignored under `"together"`
448
+ * and `"natural"` — those orders have no frontier.
449
+ *
450
+ * Nested `createRevealOrder` groups compose: the inner controller registers as a
451
+ * single slot in the outer controller and is held on its fallbacks until the outer
452
+ * releases that slot. Once released, the inner controller runs its own order locally
453
+ * over anything still pending. There is no opt-out from an outer hold.
454
+ *
455
+ * "Minimally ready" is what an order considers its first visible content:
456
+ * - `sequential` — frontier-0 is minimally ready (leaf: on resolve; nested: via its
457
+ * own minimal signal).
458
+ * - `together` — every direct slot is minimally ready.
459
+ * - `natural` — any direct slot has visible content (leaves on resolve; nested
460
+ * composites via their own minimal signal).
461
+ *
462
+ * @example
463
+ * ```ts
464
+ * // Primitive form of `<Reveal>` — coordinate sibling loading boundaries
465
+ * // programmatically. App code uses the JSX `<Reveal>` component instead.
466
+ * // Both options are accessors so they can react to state changes.
467
+ * createRevealOrder(
468
+ * () => renderSiblings(),
469
+ * { order: () => mode(), collapsed: () => true }
470
+ * );
471
+ * ```
472
+ */ function createRevealOrder(e, t) {
473
+ _revealUsed = true;
474
+ const r = createOwner();
475
+ const n = getContext(RevealControllerContext);
476
+ const s = t?.order || SEQUENTIAL_ACCESSOR, i = t?.collapsed || FALSE_ACCESSOR;
477
+ const o = new RevealController(s, i);
478
+ setContext(RevealControllerContext, o, r);
479
+ return runWithOwner(r, () => {
480
+ const t = e();
481
+ computed(() => {
482
+ s();
483
+ i();
484
+ o.j();
485
+ });
486
+ if (n) {
487
+ o.P = n;
488
+ n.Y(o);
489
+ cleanup(() => n.Z(o));
490
+ }
491
+ return t;
492
+ });
493
+ }
494
+
495
+ /**
496
+ * Resolves a children value to its renderable form: unwraps zero-arg functions
497
+ * (accessors), recursively flattens arrays, and optionally skips
498
+ * non-rendering values (`null`, `undefined`, `true`, `false`, `""`).
499
+ *
500
+ * Used internally by flow components and by the renderer to walk a children
501
+ * tree. App code rarely needs this directly — see `children()` in `solid-js`
502
+ * for the user-facing helper that memoizes the result.
503
+ *
504
+ * @param children value or array of values to flatten
505
+ * @param options
506
+ * - `skipNonRendered` — drop values that won't render
507
+ * - `doNotUnwrap` — leave function children as-is (caller will resolve)
508
+ *
509
+ * @example
510
+ * ```ts
511
+ * // Custom renderer walking a children tree manually. Most authors should
512
+ * // use `children()` from solid-js, which memoizes the resolved value.
513
+ * function renderChildren(value: unknown): unknown {
514
+ * return flatten(value, { skipNonRendered: true });
515
+ * }
516
+ * ```
517
+ */ function flatten(e, t) {
518
+ if (typeof e === "function" && !e.length) {
519
+ if (t?.doNotUnwrap) return e;
520
+ do {
521
+ e = e();
522
+ } while (typeof e === "function" && !e.length);
523
+ }
524
+ if (t?.skipNonRendered && (e == null || e === true || e === false || e === "")) return;
525
+ if (Array.isArray(e)) {
526
+ let r = [];
527
+ if (flattenArray(e, r, t)) {
528
+ return () => {
529
+ let e = [];
530
+ flattenArray(r, e, {
531
+ ...t,
532
+ doNotUnwrap: false
533
+ });
534
+ return e;
535
+ };
536
+ }
537
+ return r;
538
+ }
539
+ return e;
540
+ }
541
+
542
+ function flattenArray(e, t = [], r) {
543
+ let n = null;
544
+ let s = false;
545
+ for (let i = 0; i < e.length; i++) {
546
+ try {
547
+ let n = e[i];
548
+ if (typeof n === "function" && !n.length) {
549
+ if (r?.doNotUnwrap) {
550
+ t.push(n);
551
+ s = true;
552
+ continue;
553
+ }
554
+ do {
555
+ n = n();
556
+ } while (typeof n === "function" && !n.length);
557
+ }
558
+ if (Array.isArray(n)) {
559
+ s = flattenArray(n, t, r);
560
+ } else if (r?.skipNonRendered && (n == null || n === true || n === false || n === "")) {
561
+ // skip
562
+ } else t.push(n);
563
+ } catch (e) {
564
+ if (!(e instanceof NotReadyError)) throw e;
565
+ n = e;
566
+ }
567
+ }
568
+ if (n) throw n;
569
+ return s;
570
+ }
571
+
572
+ export { CollectionQueue, RevealController, createErrorBoundary, createLoadingBoundary, createRevealOrder, flatten };