@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.
Files changed (150) hide show
  1. package/dist/dev-shared.js +7138 -0
  2. package/dist/dev.attribution.js +3307 -0
  3. package/dist/dev.js +5691 -4491
  4. package/dist/observe/affects.js +129 -0
  5. package/dist/observe/attribution.js +7 -0
  6. package/dist/observe/boundaries.js +793 -0
  7. package/dist/observe/core/action.js +177 -0
  8. package/dist/observe/core/async.js +849 -0
  9. package/dist/observe/core/attribution-costs.js +66 -0
  10. package/dist/observe/core/attribution-feedback.js +280 -0
  11. package/dist/observe/core/attribution-hooks.js +83 -0
  12. package/dist/observe/core/attribution-queries.js +43 -0
  13. package/dist/observe/core/attribution.js +2904 -0
  14. package/dist/observe/core/constants.js +283 -0
  15. package/dist/{types-cjs/core/context.d.cts → observe/core/context.js} +37 -12
  16. package/dist/observe/core/core.js +1999 -0
  17. package/dist/observe/core/dev.js +343 -0
  18. package/dist/observe/core/effect.js +200 -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 +627 -0
  27. package/dist/observe/core/owner.js +353 -0
  28. package/dist/observe/core/scheduler.js +1547 -0
  29. package/dist/observe/core/verdict.js +674 -0
  30. package/dist/observe/index.js +59 -0
  31. package/dist/observe/map.js +484 -0
  32. package/dist/observe/signals.js +731 -0
  33. package/dist/observe/store/index.js +44 -0
  34. package/dist/observe/store/next/optimistic.js +717 -0
  35. package/dist/observe/store/next/projection.js +266 -0
  36. package/dist/observe/store/next/reconcile.js +375 -0
  37. package/dist/observe/store/next/store.js +2480 -0
  38. package/dist/observe/store/next/target.js +51 -0
  39. package/dist/observe/store/store.js +331 -0
  40. package/dist/observe/store/storePath.js +103 -0
  41. package/dist/observe/store/utils.js +1070 -0
  42. package/dist/prod/affects.js +10 -9
  43. package/dist/prod/attribution.js +45 -0
  44. package/dist/prod/boundaries.js +388 -178
  45. package/dist/prod/core/action.js +65 -37
  46. package/dist/prod/core/async.js +378 -163
  47. package/dist/prod/core/attribution-hooks.js +3 -0
  48. package/dist/prod/core/constants.js +186 -1
  49. package/dist/prod/core/context.js +10 -16
  50. package/dist/prod/core/core.js +1546 -416
  51. package/dist/prod/core/dev.js +18 -1
  52. package/dist/prod/core/effect.js +119 -79
  53. package/dist/prod/core/error-hooks.js +71 -0
  54. package/dist/prod/core/error.js +13 -1
  55. package/dist/prod/core/external.js +4 -4
  56. package/dist/prod/core/graph.js +105 -54
  57. package/dist/prod/core/heap.js +72 -65
  58. package/dist/prod/core/invariants.js +3 -2
  59. package/dist/prod/core/lanes.js +117 -52
  60. package/dist/prod/core/optimistic.js +458 -104
  61. package/dist/prod/core/owner.js +131 -84
  62. package/dist/prod/core/scheduler.js +998 -241
  63. package/dist/prod/core/verdict.js +417 -112
  64. package/dist/prod/index.js +20 -8
  65. package/dist/prod/map.js +312 -151
  66. package/dist/prod/signals.js +363 -32
  67. package/dist/prod/store/index.js +2 -0
  68. package/dist/prod/store/next/optimistic.js +530 -197
  69. package/dist/prod/store/next/projection.js +142 -57
  70. package/dist/prod/store/next/reconcile.js +149 -103
  71. package/dist/prod/store/next/store.js +1470 -346
  72. package/dist/prod/store/next/target.js +40 -9
  73. package/dist/prod/store/store.js +23 -19
  74. package/dist/prod/store/utils.js +997 -130
  75. package/dist/types/attribution.d.ts +19 -0
  76. package/dist/types/attribution.prod.d.ts +22 -0
  77. package/dist/types/boundaries.d.ts +78 -5
  78. package/dist/types/core/action.d.ts +12 -5
  79. package/dist/types/core/async.d.ts +3 -1
  80. package/dist/types/core/attribution-costs.d.ts +35 -0
  81. package/dist/types/core/attribution-feedback.d.ts +133 -0
  82. package/dist/types/core/attribution-hooks.d.ts +304 -0
  83. package/dist/types/core/attribution-queries.d.ts +24 -0
  84. package/dist/types/core/attribution.d.ts +892 -0
  85. package/dist/types/core/constants.d.ts +179 -0
  86. package/dist/types/core/core.d.ts +299 -25
  87. package/dist/types/core/dev.d.ts +421 -8
  88. package/dist/types/core/effect.d.ts +8 -1
  89. package/dist/types/core/error-hooks.d.ts +71 -0
  90. package/dist/types/core/error.d.ts +9 -0
  91. package/dist/types/core/graph.d.ts +23 -0
  92. package/dist/types/core/heap.d.ts +5 -3
  93. package/dist/types/core/index.d.ts +6 -3
  94. package/dist/types/core/invariants.d.ts +5 -1
  95. package/dist/types/core/lanes.d.ts +51 -19
  96. package/dist/types/core/owner.d.ts +15 -3
  97. package/dist/types/core/scheduler.d.ts +248 -1
  98. package/dist/types/core/types.d.ts +124 -41
  99. package/dist/types/index.d.ts +18 -5
  100. package/dist/types/map.d.ts +2 -0
  101. package/dist/types/signals.d.ts +145 -13
  102. package/dist/types/store/index.d.ts +7 -6
  103. package/dist/types/store/next/optimistic.d.ts +18 -13
  104. package/dist/types/store/next/projection.d.ts +5 -2
  105. package/dist/types/store/next/reconcile.d.ts +7 -0
  106. package/dist/types/store/next/store.d.ts +83 -11
  107. package/dist/types/store/next/target.d.ts +108 -11
  108. package/dist/types/store/store.d.ts +20 -11
  109. package/dist/types/store/utils.d.ts +188 -0
  110. package/package.json +31 -26
  111. package/dist/node.cjs +0 -8137
  112. package/dist/types/store/optimistic.d.ts +0 -45
  113. package/dist/types/store/projection.d.ts +0 -70
  114. package/dist/types/store/reconcile.d.ts +0 -46
  115. package/dist/types-cjs/affects.d.cts +0 -47
  116. package/dist/types-cjs/boundaries.d.cts +0 -175
  117. package/dist/types-cjs/core/action.d.cts +0 -64
  118. package/dist/types-cjs/core/async.d.cts +0 -21
  119. package/dist/types-cjs/core/constants.d.cts +0 -71
  120. package/dist/types-cjs/core/core.d.cts +0 -156
  121. package/dist/types-cjs/core/dev.d.cts +0 -64
  122. package/dist/types-cjs/core/effect.d.cts +0 -30
  123. package/dist/types-cjs/core/error.d.cts +0 -47
  124. package/dist/types-cjs/core/external.d.cts +0 -15
  125. package/dist/types-cjs/core/graph.d.cts +0 -5
  126. package/dist/types-cjs/core/heap.d.cts +0 -22
  127. package/dist/types-cjs/core/index.d.cts +0 -13
  128. package/dist/types-cjs/core/invariants.d.cts +0 -59
  129. package/dist/types-cjs/core/lanes.d.cts +0 -56
  130. package/dist/types-cjs/core/optimistic.d.cts +0 -6
  131. package/dist/types-cjs/core/owner.d.cts +0 -124
  132. package/dist/types-cjs/core/scheduler.d.cts +0 -172
  133. package/dist/types-cjs/core/types.d.cts +0 -148
  134. package/dist/types-cjs/core/verdict.d.cts +0 -2
  135. package/dist/types-cjs/index.d.cts +0 -10
  136. package/dist/types-cjs/map.d.cts +0 -69
  137. package/dist/types-cjs/package.json +0 -3
  138. package/dist/types-cjs/signals.d.cts +0 -624
  139. package/dist/types-cjs/store/index.d.cts +0 -19
  140. package/dist/types-cjs/store/next/optimistic.d.cts +0 -20
  141. package/dist/types-cjs/store/next/projection.d.cts +0 -24
  142. package/dist/types-cjs/store/next/reconcile.d.cts +0 -3
  143. package/dist/types-cjs/store/next/store.d.cts +0 -71
  144. package/dist/types-cjs/store/next/target.d.cts +0 -99
  145. package/dist/types-cjs/store/optimistic.d.cts +0 -45
  146. package/dist/types-cjs/store/projection.d.cts +0 -70
  147. package/dist/types-cjs/store/reconcile.d.cts +0 -46
  148. package/dist/types-cjs/store/store.d.cts +0 -138
  149. package/dist/types-cjs/store/storePath.d.cts +0 -58
  150. package/dist/types-cjs/store/utils.d.cts +0 -74
