@solidjs/signals 2.0.0-rc.2 → 2.0.0-rc.20

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 (198) hide show
  1. package/dist/dev-shared.js +6505 -0
  2. package/dist/dev.attribution.js +3484 -0
  3. package/dist/dev.js +10227 -9508
  4. package/dist/observe/affects-marks.js +86 -0
  5. package/dist/observe/affects.js +112 -0
  6. package/dist/observe/attribution.js +7 -0
  7. package/dist/observe/boundaries.js +696 -0
  8. package/dist/observe/core/action.js +182 -0
  9. package/dist/observe/core/async.js +824 -0
  10. package/dist/observe/core/attribution-costs.js +66 -0
  11. package/dist/observe/core/attribution-feedback.js +280 -0
  12. package/dist/observe/core/attribution-hooks.js +83 -0
  13. package/dist/observe/core/attribution-queries.js +43 -0
  14. package/dist/observe/core/attribution.js +3079 -0
  15. package/dist/observe/core/constants.js +269 -0
  16. package/dist/observe/core/context.js +63 -0
  17. package/dist/observe/core/copies.js +10 -0
  18. package/dist/observe/core/core.js +1707 -0
  19. package/dist/observe/core/dev.js +394 -0
  20. package/dist/observe/core/effect.js +193 -0
  21. package/dist/observe/core/error-hooks.js +71 -0
  22. package/dist/observe/core/error.js +82 -0
  23. package/dist/observe/core/external.js +97 -0
  24. package/dist/observe/core/graph.js +162 -0
  25. package/dist/observe/core/heap.js +124 -0
  26. package/dist/observe/core/identities.js +62 -0
  27. package/dist/observe/core/invariants.js +12 -0
  28. package/dist/observe/core/lanes.js +972 -0
  29. package/dist/observe/core/owner.js +371 -0
  30. package/dist/observe/core/scheduler.js +1157 -0
  31. package/dist/observe/core/truth.js +47 -0
  32. package/dist/observe/core/verdict.js +470 -0
  33. package/dist/observe/deferred.js +186 -0
  34. package/dist/observe/flatten.js +79 -0
  35. package/dist/observe/from.js +248 -0
  36. package/dist/observe/index.js +71 -0
  37. package/dist/observe/map.js +593 -0
  38. package/dist/observe/reveal.js +212 -0
  39. package/dist/observe/signals.js +717 -0
  40. package/dist/observe/store/affects.js +142 -0
  41. package/dist/observe/store/edges.js +39 -0
  42. package/dist/observe/store/hooks.js +16 -0
  43. package/dist/observe/store/index.js +47 -0
  44. package/dist/observe/store/optimistic.js +713 -0
  45. package/dist/observe/store/projection.js +345 -0
  46. package/dist/observe/store/reconcile.js +281 -0
  47. package/dist/observe/store/store.js +2127 -0
  48. package/dist/observe/store/storePath.js +103 -0
  49. package/dist/observe/store/target.js +46 -0
  50. package/dist/observe/store/types.js +83 -0
  51. package/dist/observe/store/utils.js +1063 -0
  52. package/dist/prod/affects-marks.js +86 -0
  53. package/dist/prod/affects.js +98 -112
  54. package/dist/prod/attribution.js +45 -0
  55. package/dist/prod/boundaries.js +578 -468
  56. package/dist/prod/core/action.js +92 -59
  57. package/dist/prod/core/async.js +522 -336
  58. package/dist/prod/core/attribution-hooks.js +3 -0
  59. package/dist/prod/core/constants.js +168 -44
  60. package/dist/prod/core/context.js +12 -16
  61. package/dist/prod/core/copies.js +10 -0
  62. package/dist/prod/core/core.js +1345 -627
  63. package/dist/prod/core/dev.js +123 -1
  64. package/dist/prod/core/effect.js +113 -80
  65. package/dist/prod/core/error-hooks.js +71 -0
  66. package/dist/prod/core/error.js +18 -4
  67. package/dist/prod/core/external.js +6 -7
  68. package/dist/prod/core/graph.js +119 -72
  69. package/dist/prod/core/heap.js +85 -109
  70. package/dist/prod/core/identities.js +62 -0
  71. package/dist/prod/core/invariants.js +1 -32
  72. package/dist/prod/core/lanes.js +931 -132
  73. package/dist/prod/core/owner.js +192 -129
  74. package/dist/prod/core/scheduler.js +948 -642
  75. package/dist/prod/core/truth.js +47 -0
  76. package/dist/prod/core/verdict.js +409 -420
  77. package/dist/prod/deferred.js +184 -0
  78. package/dist/prod/flatten.js +77 -0
  79. package/dist/prod/from.js +248 -0
  80. package/dist/prod/index.js +40 -16
  81. package/dist/prod/map.js +481 -211
  82. package/dist/prod/reveal.js +212 -0
  83. package/dist/prod/signals.js +401 -84
  84. package/dist/prod/store/affects.js +142 -0
  85. package/dist/prod/store/edges.js +39 -0
  86. package/dist/prod/store/hooks.js +16 -0
  87. package/dist/prod/store/index.js +27 -18
  88. package/dist/prod/store/optimistic.js +707 -0
  89. package/dist/prod/store/projection.js +331 -0
  90. package/dist/prod/store/reconcile.js +281 -0
  91. package/dist/prod/store/store.js +1952 -267
  92. package/dist/prod/store/storePath.js +1 -1
  93. package/dist/prod/store/target.js +43 -0
  94. package/dist/prod/store/types.js +83 -0
  95. package/dist/prod/store/utils.js +997 -138
  96. package/dist/types/affects-marks.d.ts +14 -0
  97. package/dist/types/affects.d.ts +12 -30
  98. package/dist/types/attribution.d.ts +19 -0
  99. package/dist/types/attribution.prod.d.ts +22 -0
  100. package/dist/types/boundaries.d.ts +99 -124
  101. package/dist/types/carved.d.ts +1 -0
  102. package/dist/types/core/action.d.ts +23 -9
  103. package/dist/types/core/async.d.ts +34 -6
  104. package/dist/types/core/attribution-costs.d.ts +35 -0
  105. package/dist/types/core/attribution-feedback.d.ts +133 -0
  106. package/dist/types/core/attribution-hooks.d.ts +307 -8
  107. package/dist/types/core/attribution-queries.d.ts +24 -0
  108. package/dist/types/core/attribution.d.ts +802 -72
  109. package/dist/types/core/constants.d.ts +195 -38
  110. package/dist/types/core/copies.d.ts +54 -0
  111. package/dist/types/core/core.d.ts +295 -65
  112. package/dist/types/core/dev.d.ts +509 -22
  113. package/dist/types/core/effect.d.ts +1 -1
  114. package/dist/types/core/error-hooks.d.ts +71 -0
  115. package/dist/types/core/error.d.ts +18 -1
  116. package/dist/types/core/graph.d.ts +40 -1
  117. package/dist/types/core/heap.d.ts +5 -5
  118. package/dist/types/core/identities.d.ts +17 -0
  119. package/dist/types/core/index.d.ts +11 -7
  120. package/dist/types/core/invariants.d.ts +1 -26
  121. package/dist/types/core/lanes.d.ts +74 -43
  122. package/dist/types/core/owner.d.ts +27 -9
  123. package/dist/types/core/scheduler.d.ts +353 -102
  124. package/dist/types/core/truth.d.ts +18 -0
  125. package/dist/types/core/types.d.ts +97 -71
  126. package/dist/types/core/verdict.d.ts +35 -0
  127. package/dist/types/deferred.d.ts +28 -0
  128. package/dist/types/flatten.d.ts +8 -0
  129. package/dist/types/from.d.ts +47 -0
  130. package/dist/types/index.d.ts +33 -7
  131. package/dist/types/map.d.ts +4 -2
  132. package/dist/types/reveal.d.ts +19 -0
  133. package/dist/types/signals.d.ts +196 -45
  134. package/dist/types/store/affects.d.ts +12 -0
  135. package/dist/types/store/edges.d.ts +9 -0
  136. package/dist/types/store/hooks.d.ts +62 -0
  137. package/dist/types/store/index.d.ts +42 -15
  138. package/dist/types/store/optimistic.d.ts +24 -45
  139. package/dist/types/store/projection.d.ts +17 -68
  140. package/dist/types/store/reconcile.d.ts +3 -46
  141. package/dist/types/store/store.d.ts +133 -136
  142. package/dist/types/store/storePath.d.ts +1 -1
  143. package/dist/types/store/target.d.ts +166 -0
  144. package/dist/types/store/types.d.ts +105 -0
  145. package/dist/types/store/utils.d.ts +188 -0
  146. package/package.json +31 -26
  147. package/dist/node.cjs +0 -8745
  148. package/dist/prod/core/optimistic.js +0 -265
  149. package/dist/prod/store/next/optimistic.js +0 -385
  150. package/dist/prod/store/next/projection.js +0 -172
  151. package/dist/prod/store/next/reconcile.js +0 -331
  152. package/dist/prod/store/next/store.js +0 -1499
  153. package/dist/prod/store/next/target.js +0 -20
  154. package/dist/types/core/optimistic.d.ts +0 -6
  155. package/dist/types/store/next/optimistic.d.ts +0 -20
  156. package/dist/types/store/next/projection.d.ts +0 -8
  157. package/dist/types/store/next/reconcile.d.ts +0 -3
  158. package/dist/types/store/next/store.d.ts +0 -77
  159. package/dist/types/store/next/target.d.ts +0 -117
  160. package/dist/types-cjs/affects.d.cts +0 -47
  161. package/dist/types-cjs/boundaries.d.cts +0 -175
  162. package/dist/types-cjs/core/action.d.cts +0 -64
  163. package/dist/types-cjs/core/async.d.cts +0 -21
  164. package/dist/types-cjs/core/attribution-hooks.d.cts +0 -52
  165. package/dist/types-cjs/core/attribution.d.cts +0 -186
  166. package/dist/types-cjs/core/constants.d.cts +0 -97
  167. package/dist/types-cjs/core/context.d.cts +0 -36
  168. package/dist/types-cjs/core/core.d.cts +0 -163
  169. package/dist/types-cjs/core/dev.d.cts +0 -81
  170. package/dist/types-cjs/core/effect.d.cts +0 -30
  171. package/dist/types-cjs/core/error.d.cts +0 -47
  172. package/dist/types-cjs/core/external.d.cts +0 -15
  173. package/dist/types-cjs/core/graph.d.cts +0 -6
  174. package/dist/types-cjs/core/heap.d.cts +0 -22
  175. package/dist/types-cjs/core/index.d.cts +0 -13
  176. package/dist/types-cjs/core/invariants.d.cts +0 -59
  177. package/dist/types-cjs/core/lanes.d.cts +0 -44
  178. package/dist/types-cjs/core/optimistic.d.cts +0 -6
  179. package/dist/types-cjs/core/owner.d.cts +0 -124
  180. package/dist/types-cjs/core/scheduler.d.cts +0 -180
  181. package/dist/types-cjs/core/types.d.cts +0 -192
  182. package/dist/types-cjs/core/verdict.d.cts +0 -2
  183. package/dist/types-cjs/index.d.cts +0 -10
  184. package/dist/types-cjs/map.d.cts +0 -69
  185. package/dist/types-cjs/package.json +0 -3
  186. package/dist/types-cjs/signals.d.cts +0 -624
  187. package/dist/types-cjs/store/index.d.cts +0 -19
  188. package/dist/types-cjs/store/next/optimistic.d.cts +0 -20
  189. package/dist/types-cjs/store/next/projection.d.cts +0 -8
  190. package/dist/types-cjs/store/next/reconcile.d.cts +0 -3
  191. package/dist/types-cjs/store/next/store.d.cts +0 -77
  192. package/dist/types-cjs/store/next/target.d.cts +0 -117
  193. package/dist/types-cjs/store/optimistic.d.cts +0 -45
  194. package/dist/types-cjs/store/projection.d.cts +0 -70
  195. package/dist/types-cjs/store/reconcile.d.cts +0 -46
  196. package/dist/types-cjs/store/store.d.cts +0 -138
  197. package/dist/types-cjs/store/storePath.d.cts +0 -58
  198. package/dist/types-cjs/store/utils.d.cts +0 -74
