@solidjs/signals 2.0.0-rc.1 → 2.0.0-rc.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dev-shared.js +7138 -0
- package/dist/dev.attribution.js +3307 -0
- package/dist/dev.js +5691 -4491
- package/dist/observe/affects.js +129 -0
- package/dist/observe/attribution.js +7 -0
- package/dist/observe/boundaries.js +793 -0
- package/dist/observe/core/action.js +177 -0
- package/dist/observe/core/async.js +849 -0
- package/dist/observe/core/attribution-costs.js +66 -0
- package/dist/observe/core/attribution-feedback.js +280 -0
- package/dist/observe/core/attribution-hooks.js +83 -0
- package/dist/observe/core/attribution-queries.js +43 -0
- package/dist/observe/core/attribution.js +2904 -0
- package/dist/observe/core/constants.js +283 -0
- package/dist/{types-cjs/core/context.d.cts → observe/core/context.js} +37 -12
- package/dist/observe/core/core.js +1999 -0
- package/dist/observe/core/dev.js +343 -0
- package/dist/observe/core/effect.js +200 -0
- package/dist/observe/core/error-hooks.js +71 -0
- package/dist/observe/core/error.js +80 -0
- package/dist/observe/core/external.js +98 -0
- package/dist/observe/core/graph.js +155 -0
- package/dist/observe/core/heap.js +147 -0
- package/dist/observe/core/invariants.js +45 -0
- package/dist/observe/core/lanes.js +205 -0
- package/dist/observe/core/optimistic.js +627 -0
- package/dist/observe/core/owner.js +353 -0
- package/dist/observe/core/scheduler.js +1547 -0
- package/dist/observe/core/verdict.js +674 -0
- package/dist/observe/index.js +59 -0
- package/dist/observe/map.js +484 -0
- package/dist/observe/signals.js +731 -0
- package/dist/observe/store/index.js +44 -0
- package/dist/observe/store/next/optimistic.js +717 -0
- package/dist/observe/store/next/projection.js +266 -0
- package/dist/observe/store/next/reconcile.js +375 -0
- package/dist/observe/store/next/store.js +2480 -0
- package/dist/observe/store/next/target.js +51 -0
- package/dist/observe/store/store.js +331 -0
- package/dist/observe/store/storePath.js +103 -0
- package/dist/observe/store/utils.js +1070 -0
- package/dist/prod/affects.js +10 -9
- package/dist/prod/attribution.js +45 -0
- package/dist/prod/boundaries.js +388 -178
- package/dist/prod/core/action.js +65 -37
- package/dist/prod/core/async.js +378 -163
- package/dist/prod/core/attribution-hooks.js +3 -0
- package/dist/prod/core/constants.js +186 -1
- package/dist/prod/core/context.js +10 -16
- package/dist/prod/core/core.js +1546 -416
- package/dist/prod/core/dev.js +18 -1
- package/dist/prod/core/effect.js +119 -79
- package/dist/prod/core/error-hooks.js +71 -0
- package/dist/prod/core/error.js +13 -1
- package/dist/prod/core/external.js +4 -4
- package/dist/prod/core/graph.js +105 -54
- package/dist/prod/core/heap.js +72 -65
- package/dist/prod/core/invariants.js +3 -2
- package/dist/prod/core/lanes.js +117 -52
- package/dist/prod/core/optimistic.js +458 -104
- package/dist/prod/core/owner.js +131 -84
- package/dist/prod/core/scheduler.js +998 -241
- package/dist/prod/core/verdict.js +417 -112
- package/dist/prod/index.js +20 -8
- package/dist/prod/map.js +312 -151
- package/dist/prod/signals.js +363 -32
- package/dist/prod/store/index.js +2 -0
- package/dist/prod/store/next/optimistic.js +530 -197
- package/dist/prod/store/next/projection.js +142 -57
- package/dist/prod/store/next/reconcile.js +149 -103
- package/dist/prod/store/next/store.js +1470 -346
- package/dist/prod/store/next/target.js +40 -9
- package/dist/prod/store/store.js +23 -19
- package/dist/prod/store/utils.js +997 -130
- package/dist/types/attribution.d.ts +19 -0
- package/dist/types/attribution.prod.d.ts +22 -0
- package/dist/types/boundaries.d.ts +78 -5
- package/dist/types/core/action.d.ts +12 -5
- package/dist/types/core/async.d.ts +3 -1
- package/dist/types/core/attribution-costs.d.ts +35 -0
- package/dist/types/core/attribution-feedback.d.ts +133 -0
- package/dist/types/core/attribution-hooks.d.ts +304 -0
- package/dist/types/core/attribution-queries.d.ts +24 -0
- package/dist/types/core/attribution.d.ts +892 -0
- package/dist/types/core/constants.d.ts +179 -0
- package/dist/types/core/core.d.ts +299 -25
- package/dist/types/core/dev.d.ts +421 -8
- package/dist/types/core/effect.d.ts +8 -1
- package/dist/types/core/error-hooks.d.ts +71 -0
- package/dist/types/core/error.d.ts +9 -0
- package/dist/types/core/graph.d.ts +23 -0
- package/dist/types/core/heap.d.ts +5 -3
- package/dist/types/core/index.d.ts +6 -3
- package/dist/types/core/invariants.d.ts +5 -1
- package/dist/types/core/lanes.d.ts +51 -19
- package/dist/types/core/owner.d.ts +15 -3
- package/dist/types/core/scheduler.d.ts +248 -1
- package/dist/types/core/types.d.ts +124 -41
- package/dist/types/index.d.ts +18 -5
- package/dist/types/map.d.ts +2 -0
- package/dist/types/signals.d.ts +145 -13
- package/dist/types/store/index.d.ts +7 -6
- package/dist/types/store/next/optimistic.d.ts +18 -13
- package/dist/types/store/next/projection.d.ts +5 -2
- package/dist/types/store/next/reconcile.d.ts +7 -0
- package/dist/types/store/next/store.d.ts +83 -11
- package/dist/types/store/next/target.d.ts +108 -11
- package/dist/types/store/store.d.ts +20 -11
- package/dist/types/store/utils.d.ts +188 -0
- package/package.json +31 -26
- package/dist/node.cjs +0 -8137
- package/dist/types/store/optimistic.d.ts +0 -45
- package/dist/types/store/projection.d.ts +0 -70
- package/dist/types/store/reconcile.d.ts +0 -46
- package/dist/types-cjs/affects.d.cts +0 -47
- package/dist/types-cjs/boundaries.d.cts +0 -175
- package/dist/types-cjs/core/action.d.cts +0 -64
- package/dist/types-cjs/core/async.d.cts +0 -21
- package/dist/types-cjs/core/constants.d.cts +0 -71
- package/dist/types-cjs/core/core.d.cts +0 -156
- package/dist/types-cjs/core/dev.d.cts +0 -64
- package/dist/types-cjs/core/effect.d.cts +0 -30
- package/dist/types-cjs/core/error.d.cts +0 -47
- package/dist/types-cjs/core/external.d.cts +0 -15
- package/dist/types-cjs/core/graph.d.cts +0 -5
- package/dist/types-cjs/core/heap.d.cts +0 -22
- package/dist/types-cjs/core/index.d.cts +0 -13
- package/dist/types-cjs/core/invariants.d.cts +0 -59
- package/dist/types-cjs/core/lanes.d.cts +0 -56
- package/dist/types-cjs/core/optimistic.d.cts +0 -6
- package/dist/types-cjs/core/owner.d.cts +0 -124
- package/dist/types-cjs/core/scheduler.d.cts +0 -172
- package/dist/types-cjs/core/types.d.cts +0 -148
- package/dist/types-cjs/core/verdict.d.cts +0 -2
- package/dist/types-cjs/index.d.cts +0 -10
- package/dist/types-cjs/map.d.cts +0 -69
- package/dist/types-cjs/package.json +0 -3
- package/dist/types-cjs/signals.d.cts +0 -624
- package/dist/types-cjs/store/index.d.cts +0 -19
- package/dist/types-cjs/store/next/optimistic.d.cts +0 -20
- package/dist/types-cjs/store/next/projection.d.cts +0 -24
- package/dist/types-cjs/store/next/reconcile.d.cts +0 -3
- package/dist/types-cjs/store/next/store.d.cts +0 -71
- package/dist/types-cjs/store/next/target.d.cts +0 -99
- package/dist/types-cjs/store/optimistic.d.cts +0 -45
- package/dist/types-cjs/store/projection.d.cts +0 -70
- package/dist/types-cjs/store/reconcile.d.cts +0 -46
- package/dist/types-cjs/store/store.d.cts +0 -138
- package/dist/types-cjs/store/storePath.d.cts +0 -58
- package/dist/types-cjs/store/utils.d.cts +0 -74
|
@@ -0,0 +1,793 @@
|
|
|
1
|
+
import { runWithOwner, signal, spectate, computed, read, untrack, setSignal, notifyOnLane, recompute, currentOptimisticLane, ext } 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, reporterBlocksSource, wakeParked, activeTransition, schedule, queueRearm, haltReactivity } from "./core/scheduler.js";
|
|
8
|
+
|
|
9
|
+
import { getContext, setContext, createContext } from "./core/context.js";
|
|
10
|
+
|
|
11
|
+
import { STATUS_PENDING, STATUS_ERROR, REACTIVE_DISPOSED, REACTIVE_ZOMBIE, STATUS_UNINITIALIZED, NOT_PENDING, 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 { enqueueSub } from "./core/heap.js";
|
|
20
|
+
|
|
21
|
+
import "./core/verdict.js";
|
|
22
|
+
|
|
23
|
+
import "./core/effect.js";
|
|
24
|
+
|
|
25
|
+
import { reportClientError } from "./core/error-hooks.js";
|
|
26
|
+
|
|
27
|
+
import { accessor } from "./signals.js";
|
|
28
|
+
|
|
29
|
+
function boundaryComputed(e, t) {
|
|
30
|
+
const r = computed(e, {
|
|
31
|
+
name: "boundary",
|
|
32
|
+
lazy: true
|
|
33
|
+
});
|
|
34
|
+
ext(r).h = (e, t) => {
|
|
35
|
+
// Use passed values if provided, otherwise read from node
|
|
36
|
+
const n = e !== undefined ? e : r.S;
|
|
37
|
+
const i = t !== undefined ? t : r.o?._;
|
|
38
|
+
// Notify both status dimensions like a render effect does; the queue chain
|
|
39
|
+
// consumes this boundary's own type and forwards the remainder upward until
|
|
40
|
+
// a boundary that handles it is found.
|
|
41
|
+
r.S &= ~r.R;
|
|
42
|
+
const s = r.T.notify(r, STATUS_PENDING | STATUS_ERROR, n, i);
|
|
43
|
+
// The queue is the only propagation channel: a foreign status must not stay
|
|
44
|
+
// reader-visible on the tree, or reads re-throw it across the boundary and
|
|
45
|
+
// link unrelated ambient contexts (the #2809 nested-boundary loop). Deps are
|
|
46
|
+
// untouched, so the tree still recomputes when the foreign source settles.
|
|
47
|
+
const o = n & ~r.R & (STATUS_PENDING | STATUS_ERROR);
|
|
48
|
+
if (o) {
|
|
49
|
+
r.S &= ~o;
|
|
50
|
+
if (r.o?._ === i && !(r.S & (STATUS_PENDING | STATUS_ERROR))) if (r.o !== null) r.o._ = undefined;
|
|
51
|
+
}
|
|
52
|
+
// An ERROR the chain could not deliver to any boundary is uncaught. The
|
|
53
|
+
// scrub above already removed it from reader-visible state, so without
|
|
54
|
+
// escalation here it would vanish entirely (#2884) — halt-and-throw,
|
|
55
|
+
// exactly like an unhandled effect error.
|
|
56
|
+
if (!s && n & STATUS_ERROR) {
|
|
57
|
+
haltReactivity(unwrapStatusError(i));
|
|
58
|
+
throw i;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
r.R = t;
|
|
62
|
+
r.C &= ~CONFIG_AUTO_DISPOSE;
|
|
63
|
+
recompute(r, true);
|
|
64
|
+
return r;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* A boundary's `on` dependencies (#3540): `onFn` runs tracked, as a
|
|
69
|
+
* computation whose value is discarded — what it READS is the point. Every
|
|
70
|
+
* run after the first is a notification (a source it read was written, went
|
|
71
|
+
* pending, or landed; an optimistic write notifies like any other) and
|
|
72
|
+
* queues the boundary for re-arming once this pass's heap has run
|
|
73
|
+
* (scheduler.ts `pendingRearms`: the re-arm needs what the notifying write
|
|
74
|
+
* put in flight, which this pass — at the height of its reads — runs ahead
|
|
75
|
+
* of). The value is never compared: a thunk that returns a fresh object per
|
|
76
|
+
* run but reads nothing reactive never re-arms, and one that returns the
|
|
77
|
+
* same constant re-arms whenever a read source changes. A zero-argument
|
|
78
|
+
* function is an accessor, tracked like any other.
|
|
79
|
+
*
|
|
80
|
+
* The pass's posture is the notification's. A plain pass derives from the
|
|
81
|
+
* frame the write belongs to, and the re-arm follows that frame. A pass
|
|
82
|
+
* under a lane read display-ahead state — `latest()` (its shadow is an
|
|
83
|
+
* optimistic computed), an optimistic write — and the re-arm shows the
|
|
84
|
+
* fallback through that lane (`_rearmLane`): now, beside whatever frame a
|
|
85
|
+
* transaction still holds.
|
|
86
|
+
*
|
|
87
|
+
* Created under `owner` while the owner's queue is still the parent's, so
|
|
88
|
+
* the node belongs to the parent boundary, not to this one — as the
|
|
89
|
+
* condition of a `<Show>` wrapping the boundary would. Two status rules set
|
|
90
|
+
* it apart from a plain memo:
|
|
91
|
+
* - Pending is not the parent's: a source of `on` that is not ready is a
|
|
92
|
+
* notification for this boundary (it re-arms: the fallback shows here, not
|
|
93
|
+
* in an outer boundary). Propagation marks the node without a pass, so the
|
|
94
|
+
* channel scrubs the mark and re-derives it; the pass reads the source
|
|
95
|
+
* (linking to its landing) and catches. The node never registers as a
|
|
96
|
+
* reporter: `on` reading a pending source holds no frame.
|
|
97
|
+
* - An error IS the parent's, as a wrapping `<Show>` condition's would be:
|
|
98
|
+
* forwarded up the queue chain like a render effect's; uncaught, it halts
|
|
99
|
+
* (#2884).
|
|
100
|
+
*/ function onNode(e, t, r) {
|
|
101
|
+
let n = false;
|
|
102
|
+
const i = runWithOwner(e, () => computed(() => {
|
|
103
|
+
try {
|
|
104
|
+
r();
|
|
105
|
+
} catch (e) {
|
|
106
|
+
if (!(e instanceof NotReadyError)) throw e;
|
|
107
|
+
}
|
|
108
|
+
if (n) {
|
|
109
|
+
if (currentOptimisticLane !== null) t.N = currentOptimisticLane;
|
|
110
|
+
queueRearm(t);
|
|
111
|
+
} else n = true;
|
|
112
|
+
}, {
|
|
113
|
+
lazy: true
|
|
114
|
+
}));
|
|
115
|
+
ext(i).h = (e, t) => {
|
|
116
|
+
const r = e !== undefined ? e : i.S;
|
|
117
|
+
if (r & STATUS_PENDING) {
|
|
118
|
+
i.S &= ~STATUS_PENDING;
|
|
119
|
+
if (i.o?._ instanceof NotReadyError) i.o._ = undefined;
|
|
120
|
+
enqueueSub(i);
|
|
121
|
+
schedule();
|
|
122
|
+
}
|
|
123
|
+
if (r & STATUS_ERROR) {
|
|
124
|
+
const e = t !== undefined ? t : i.o?._;
|
|
125
|
+
i.S &= ~STATUS_ERROR;
|
|
126
|
+
if (i.o?._ === e && i.o !== null) i.o._ = undefined;
|
|
127
|
+
if (!i.T.notify(i, STATUS_ERROR, r, e)) {
|
|
128
|
+
haltReactivity(unwrapStatusError(e));
|
|
129
|
+
throw e;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
i.C &= ~CONFIG_AUTO_DISPOSE;
|
|
134
|
+
recompute(i, true);
|
|
135
|
+
return i;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function createBoundChildren(e, t, r, n) {
|
|
139
|
+
const i = e.T;
|
|
140
|
+
i.addChild(e.T = r);
|
|
141
|
+
cleanup(() => i.removeChild(e.T));
|
|
142
|
+
// Named for the observe tier's owner paths: user content under a boundary
|
|
143
|
+
// is owned by `children`, and the boundary's own two nodes read as
|
|
144
|
+
// structure rather than as anonymous `computed`s between `<Loading>` and
|
|
145
|
+
// the content (`<App> › <Loading> › children › <Feed>`).
|
|
146
|
+
return runWithOwner(e, () => {
|
|
147
|
+
// The call, not the argument, is gated: `computed(fn, void 0)` would keep
|
|
148
|
+
// a trailing argument in the prod artifact.
|
|
149
|
+
const e = true ? computed(t, {
|
|
150
|
+
name: "children"
|
|
151
|
+
}) : computed(t);
|
|
152
|
+
return boundaryComputed(() => flatten(read(e)), n);
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const RevealControllerContext = /* @__PURE__ */ createContext(null);
|
|
157
|
+
|
|
158
|
+
let _revealUsed = false;
|
|
159
|
+
|
|
160
|
+
const FALSE_ACCESSOR = () => false;
|
|
161
|
+
|
|
162
|
+
const SEQUENTIAL_ACCESSOR = () => "sequential";
|
|
163
|
+
|
|
164
|
+
function isRevealController(e) {
|
|
165
|
+
return e instanceof RevealController;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function isSlotReady(e) {
|
|
169
|
+
return isRevealController(e) ? e.O() : e.I.size === 0 && !e.U;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function isSlotMinimallyReady(e) {
|
|
173
|
+
return isRevealController(e) ? e.v() : isSlotReady(e);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function setSlotState(e, t, r, n) {
|
|
177
|
+
setSignal(e.D, r);
|
|
178
|
+
setSignal(e.P, n);
|
|
179
|
+
if (isRevealController(e)) {
|
|
180
|
+
if (!r && e.L === t) e.L = undefined;
|
|
181
|
+
return e.B(r, n);
|
|
182
|
+
}
|
|
183
|
+
if (!r && e.W === t && e.H) e.W = undefined;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
class RevealController {
|
|
187
|
+
q;
|
|
188
|
+
V;
|
|
189
|
+
F=[];
|
|
190
|
+
L;
|
|
191
|
+
D=signal(false, {
|
|
192
|
+
ownedWrite: true,
|
|
193
|
+
Z: true
|
|
194
|
+
});
|
|
195
|
+
P=signal(false, {
|
|
196
|
+
ownedWrite: true,
|
|
197
|
+
Z: true
|
|
198
|
+
});
|
|
199
|
+
J=true;
|
|
200
|
+
K=true;
|
|
201
|
+
X=false;
|
|
202
|
+
constructor(e, t) {
|
|
203
|
+
this.q = e;
|
|
204
|
+
this.V = t;
|
|
205
|
+
}
|
|
206
|
+
Y(e) {
|
|
207
|
+
for (let t = 0; t < this.F.length; t++) {
|
|
208
|
+
const r = this.F[t];
|
|
209
|
+
if ((isRevealController(r) ? r.L : r.W) !== this) continue;
|
|
210
|
+
if (e(r) === false) return false;
|
|
211
|
+
}
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
214
|
+
O() {
|
|
215
|
+
return this.Y(isSlotReady);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* "Minimally ready" = this group has something visible to show under its own policy.
|
|
219
|
+
* Used by an enclosing `together` group to decide when it can release.
|
|
220
|
+
* - `together`: every direct slot is minimally ready.
|
|
221
|
+
* - `sequential`: the first owned slot is minimally ready (frontier can advance).
|
|
222
|
+
* - `natural`: any owned slot is minimally ready.
|
|
223
|
+
*/ v() {
|
|
224
|
+
const e = untrack(this.q);
|
|
225
|
+
if (e === "together") return this.Y(isSlotMinimallyReady);
|
|
226
|
+
if (e === "natural") {
|
|
227
|
+
let e = false;
|
|
228
|
+
let t = false;
|
|
229
|
+
this.Y(r => {
|
|
230
|
+
e = true;
|
|
231
|
+
if (isSlotMinimallyReady(r)) {
|
|
232
|
+
t = true;
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
return !e || t;
|
|
237
|
+
}
|
|
238
|
+
// sequential: only the first owned slot matters.
|
|
239
|
+
let t = true;
|
|
240
|
+
this.Y(e => {
|
|
241
|
+
t = isSlotMinimallyReady(e);
|
|
242
|
+
return false;
|
|
243
|
+
});
|
|
244
|
+
return t;
|
|
245
|
+
}
|
|
246
|
+
$(e) {
|
|
247
|
+
if (this.F.includes(e)) return;
|
|
248
|
+
this.F.push(e);
|
|
249
|
+
const t = untrack(this.q);
|
|
250
|
+
setSignal(e.D, true), setSignal(e.P, t === "sequential" ? !!untrack(this.V) : false);
|
|
251
|
+
untrack(() => this.B());
|
|
252
|
+
}
|
|
253
|
+
ee(e) {
|
|
254
|
+
const t = this.F.indexOf(e);
|
|
255
|
+
if (t >= 0) this.F.splice(t, 1);
|
|
256
|
+
untrack(() => this.B());
|
|
257
|
+
}
|
|
258
|
+
B(e, t) {
|
|
259
|
+
if (this.X) return;
|
|
260
|
+
this.X = true;
|
|
261
|
+
const r = this.J;
|
|
262
|
+
const n = this.K;
|
|
263
|
+
try {
|
|
264
|
+
const r = e ?? read(this.D), n = untrack(this.q), i = n === "sequential" && !!untrack(this.V), s = t ?? i;
|
|
265
|
+
if (r) {
|
|
266
|
+
// Held by an outer group. Propagate the hold (and whatever collapsed policy
|
|
267
|
+
// the outer asked for) down the whole subtree. Inner order is ignored while
|
|
268
|
+
// held; it resumes once the outer releases us.
|
|
269
|
+
this.Y(e => setSlotState(e, this, true, s));
|
|
270
|
+
} else if (n === "natural") {
|
|
271
|
+
// Each child reveals based on its own readiness. A nested controller slot
|
|
272
|
+
// is released to run its own order locally — we bypass setSlotState for it
|
|
273
|
+
// so the parent backpointer survives for upward readiness notifications.
|
|
274
|
+
this.Y(e => {
|
|
275
|
+
if (isRevealController(e)) {
|
|
276
|
+
setSignal(e.P, false);
|
|
277
|
+
setSignal(e.D, false);
|
|
278
|
+
e.B(false, false);
|
|
279
|
+
} else {
|
|
280
|
+
setSlotState(e, this, !isSlotReady(e), false);
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
} else if (n === "together") {
|
|
284
|
+
// Release when every direct slot is minimally ready (has something to show
|
|
285
|
+
// under its own order). A fully-ready inner together is minimally ready;
|
|
286
|
+
// sequential's first slot being ready is minimally ready; natural having any
|
|
287
|
+
// ready child is minimally ready. This lets `together` guarantee a single
|
|
288
|
+
// cohesive reveal without waiting for every grandchild.
|
|
289
|
+
const e = this.Y(isSlotMinimallyReady);
|
|
290
|
+
this.Y(t => setSlotState(t, this, !e, false));
|
|
291
|
+
} else {
|
|
292
|
+
let e = false;
|
|
293
|
+
this.Y(t => {
|
|
294
|
+
if (e) return setSlotState(t, this, true, i);
|
|
295
|
+
if (isSlotReady(t)) return setSlotState(t, this, false, false);
|
|
296
|
+
e = true;
|
|
297
|
+
// Frontier slot. For a leaf, holding `_disabled=true` is what keeps its
|
|
298
|
+
// fallback visible. For a composite, we instead release it so it runs
|
|
299
|
+
// its own order locally — its leaves will each show their own fallback
|
|
300
|
+
// until their data lands. Outer still waits on full readiness before
|
|
301
|
+
// advancing past this slot, and we bypass setSlotState so the parent
|
|
302
|
+
// backpointer survives for upward readiness notifications.
|
|
303
|
+
if (isRevealController(t)) {
|
|
304
|
+
setSignal(t.P, false);
|
|
305
|
+
setSignal(t.D, false);
|
|
306
|
+
t.B(false, false);
|
|
307
|
+
} else {
|
|
308
|
+
setSlotState(t, this, true, false);
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
} finally {
|
|
313
|
+
this.J = this.O();
|
|
314
|
+
this.K = this.v();
|
|
315
|
+
this.X = false;
|
|
316
|
+
}
|
|
317
|
+
if (this.L && (r !== this.J || n !== this.K)) this.L.B();
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
class CollectionQueue extends Queue {
|
|
322
|
+
te;
|
|
323
|
+
I=new Set;
|
|
324
|
+
re;
|
|
325
|
+
/** The output pass — fallback or content (createCollectionBoundary). */
|
|
326
|
+
ne;
|
|
327
|
+
U=true;
|
|
328
|
+
D=signal(false, {
|
|
329
|
+
ownedWrite: true,
|
|
330
|
+
Z: true
|
|
331
|
+
});
|
|
332
|
+
_;
|
|
333
|
+
P=signal(false, {
|
|
334
|
+
ownedWrite: true,
|
|
335
|
+
Z: true
|
|
336
|
+
});
|
|
337
|
+
W;
|
|
338
|
+
H=false;
|
|
339
|
+
/** The boundary's owner — where a `caught` report locates itself, set before the children are built (a creation-time throw arrives before `_tree`). */
|
|
340
|
+
ie;
|
|
341
|
+
/** The lane the `on` pass that queued this re-arm ran under (onNode), if
|
|
342
|
+
* any: the fallback swap is display-ahead — shown through the lane. */
|
|
343
|
+
N=null;
|
|
344
|
+
constructor(e) {
|
|
345
|
+
super();
|
|
346
|
+
this.te = e;
|
|
347
|
+
}
|
|
348
|
+
run(e) {
|
|
349
|
+
if (!e || read(this.D) && (!_revealUsed || read(this.P))) return;
|
|
350
|
+
return super.run(e);
|
|
351
|
+
}
|
|
352
|
+
/** An `on` dependency notified (onNode → scheduler `pendingRearms`);
|
|
353
|
+
* drained after the heap, before the verdict, under the notifying write's
|
|
354
|
+
* transaction (#3540). A boundary showing content is fresh again: it
|
|
355
|
+
* releases its hold now and, if anything under it is still pending, swaps
|
|
356
|
+
* to its fallback. The swap is staged, so it lands with the write's frame
|
|
357
|
+
* — at once when nothing else holds it, with the rest of the new page
|
|
358
|
+
* when something outside the boundary does; if the pending lands first,
|
|
359
|
+
* `_checkSources` clears it and no fallback is shown. An `on` that read a
|
|
360
|
+
* lane (`latest()`, an optimistic write) asked for the change now:
|
|
361
|
+
* `_rearmLane` shows the swap through the lane, beside the held frame.
|
|
362
|
+
* Children stay alive behind the fallback. */ se() {
|
|
363
|
+
const e = this.N;
|
|
364
|
+
this.N = null;
|
|
365
|
+
if (this.re === undefined || this.re.oe & REACTIVE_DISPOSED) return;
|
|
366
|
+
if (!this.H) return;
|
|
367
|
+
// Readers forwarded while this boundary showed content are what it
|
|
368
|
+
// would wait on now. They never re-notify (status propagation dedupes on
|
|
369
|
+
// the reader's `_pendingSources`), so the re-arm collects it from their
|
|
370
|
+
// registrations — the one place a forwarded reader is recorded (INV-3)
|
|
371
|
+
// — or a sibling reader's flight that lands first reveals them stale
|
|
372
|
+
// (A33, #3459). Before the verdict, a registration may have stopped
|
|
373
|
+
// counting without being pruned yet (its flight landed this pass):
|
|
374
|
+
// `reporterBlocksSource` is the verdict's own test.
|
|
375
|
+
const t = new Set;
|
|
376
|
+
for (const e of transitions) for (const [r, n] of e.ae) {
|
|
377
|
+
for (const e of n) if (this.le(e) && reporterBlocksSource(e, r)) {
|
|
378
|
+
t.add(r);
|
|
379
|
+
e.o?.ue?.forEach(e => t.add(e));
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
if (!t.size) return;
|
|
383
|
+
this.H = false;
|
|
384
|
+
this.I = t;
|
|
385
|
+
this.U = true;
|
|
386
|
+
this.fe(e);
|
|
387
|
+
// Those readers are behind the fallback now: they stop blocking
|
|
388
|
+
// (`reporterBlocksSource`), and the transactions they were holding must
|
|
389
|
+
// be re-judged for it (A33, #3375) — the active one by the verdict that
|
|
390
|
+
// follows this drain, parked ones by the wake. A live action keeps its
|
|
391
|
+
// transaction parked regardless (transitionComplete): its batch commits
|
|
392
|
+
// when it settles, intact.
|
|
393
|
+
wakeParked();
|
|
394
|
+
}
|
|
395
|
+
/** Show the fallback: the swap the output pass selects on. Staged, it is
|
|
396
|
+
* the frame's and lands with its commit. Re-armed from a lane pass
|
|
397
|
+
* (`lane`), it is the current frame's — committed outright, as the lane's
|
|
398
|
+
* view already is on screen — and shown through the lane: the output pass
|
|
399
|
+
* publishes a derived override and its readers run from the lane's queue,
|
|
400
|
+
* at the park, ahead of the transaction (a lane pass reads staged plain
|
|
401
|
+
* writes committed, so a staged swap would be invisible to it). */ fe(e) {
|
|
402
|
+
if (e === null) setSignal(this.D, true); else {
|
|
403
|
+
this.D.ce = true;
|
|
404
|
+
notifyOnLane(this.D, e);
|
|
405
|
+
}
|
|
406
|
+
// Observe: the staged swap is displayed when the transaction carrying
|
|
407
|
+
// this pass commits; the lane's readers run in this drain.
|
|
408
|
+
if (attrHooks !== null) attrHooks.boundaryFallback(this, this.re, true, e === null ? activeTransition : null);
|
|
409
|
+
}
|
|
410
|
+
/** Retry the collected failures of an error boundary: recompute each
|
|
411
|
+
* source that threw, so the boundary can recover. */ he() {
|
|
412
|
+
for (const e of this.I) {
|
|
413
|
+
// Non-computed sources (patch-channel registrations under plain
|
|
414
|
+
// owners) are not recomputable — their reset is the record's next
|
|
415
|
+
// transition re-applying the patch (re-audit 2, P1-4).
|
|
416
|
+
if (e.Se !== undefined) recompute(e);
|
|
417
|
+
}
|
|
418
|
+
schedule();
|
|
419
|
+
}
|
|
420
|
+
notify(e, t, r, n) {
|
|
421
|
+
if (!(t & this.te)) return super.notify(e, t, r, n);
|
|
422
|
+
// Routing is dimension-independent: each boundary consumes only its own
|
|
423
|
+
// status dimension from the mask (`type &= ~collectionType` below) and
|
|
424
|
+
// forwards the remainder up the queue chain. An error inside a `Loading`
|
|
425
|
+
// needs no special rule — the ERROR dimension survives consumption here and
|
|
426
|
+
// reaches the `Errored` that catches it natively, and `flags & collectionType`
|
|
427
|
+
// keeps this boundary from collecting a node that isn't actually pending.
|
|
428
|
+
// Symmetrically, a pending inside an `Errored` forwards on the PENDING
|
|
429
|
+
// dimension, while a status already caught by an inner boundary arrives with
|
|
430
|
+
// its dimension consumed from the mask and is correctly not re-routed
|
|
431
|
+
// (the Loading > Errored > content composition escape, #2856).
|
|
432
|
+
if (this.te & STATUS_PENDING && this.H) return super.notify(e, t, r, n);
|
|
433
|
+
if (r & this.te) {
|
|
434
|
+
this.U = true;
|
|
435
|
+
const t = n?.source || e.o?._?.source;
|
|
436
|
+
if (t) {
|
|
437
|
+
const r = this.I.size === 0;
|
|
438
|
+
this.I.add(t);
|
|
439
|
+
// A collecting boundary waits on everything the effect is pending on,
|
|
440
|
+
// not only the source this notification carries. Status propagation
|
|
441
|
+
// dedupes on the effect's `_pendingSources`: a source it already
|
|
442
|
+
// carries (a flight that started before an `on` reset cleared the
|
|
443
|
+
// set) is never re-reported, and that source's later re-flight
|
|
444
|
+
// stays invisible — the boundary revealed when its one collected
|
|
445
|
+
// source settled while the effect was still pending (#3375).
|
|
446
|
+
if (this.te & STATUS_PENDING) e.o?.ue?.forEach(e => this.I.add(e));
|
|
447
|
+
if (r) {
|
|
448
|
+
setSignal(this.D, true);
|
|
449
|
+
if (attrHooks !== null && this.te & STATUS_PENDING) attrHooks.boundaryFallback(this, this.re, true, activeTransition);
|
|
450
|
+
}
|
|
451
|
+
if (this.te & STATUS_ERROR) {
|
|
452
|
+
const e = unwrapStatusError(t.o?._);
|
|
453
|
+
setSignal(this._, e);
|
|
454
|
+
// The client error hook: this boundary renders its fallback for
|
|
455
|
+
// it — the one road a rendered failure took that no global handler
|
|
456
|
+
// ever saw. `source` is the computation that threw (the status
|
|
457
|
+
// wrapper's, made at the first landing and kept downstream), so the
|
|
458
|
+
// hook hears where it broke as well as where it was met. Once per
|
|
459
|
+
// error object; a `reset()` re-collecting the same failure says
|
|
460
|
+
// nothing new.
|
|
461
|
+
reportClientError(e, this.ie, t);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
t &= ~this.te;
|
|
466
|
+
return t ? super.notify(e, t, r, n) : true;
|
|
467
|
+
}
|
|
468
|
+
/** Is `reporter` live and routed to this boundary — under it, with no
|
|
469
|
+
* collecting pending-type boundary in between (`reporterBlocksSource`'s test)? */ le(e) {
|
|
470
|
+
if (e.oe & (REACTIVE_ZOMBIE | REACTIVE_DISPOSED)) return false;
|
|
471
|
+
for (let t = e.T; t; t = t._parent) {
|
|
472
|
+
if (t === this) return true;
|
|
473
|
+
if (t.te & STATUS_PENDING && !t.H) return false;
|
|
474
|
+
}
|
|
475
|
+
return false;
|
|
476
|
+
}
|
|
477
|
+
/** Has a collected source stopped counting for this boundary? A source
|
|
478
|
+
* with a live affects() mark holds display state for the mark's lifetime
|
|
479
|
+
* (the visual channel): the marked node carries no status of its own, so
|
|
480
|
+
* the count is the liveness test. The release sweep (finalizePureQueue
|
|
481
|
+
* after mark release) re-runs this check. A source born held under this
|
|
482
|
+
* boundary (recompute, #3540) carries no status either: it is collected
|
|
483
|
+
* while it has a staged value and no committed one, and released by the
|
|
484
|
+
* commit that initializes it. */ de(e) {
|
|
485
|
+
return !!(e.oe & REACTIVE_DISPOSED || !e.o?.t && !(e.S & this.te) && !(this.te & STATUS_ERROR && e.S & STATUS_PENDING) && !(this.te & STATUS_PENDING && e.S & STATUS_UNINITIALIZED && e._e !== NOT_PENDING));
|
|
486
|
+
}
|
|
487
|
+
/** The pre-verdict sweep (scheduler run(), #3540): a collecting boundary
|
|
488
|
+
* whose OUTPUT is pending — its fallback read something not ready — is
|
|
489
|
+
* judged here, under the transaction. That output is what an initialized
|
|
490
|
+
* parent holds the frame on, and it derives from `_disabled`, not the
|
|
491
|
+
* tree: the tree settling never re-runs it, only a sweep does, and the
|
|
492
|
+
* commit sweep runs after the verdict the output's own read keeps parking
|
|
493
|
+
* — the content waited for the fallback's flight. Judged ready here, the
|
|
494
|
+
* boundary stages `_disabled` false with the frame and the output re-runs
|
|
495
|
+
* in this heap: it reads the tree and drops the fallback's read (recompute
|
|
496
|
+
* settles a pass's outgoing pending sources), so the verdict sees the
|
|
497
|
+
* release. A boundary showing a ready fallback parks nothing and keeps the
|
|
498
|
+
* commit sweep's reveal. */ Re() {
|
|
499
|
+
if (this.H || !(this.ne.S & STATUS_PENDING)) return;
|
|
500
|
+
this.Te();
|
|
501
|
+
}
|
|
502
|
+
Te() {
|
|
503
|
+
for (const e of this.I) if (this.de(e)) this.I.delete(e);
|
|
504
|
+
if (!this.I.size) {
|
|
505
|
+
if (this.te & STATUS_PENDING && this.U && !this.H && this.re) {
|
|
506
|
+
this.U = !!(this.re.S & this.te);
|
|
507
|
+
} else {
|
|
508
|
+
this.U = false;
|
|
509
|
+
}
|
|
510
|
+
if (!this.U) {
|
|
511
|
+
setSignal(this.D, false);
|
|
512
|
+
if (attrHooks !== null && this.te & STATUS_PENDING) attrHooks.boundaryFallback(this, this.re, false);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
if (_revealUsed) this.W?.B();
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
function createCollectionBoundary(e, t, r, n) {
|
|
520
|
+
const i = createOwner();
|
|
521
|
+
if (_revealUsed) setContext(RevealControllerContext, null, i);
|
|
522
|
+
const s = new CollectionQueue(e);
|
|
523
|
+
s.ie = i;
|
|
524
|
+
if (e === STATUS_ERROR) s._ = signal(undefined, {
|
|
525
|
+
ownedWrite: true,
|
|
526
|
+
Z: true
|
|
527
|
+
});
|
|
528
|
+
// The `on` dependencies live OUTSIDE the boundary, as the condition of a
|
|
529
|
+
// `<Show>` wrapping it would: created before the owner's queue becomes
|
|
530
|
+
// this boundary's (onNode).
|
|
531
|
+
n && onNode(i, s, n);
|
|
532
|
+
const o = s.re = createBoundChildren(i, t, s, e);
|
|
533
|
+
// Prime source tracking so reveal registration sees pending sources. A
|
|
534
|
+
// bookkeeping read (`spectate`): the mounting pass derives nothing from
|
|
535
|
+
// the tree — it must not be linked to it, nor enter the transaction a
|
|
536
|
+
// tree born held (A29 under a boundary, #3540) was staged into.
|
|
537
|
+
spectate(() => {
|
|
538
|
+
let t = false;
|
|
539
|
+
try {
|
|
540
|
+
read(o);
|
|
541
|
+
} catch (e) {
|
|
542
|
+
if (e instanceof NotReadyError) t = true; else throw e;
|
|
543
|
+
}
|
|
544
|
+
s.U = t || !!(o.S & e) || o.o?._ instanceof NotReadyError;
|
|
545
|
+
});
|
|
546
|
+
const a = _revealUsed && e === STATUS_PENDING ? getContext(RevealControllerContext) : null;
|
|
547
|
+
if (a) {
|
|
548
|
+
s.W = a;
|
|
549
|
+
a.$(s);
|
|
550
|
+
cleanup(() => a.ee(s));
|
|
551
|
+
}
|
|
552
|
+
return accessor(s.ne = computed(() => {
|
|
553
|
+
// `_disabled` selects fallback or content: set by a collecting
|
|
554
|
+
// notification or a re-arm (`_rearm`), cleared by the sweep when the
|
|
555
|
+
// collected sources settle — each re-runs this pass.
|
|
556
|
+
if (!read(s.D)) {
|
|
557
|
+
const e = read(o);
|
|
558
|
+
if (!untrack(() => read(s.D))) return s.H = true, e;
|
|
559
|
+
}
|
|
560
|
+
// Collapsed reveal slots suppress their own output entirely; the
|
|
561
|
+
// renderer treats the hole as empty, so the cast never leaks to users
|
|
562
|
+
// outside a `createRevealOrder` scope.
|
|
563
|
+
if (_revealUsed && read(s.P)) return undefined;
|
|
564
|
+
return r(s);
|
|
565
|
+
},
|
|
566
|
+
// Boundary structure, not a user source: its value is fallback-or-content and
|
|
567
|
+
// legitimately swaps mid-hydration (reveal/resume), so it must never be frozen
|
|
568
|
+
// by snapshot capture. The tree no longer carries foreign status flags, so
|
|
569
|
+
// capture can't rely on PENDING to skip this node the way it used to.
|
|
570
|
+
{
|
|
571
|
+
name: "value",
|
|
572
|
+
Z: true
|
|
573
|
+
}));
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* Lower-level primitive that backs the `<Loading>` flow control. Catches
|
|
578
|
+
* pending async reads inside `fn` and renders `fallback` until they settle.
|
|
579
|
+
*
|
|
580
|
+
* App code should use `<Loading fallback={...}>` instead — reach for this only
|
|
581
|
+
* when authoring custom boundary components.
|
|
582
|
+
*
|
|
583
|
+
* @param fn the tracked subtree
|
|
584
|
+
* @param fallback the fallback shown while async reads in `fn` are unresolved
|
|
585
|
+
* @param options `on` — a dependency list: a tracked function whose reads
|
|
586
|
+
* re-arm the boundary. Its return value is irrelevant (never compared);
|
|
587
|
+
* what matters is what it reads. Without `on`, a boundary that has shown
|
|
588
|
+
* content keeps it through a refetch (the pending holds with the
|
|
589
|
+
* transaction). With `on`, a write to anything it reads makes the boundary
|
|
590
|
+
* fresh again: it stops waiting on its current content, and if something
|
|
591
|
+
* under it is pending it shows `fallback` until the new content is ready;
|
|
592
|
+
* if nothing is pending, the notification is a no-op. The fallback lands
|
|
593
|
+
* with the same frame as the change that caused it — now, when nothing
|
|
594
|
+
* else holds that frame; together with the rest of the new page during a
|
|
595
|
+
* held navigation, not before it. If the same data is also read outside
|
|
596
|
+
* the boundary, the frame waits on it and the fallback can never be seen
|
|
597
|
+
* (DEV warns `LOADING_ON_OUTSIDE_HOLD`); the fix is structural — move the
|
|
598
|
+
* outside read under the boundary so one hold owns the data. A frame held
|
|
599
|
+
* past the content's landing by something else (the write's action, other
|
|
600
|
+
* pending data) also shows no fallback; that is a race the fallback may
|
|
601
|
+
* lose, a legitimate outcome, and not reported. A display-ahead read in
|
|
602
|
+
* `on` (`latest()`) shows the fallback now, beside the held frame; that
|
|
603
|
+
* is a capability, not the recommended shape. Optimistic writes and a
|
|
604
|
+
* source going pending notify like any other. The children are not
|
|
605
|
+
* re-created — they stay alive behind the fallback.
|
|
606
|
+
*
|
|
607
|
+
* @example
|
|
608
|
+
* ```tsx
|
|
609
|
+
* // Custom boundary component built on top of the primitive.
|
|
610
|
+
* function MyLoading(props: { fallback: JSX.Element; children: JSX.Element }) {
|
|
611
|
+
* return createLoadingBoundary(
|
|
612
|
+
* () => props.children,
|
|
613
|
+
* () => props.fallback
|
|
614
|
+
* ) as unknown as JSX.Element;
|
|
615
|
+
* }
|
|
616
|
+
* ```
|
|
617
|
+
*/ function createLoadingBoundary(e, t, r) {
|
|
618
|
+
return createCollectionBoundary(STATUS_PENDING, e, () => t(), r?.on);
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
/**
|
|
622
|
+
* Lower-level primitive that backs the `<Errored>` flow control. Catches
|
|
623
|
+
* thrown errors inside `fn` and invokes `fallback(error, reset)` instead.
|
|
624
|
+
* `error` is an accessor for the latest captured error; `reset()` recomputes
|
|
625
|
+
* the failing sources so the boundary can attempt to recover.
|
|
626
|
+
*
|
|
627
|
+
* App code should use `<Errored fallback={...}>` instead — reach for this only
|
|
628
|
+
* when authoring custom boundary components.
|
|
629
|
+
*
|
|
630
|
+
* @example
|
|
631
|
+
* ```tsx
|
|
632
|
+
* // Custom boundary that wraps the primitive and adds telemetry.
|
|
633
|
+
* function TracedErrored(props: { fallback: (e: () => unknown) => JSX.Element; children: JSX.Element }) {
|
|
634
|
+
* return createErrorBoundary(
|
|
635
|
+
* () => props.children,
|
|
636
|
+
* (err, reset) => {
|
|
637
|
+
* reportError(err());
|
|
638
|
+
* return props.fallback(err);
|
|
639
|
+
* }
|
|
640
|
+
* ) as unknown as JSX.Element;
|
|
641
|
+
* }
|
|
642
|
+
* ```
|
|
643
|
+
*/ function createErrorBoundary(e, t) {
|
|
644
|
+
return createCollectionBoundary(STATUS_ERROR, e, e => t(accessor(e._), () => e.he()));
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
* Coordinate the reveal timing of sibling loading boundaries.
|
|
649
|
+
*
|
|
650
|
+
* Accepts reactive accessors:
|
|
651
|
+
* - `order`: `"sequential"` (default) | `"together"` | `"natural"`.
|
|
652
|
+
* - `"sequential"` — classic frontier reveal: siblings reveal in registration order
|
|
653
|
+
* as each resolves; later siblings stay hidden until earlier ones complete.
|
|
654
|
+
* - `"together"` — every direct slot stays on its fallback until the whole group
|
|
655
|
+
* is "minimally ready" (each direct slot has produced its own first visible
|
|
656
|
+
* content under its own order), then the whole group releases at once.
|
|
657
|
+
* - `"natural"` — children reveal independently (as each resolves). At the top
|
|
658
|
+
* level this is a no-op compared to not using `createRevealOrder`; the mode
|
|
659
|
+
* exists for nesting, where the group registers as a single composite slot to
|
|
660
|
+
* any enclosing `createRevealOrder`.
|
|
661
|
+
* - `collapsed`: only meaningful when `order === "sequential"`. When set, tail siblings
|
|
662
|
+
* past the frontier suppress their own fallback output. Ignored under `"together"`
|
|
663
|
+
* and `"natural"` — those orders have no frontier.
|
|
664
|
+
*
|
|
665
|
+
* Nested `createRevealOrder` groups compose: the inner controller registers as a
|
|
666
|
+
* single slot in the outer controller and is held on its fallbacks until the outer
|
|
667
|
+
* releases that slot. Once released, the inner controller runs its own order locally
|
|
668
|
+
* over anything still pending. There is no opt-out from an outer hold.
|
|
669
|
+
*
|
|
670
|
+
* "Minimally ready" is what an order considers its first visible content:
|
|
671
|
+
* - `sequential` — frontier-0 is minimally ready (leaf: on resolve; nested: via its
|
|
672
|
+
* own minimal signal).
|
|
673
|
+
* - `together` — every direct slot is minimally ready.
|
|
674
|
+
* - `natural` — any direct slot has visible content (leaves on resolve; nested
|
|
675
|
+
* composites via their own minimal signal).
|
|
676
|
+
*
|
|
677
|
+
* @example
|
|
678
|
+
* ```ts
|
|
679
|
+
* // Primitive form of `<Reveal>` — coordinate sibling loading boundaries
|
|
680
|
+
* // programmatically. App code uses the JSX `<Reveal>` component instead.
|
|
681
|
+
* // Both options are accessors so they can react to state changes.
|
|
682
|
+
* createRevealOrder(
|
|
683
|
+
* () => renderSiblings(),
|
|
684
|
+
* { order: () => mode(), collapsed: () => true }
|
|
685
|
+
* );
|
|
686
|
+
* ```
|
|
687
|
+
*/ function createRevealOrder(e, t) {
|
|
688
|
+
_revealUsed = true;
|
|
689
|
+
const r = createOwner();
|
|
690
|
+
const n = getContext(RevealControllerContext);
|
|
691
|
+
const i = t?.order || SEQUENTIAL_ACCESSOR, s = t?.collapsed || FALSE_ACCESSOR;
|
|
692
|
+
const o = new RevealController(i, s);
|
|
693
|
+
setContext(RevealControllerContext, o, r);
|
|
694
|
+
return runWithOwner(r, () => {
|
|
695
|
+
const t = e();
|
|
696
|
+
const r = computed(() => {
|
|
697
|
+
i();
|
|
698
|
+
s();
|
|
699
|
+
o.B();
|
|
700
|
+
});
|
|
701
|
+
// Post-construction rather than an options argument, so the prod call
|
|
702
|
+
// keeps its shape; the observe node literal already carries the slot.
|
|
703
|
+
if (true) r._name = "reveal order";
|
|
704
|
+
if (n) {
|
|
705
|
+
o.L = n;
|
|
706
|
+
n.$(o);
|
|
707
|
+
cleanup(() => n.ee(o));
|
|
708
|
+
}
|
|
709
|
+
return t;
|
|
710
|
+
});
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
/**
|
|
714
|
+
* Resolves a children value to its renderable form: unwraps zero-arg functions
|
|
715
|
+
* (accessors), recursively flattens arrays, and optionally skips
|
|
716
|
+
* non-rendering values (`null`, `undefined`, `true`, `false`, `""`).
|
|
717
|
+
*
|
|
718
|
+
* Used internally by flow components and by the renderer to walk a children
|
|
719
|
+
* tree. App code rarely needs this directly — see `children()` in `solid-js`
|
|
720
|
+
* for the user-facing helper that memoizes the result.
|
|
721
|
+
*
|
|
722
|
+
* @param children value or array of values to flatten
|
|
723
|
+
* @param options
|
|
724
|
+
* - `skipNonRendered` — drop values that won't render
|
|
725
|
+
* - `doNotUnwrap` — leave function children as-is (caller will resolve)
|
|
726
|
+
*
|
|
727
|
+
* @example
|
|
728
|
+
* ```ts
|
|
729
|
+
* // Custom renderer walking a children tree manually. Most authors should
|
|
730
|
+
* // use `children()` from solid-js, which memoizes the resolved value.
|
|
731
|
+
* function renderChildren(value: unknown): unknown {
|
|
732
|
+
* return flatten(value, { skipNonRendered: true });
|
|
733
|
+
* }
|
|
734
|
+
* ```
|
|
735
|
+
*/ function flatten(e, t) {
|
|
736
|
+
if (typeof e === "function" && !e.length) {
|
|
737
|
+
if (t?.doNotUnwrap) return e;
|
|
738
|
+
do {
|
|
739
|
+
e = e();
|
|
740
|
+
} while (typeof e === "function" && !e.length);
|
|
741
|
+
}
|
|
742
|
+
if (t?.skipNonRendered && (e == null || e === true || e === false || e === "")) return;
|
|
743
|
+
if (Array.isArray(e)) {
|
|
744
|
+
let r = [];
|
|
745
|
+
if (flattenArray(e, r, t)) {
|
|
746
|
+
return () => {
|
|
747
|
+
let e = [];
|
|
748
|
+
flattenArray(r, e, {
|
|
749
|
+
...t,
|
|
750
|
+
doNotUnwrap: false
|
|
751
|
+
});
|
|
752
|
+
return e;
|
|
753
|
+
};
|
|
754
|
+
}
|
|
755
|
+
return r;
|
|
756
|
+
}
|
|
757
|
+
return e;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
function flattenArray(e, t = [], r) {
|
|
761
|
+
let n = null;
|
|
762
|
+
let i = false;
|
|
763
|
+
for (let s = 0; s < e.length; s++) {
|
|
764
|
+
try {
|
|
765
|
+
let n = e[s];
|
|
766
|
+
if (typeof n === "function" && !n.length) {
|
|
767
|
+
if (r?.doNotUnwrap) {
|
|
768
|
+
t.push(n);
|
|
769
|
+
i = true;
|
|
770
|
+
continue;
|
|
771
|
+
}
|
|
772
|
+
do {
|
|
773
|
+
n = n();
|
|
774
|
+
} while (typeof n === "function" && !n.length);
|
|
775
|
+
}
|
|
776
|
+
if (Array.isArray(n)) {
|
|
777
|
+
// OR, don't overwrite: an accessor already pushed under doNotUnwrap
|
|
778
|
+
// still needs the resolving wrapper even when a later sibling
|
|
779
|
+
// fragment contains no functions (#3133).
|
|
780
|
+
i = flattenArray(n, t, r) || i;
|
|
781
|
+
} else if (r?.skipNonRendered && (n == null || n === true || n === false || n === "")) {
|
|
782
|
+
// skip
|
|
783
|
+
} else t.push(n);
|
|
784
|
+
} catch (e) {
|
|
785
|
+
if (!(e instanceof NotReadyError)) throw e;
|
|
786
|
+
n = e;
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
if (n) throw n;
|
|
790
|
+
return i;
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
export { CollectionQueue, RevealController, createErrorBoundary, createLoadingBoundary, createRevealOrder, flatten };
|