@@ -1,10 +1,12 @@
1
- import { computed, optimisticComputed, setSignal, optimisticSignal, runWithOwner, setMemo, signal, read, untrack } from "./core/core.js";
1
+ import { TimeoutError } from "./core/error.js";
2
2
 
3
- import { cleanup, createRoot, getOwner, dispose } from "./core/owner.js";
3
+ import { computed, optimisticComputed, setSignal, optimisticSignal, runWithOwner, setMemo, signal, installAuthoritativeRead, markRefresh, read, untrack } from "./core/core.js";
4
4
 
5
- import { globalQueue, Queue } from "./core/scheduler.js";
5
+ import { cleanup, createRoot, getOwner, dispose, getObserver } from "./core/owner.js";
6
6
 
7
- import { CONFIG_AUTO_DISPOSE, CONFIG_CHILDREN_FORBIDDEN, EFFECT_USER, $REFRESH } from "./core/constants.js";
7
+ import { globalQueue, dirtyQueue, Queue, entangleConfirmingTransitions, activeTransition } from "./core/scheduler.js";
8
+
9
+ import { CONFIG_AUTO_DISPOSE, CONFIG_CHILDREN_FORBIDDEN, EFFECT_USER, $REFRESH, CONFIG_DIRECT_COMMIT, CONFIG_AUTHORITATIVE_READ, CONFIG_FRESH_READ } from "./core/constants.js";
8
10
 