@@ -1,43 +1,58 @@
1
- import { CONFIG_AUTO_DISPOSE, REACTIVE_ZOMBIE, STATUS_PENDING, REACTIVE_RECOMPUTING_DEPS } from "./constants.js";
1
+ import { NewSet, REACTIVE_RECOMPUTING_DEPS, CONFIG_AUTO_DISPOSE, STATUS_PENDING, REACTIVE_DISPOSED, REACTIVE_ZOMBIE, CONFIG_SLOT_NODE } from "./constants.js";
2
2
 
3
- import { deleteFromHeap, queueFor } from "./heap.js";
3
+ import { deleteFromHeap } from "./heap.js";
4
4
 
5
- import { disposeChildren } from "./owner.js";
5
+ import { disposeChildren, runCleanup } from "./owner.js";
6
6
 
7
- import { bumpNotifyEpoch } from "./scheduler.js";
7
+ import { bumpNotifyEpoch, dirtyQueue } from "./scheduler.js";
8
+
9
+ /** The store's shared slot-node release handler (store/store.ts installs it
10
+ * once) — a live binding read directly by the sweep site: no wrapper frame,
11
+ * no null check (a CONFIG_SLOT_NODE node existing implies the store module
12
+ * loaded and registered it). */ let slotUnobservedHook;
13
+
14
+ function setSlotUnobserved(e) {
15
+ slotUnobservedHook = e;
16
+ }
8
17
 
