@solidjs/signals 2.0.0-rc.7 → 2.0.0-rc.9

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 (134) hide show
  1. package/dist/dev-shared.js +6357 -0
  2. package/dist/dev.attribution.js +2485 -0
  3. package/dist/dev.js +2851 -7027
  4. package/dist/observe/affects.js +129 -0
  5. package/dist/observe/attribution.js +7 -0
  6. package/dist/observe/boundaries.js +641 -0
  7. package/dist/observe/core/action.js +177 -0
  8. package/dist/observe/core/async.js +846 -0
  9. package/dist/observe/core/attribution-costs.js +66 -0
  10. package/dist/observe/core/attribution-feedback.js +282 -0
  11. package/dist/observe/core/attribution-hooks.js +82 -0
  12. package/dist/observe/core/attribution-queries.js +28 -0
  13. package/dist/observe/core/attribution.js +2095 -0
  14. package/dist/observe/core/constants.js +248 -0
  15. package/dist/{types-cjs/core/context.d.cts → observe/core/context.js} +37 -12
  16. package/dist/observe/core/core.js +1789 -0
  17. package/dist/observe/core/dev.js +293 -0
  18. package/dist/observe/core/effect.js +195 -0
  19. package/dist/observe/core/error-hooks.js +71 -0
  20. package/dist/observe/core/error.js +80 -0
  21. package/dist/observe/core/external.js +98 -0
  22. package/dist/observe/core/graph.js +155 -0
  23. package/dist/observe/core/heap.js +147 -0
  24. package/dist/observe/core/invariants.js +45 -0
  25. package/dist/observe/core/lanes.js +205 -0
  26. package/dist/observe/core/optimistic.js +585 -0
  27. package/dist/observe/core/owner.js +322 -0
  28. package/dist/observe/core/scheduler.js +1428 -0
  29. package/dist/observe/core/verdict.js +669 -0
  30. package/dist/observe/index.js +59 -0
  31. package/dist/observe/map.js +484 -0
  32. package/dist/{types-cjs/signals.d.cts → observe/signals.js} +311 -317
  33. package/dist/observe/store/index.js +40 -0
  34. package/dist/observe/store/next/optimistic.js +660 -0
  35. package/dist/observe/store/next/projection.js +255 -0
  36. package/dist/observe/store/next/reconcile.js +375 -0
  37. package/dist/observe/store/next/store.js +2327 -0
  38. package/dist/observe/store/next/target.js +51 -0
  39. package/dist/observe/store/store.js +325 -0
  40. package/dist/observe/store/storePath.js +103 -0
  41. package/dist/observe/store/utils.js +1023 -0
  42. package/dist/prod/attribution.js +41 -0
  43. package/dist/prod/boundaries.js +128 -76
  44. package/dist/prod/core/action.js +65 -37
  45. package/dist/prod/core/async.js +324 -172
  46. package/dist/prod/core/constants.js +57 -1
  47. package/dist/prod/core/context.js +3 -3
  48. package/dist/prod/core/core.js +1003 -364
  49. package/dist/prod/core/dev.js +17 -1
  50. package/dist/prod/core/effect.js +76 -42
  51. package/dist/prod/core/error-hooks.js +71 -0
  52. package/dist/prod/core/external.js +4 -4
  53. package/dist/prod/core/graph.js +37 -37
  54. package/dist/prod/core/heap.js +61 -56
  55. package/dist/prod/core/lanes.js +107 -63
  56. package/dist/prod/core/optimistic.js +374 -93
  57. package/dist/prod/core/owner.js +62 -46
  58. package/dist/prod/core/scheduler.js +653 -286
  59. package/dist/prod/core/verdict.js +245 -127
  60. package/dist/prod/index.js +15 -5
  61. package/dist/prod/map.js +292 -141
  62. package/dist/prod/signals.js +29 -16
  63. package/dist/prod/store/next/optimistic.js +77 -55
  64. package/dist/prod/store/next/projection.js +31 -20
  65. package/dist/prod/store/next/reconcile.js +87 -84
  66. package/dist/prod/store/next/store.js +718 -401
  67. package/dist/prod/store/next/target.js +32 -10
  68. package/dist/prod/store/store.js +12 -14
  69. package/dist/prod/store/utils.js +950 -130
  70. package/dist/types/attribution.d.ts +20 -0
  71. package/dist/types/attribution.prod.d.ts +22 -0
  72. package/dist/types/boundaries.d.ts +10 -1
  73. package/dist/types/core/action.d.ts +12 -5
  74. package/dist/types/core/async.d.ts +1 -1
  75. package/dist/types/core/attribution-costs.d.ts +35 -0
  76. package/dist/types/core/attribution-feedback.d.ts +133 -0
  77. package/dist/types/core/attribution-hooks.d.ts +147 -9
  78. package/dist/types/core/attribution-queries.d.ts +10 -0
  79. package/dist/types/core/attribution.d.ts +216 -182
  80. package/dist/types/core/constants.d.ts +56 -0
  81. package/dist/types/core/core.d.ts +190 -2
  82. package/dist/types/core/dev.d.ts +246 -28
  83. package/dist/types/core/effect.d.ts +8 -1
  84. package/dist/types/core/error-hooks.d.ts +71 -0
  85. package/dist/types/core/index.d.ts +4 -1
  86. package/dist/types/core/invariants.d.ts +4 -0
  87. package/dist/types/core/lanes.d.ts +39 -5
  88. package/dist/types/core/scheduler.d.ts +153 -0
  89. package/dist/types/core/types.d.ts +32 -9
  90. package/dist/types/index.d.ts +10 -3
  91. package/dist/types/map.d.ts +2 -0
  92. package/dist/types/signals.d.ts +8 -0
  93. package/dist/types/store/index.d.ts +2 -0
  94. package/dist/types/store/next/optimistic.d.ts +1 -1
  95. package/dist/types/store/next/store.d.ts +11 -5
  96. package/dist/types/store/next/target.d.ts +37 -10
  97. package/dist/types/store/utils.d.ts +178 -0
  98. package/package.json +21 -17
  99. package/dist/node.cjs +0 -10541
  100. package/dist/node.dev.cjs +0 -13724
  101. package/dist/types-cjs/affects.d.cts +0 -47
  102. package/dist/types-cjs/boundaries.d.cts +0 -175
  103. package/dist/types-cjs/core/action.d.cts +0 -64
  104. package/dist/types-cjs/core/async.d.cts +0 -23
  105. package/dist/types-cjs/core/attribution-hooks.d.cts +0 -127
  106. package/dist/types-cjs/core/attribution.d.cts +0 -495
  107. package/dist/types-cjs/core/constants.d.cts +0 -159
  108. package/dist/types-cjs/core/core.d.cts +0 -185
  109. package/dist/types-cjs/core/dev.d.cts +0 -136
  110. package/dist/types-cjs/core/effect.d.cts +0 -30
  111. package/dist/types-cjs/core/error.d.cts +0 -56
  112. package/dist/types-cjs/core/external.d.cts +0 -15
  113. package/dist/types-cjs/core/graph.d.cts +0 -28
  114. package/dist/types-cjs/core/heap.d.cts +0 -24
  115. package/dist/types-cjs/core/index.d.cts +0 -13
  116. package/dist/types-cjs/core/invariants.d.cts +0 -59
  117. package/dist/types-cjs/core/lanes.d.cts +0 -54
  118. package/dist/types-cjs/core/optimistic.d.cts +0 -6
  119. package/dist/types-cjs/core/owner.d.cts +0 -124
  120. package/dist/types-cjs/core/scheduler.d.cts +0 -236
  121. package/dist/types-cjs/core/types.d.cts +0 -204
  122. package/dist/types-cjs/core/verdict.d.cts +0 -2
  123. package/dist/types-cjs/index.d.cts +0 -10
  124. package/dist/types-cjs/map.d.cts +0 -69
  125. package/dist/types-cjs/package.json +0 -3
  126. package/dist/types-cjs/store/index.d.cts +0 -18
  127. package/dist/types-cjs/store/next/optimistic.d.cts +0 -25
  128. package/dist/types-cjs/store/next/projection.d.cts +0 -8
  129. package/dist/types-cjs/store/next/reconcile.d.cts +0 -10
  130. package/dist/types-cjs/store/next/store.d.cts +0 -121
  131. package/dist/types-cjs/store/next/target.d.cts +0 -166
  132. package/dist/types-cjs/store/store.d.cts +0 -143
  133. package/dist/types-cjs/store/storePath.d.cts +0 -58
  134. package/dist/types-cjs/store/utils.d.cts +0 -74