9
11
  import "./core/invariants.js";
10
12
 
@@ -41,6 +43,12 @@ import { installOptimisticEngine } from "./core/optimistic.js";
41
43
  * Cannot be used inside `createTrackedEffect` or `onSettled` — return a
42
44
  * cleanup function from the callback body instead.
43
45
  *
46
+ * Cleanups run in unwind order: an owner's children are disposed before its
47
+ * own cleanups, and within one owner later registrations run before earlier
48
+ * ones. In production a component body shares its enclosing owner, so
49
+ * register cleanup before creating children when the order between them
50
+ * matters.
51
+ *
44
52
  * @example
45
53
  * ```ts
46
54
  * // Library shape: thread a resource's disposal into a *captured* owner
@@ -65,7 +73,7 @@ function accessor(e) {
65
73
  function createSignal(e, t) {
66
74
  if (typeof e === "function") {
67
75
  const n = computed(e, t);
68
- n.T &= ~CONFIG_AUTO_DISPOSE;
76
+ n.C &= ~CONFIG_AUTO_DISPOSE;
69
77
  return [ accessor(n), setMemo.bind(null, n) ];
70
78
  }
71
79
  const n = signal(e, t);
@@ -76,7 +84,74 @@ function createMemo(e, t) {
76
84
  return accessor(computed(e, t));
77
85
  }
78
86
 
79
- function createEffect(e, t, n) {
87
+ /**
88
+ * Creates a reactive effect with **separate compute and effect phases**.
89
+ *
90
+ * - `compute(prev)` runs reactively — *put all reactive reads here*. The
91
+ * returned value is passed to `effect` and is also the new "previous" value
92
+ * for the next run.
93
+ * - `effect(next, prev?)` runs imperatively (untracked) after the queue
94
+ * flushes. *Put DOM writes / fetch / logging / subscriptions here.* It may
95
+ * return a cleanup function which runs before the next effect or on
96
+ * disposal.
97
+ *
98
+ * Reactive reads inside `effect` will *not* re-trigger this effect — that's
99
+ * intentional. If you need a single-phase tracked effect, use
100
+ * `createTrackedEffect` (with the tradeoffs noted there).
101
+ *
102
+ * Pass an `EffectBundle` (`{ effect, error }`) instead of a plain function to
103
+ * intercept **compute-phase** errors — errors thrown by `compute` or arriving
104
+ * from upstream reactive sources (including async rejections), which your own
105
+ * code has no frame to `try/catch`. The `error` handler is the error arm of
106
+ * the effect phase: it runs on the same schedule and in the same imperative,
107
+ * writable scope as `effect` (setting error state via signals is fine), and
108
+ * only for *settled* errors — a transient error that recovers before the
109
+ * effect phase runs `effect` with the recovered value instead, and a held
110
+ * transition defers it exactly as it defers `effect`. Without an `error`
111
+ * handler a compute-phase error is logged and the effect simply skips that
112
+ * run — a non-render effect's reactivity failing does not crash the app.
113
+ * Rethrowing from `error` escalates it to the nearest error boundary
114
+ * (halting the system if none exists).
115
+ *
116
+ * The **effect phase is different**: it is your own imperative code, so handle
117
+ * failures with `try/catch` where they occur. An uncaught effect-phase throw
118
+ * is treated as an unhandled application error — caught by the nearest
119
+ * `createErrorBoundary`/`<Errored>`, and permanently halting the reactive
120
+ * system if there is none. It is *not* routed to the bundle's `error` handler.
121
+ *
122
+ * ```typescript
123
+ * createEffect<T>(compute, effectFn | { effect, error }, options?: EffectOptions);
124
+ * ```
125
+ * @param compute a function that receives its previous value and returns a new value used to react on a computation
126
+ * @param effectFn a function that receives the new value and is used to perform side effects (return a cleanup function), or an `EffectBundle` with `effect` and `error` handlers
127
+ * @param options `EffectOptions` -- name, defer, schedule, transparent
128
+ *
129
+ * @example
130
+ * ```ts
131
+ * const [count, setCount] = createSignal(0);
132
+ *
133
+ * createEffect(
134
+ * () => count(), // compute: tracks `count`
135
+ * value => console.log(value) // effect: side effect
136
+ * );
137
+ *
138
+ * setCount(1); // logs 1 after the next flush
139
+ * ```
140
+ *
141
+ * @example
142
+ * ```ts
143
+ * createEffect(
144
+ * () => userId(),
145
+ * id => {
146
+ * const ctrl = new AbortController();
147
+ * fetch(`/users/${id}`, { signal: ctrl.signal });
148
+ * return () => ctrl.abort(); // cleanup before next run / disposal
149
+ * }
150
+ * );
151
+ * ```
152
+ *
153
+ * @description https://docs.solidjs.com/reference/basic-reactivity/create-effect
154
+ */ function createEffect(e, t, n) {
80
155
  effect(e, t.effect || t, t.error, {
81
156
  user: true,
82
157
  ...n
@@ -119,6 +194,16 @@ function createEffect(e, t, n) {
119
194
  * Creates a tracked reactive effect where dependency tracking and side effects happen
120
195
  * in the same scope.
121
196
  *
197
+ * @deprecated Do not use in new code. For a side effect that follows reactive
198
+ * state, use `createEffect(compute, effect)` — it separates tracking from the
199
+ * side effect, knows its dependencies before it runs, and participates in
200
+ * async and transitions. For one-time DOM work after render (measuring,
201
+ * attaching third-party widgets to a ref), use `onSettled`. Tracking from
202
+ * inside the effect phase — the only thing this primitive adds — is retained
203
+ * solely to ease 1.x migration: it runs beside user-effect callbacks after
204
+ * values commit, never holds a transition, and cannot observe a write staged
205
+ * earlier in the same flush by a signal it has not read yet.
206
+ *
122
207
  * WARNING: Because tracking and effects happen in the same scope, this primitive
123
208
  * may run multiple times for a single change or show tearing (reading inconsistent
124
209
  * state). Use only when dynamic subscription patterns require same-scope tracking.
@@ -181,31 +266,28 @@ function createEffect(e, t, n) {
181
266
  */ function createReaction(e, t) {
182
267
  let n = undefined;
183
268
  cleanup(() => n?.());
184
- const c = getOwner();
269
+ const r = getOwner();
185
270
  // The currently armed effect node. `track()` replaces the previous
186
271
  // subscription (1.x semantics): without disposing the superseded arm, its
187
272
  // sources stayed live (firing the callback for replaced dependencies), each
188
273
  // accumulated arm delivered its own fire, and un-fired arms leaked as live
189
274
  // effect nodes until the owner disposed (#2861).
190
- let r;
275
+ let i;
191
276
  return o => {
192
- if (r) {
193
- dispose(r);
194
- r = undefined;
277
+ if (i) {
278
+ dispose(i);
279
+ i = undefined;
195
280
  }
196
- runWithOwner(c, () => {
197
- effect(() => (o(), r = getOwner()), t => {
198
- r = undefined;
281
+ runWithOwner(r, () => {
282
+ effect(() => (o(), i = getOwner()), t => {
283
+ i = undefined;
199
284
  n?.();
200
- const c = (e.effect || e)?.();
201
- if (false && c !== undefined && typeof c !== "function") ;
202
- n = c;
285
+ const r = (e.effect || e)?.();
286
+ if (false && r !== undefined && typeof r !== "function") ;
287
+ n = r;
203
288
  dispose(t);
204
289
  }, e.error, {
205
- ...false ? {
206
- ...t,
207
- name: t?.name ?? "effect"
208
- } : t,
290
+ ...t,
209
291
  user: true,
210
292
  defer: true
211
293
  });
@@ -241,7 +323,7 @@ function createEffect(e, t, n) {
241
323
  * @param fn a reactive expression to resolve
242
324
  */ function resolve(e) {
243
325
  return new Promise((t, n) => {
244
- createRoot(c => {
326
+ createRoot(r => {
245
327
  // Deliver effect applies on a microtask instead of the owner queue: an
246
328
  // incomplete transition stashes its effect queues until it settles, but
247
329
  // an action yielding this promise is itself what keeps the transition
@@ -249,26 +331,267 @@ function createEffect(e, t, n) {
249
331
  // still runs in place (under the transaction's view when created inside
250
332
  // an action step), and status/boundary notifications keep their normal
251
333
  // route through the inherited queue.
252
- const r = getOwner();
334
+ const i = getOwner();
253
335
  const o = new MicrotaskQueue;
254
- o.Fe = r.C;
336
+ o._parent = i.T;
255
337
  // notify() forwards up the normal chain
256
- r.C = o;
338
+ i.T = o;
257
339
  // A user effect rather than a bare computed: computeds are pull-based and
258
340
  // are only re-enqueued when a pending source *resolves* — a rejection just
259
341
  // marks them errored, so nothing would re-run and the promise would never
260
342
  // settle (#2842). The effect's error channel is notified on rejection.
261
343
  effect(e, e => {
262
344
  t(e);
263
- c();
345
+ r();
264
346
  }, e => {
265
347
  // The error arm already unwraps StatusError (#2840) — `err` is the
266
348
  // user's original error, matching what error boundaries expose.
267
349
  n(e);
268
- c();
350
+ r();
351
+ },
352
+ // DIRECT_COMMIT: a source settling INTO the held transaction (e.g. a
353
+ // refresh this action issued) stages its landing; the effect's own
354
+ // recompute must not stage too, or the microtask apply reads the
355
+ // stale mainline value and resolves with old data.
356
+ {
357
+ user: true,
358
+ yn: CONFIG_DIRECT_COMMIT
359
+ });
360
+ });
361
+ });
362
+ }
363
+
364
+ /**
365
+ * Invalidates one reactive source, forcing it to re-execute even if its inputs
366
+ * haven't changed, and returns a promise for the target's NEXT QUIESCENT
367
+ * STATE — the re-ask (and anything that supersedes it) has settled.
368
+ *
369
+ * Pass either a Solid-created accessor or a projected store created from
370
+ * `createStore(fn, ...)` / `createProjection(...)`. `refresh()` is a
371
+ * write-like invalidation operation: it does not read the target's value, and
372
+ * refreshing a plain signal accessor is a no-op that resolves immediately.
373
+ *
374
+ * The returned promise is safe to ignore (fire-and-forget refresh is
375
+ * unchanged, and a failed refetch will not surface an unhandled rejection).
376
+ * Awaiting it gives imperative flows the settle point without a reactive
377
+ * read:
378
+ * - Accessor targets resolve with the settled value; store targets resolve
379
+ * with the store node passed (reads through it are fresh after the await).
380
+ * - A failed re-ask rejects with the error (inside an action's generator,
381
+ * `yield refresh(x)` throws back at the yield point and the action reverts
382
+ * like any other failure).
383
+ * - Semantics are quiescence, not flight identity: if another refresh (or
384
+ * any invalidation) supersedes this one mid-flight, the promise waits for
385
+ * — and delivers — whatever finally lands.
386
+ * - Inside an action, truth landing into the held transaction is STAGED;
387
+ * the promise still settles then (matching `resolve()`/`until()`, #2930)
388
+ * and delivers the staged value — the caller's own optimistic override is
389
+ * never the delivered value.
390
+ * - The re-ask itself stays verdict-quiet exactly as before: `isPending`
391
+ * does not flip for a bare refresh (pair with `affects()` for a visible
392
+ * pending window).
393
+ *
394
+ * @example
395
+ * ```ts
396
+ * const user = createMemo(async () => fetch(`/users/${id()}`).then(r => r.json()));
397
+ *
398
+ * // Fire-and-forget re-fetch
399
+ * <button onClick={() => refresh(user)}>Reload</button>;
400
+ *
401
+ * // Imperative settle point
402
+ * const fresh = await refresh(user);
403
+ * ```
404
+ */ function refresh(e) {
405
+ const t = e?.[$REFRESH];
406
+ if (!t) {
407
+ return Promise.resolve(undefined);
408
+ }
409
+ // Mark now, watch on a microtask. The waiter is resolve()'s machinery with
410
+ // two extra reader bits, but it must NOT compute at call time (effects
411
+ // recompute eagerly on creation): same-tick refreshes coalesce into ONE
412
+ // re-ask only because every mark lands before anything pulls, and eager
413
+ // per-call pulls turned three refreshes into three fetches. Deferred, the
414
+ // waiter's first read sees the coalesced state: FRESH_READ pulls the node
415
+ // through recompute if it is still dirty (self-deduping — a clean node
416
+ // no-ops, so N waiters cost one pull; this also closes the race where a
417
+ // waiter reads the PRE-re-ask value as settled and delivers stale), after
418
+ // which the read either parks on the re-ask's pending window (async — the
419
+ // settle walk re-runs it on every landing, equal-value and
420
+ // staged-under-hold included, and a rejection arrives through the effect's
421
+ // error channel) or serves the sync answer. AUTHORITATIVE_READ keeps an
422
+ // action's own optimistic override out of the delivered value. resolve()'s
423
+ // own eager compute is untouched: created after a refresh it still settles
424
+ // stale-while-revalidate (#2930) — its contract is "first settled value",
425
+ // not "next quiescent state".
426
+
427
+ // An authoritative reader is woken through a late-bound hook when the truth
428
+ // lands EQUAL to a standing override (the A17-silent path). Every setter of
429
+ // that reader bit must install it — until() does, and this waiter is the
430
+ // other one (#3303: refresh of an optimistic in an app that never called
431
+ // until() dereferenced the null hook).
432
+ installAuthoritativeRead();
433
+ markRefresh(t);
434
+ const n = new Promise((n, r) => {
435
+ queueMicrotask(() => {
436
+ // No createRoot: the microtask has no ambient owner, so the effect is
437
+ // naturally detached, and settle disposes the node directly — the root
438
+ // added ~560B of otherwise-shakeable machinery for nothing but the
439
+ // dev-mode NO_OWNER_EFFECT warning, so dev keeps a root husk purely to
440
+ // stay quiet. The waiter swaps in its microtask queue during its own
441
+ // first compute (before the initial apply enqueue), replacing the
442
+ // root-owner plumbing.
443
+ // Typed as the effect node, not Owner: the capture runs inside the
444
+ // effect's own compute, where the ambient owner IS the effect —
445
+ // exactly what dispose() takes.
446
+ let i = null;
447
+ const make = () => effect(() => {
448
+ if (i === null) {
449
+ i = getOwner();
450
+ const e = new MicrotaskQueue;
451
+ e._parent = i.T;
452
+ i.T = e;
453
+ }
454
+ return read(t);
455
+ }, t => {
456
+ n(typeof e === "function" ? t : e);
457
+ dispose(i);
458
+ }, e => {
459
+ r(e);
460
+ dispose(i);
269
461
  }, {
270
- user: true
462
+ user: true,
463
+ yn: CONFIG_DIRECT_COMMIT | CONFIG_AUTHORITATIVE_READ | CONFIG_FRESH_READ
464
+ });
465
+ make();
466
+ });
467
+ });
468
+ // Fire-and-forget refresh must not turn a failed refetch into an unhandled
469
+ // rejection; awaiting callers attach their own handlers to `promise`.
470
+ n.catch(() => {});
471
+ return n;
472
+ }
473
+
474
+ /**
475
+ * Awaits a reactive predicate and resolves the first time it settles *truthy*,
476
+ * with that (narrowed) value. Falsy results and pending async reads both mean
477
+ * "not yet": the subscription stays live and re-evaluates as sources change.
478
+ * If the predicate settles with an error — a throw, or an async source that
479
+ * rejects — the promise rejects with it, as do timeout and abort.
480
+ *
481
+ * Where {@link resolve} answers "what is this value" (first settled value,
482
+ * whatever it is), `until` answers "when does the world confirm this
483
+ * condition". The difference matters inside an `action()`: `yield until(...)`
484
+ * holds the action's transaction — and any optimistic state riding it — open
485
+ * until the condition is independently true.
486
+ *
487
+ * To make that sound, `until`'s predicate reads the AUTHORITATIVE view — and
488
+ * this is the one read-semantics difference from `resolve`, which reads the
489
+ * normal (transaction's own) view where overrides are visible:
490
+ *
491
+ * - **Optimistic overrides are invisible** to the predicate. Your own
492
+ * tentative write can never satisfy your own ack, even on the
493
+ * single-primitive shape where the optimistic store IS the live-fed store.
494
+ * (Derived computeds serve their normal cached values — express the
495
+ * condition over sources of truth, not derived views of the overlay.)
496
+ * - **Everything else reads normally, including uncommitted transition-staged
497
+ * data.** Real data is real wherever it currently lives. This is
498
+ * load-bearing, not a loophole: truth that arrives *into* the open
499
+ * transaction (a `refresh()` this action issued, an entangled landing)
500
+ * stages and cannot commit until the hold releases — a predicate that
501
+ * refused staged reads would deadlock on the very data it is waiting for.
502
+ *
503
+ * This is the acknowledgment mechanism for mutations confirmed on a live data
504
+ * channel (sockets, subscriptions, live queries) rather than by the mutation's
505
+ * own response: correlate by a client-generated id or version in the predicate,
506
+ * and let truth arrive however it arrives — push, refetch, or another tab.
507
+ *
508
+ * Failure composes with action semantics: a rejection is thrown back into the
509
+ * generator at the `yield` point — catchable there, or the action fails and
510
+ * its optimistic state reverts.
511
+ *
512
+ * Must be called *outside* a tracking scope.
513
+ *
514
+ * Inside an action, call it from a step: after an `await`, put a bare `yield`
515
+ * before `yield until(...)`. The runtime cannot hook an async generator's
516
+ * `await` continuation, so the `until(...)` expression — which CREATES the
517
+ * predicate's reader — would otherwise run outside the transaction; created
518
+ * there it is born held (A29) and replays only at the commit its own promise
519
+ * holds open (#3482). See {@link action}.
520
+ *
521
+ * @example
522
+ * ```ts
523
+ * const send = action(async function* (text: string) {
524
+ * const clientId = crypto.randomUUID();
525
+ * setMessages(m => { m.push({ clientId, text, pending: true }); }); // optimistic
526
+ * await socket.send({ clientId, text }); // fire-and-forget transport
527
+ * yield; // re-enter the transaction after the await
528
+ * // Hold until the live source echoes the write (authoritative view —
529
+ * // the optimistic row above cannot satisfy this):
530
+ * yield until(() => messages.some(m => m.clientId === clientId), { timeout: 10_000 });
531
+ * });
532
+ * ```
533
+ *
534
+ * @param fn a reactive predicate over authoritative state
535
+ * @param options optional `timeout` (ms) and abort `signal`
536
+ */ function until(e, t) {
537
+ // Late-bind the wakeup hook for the A17-silent ack paths (pay-for-use:
538
+ // apps that never call until() never retain it).
539
+ installAuthoritativeRead();
540
+ // Flip-entanglement (#3164 follow-up): the transaction this until() holds
541
+ // open (the action's, when yielded from one). The predicate is the user's
542
+ // declaration of what confirms it — when a foreign transition's staged
543
+ // write flips it truthy, that transition merges here and reveals at the
544
+ // joint settle instead of painting the confirmation under live optimism.
545
+ const n = activeTransition;
546
+ return new Promise((r, i) => {
547
+ const o = t?.signal;
548
+ if (o?.aborted) return i(o.reason);
549
+ createRoot(c => {
550
+ // Same delivery contract as resolve() (#2930): effect applies ride a
551
+ // microtask so the promise can settle while the transaction the caller
552
+ // yielded it into is still open — that transaction being open is the
553
+ // entire point of the hold.
554
+ const u = getOwner();
555
+ const s = new MicrotaskQueue;
556
+ s._parent = u.T;
557
+ u.T = s;
558
+ let f;
559
+ let a;
560
+ const settle = e => {
561
+ if (f !== undefined) clearTimeout(f);
562
+ if (a !== undefined) o.removeEventListener("abort", a);
563
+ e();
564
+ c();
565
+ };
566
+ effect(n === null ? e : () => {
567
+ const t = e();
568
+ // Runs inside the compute (pure phase): the confirming
569
+ // transition's stamps are live and its commit hasn't run, so
570
+ // the merge lands before any reveal. Falsy evaluations skip —
571
+ // non-flipping updates were never named as the confirmation.
572
+ if (t) entangleConfirmingTransitions(getObserver(), n);
573
+ return t;
574
+ }, e => {
575
+ // Falsy is "not yet": keep the subscription live and wait for the
576
+ // next evaluation. Only a truthy settled value resolves.
577
+ if (e) settle(() => r(e));
578
+ }, e => settle(() => i(e)),
579
+ // AUTHORITATIVE_READ: overrides invisible to the predicate.
580
+ // DIRECT_COMMIT: truth that stages into the held transaction (a
581
+ // refresh the action issued) must flow through to the microtask
582
+ // apply — a staged effect value would deadlock the hold on data
583
+ // the hold itself is keeping uncommitted.
584
+ {
585
+ user: true,
586
+ yn: CONFIG_AUTHORITATIVE_READ | CONFIG_DIRECT_COMMIT
271
587
  });
588
+ if (t?.timeout !== undefined) f = setTimeout(() => settle(() => i(new TimeoutError)), t.timeout);
589
+ if (o !== undefined) {
590
+ a = () => settle(() => i(o.reason));
591
+ o.addEventListener("abort", a, {
592
+ once: true
593
+ });
594
+ }
272
595
  });
273
596
  });
274
597
  }
@@ -280,7 +603,7 @@ function createOptimistic(e, t) {
280
603
  installOptimisticEngine();
281
604
  if (typeof e === "function") {
282
605
  const n = optimisticComputed(e, t);
283
- n.T &= ~CONFIG_AUTO_DISPOSE;
606
+ n.C &= ~CONFIG_AUTO_DISPOSE;
284
607
  return [ accessor(n), setSignal.bind(null, n) ];
285
608
  }
286
609
  const n = optimisticSignal(e, t);
@@ -382,13 +705,21 @@ function createOptimistic(e, t) {
382
705
  * on owner disposal
383
706
  */ function onSettled(e) {
384
707
  const t = getOwner();
385
- t && !(t.T & CONFIG_CHILDREN_FORBIDDEN) ? createTrackedEffect(() => untrack(e), undefined) : globalQueue.enqueue(EFFECT_USER, () => {
708
+ t && !(t.C & CONFIG_CHILDREN_FORBIDDEN) ? trackedEffect(() => untrack(e), undefined) : globalQueue.enqueue(EFFECT_USER, function fire() {
709
+ // Settled means derived. A settle that reverts optimism (or replays
710
+ // gated reads) only enqueues the affected subscribers; the pass after
711
+ // the commit re-derives them. Fired in the commit pass, the callback
712
+ // read the optimistic source already reverted beside a sync memo of it
713
+ // still holding the optimistic value — reads do not pull (#3411). Fall
714
+ // to the next pass while the heap has work; `run` swapped the queue,
715
+ // so this lands there, and `enqueue` keeps the drain alive.
716
+ if (dirtyQueue.EE >= dirtyQueue.ln) return globalQueue.enqueue(EFFECT_USER, fire);
386
717
  // Unowned, out-of-band fire (no owner, or a children-forbidden one this
387
718
  // one-shot must not bind to): a returned cleanup has no lifecycle to
388
719
  // attach to. Reject it in dev; in production the return is simply
389
720
  // dropped — never bound to an unrelated owner or run eagerly.
390
- e();
721
+ e();
391
722
  });
392
723
  }
393
724
 
394
- export { accessor, createEffect, createMemo, createOptimistic, createReaction, createRenderEffect, createSignal, createTrackedEffect, onCleanup, onSettled, resolve };
725
+ export { accessor, createEffect, createMemo, createOptimistic, createReaction, createRenderEffect, createSignal, createTrackedEffect, onCleanup, onSettled, refresh, resolve, until };
@@ -10,6 +10,8 @@ import "../core/effect.js";
10
10
 
11
11
  import { createStoreNext, deepNext, snapshotNext } from "./next/store.js";
12
12
 
13
+ export { storeHasFamily, storeHasOptimisticFamily, storeIsShallow } from "./next/store.js";
14
+
13
15
  import { reconcileNextState } from "./next/reconcile.js";
14
16
 
15
17
  import { createStoreDerivedNext } from "./next/projection.js";