9
18
  // https://github.com/stackblitz/alien-signals/blob/v2.0.3/src/system.ts#L100
10
19
  function unlinkSubs(e) {
11
- const l = e.ut;
12
- const n = e.it;
13
- const u = e.fe;
14
- const s = e.el;
15
- if (u !== null) u.el = s; else l.rt = s;
16
- if (s !== null) s.fe = u; else {
17
- l.u = u;
18
- if (u === null) {
19
- l.o?.ft?.();
20
+ const n = e.S;
21
+ const l = e.G;
22
+ const o = e.t;
23
+ const s = e.$e;
24
+ if (o !== null) o.$e = s; else n.Ze = s;
25
+ if (s !== null) s.t = o; else {
26
+ n.o = o;
27
+ if (o === null) {
28
+ // Store slot nodes dispatch to the ONE shared hook — no per-node
29
+ // unobserved closure, no NodeExtension to hold it.
30
+ // A user hook that throws is collected like a cleanup (owner.ts): the
31
+ // unlink and the teardown around it carry on.
32
+ if (n.l & CONFIG_SLOT_NODE) slotUnobservedHook(n); else if (n.T?.Ye) runCleanup(n.T.Ye);
20
33
  // No more subscribers; only tear down if CONFIG_AUTO_DISPOSE is set.
21
- // A pending node is exempt: its in-flight async work (or the
22
- // transition holding it) is an observer — tearing down would orphan
23
- // the work and re-execute it on the next read. The settle path runs
24
- // this same last-one-out check when that observer releases (the
25
- // untracked-read dispose in core.ts guards on pending identically).
26
- const e = l;
27
- e.Se && e.T & CONFIG_AUTO_DISPOSE && !(e.ie & REACTIVE_ZOMBIE) && !(e.S & STATUS_PENDING) && unobserved(e);
34
+ // A pending node is exempt: its in-flight async work is an observer —
35
+ // tearing down would orphan the work and re-execute it on the next
36
+ // read. The settle path runs this same last-one-out check when that
37
+ // observer releases (the untracked-read dormancy sweep guards on
38
+ // pending identically).
39
+ // During a pass's teardown of its unfinished frame, the release waits
40
+ // for the pass to end (`deferredReleases`, #4142).
41
+ const e = n;
42
+ e.X && e.l & CONFIG_AUTO_DISPOSE && !(e.R & REACTIVE_ZOMBIE) && !(e.m & STATUS_PENDING) && (deferredReleases ? deferredReleases.push(e) : unobserved(e));
28
43
  }
29
44
  }
30
- return n;
45
+ return l;
31
46
  }
32
47
 
33
48
  function trimStaleDeps(e) {
34
- const l = e.Ye;
35
- let n = l !== null ? l.it : e.nt;
36
- if (n !== null) {
49
+ const n = e._;
50
+ let l = n !== null ? n.G : e.C;
51
+ if (l !== null) {
37
52
  do {
38
- n = unlinkSubs(n);
39
- } while (n !== null);
40
- if (l !== null) l.it = null; else e.nt = null;
53
+ l = unlinkSubs(l);
54
+ } while (l !== null);
55
+ if (n !== null) n.G = null; else e.C = null;
41
56
  }
42
57
  }
43
58
 
@@ -46,42 +61,80 @@ function trimStaleDeps(e) {
46
61
  // and skipping early also avoids adding one (hidden-class churn) via the
47
62
  // null-out below.
48
63
  function clearDeps(e) {
49
- let l = e.nt;
50
- if (!l) return;
64
+ let n = e.C;
65
+ if (!n) return;
51
66
  do {
52
- l = unlinkSubs(l);
53
- } while (l !== null);
54
- e.nt = null;
55
- e.Ye = null;
67
+ n = unlinkSubs(n);
68
+ } while (n !== null);
69
+ e.C = null;
70
+ e._ = null;
56
71
  }
57
72
 
73
+ /**
74
+ * Last-one-out releases held back while a pass tears down the frame of an
75
+ * earlier pass that never committed (#4142). The pass is about to rebuild
76
+ * the same children, which read the same lazy nodes again. Released on the
77
+ * spot, a lazy async memo whose only reader was the old frame's child memo
78
+ * was torn down, re-ran on the new child's read, went pending, and the cycle
79
+ * repeated forever. `recompute` collects them around that teardown and
80
+ * releases what is still unobserved when the pass ends.
81
+ */ let deferredReleases = null;
82
+
83
+ const deferReleases = e => deferredReleases = e;
84
+
58
85
  function unobserved(e) {
59
- deleteFromHeap(e, queueFor(e));
86
+ deleteFromHeap(e, dirtyQueue);
60
87
  clearDeps(e);
61
88
  disposeChildren(e, true);
62
89
  }
63
90
 
64
- // https://github.com/stackblitz/alien-signals/blob/v2.0.3/src/system.ts#L52
65
- function link(e, l, n = false) {
66
- // Repeat touches within one pass AND-combine `_pendingObserver`: a probe
67
- // read (`isPending(() => x())`) beside a value read of the same dep must
68
- // not relabel the value dependency as probe-only — the value read is what
69
- // real-error propagation and affects() coverage key off, regardless of
70
- // read order within the computation.
71
- const u = l.Ye;
72
- if (u !== null && u.ut === e) {
73
- u.me &&= n;
74
- return;
91
+ /**
92
+ * Deferred dormancy for never-observed auto-dispose computeds (#3078).
93
+ *
94
+ * An untracked top-level read of a subscriber-less observation-lifecycle memo
95
+ * used to call unobserved() inline at the end of read(). That kept the leak
96
+ * closed (the compute links the memo into its deps' sub lists — without a
97
+ * teardown point a never-observed memo is retained by its sources forever;
98
+ * upstream alien-signals has exactly this retention), but it made reads
99
+ * destructive: each read disposed the node, the next read revived it with a
100
+ * full recompute in whatever ambient transition/lane context happened to be
101
+ * current, so consecutive reads could return different answers with no write
102
+ * in between.
103
+ *
104
+ * Instead, reads queue the node here and the scheduler sweeps at the top of
105
+ * the next flush (before runHeap, so a same-tick dirtying is reclaimed
106
+ * instead of recomputed). Reads become idempotent within a tick (the node
107
+ * stays alive and serves its cache, uniform with observed memos) while
108
+ * reclamation still happens within one microtask — the enqueue site arms
109
+ * schedule(), so a flush is guaranteed even when no other work is queued.
110
+ */ const dormantNodes = new NewSet;
111
+
112
+ function sweepDormant() {
113
+ if (dormantNodes.size === 0) return;
114
+ for (const e of dormantNodes) {
115
+ // Re-validate at sweep time: the node may have gained a subscriber (its
116
+ // lifecycle is the unlinkSubs cascade now), gone pending (in-flight async
117
+ // is an observer; the settle path re-runs last-one-out), lost its
118
+ // AUTO_DISPOSE bit (owner teardown strips it, #3024), or already been
119
+ // torn down.
120
+ if (!e.o && e.l & CONFIG_AUTO_DISPOSE && !(e.m & STATUS_PENDING) && !(e.R & (REACTIVE_DISPOSED | REACTIVE_ZOMBIE))) {
121
+ unobserved(e);
122
+ }
75
123
  }
76
- let s = null;
77
- const o = l.ie & REACTIVE_RECOMPUTING_DEPS;
78
- if (o) {
79
- s = u !== null ? u.it : l.nt;
80
- if (s !== null && s.ut === e) {
81
- s.ll = l.Ze;
82
- l.Ye = s;
83
- // First touch of this pass: the previous pass's label is stale.
84
- s.me = n;
124
+ dormantNodes.clear();
125
+ }
126
+
127
+ // https://github.com/stackblitz/alien-signals/blob/v2.0.3/src/system.ts#L52
128
+ function link(e, n) {
129
+ const l = n._;
130
+ if (l !== null && l.S === e) return;
131
+ let o = null;
132
+ const s = n.R & REACTIVE_RECOMPUTING_DEPS;
133
+ if (s) {
134
+ o = l !== null ? l.G : n.C;
135
+ if (o !== null && o.S === e) {
136
+ o.Ne = n.de;
137
+ n._ = o;
85
138
  return;
86
139
  }
87
140
  }
@@ -90,26 +143,20 @@ function link(e, l, n = false) {
90
143
  // [deps.._depsTail] prefix — the O(1) equivalent of scanning the dep list
91
144
  // (the old alien-signals `isValidLink` walk, O(n²) when a computation
92
145
  // re-reads earlier deps non-consecutively, e.g. store leaf reads).
93
- const t = e.rt;
94
- if (t !== null && t.ae === l && (!o || t.ll === l.Ze)) {
95
- // Gen-matched during a recompute = repeat touch this pass (AND); outside
96
- // a recompute there is no pass boundary, so the latest read labels it.
97
- if (o) t.me &&= n; else t.me = n;
98
- return;
99
- }
100
- const i = l.Ye = e.rt = {
101
- ut: e,
102
- ae: l,
103
- it: s,
104
- el: t,
105
- fe: null,
106
- ll: l.Ze,
107
- me: n
146
+ const r = e.Ze;
147
+ if (r !== null && r.u === n && (!s || r.Ne === n.de)) return;
148
+ const t = n._ = e.Ze = {
149
+ S: e,
150
+ u: n,
151
+ G: o,
152
+ $e: r,
153
+ t: null,
154
+ Ne: n.de
108
155
  };
109
- if (u !== null) u.it = i; else l.nt = i;
110
- if (t !== null) t.fe = i; else e.u = i;
156
+ if (l !== null) l.G = t; else n.C = t;
157
+ if (r !== null) r.t = t; else e.o = t;
111
158
  // New subscriber edge: staged-rewrite skips (§12d) must not miss it.
112
159
  bumpNotifyEpoch();
113
160
  }
114
161
 
115
- export { clearDeps, link, trimStaleDeps, unlinkSubs, unobserved };
162
+ export { clearDeps, deferReleases, deferredReleases, dormantNodes, link, setSlotUnobserved, slotUnobservedHook, sweepDormant, trimStaleDeps, unlinkSubs, unobserved };
@@ -1,148 +1,124 @@
1
1
  import "./core.js";
2
2
 
3
- import { REACTIVE_IN_HEAP, REACTIVE_IN_HEAP_HEIGHT, EFFECT_TRACKED, EFFECT_USER, REACTIVE_RECOMPUTING_DEPS, REACTIVE_MANUAL_WRITE, REACTIVE_ZOMBIE, REACTIVE_CHECK, REACTIVE_DIRTY, CONFIG_FW_CHILDREN } from "./constants.js";
3
+ import { REACTIVE_IN_HEAP, REACTIVE_RECOMPUTING_DEPS, REACTIVE_CHECK, REACTIVE_DIRTY, REACTIVE_IN_HEAP_HEIGHT } from "./constants.js";
4
4
 
5
- import { zombieQueue, dirtyQueue } from "./scheduler.js";
6
-
7
- /** The queue a node belongs to, picked from its own zombie flag. */ function queueFor(e) {
8
- return e.ie & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue;
9
- }
5
+ import { dirtyQueue } from "./scheduler.js";
10
6
 
11
7
  /**
12
- * Schedule one subscriber to re-run on the next flush: tracked effects bypass
13
- * the heap and go directly to their effect queue; everything else is inserted
14
- * into its own (zombie-flag-routed) heap with the `_min` cursor pulled down.
8
+ * Schedule one subscriber to re-run on the next flush: inserted into the
9
+ * dirty heap with the `_min` cursor pulled down. Tracked effects ride the
10
+ * heap too — the heap visit is their (empty) compute phase, which hands the
11
+ * callback to the user queue once the pass has committed (see
12
+ * GlobalQueue._update, #3291).
15
13
  */ function enqueueSub(e) {
16
- if (e.Re === EFFECT_TRACKED) {
17
- const E = e;
18
- if (!E.Xe) {
19
- E.Xe = true;
20
- E.C.enqueue(EFFECT_USER, E.Ut);
21
- }
22
- return;
23
- }
24
- const E = queueFor(e);
25
- if (E.xe > e.Le) E.xe = e.Le;
26
- insertIntoHeap(e, E);
14
+ if (dirtyQueue.Fe > e.he) dirtyQueue.Fe = e.he;
15
+ insertIntoHeap(e, dirtyQueue);
27
16
  }
28
17
 
29
- function actualInsertIntoHeap(e, E) {
30
- const t = (e.ve?.Ct ? e.ve.Ot?.Le : e.ve?.Le) ?? -1;
31
- if (t >= e.Le) e.Le = t + 1;
32
- const n = e.Le;
33
- const I = E.eE[n];
34
- if (I === undefined) E.eE[n] = e; else {
35
- const E = I.st;
36
- E.ot = e;
37
- e.st = E;
38
- I.st = e;
18
+ function actualInsertIntoHeap(e, t) {
19
+ const E = (e._parent?.Qe ? e._parent.Ke?.he : e._parent?.he) ?? -1;
20
+ if (E >= e.he) e.he = E + 1;
21
+ const n = e.he;
22
+ const I = t.et[n];
23
+ if (I === undefined) t.et[n] = e; else {
24
+ const t = I.We;
25
+ t.ve = e;
26
+ e.We = t;
27
+ I.We = e;
39
28
  }
40
- if (n > E.EE) E.EE = n;
29
+ if (n > t.Et) t.Et = n;
41
30
  }
42
31
 
43
- function insertIntoHeap(e, E) {
44
- let t = e.ie;
32
+ function insertIntoHeap(e, t) {
33
+ let E = e.R;
45
34
  // RECOMPUTING refusals are not always losses: a genuinely missed wake (a
46
35
  // write to a link this pass already validated) is latched link-side in
47
36
  // insertSubs as REACTIVE_MISSED_WAKE for recompute's tail (#3037).
48
- if (t & (REACTIVE_IN_HEAP | REACTIVE_RECOMPUTING_DEPS | REACTIVE_MANUAL_WRITE)) return;
49
- if (t & REACTIVE_CHECK) {
50
- e.ie = t & -4 | REACTIVE_DIRTY | REACTIVE_IN_HEAP;
37
+ if (E & (REACTIVE_IN_HEAP | REACTIVE_RECOMPUTING_DEPS)) return;
38
+ if (E & REACTIVE_CHECK) {
39
+ e.R = E & -4 | REACTIVE_DIRTY | REACTIVE_IN_HEAP;
51
40
  } else {
52
- e.ie = t | REACTIVE_IN_HEAP;
53
- // An unmarked node entering a marked heap invalidates the markHeap memo:
54
- // `_marked` is only reset by runHeap, so a write between two mid-tick
55
- // pulls (read-time markHeap + updateIfNecessary) would otherwise leave
56
- // this node unmarked and every downstream pull stale until the next
57
- // flush (#2922: the second `latest()` returned the first write's value).
58
- if (E.tE && !(t & REACTIVE_DIRTY)) E.tE = false;
41
+ e.R = E | REACTIVE_IN_HEAP;
42
+ // An unmarked node entering an already-marked heap is marked on the
43
+ // spot, keeping the markHeap memo valid. `_marked` is only reset by
44
+ // runHeap, so a write between two mid-tick pulls (read-time markHeap +
45
+ // updateIfNecessary) would otherwise leave this node unmarked and every
46
+ // downstream pull stale until the next flush (#2922: the second
47
+ // `latest()` returned the first write's value). Invalidating the memo
48
+ // instead re-walked the WHOLE heap on the next pull — with N effects
49
+ // parked in the heap for a synchronous mount (each row writing a ref
50
+ // signal its effect subscribes to), mounting N rows was O(N²) (#3350).
51
+ // markNode's own guard skips an already-DIRTY node.
52
+ if (t.p) markNode(e);
59
53
  }
60
- if (!(t & REACTIVE_IN_HEAP_HEIGHT)) actualInsertIntoHeap(e, E);
54
+ if (!(E & REACTIVE_IN_HEAP_HEIGHT)) actualInsertIntoHeap(e, t);
61
55
  }
62
56
 
63
- function insertIntoHeapHeight(e, E) {
64
- let t = e.ie;
65
- if (t & (REACTIVE_IN_HEAP | REACTIVE_RECOMPUTING_DEPS | REACTIVE_IN_HEAP_HEIGHT | REACTIVE_MANUAL_WRITE)) return;
66
- e.ie = t | REACTIVE_IN_HEAP_HEIGHT;
67
- actualInsertIntoHeap(e, E);
57
+ function insertIntoHeapHeight(e, t) {
58
+ let E = e.R;
59
+ if (E & (REACTIVE_IN_HEAP | REACTIVE_RECOMPUTING_DEPS | REACTIVE_IN_HEAP_HEIGHT)) return;
60
+ e.R = E | REACTIVE_IN_HEAP_HEIGHT;
61
+ actualInsertIntoHeap(e, t);
68
62
  }
69
63
 
70
- function deleteFromHeap(e, E) {
71
- const t = e.ie;
72
- if (!(t & (REACTIVE_IN_HEAP | REACTIVE_IN_HEAP_HEIGHT))) return;
73
- e.ie = t & -25;
74
- const n = e.Le;
75
- if (e.st === e) E.eE[n] = undefined; else {
76
- const t = e.ot;
77
- const I = E.eE[n];
78
- const o = t ?? I;
79
- if (e === I) E.eE[n] = t; else e.st.ot = t;
80
- o.st = e.st;
64
+ function deleteFromHeap(e, t) {
65
+ const E = e.R;
66
+ if (!(E & (REACTIVE_IN_HEAP | REACTIVE_IN_HEAP_HEIGHT))) return;
67
+ e.R = E & -25;
68
+ const n = e.he;
69
+ if (e.We === e) t.et[n] = undefined; else {
70
+ const E = e.ve;
71
+ const I = t.et[n];
72
+ const i = E ?? I;
73
+ if (e === I) t.et[n] = E; else e.We.ve = E;
74
+ i.We = e.We;
81
75
  }
82
- e.st = e;
83
- e.ot = undefined;
76
+ e.We = e;
77
+ e.ve = undefined;
84
78
  }
85
79
 
86
80
  function markHeap(e) {
87
- if (e.tE) return;
88
- e.tE = true;
89
- for (let E = 0; E <= e.EE; E++) {
90
- for (let t = e.eE[E]; t !== undefined; t = t.ot) {
91
- if (t.ie & REACTIVE_IN_HEAP) markNode(t);
81
+ if (e.p) return;
82
+ e.p = true;
83
+ for (let t = 0; t <= e.Et; t++) {
84
+ for (let E = e.et[t]; E !== undefined; E = E.ve) {
85
+ if (E.R & REACTIVE_IN_HEAP) markNode(E);
92
86
  }
93
87
  }
94
88
  }
95
89
 
96
- function markNode(e, E = REACTIVE_DIRTY) {
97
- const t = e.ie;
98
- if ((t & (REACTIVE_CHECK | REACTIVE_DIRTY)) >= E) return;
99
- e.ie = t & -4 | E;
100
- for (let E = e.u; E !== null; E = E.fe) {
101
- markNode(E.ae, REACTIVE_CHECK);
102
- }
103
- // Firewall children (projection machinery only): gate the cold-extension
104
- // deref on the config bit — markNode runs per sub edge per write, and an
105
- // unconditional _x chase here taxed every propagation (diamond -22%).
106
- if (e.T & CONFIG_FW_CHILDREN) {
107
- for (let E = e.o.l; E !== null; E = E.ce) {
108
- for (let e = E.u; e !== null; e = e.fe) {
109
- markNode(e.ae, REACTIVE_CHECK);
110
- }
111
- }
90
+ function markNode(e, t = REACTIVE_DIRTY) {
91
+ const E = e.R;
92
+ if ((E & (REACTIVE_CHECK | REACTIVE_DIRTY)) >= t) return;
93
+ e.R = E & -4 | t;
94
+ for (let t = e.o; t !== null; t = t.t) {
95
+ markNode(t.u, REACTIVE_CHECK);
112
96
  }
113
97
  }
114
98
 
115
- function runHeap(e, E) {
116
- e.tE = false;
117
- for (e.xe = 0; e.xe <= e.EE; e.xe++) {
118
- let t = e.eE[e.xe];
119
- while (t !== undefined) {
120
- if (t.ie & REACTIVE_IN_HEAP) E(t); else adjustHeight(t, e);
121
- t = e.eE[e.xe];
99
+ function runHeap(e, t) {
100
+ e.p = false;
101
+ for (e.Fe = 0; e.Fe <= e.Et; e.Fe++) {
102
+ let E = e.et[e.Fe];
103
+ while (E !== undefined) {
104
+ if (E.R & REACTIVE_IN_HEAP) t(E); else adjustHeight(E, e);
105
+ E = e.et[e.Fe];
122
106
  }
123
107
  }
124
- e.EE = 0;
108
+ e.Et = 0;
125
109
  }
126
110
 
127
- function adjustHeight(e, E) {
128
- deleteFromHeap(e, E);
129
- let t = e.Le;
130
- for (let E = e.nt; E; E = E.it) {
131
- const e = E.ut;
132
- const n = e.lt || e;
133
- if (n.Se && n.Le >= t) t = n.Le + 1;
111
+ function adjustHeight(e, t) {
112
+ deleteFromHeap(e, t);
113
+ let E = e.he;
114
+ for (let t = e.C; t; t = t.G) {
115
+ const e = t.S;
116
+ if (e.X && e.he >= E) E = e.he + 1;
134
117
  }
135
- if (e.Le !== t) {
136
- e.Le = t;
137
- for (let E = e.u; E !== null; E = E.fe) {
138
- // Route each subscriber by its own zombie flag, mirroring the
139
- // post-recompute height-adjust path. Inserting into the running `heap`
140
- // unconditionally can park a zombie in `dirtyQueue` (or a live node in
141
- // `zombieQueue`), breaking the flag/queue invariant `deleteFromHeap`
142
- // relies on — the same corruption class as #2759.
143
- insertIntoHeapHeight(E.ae, queueFor(E.ae));
144
- }
118
+ if (e.he !== E) {
119
+ e.he = E;
120
+ for (let E = e.o; E !== null; E = E.t) insertIntoHeapHeight(E.u, t);
145
121
  }
146
122
  }
147
123
 
148
- export { deleteFromHeap, enqueueSub, insertIntoHeap, insertIntoHeapHeight, markHeap, markNode, queueFor, runHeap };
124
+ export { deleteFromHeap, enqueueSub, insertIntoHeap, insertIntoHeapHeight, markHeap, markNode, runHeap };
@@ -0,0 +1,62 @@
1
+ import { CONFIG_TRANSPARENT } from "./constants.js";
2
+
3
+ import "./core.js";
4
+
5
+ import { getOwner } from "./owner.js";
6
+
7
+ // Deferred hydration, dependency edges: plain-signal identities.
8
+ // While on (`setSignalIdentities`; the server-components client turns it on
9
+ // before hydrating), a plain signal created under an id-bearing owner is
10
+ // named `<owner id>~<n>`, n counting the plain signals (and plain store
11
+ // roots: `createStore` over an object, store/edges.ts) created under that
12
+ // owner in its current pass (transparent owners defer to the nearest
13
+ // id-bearing one, as child ids do). The server names the same signal the
14
+ // same way and restarts the count on every re-run, so an edge it shipped (a
15
+ // slot fill read it) matches the client node; the write hook receives the
16
+ // node and looks its name up (`signalName`). The count restarts when the owner's pass
17
+ // generation (`_depGen`, bumped by every recompute) moves on. Only the
18
+ // frames client imports this module, so nothing here ships without it.
19
+ // Names live in a side table, not on the node: frames reads them across the
20
+ // package boundary, where a mangled field would not survive.
21
+ let counts = null;
22
+
23
+ const names = new WeakMap;
24
+
25
+ /** @internal The identity of a plain signal named while identities were on. */ function signalName(n) {
26
+ return n === undefined ? undefined : names.get(n);
27
+ }
28
+
29
+ function identify(n) {
30
+ let e = getOwner();
31
+ if (!e) return;
32
+ while (e.l & CONFIG_TRANSPARENT && e._parent) e = e._parent;
33
+ if (e.id == null) return;
34
+ const t = e.de;
35
+ let i = counts.get(e);
36
+ if (i === undefined || i[0] !== t) counts.set(e, i = [ t, 0 ]);
37
+ const s = e.id + "~" + i[1]++;
38
+ // A store root named twice (one object made into two stores, or a store
39
+ // handed to `createStore`) is one target under two server names: its
40
+ // writes cannot be attributed (an empty name).
41
+ names.set(n, names.has(n) ? "" : s);
42
+ }
43
+
44
+ /** @internal Name plain signals from now on (`on`), or stop. */ function setSignalIdentities(n) {
45
+ counts = n ? counts || new WeakMap : null;
46
+ signalHook = n ? identify : null;
47
+ }
48
+
49
+ /**
50
+ * @internal Called with every plain signal `createSignal` makes, and every
51
+ * plain store root `createStore` makes, while set (the namer above). Never
52
+ * set unless `setSignalIdentities` is imported, so a bundle without it keeps
53
+ * only a null check.
54
+ */ let signalHook = null;
55
+
56
+ /**
57
+ * @internal Dev only: `watch` is called with every node read while set (the
58
+ * dev hook `onRead`) — the frames client's identity-drift check watches the
59
+ * named signals a deferred occurrence reads as it mounts. A no-op in prod.
60
+ */ function setReadWatch(n) {}
61
+
62
+ export { setReadWatch, setSignalIdentities, signalHook, signalName };
@@ -1,36 +1,5 @@
1
1
  import "./core.js";
2
2
 
3
- /**
4
- * INV-2: a node with an *active* override must be registered for reversion in
5
- * the queue's or a transition's `_optimisticNodes`. An unregistered active
6
- * override would survive transition completion forever. Runs at the end of
7
- * every flush (not just quiescence — the invariant holds mid-transition).
8
- * (There is no revert-target requirement: authoritative values commit
9
- * silently into `_value` under the override mask — A17 — so reverting is
10
- * just dropping the override.)
11
- */ function devCheckActiveOverrides(e) {
12
- return;
13
- }
14
-
15
- /** INV-1: an isPending() probe must never leak past its own call. */ function devCheckFlushStart() {
16
- return;
17
- }
18
-
19
- /**
20
- * Companion-vs-oracle census (#2838 pre-work). A NON-ASSERTING diff logger:
21
- * at the end of every flush it compares each live companion's cached state
22
- * against a fresh oracle and logs every distinct divergence fingerprint once
23
- * (console, `[census]` prefix). Legit lane-scoped windows will show up too —
24
- * the census exists to enumerate the full taxonomy of mid-flight divergence
25
- * so the write-driven redesign knows every case it must produce, not to
26
- * judge them. Enabled only when the COMPANION_CENSUS env var is set (in
27
- * addition to `false`), so normal test runs pay one boolean check.
28
- */ typeof globalThis !== "undefined" && !!globalThis.process?.env?.COMPANION_CENSUS;
29
-
30
- function devCensusCompanions(e) {
31
- return;
32
- }
33
-
34
3
  /**
35
4
  * Quiescence checks. Run only when the system is fully drained: nothing
36
5
  * scheduled, no active/stashed transitions, no live lanes. At that point no
@@ -40,4 +9,4 @@ function devCensusCompanions(e) {
40
9
  return;
41
10
  }
42
11
 
43
- export { devCensusCompanions, devCheckActiveOverrides, devCheckFlushStart, devCheckQuiescent };
12
+ export { devCheckQuiescent };