@@ -0,0 +1,641 @@
1
+ import { runWithOwner, signal, untrack, read, computed, spectate, setSignal, ext, 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, transitions, wakeParked, haltReactivity, schedule } from "./core/scheduler.js";
8
+
9
+ import { getContext, setContext, createContext } from "./core/context.js";
10
+
11
+ import { STATUS_PENDING, STATUS_ERROR, REACTIVE_ZOMBIE, REACTIVE_DISPOSED, CONFIG_AUTO_DISPOSE } from "./core/constants.js";
12
+
13
+ import { attrHooks } from "./core/attribution-hooks.js";
14
+
15
+ import "./core/invariants.js";
16
+
17
+ import "./core/dev.js";
18
+
19
+ import "./core/verdict.js";
20
+
21
+ import "./core/effect.js";
22
+
23
+ import { reportClientError } from "./core/error-hooks.js";
24
+
25
+ import { accessor } from "./signals.js";
26
+
27
+ function boundaryComputed(t, e) {
28
+ const r = computed(t, {
29
+ lazy: true
30
+ });
31
+ ext(r).h = (t, e) => {
32
+ // Use passed values if provided, otherwise read from node
33
+ const s = t !== undefined ? t : r.S;
34
+ const n = e !== undefined ? e : r.o?._;
35
+ // Notify both status dimensions like a render effect does; the queue chain
36
+ // consumes this boundary's own type and forwards the remainder upward until
37
+ // a boundary that handles it is found.
38
+ r.S &= ~r.R;
39
+ const i = r.T.notify(r, STATUS_PENDING | STATUS_ERROR, s, n);
40
+ // The queue is the only propagation channel: a foreign status must not stay
41
+ // reader-visible on the tree, or reads re-throw it across the boundary and
42
+ // link unrelated ambient contexts (the #2809 nested-boundary loop). Deps are
43
+ // untouched, so the tree still recomputes when the foreign source settles.
44
+ const o = s & ~r.R & (STATUS_PENDING | STATUS_ERROR);
45
+ if (o) {
46
+ r.S &= ~o;
47
+ if (r.o?._ === n && !(r.S & (STATUS_PENDING | STATUS_ERROR))) if (r.o !== null) r.o._ = undefined;
48
+ }
49
+ // An ERROR the chain could not deliver to any boundary is uncaught. The
50
+ // scrub above already removed it from reader-visible state, so without
51
+ // escalation here it would vanish entirely (#2884) — halt-and-throw,
52
+ // exactly like an unhandled effect error.
53
+ if (!i && s & STATUS_ERROR) {
54
+ haltReactivity(unwrapStatusError(n));
55
+ throw n;
56
+ }
57
+ };
58
+ r.R = e;
59
+ r.C &= ~CONFIG_AUTO_DISPOSE;
60
+ recompute(r, true);
61
+ return r;
62
+ }
63
+
64
+ function createBoundChildren(t, e, r, s) {
65
+ const n = t.T;
66
+ n.addChild(t.T = r);
67
+ cleanup(() => n.removeChild(t.T));
68
+ return runWithOwner(t, () => {
69
+ const t = computed(e);
70
+ return boundaryComputed(() => flatten(read(t)), s);
71
+ });
72
+ }
73
+
74
+ const ON_INIT = Symbol();
75
+
76
+ const RevealControllerContext = /* @__PURE__ */ createContext(null);
77
+
78
+ let _revealUsed = false;
79
+
80
+ const FALSE_ACCESSOR = () => false;
81
+
82
+ const SEQUENTIAL_ACCESSOR = () => "sequential";
83
+
84
+ function isRevealController(t) {
85
+ return t instanceof RevealController;
86
+ }
87
+
88
+ function isSlotReady(t) {
89
+ return isRevealController(t) ? t.N() : t.O.size === 0 && !t.I;
90
+ }
91
+
92
+ function isSlotMinimallyReady(t) {
93
+ return isRevealController(t) ? t.U() : isSlotReady(t);
94
+ }
95
+
96
+ function setSlotState(t, e, r, s) {
97
+ setSignal(t.v, r);
98
+ setSignal(t.D, s);
99
+ if (isRevealController(t)) {
100
+ if (!r && t.P === e) t.P = undefined;
101
+ return t.B(r, s);
102
+ }
103
+ if (!r && t.W === e && t.H) t.W = undefined;
104
+ }
105
+
106
+ class RevealController {
107
+ L;
108
+ F;
109
+ V=[];
110
+ P;
111
+ v=signal(false, {
112
+ ownedWrite: true,
113
+ q: true
114
+ });
115
+ D=signal(false, {
116
+ ownedWrite: true,
117
+ q: true
118
+ });
119
+ Z=true;
120
+ J=true;
121
+ K=false;
122
+ constructor(t, e) {
123
+ this.L = t;
124
+ this.F = e;
125
+ }
126
+ X(t) {
127
+ for (let e = 0; e < this.V.length; e++) {
128
+ const r = this.V[e];
129
+ if ((isRevealController(r) ? r.P : r.W) !== this) continue;
130
+ if (t(r) === false) return false;
131
+ }
132
+ return true;
133
+ }
134
+ N() {
135
+ return this.X(isSlotReady);
136
+ }
137
+ /**
138
+ * "Minimally ready" = this group has something visible to show under its own policy.
139
+ * Used by an enclosing `together` group to decide when it can release.
140
+ * - `together`: every direct slot is minimally ready.
141
+ * - `sequential`: the first owned slot is minimally ready (frontier can advance).
142
+ * - `natural`: any owned slot is minimally ready.
143
+ */ U() {
144
+ const t = untrack(this.L);
145
+ if (t === "together") return this.X(isSlotMinimallyReady);
146
+ if (t === "natural") {
147
+ let t = false;
148
+ let e = false;
149
+ this.X(r => {
150
+ t = true;
151
+ if (isSlotMinimallyReady(r)) {
152
+ e = true;
153
+ return false;
154
+ }
155
+ });
156
+ return !t || e;
157
+ }
158
+ // sequential: only the first owned slot matters.
159
+ let e = true;
160
+ this.X(t => {
161
+ e = isSlotMinimallyReady(t);
162
+ return false;
163
+ });
164
+ return e;
165
+ }
166
+ Y(t) {
167
+ if (this.V.includes(t)) return;
168
+ this.V.push(t);
169
+ const e = untrack(this.L);
170
+ setSignal(t.v, true), setSignal(t.D, e === "sequential" ? !!untrack(this.F) : false);
171
+ untrack(() => this.B());
172
+ }
173
+ $(t) {
174
+ const e = this.V.indexOf(t);
175
+ if (e >= 0) this.V.splice(e, 1);
176
+ untrack(() => this.B());
177
+ }
178
+ B(t, e) {
179
+ if (this.K) return;
180
+ this.K = true;
181
+ const r = this.Z;
182
+ const s = this.J;
183
+ try {
184
+ const r = t ?? read(this.v), s = untrack(this.L), n = s === "sequential" && !!untrack(this.F), i = e ?? n;
185
+ if (r) {
186
+ // Held by an outer group. Propagate the hold (and whatever collapsed policy
187
+ // the outer asked for) down the whole subtree. Inner order is ignored while
188
+ // held; it resumes once the outer releases us.
189
+ this.X(t => setSlotState(t, this, true, i));
190
+ } else if (s === "natural") {
191
+ // Each child reveals based on its own readiness. A nested controller slot
192
+ // is released to run its own order locally — we bypass setSlotState for it
193
+ // so the parent backpointer survives for upward readiness notifications.
194
+ this.X(t => {
195
+ if (isRevealController(t)) {
196
+ setSignal(t.D, false);
197
+ setSignal(t.v, false);
198
+ t.B(false, false);
199
+ } else {
200
+ setSlotState(t, this, !isSlotReady(t), false);
201
+ }
202
+ });
203
+ } else if (s === "together") {
204
+ // Release when every direct slot is minimally ready (has something to show
205
+ // under its own order). A fully-ready inner together is minimally ready;
206
+ // sequential's first slot being ready is minimally ready; natural having any
207
+ // ready child is minimally ready. This lets `together` guarantee a single
208
+ // cohesive reveal without waiting for every grandchild.
209
+ const t = this.X(isSlotMinimallyReady);
210
+ this.X(e => setSlotState(e, this, !t, false));
211
+ } else {
212
+ let t = false;
213
+ this.X(e => {
214
+ if (t) return setSlotState(e, this, true, n);
215
+ if (isSlotReady(e)) return setSlotState(e, this, false, false);
216
+ t = true;
217
+ // Frontier slot. For a leaf, holding `_disabled=true` is what keeps its
218
+ // fallback visible. For a composite, we instead release it so it runs
219
+ // its own order locally — its leaves will each show their own fallback
220
+ // until their data lands. Outer still waits on full readiness before
221
+ // advancing past this slot, and we bypass setSlotState so the parent
222
+ // backpointer survives for upward readiness notifications.
223
+ if (isRevealController(e)) {
224
+ setSignal(e.D, false);
225
+ setSignal(e.v, false);
226
+ e.B(false, false);
227
+ } else {
228
+ setSlotState(e, this, true, false);
229
+ }
230
+ });
231
+ }
232
+ } finally {
233
+ this.Z = this.N();
234
+ this.J = this.U();
235
+ this.K = false;
236
+ }
237
+ if (this.P && (r !== this.Z || s !== this.J)) this.P.B();
238
+ }
239
+ }
240
+
241
+ class CollectionQueue extends Queue {
242
+ tt;
243
+ O=new Set;
244
+ et;
245
+ I=true;
246
+ v=signal(false, {
247
+ ownedWrite: true,
248
+ q: true
249
+ });
250
+ _;
251
+ D=signal(false, {
252
+ ownedWrite: true,
253
+ q: true
254
+ });
255
+ W;
256
+ H=false;
257
+ rt;
258
+ st=ON_INIT;
259
+ /** The boundary's owner — where a `caught` report locates itself, set before the children are built (a creation-time throw arrives before `_tree`). */
260
+ nt;
261
+ constructor(t) {
262
+ super();
263
+ this.tt = t;
264
+ }
265
+ run(t) {
266
+ if (!t || read(this.v) && (!_revealUsed || read(this.D))) return;
267
+ return super.run(t);
268
+ }
269
+ /** The `on` key, or ON_INIT when it throws. Evaluated mid-propagation,
270
+ * inside the pending node's own pass: read as a spectator so the key's
271
+ * sources never become that node's dependencies (#3528). */ it() {
272
+ return spectate(() => {
273
+ try {
274
+ return this.rt();
275
+ } catch {
276
+ return ON_INIT;
277
+ }
278
+ });
279
+ }
280
+ notify(t, e, r, s) {
281
+ if (!(e & this.tt)) return super.notify(t, e, r, s);
282
+ if (this.H && this.rt) {
283
+ const t = this.it();
284
+ if (t !== this.st) {
285
+ this.st = t;
286
+ this.H = false;
287
+ this.O.clear();
288
+ // Readers forwarded while this boundary showed content are behind the
289
+ // fallback now: they stop blocking (`reporterBlocksSource`), and the
290
+ // transactions they were holding must be re-judged for it (A33, #3375).
291
+ // What those readers still wait on is this boundary's to wait on now:
292
+ // they never re-notify (status propagation dedupes on the reader's
293
+ // `_pendingSources`), so the reset collects it from their registrations
294
+ // — the one place a forwarded reader is recorded (INV-3) — or a sibling
295
+ // reader's flight that lands first reveals them stale (A33, #3459).
296
+ for (const t of transitions) for (const [e, r] of t.ot) for (const t of r) if (this.lt(t)) {
297
+ this.O.add(e);
298
+ t.o?.ut?.forEach(t => this.O.add(t));
299
+ }
300
+ if (this.O.size) {
301
+ setSignal(this.v, true);
302
+ if (attrHooks !== null && this.tt & STATUS_PENDING) attrHooks.boundaryFallback(this, this.et, true);
303
+ }
304
+ wakeParked();
305
+ }
306
+ }
307
+ // Routing is dimension-independent: each boundary consumes only its own
308
+ // status dimension from the mask (`type &= ~collectionType` below) and
309
+ // forwards the remainder up the queue chain. An error inside a `Loading`
310
+ // needs no special rule — the ERROR dimension survives consumption here and
311
+ // reaches the `Errored` that catches it natively, and `flags & collectionType`
312
+ // keeps this boundary from collecting a node that isn't actually pending.
313
+ // Symmetrically, a pending inside an `Errored` forwards on the PENDING
314
+ // dimension, while a status already caught by an inner boundary arrives with
315
+ // its dimension consumed from the mask and is correctly not re-routed
316
+ // (the Loading > Errored > content composition escape, #2856).
317
+ if (this.tt & STATUS_PENDING && this.H) return super.notify(t, e, r, s);
318
+ if (r & this.tt) {
319
+ this.I = true;
320
+ const e = s?.source || t.o?._?.source;
321
+ if (e) {
322
+ const r = this.O.size === 0;
323
+ this.O.add(e);
324
+ // A collecting boundary waits on everything the effect is pending on,
325
+ // not only the source this notification carries. Status propagation
326
+ // dedupes on the effect's `_pendingSources`: a source it already
327
+ // carries (a flight that started before an `on` reset cleared the
328
+ // set) is never re-reported, and that source's later re-flight
329
+ // stays invisible — the boundary revealed when its one collected
330
+ // source settled while the effect was still pending (#3375).
331
+ if (this.tt & STATUS_PENDING) t.o?.ut?.forEach(t => this.O.add(t));
332
+ if (r) {
333
+ setSignal(this.v, true);
334
+ if (attrHooks !== null && this.tt & STATUS_PENDING) attrHooks.boundaryFallback(this, this.et, true);
335
+ }
336
+ if (this.tt & STATUS_ERROR) {
337
+ const t = unwrapStatusError(e.o?._);
338
+ setSignal(this._, t);
339
+ // The client error hook: this boundary renders its fallback for
340
+ // it — the one road a rendered failure took that no global handler
341
+ // ever saw. `source` is the computation that threw (the status
342
+ // wrapper's, made at the first landing and kept downstream), so the
343
+ // hook hears where it broke as well as where it was met. Once per
344
+ // error object; a `reset()` re-collecting the same failure says
345
+ // nothing new.
346
+ reportClientError(t, this.nt, e);
347
+ }
348
+ }
349
+ }
350
+ e &= ~this.tt;
351
+ return e ? super.notify(t, e, r, s) : true;
352
+ }
353
+ /** Is `reporter` live and routed to this boundary — under it, with no
354
+ * collecting pending-type boundary in between (`reporterBlocksSource`'s test)? */ lt(t) {
355
+ if (t.ft & (REACTIVE_ZOMBIE | REACTIVE_DISPOSED)) return false;
356
+ for (let e = t.T; e; e = e._parent) {
357
+ if (e === this) return true;
358
+ if (e.tt & STATUS_PENDING && !e.H) return false;
359
+ }
360
+ return false;
361
+ }
362
+ ct() {
363
+ for (const t of this.O) {
364
+ // A source with a live affects() mark holds display state for the
365
+ // mark's lifetime (the visual channel): the marked node carries no
366
+ // status of its own, so the count is the liveness test. The release
367
+ // sweep (finalizePureQueue after mark release) re-runs this check.
368
+ if (t.ft & REACTIVE_DISPOSED || !t.o?.t && !(t.S & this.tt) && !(this.tt & STATUS_ERROR && t.S & STATUS_PENDING)) this.O.delete(t);
369
+ }
370
+ if (!this.O.size) {
371
+ if (this.tt & STATUS_PENDING && this.I && !this.H && this.et) {
372
+ this.I = !!(this.et.S & this.tt);
373
+ } else {
374
+ this.I = false;
375
+ }
376
+ if (!this.I) {
377
+ setSignal(this.v, false);
378
+ if (attrHooks !== null && this.tt & STATUS_PENDING) attrHooks.boundaryFallback(this, this.et, false);
379
+ if (this.rt) {
380
+ // A throw (value not yet committed) leaves _prevOn stale; the next
381
+ // notify then resets.
382
+ const t = this.it();
383
+ if (t !== ON_INIT) this.st = t;
384
+ }
385
+ }
386
+ }
387
+ if (_revealUsed) this.W?.B();
388
+ }
389
+ }
390
+
391
+ function createCollectionBoundary(t, e, r, s) {
392
+ const n = createOwner();
393
+ if (_revealUsed) setContext(RevealControllerContext, null, n);
394
+ const i = new CollectionQueue(t);
395
+ i.nt = n;
396
+ if (t === STATUS_ERROR) i._ = signal(undefined, {
397
+ ownedWrite: true,
398
+ q: true
399
+ });
400
+ if (s) i.rt = s;
401
+ const o = i.et = createBoundChildren(n, e, i, t);
402
+ // Prime source tracking so reveal registration sees pending sources.
403
+ untrack(() => {
404
+ let e = false;
405
+ try {
406
+ read(o);
407
+ } catch (t) {
408
+ if (t instanceof NotReadyError) e = true; else throw t;
409
+ }
410
+ i.I = e || !!(o.S & t) || o.o?._ instanceof NotReadyError;
411
+ });
412
+ const l = _revealUsed && t === STATUS_PENDING ? getContext(RevealControllerContext) : null;
413
+ if (l) {
414
+ i.W = l;
415
+ l.Y(i);
416
+ cleanup(() => l.$(i));
417
+ }
418
+ return accessor(computed(() => {
419
+ if (!read(i.v)) {
420
+ const t = read(o);
421
+ if (!untrack(() => read(i.v))) return i.H = true, t;
422
+ }
423
+ // Collapsed reveal slots suppress their own output entirely; the
424
+ // renderer treats the hole as empty, so the cast never leaks to users
425
+ // outside a `createRevealOrder` scope.
426
+ if (_revealUsed && read(i.D)) return undefined;
427
+ return r(i);
428
+ },
429
+ // Boundary structure, not a user source: its value is fallback-or-content and
430
+ // legitimately swaps mid-hydration (reveal/resume), so it must never be frozen
431
+ // by snapshot capture. The tree no longer carries foreign status flags, so
432
+ // capture can't rely on PENDING to skip this node the way it used to.
433
+ {
434
+ q: true
435
+ }));
436
+ }
437
+
438
+ /**
439
+ * Lower-level primitive that backs the `<Loading>` flow control. Catches
440
+ * pending async reads inside `fn` and renders `fallback` until they settle.
441
+ *
442
+ * App code should use `<Loading fallback={...}>` instead — reach for this only
443
+ * when authoring custom boundary components.
444
+ *
445
+ * @param fn the tracked subtree
446
+ * @param fallback the fallback shown while async reads in `fn` are unresolved
447
+ * @param options `on` — accessor whose value scopes the boundary; when set,
448
+ * transitions caused by writes to other reactive sources are *not* caught
449
+ *
450
+ * @example
451
+ * ```tsx
452
+ * // Custom boundary component built on top of the primitive.
453
+ * function MyLoading(props: { fallback: JSX.Element; children: JSX.Element }) {
454
+ * return createLoadingBoundary(
455
+ * () => props.children,
456
+ * () => props.fallback
457
+ * ) as unknown as JSX.Element;
458
+ * }
459
+ * ```
460
+ */ function createLoadingBoundary(t, e, r) {
461
+ return createCollectionBoundary(STATUS_PENDING, t, () => e(), r?.on);
462
+ }
463
+
464
+ /**
465
+ * Lower-level primitive that backs the `<Errored>` flow control. Catches
466
+ * thrown errors inside `fn` and invokes `fallback(error, reset)` instead.
467
+ * `error` is an accessor for the latest captured error; `reset()` recomputes
468
+ * the failing sources so the boundary can attempt to recover.
469
+ *
470
+ * App code should use `<Errored fallback={...}>` instead — reach for this only
471
+ * when authoring custom boundary components.
472
+ *
473
+ * @example
474
+ * ```tsx
475
+ * // Custom boundary that wraps the primitive and adds telemetry.
476
+ * function TracedErrored(props: { fallback: (e: () => unknown) => JSX.Element; children: JSX.Element }) {
477
+ * return createErrorBoundary(
478
+ * () => props.children,
479
+ * (err, reset) => {
480
+ * reportError(err());
481
+ * return props.fallback(err);
482
+ * }
483
+ * ) as unknown as JSX.Element;
484
+ * }
485
+ * ```
486
+ */ function createErrorBoundary(t, e) {
487
+ return createCollectionBoundary(STATUS_ERROR, t, t => e(accessor(t._), () => {
488
+ for (const e of t.O) {
489
+ // Non-computed sources (patch-channel registrations under plain
490
+ // owners) are not recomputable — their reset is the record's next
491
+ // transition re-applying the patch (re-audit 2, P1-4).
492
+ if (e.ht !== undefined) recompute(e);
493
+ }
494
+ schedule();
495
+ }));
496
+ }
497
+
498
+ /**
499
+ * Coordinate the reveal timing of sibling loading boundaries.
500
+ *
501
+ * Accepts reactive accessors:
502
+ * - `order`: `"sequential"` (default) | `"together"` | `"natural"`.
503
+ * - `"sequential"` — classic frontier reveal: siblings reveal in registration order
504
+ * as each resolves; later siblings stay hidden until earlier ones complete.
505
+ * - `"together"` — every direct slot stays on its fallback until the whole group
506
+ * is "minimally ready" (each direct slot has produced its own first visible
507
+ * content under its own order), then the whole group releases at once.
508
+ * - `"natural"` — children reveal independently (as each resolves). At the top
509
+ * level this is a no-op compared to not using `createRevealOrder`; the mode
510
+ * exists for nesting, where the group registers as a single composite slot to
511
+ * any enclosing `createRevealOrder`.
512
+ * - `collapsed`: only meaningful when `order === "sequential"`. When set, tail siblings
513
+ * past the frontier suppress their own fallback output. Ignored under `"together"`
514
+ * and `"natural"` — those orders have no frontier.
515
+ *
516
+ * Nested `createRevealOrder` groups compose: the inner controller registers as a
517
+ * single slot in the outer controller and is held on its fallbacks until the outer
518
+ * releases that slot. Once released, the inner controller runs its own order locally
519
+ * over anything still pending. There is no opt-out from an outer hold.
520
+ *
521
+ * "Minimally ready" is what an order considers its first visible content:
522
+ * - `sequential` — frontier-0 is minimally ready (leaf: on resolve; nested: via its
523
+ * own minimal signal).
524
+ * - `together` — every direct slot is minimally ready.
525
+ * - `natural` — any direct slot has visible content (leaves on resolve; nested
526
+ * composites via their own minimal signal).
527
+ *
528
+ * @example
529
+ * ```ts
530
+ * // Primitive form of `<Reveal>` — coordinate sibling loading boundaries
531
+ * // programmatically. App code uses the JSX `<Reveal>` component instead.
532
+ * // Both options are accessors so they can react to state changes.
533
+ * createRevealOrder(
534
+ * () => renderSiblings(),
535
+ * { order: () => mode(), collapsed: () => true }
536
+ * );
537
+ * ```
538
+ */ function createRevealOrder(t, e) {
539
+ _revealUsed = true;
540
+ const r = createOwner();
541
+ const s = getContext(RevealControllerContext);
542
+ const n = e?.order || SEQUENTIAL_ACCESSOR, i = e?.collapsed || FALSE_ACCESSOR;
543
+ const o = new RevealController(n, i);
544
+ setContext(RevealControllerContext, o, r);
545
+ return runWithOwner(r, () => {
546
+ const e = t();
547
+ computed(() => {
548
+ n();
549
+ i();
550
+ o.B();
551
+ });
552
+ if (s) {
553
+ o.P = s;
554
+ s.Y(o);
555
+ cleanup(() => s.$(o));
556
+ }
557
+ return e;
558
+ });
559
+ }
560
+
561
+ /**
562
+ * Resolves a children value to its renderable form: unwraps zero-arg functions
563
+ * (accessors), recursively flattens arrays, and optionally skips
564
+ * non-rendering values (`null`, `undefined`, `true`, `false`, `""`).
565
+ *
566
+ * Used internally by flow components and by the renderer to walk a children
567
+ * tree. App code rarely needs this directly — see `children()` in `solid-js`
568
+ * for the user-facing helper that memoizes the result.
569
+ *
570
+ * @param children value or array of values to flatten
571
+ * @param options
572
+ * - `skipNonRendered` — drop values that won't render
573
+ * - `doNotUnwrap` — leave function children as-is (caller will resolve)
574
+ *
575
+ * @example
576
+ * ```ts
577
+ * // Custom renderer walking a children tree manually. Most authors should
578
+ * // use `children()` from solid-js, which memoizes the resolved value.
579
+ * function renderChildren(value: unknown): unknown {
580
+ * return flatten(value, { skipNonRendered: true });
581
+ * }
582
+ * ```
583
+ */ function flatten(t, e) {
584
+ if (typeof t === "function" && !t.length) {
585
+ if (e?.doNotUnwrap) return t;
586
+ do {
587
+ t = t();
588
+ } while (typeof t === "function" && !t.length);
589
+ }
590
+ if (e?.skipNonRendered && (t == null || t === true || t === false || t === "")) return;
591
+ if (Array.isArray(t)) {
592
+ let r = [];
593
+ if (flattenArray(t, r, e)) {
594
+ return () => {
595
+ let t = [];
596
+ flattenArray(r, t, {
597
+ ...e,
598
+ doNotUnwrap: false
599
+ });
600
+ return t;
601
+ };
602
+ }
603
+ return r;
604
+ }
605
+ return t;
606
+ }
607
+
608
+ function flattenArray(t, e = [], r) {
609
+ let s = null;
610
+ let n = false;
611
+ for (let i = 0; i < t.length; i++) {
612
+ try {
613
+ let s = t[i];
614
+ if (typeof s === "function" && !s.length) {
615
+ if (r?.doNotUnwrap) {
616
+ e.push(s);
617
+ n = true;
618
+ continue;
619
+ }
620
+ do {
621
+ s = s();
622
+ } while (typeof s === "function" && !s.length);
623
+ }
624
+ if (Array.isArray(s)) {
625
+ // OR, don't overwrite: an accessor already pushed under doNotUnwrap
626
+ // still needs the resolving wrapper even when a later sibling
627
+ // fragment contains no functions (#3133).
628
+ n = flattenArray(s, e, r) || n;
629
+ } else if (r?.skipNonRendered && (s == null || s === true || s === false || s === "")) {
630
+ // skip
631
+ } else e.push(s);
632
+ } catch (t) {
633
+ if (!(t instanceof NotReadyError)) throw t;
634
+ s = t;
635
+ }
636
+ }
637
+ if (s) throw s;
638
+ return n;
639
+ }
640
+
641
+ export { CollectionQueue, RevealController, createErrorBoundary, createLoadingBoundary, createRevealOrder, flatten };