@solidjs/signals 2.0.0-rc.6 → 2.0.0-rc.8

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 (131) hide show
  1. package/dist/dev-shared.js +5243 -0
  2. package/dist/dev.attribution.js +2333 -0
  3. package/dist/dev.js +1758 -6621
  4. package/dist/observe/affects.js +127 -0
  5. package/dist/observe/attribution.js +1 -0
  6. package/dist/observe/boundaries.js +586 -0
  7. package/dist/observe/core/action.js +167 -0
  8. package/dist/observe/core/async.js +736 -0
  9. package/dist/observe/core/attribution-hooks.js +60 -0
  10. package/dist/observe/core/attribution.js +2318 -0
  11. package/dist/{types-cjs/core/constants.d.cts → observe/core/constants.js} +135 -71
  12. package/dist/{types-cjs/core/context.d.cts → observe/core/context.js} +37 -12
  13. package/dist/observe/core/core.js +1289 -0
  14. package/dist/observe/core/dev.js +232 -0
  15. package/dist/observe/core/effect.js +179 -0
  16. package/dist/observe/core/error.js +80 -0
  17. package/dist/observe/core/external.js +98 -0
  18. package/dist/observe/core/graph.js +155 -0
  19. package/dist/observe/core/heap.js +147 -0
  20. package/dist/observe/core/invariants.js +43 -0
  21. package/dist/observe/core/lanes.js +168 -0
  22. package/dist/observe/core/optimistic.js +438 -0
  23. package/dist/observe/core/owner.js +308 -0
  24. package/dist/observe/core/scheduler.js +1190 -0
  25. package/dist/observe/core/verdict.js +551 -0
  26. package/dist/observe/index.js +55 -0
  27. package/dist/observe/map.js +482 -0
  28. package/dist/{types-cjs/signals.d.cts → observe/signals.js} +305 -317
  29. package/dist/observe/store/index.js +38 -0
  30. package/dist/observe/store/next/optimistic.js +651 -0
  31. package/dist/observe/store/next/projection.js +242 -0
  32. package/dist/observe/store/next/reconcile.js +373 -0
  33. package/dist/observe/store/next/store.js +2213 -0
  34. package/dist/observe/store/next/target.js +51 -0
  35. package/dist/observe/store/store.js +323 -0
  36. package/dist/observe/store/storePath.js +103 -0
  37. package/dist/observe/store/utils.js +210 -0
  38. package/dist/prod/attribution.js +32 -0
  39. package/dist/prod/boundaries.js +3 -1
  40. package/dist/prod/core/action.js +52 -32
  41. package/dist/prod/core/async.js +177 -128
  42. package/dist/prod/core/attribution-hooks.js +3 -0
  43. package/dist/prod/core/constants.js +32 -1
  44. package/dist/prod/core/context.js +10 -16
  45. package/dist/prod/core/core.js +505 -286
  46. package/dist/prod/core/dev.js +2 -0
  47. package/dist/prod/core/effect.js +72 -43
  48. package/dist/prod/core/external.js +2 -2
  49. package/dist/prod/core/graph.js +40 -36
  50. package/dist/prod/core/heap.js +50 -51
  51. package/dist/prod/core/lanes.js +43 -22
  52. package/dist/prod/core/optimistic.js +224 -80
  53. package/dist/prod/core/owner.js +43 -39
  54. package/dist/prod/core/scheduler.js +347 -232
  55. package/dist/prod/core/verdict.js +71 -74
  56. package/dist/prod/index.js +9 -5
  57. package/dist/prod/map.js +311 -150
  58. package/dist/prod/signals.js +52 -38
  59. package/dist/prod/store/next/optimistic.js +127 -131
  60. package/dist/prod/store/next/projection.js +3 -3
  61. package/dist/prod/store/next/reconcile.js +149 -294
  62. package/dist/prod/store/next/store.js +694 -380
  63. package/dist/prod/store/next/target.js +32 -10
  64. package/dist/prod/store/store.js +12 -14
  65. package/dist/prod/store/utils.js +36 -27
  66. package/dist/types/attribution.d.ts +15 -0
  67. package/dist/types/attribution.prod.d.ts +13 -0
  68. package/dist/types/core/async.d.ts +1 -1
  69. package/dist/types/core/attribution-hooks.d.ts +183 -6
  70. package/dist/types/core/attribution.d.ts +435 -24
  71. package/dist/types/core/constants.d.ts +31 -0
  72. package/dist/types/core/core.d.ts +19 -3
  73. package/dist/types/core/dev.d.ts +165 -26
  74. package/dist/types/core/effect.d.ts +8 -1
  75. package/dist/types/core/heap.d.ts +5 -3
  76. package/dist/types/core/index.d.ts +2 -1
  77. package/dist/types/core/invariants.d.ts +1 -1
  78. package/dist/types/core/lanes.d.ts +17 -0
  79. package/dist/types/core/scheduler.d.ts +69 -4
  80. package/dist/types/core/types.d.ts +29 -9
  81. package/dist/types/index.d.ts +9 -2
  82. package/dist/types/map.d.ts +2 -0
  83. package/dist/types/signals.d.ts +10 -0
  84. package/dist/types/store/index.d.ts +4 -6
  85. package/dist/types/store/next/optimistic.d.ts +4 -2
  86. package/dist/types/store/next/reconcile.d.ts +5 -12
  87. package/dist/types/store/next/store.d.ts +8 -9
  88. package/dist/types/store/next/target.d.ts +56 -55
  89. package/dist/types/store/store.d.ts +14 -9
  90. package/dist/types/store/utils.d.ts +7 -0
  91. package/package.json +21 -16
  92. package/dist/node.cjs +0 -11121
  93. package/dist/prod/store/next/patch-hooks.js +0 -13
  94. package/dist/prod/store/next/patch.js +0 -614
  95. package/dist/types/store/next/patch-hooks.d.ts +0 -41
  96. package/dist/types/store/next/patch.d.ts +0 -91
  97. package/dist/types-cjs/affects.d.cts +0 -47
  98. package/dist/types-cjs/boundaries.d.cts +0 -175
  99. package/dist/types-cjs/core/action.d.cts +0 -64
  100. package/dist/types-cjs/core/async.d.cts +0 -23
  101. package/dist/types-cjs/core/attribution-hooks.d.cts +0 -63
  102. package/dist/types-cjs/core/attribution.d.cts +0 -239
  103. package/dist/types-cjs/core/core.d.cts +0 -176
  104. package/dist/types-cjs/core/dev.d.cts +0 -95
  105. package/dist/types-cjs/core/effect.d.cts +0 -30
  106. package/dist/types-cjs/core/error.d.cts +0 -56
  107. package/dist/types-cjs/core/external.d.cts +0 -15
  108. package/dist/types-cjs/core/graph.d.cts +0 -28
  109. package/dist/types-cjs/core/heap.d.cts +0 -22
  110. package/dist/types-cjs/core/index.d.cts +0 -13
  111. package/dist/types-cjs/core/invariants.d.cts +0 -59
  112. package/dist/types-cjs/core/lanes.d.cts +0 -44
  113. package/dist/types-cjs/core/optimistic.d.cts +0 -6
  114. package/dist/types-cjs/core/owner.d.cts +0 -124
  115. package/dist/types-cjs/core/scheduler.d.cts +0 -231
  116. package/dist/types-cjs/core/types.d.cts +0 -204
  117. package/dist/types-cjs/core/verdict.d.cts +0 -2
  118. package/dist/types-cjs/index.d.cts +0 -10
  119. package/dist/types-cjs/map.d.cts +0 -69
  120. package/dist/types-cjs/package.json +0 -3
  121. package/dist/types-cjs/store/index.d.cts +0 -21
  122. package/dist/types-cjs/store/next/optimistic.d.cts +0 -23
  123. package/dist/types-cjs/store/next/patch-hooks.d.cts +0 -41
  124. package/dist/types-cjs/store/next/patch.d.cts +0 -91
  125. package/dist/types-cjs/store/next/projection.d.cts +0 -8
  126. package/dist/types-cjs/store/next/reconcile.d.cts +0 -17
  127. package/dist/types-cjs/store/next/store.d.cts +0 -127
  128. package/dist/types-cjs/store/next/target.d.cts +0 -192
  129. package/dist/types-cjs/store/store.d.cts +0 -138
  130. package/dist/types-cjs/store/storePath.d.cts +0 -58
  131. package/dist/types-cjs/store/utils.d.cts +0 -74
@@ -1,3 +1,5 @@
1
+ import "./core.js";
2
+
1
3
  const DEV = undefined;
2
4
 
3
5
  export { DEV };
@@ -1,29 +1,31 @@
1
- import { REACTIVE_DISPOSED, STATUS_ERROR, EFFECT_USER, CONFIG_AUTO_DISPOSE, CONFIG_CHILDREN_FORBIDDEN, EFFECT_TRACKED, EFFECT_RENDER, STATUS_PENDING } from "./constants.js";
1
+ import { REACTIVE_DISPOSED, LANE_RUN, STATUS_ERROR, EFFECT_USER, CONFIG_AUTO_DISPOSE, CONFIG_CHILDREN_FORBIDDEN, EFFECT_TRACKED, EFFECT_RENDER, STATUS_PENDING } from "./constants.js";
2
2
 
3
3
  import { setEffectStatusNotify, ext, createEffectNode, recompute, computed, staleValues } from "./core.js";
4
4
 
5
5
  import { unwrapStatusError, StatusError } from "./error.js";
6
6
 
7
- import { GlobalQueue, haltReactivity } from "./scheduler.js";
7
+ import { enqueueSub } from "./heap.js";
8
+
9
+ import { GlobalQueue, currentTransition, activeTransition, haltReactivity, schedule } from "./scheduler.js";
8
10
 
9
11
  /**
10
12
  * Effects are the leaf nodes of our reactive graph. When their sources change, they are
11
13
  * automatically added to the queue of effects to re-execute, which will cause them to fetch their
12
14
  * sources and recompute
13
- */ function effect(t, e, E, f) {
14
- const r = !!f?.user;
15
- const R = createEffectNode(t, e, E, r ? EFFECT_USER : EFFECT_RENDER, f);
16
- recompute(R, true);
17
- !f?.defer && (R.ge === EFFECT_USER || f?.schedule ? R.C.enqueue(R.ge, runEffect.bind(null, R)) : runEffect(R));
15
+ */ function effect(t, e, E, r) {
16
+ const n = !!r?.user;
17
+ const f = createEffectNode(t, e, E, n ? EFFECT_USER : EFFECT_RENDER, r);
18
+ recompute(f, true);
19
+ !r?.defer && (f.Ce === EFFECT_USER || r?.schedule ? f.C.enqueue(f.Ce, runEffect.bind(null, f)) : runEffect(f, LANE_RUN));
18
20
  }
19
21
 
20
22
  function notifyEffectStatus(t, e) {
21
23
  // Use passed values if provided, otherwise read from node
22
24
  const E = t !== undefined ? t : this.S;
23
- const f = e !== undefined ? e : this.o?._;
25
+ const r = e !== undefined ? e : this.o?._;
24
26
  if (E & STATUS_ERROR) {
25
27
  this.C.notify(this, STATUS_PENDING, 0);
26
- if (this.ge === EFFECT_USER) {
28
+ if (this.Ce === EFFECT_USER) {
27
29
  // The error handler is the error arm of the effect phase (#2840 ruling):
28
30
  // queue it like the effect function. It runs in the same imperative,
29
31
  // writable scope, throws escalate the same way, and a held transition
@@ -34,22 +36,42 @@ function notifyEffectStatus(t, e) {
34
36
  // `status` arg without node-state writes) don't queue: the status
35
37
  // re-propagates unblocked at commit.
36
38
  if (this.S & STATUS_ERROR) {
37
- this.tt = true;
38
- this.C.enqueue(this.ge, this.nt ??= runEffect.bind(null, this));
39
+ this.He = true;
40
+ this.C.enqueue(this.Ce, this.rt ??= runEffect.bind(null, this));
39
41
  }
40
42
  return;
41
43
  }
42
44
  if (!this.C.notify(this, STATUS_ERROR, STATUS_ERROR)) {
43
- haltReactivity(unwrapStatusError(f));
44
- throw f;
45
+ haltReactivity(unwrapStatusError(r));
46
+ throw r;
45
47
  }
46
- } else if (this.ge === EFFECT_RENDER) {
47
- this.C.notify(this, STATUS_PENDING | STATUS_ERROR, E, f);
48
+ } else if (this.Ce === EFFECT_RENDER) {
49
+ this.C.notify(this, STATUS_PENDING | STATUS_ERROR, E, r);
48
50
  }
49
51
  }
50
52
 
51
- function runEffect(t) {
52
- if (!t.tt || t.ie & REACTIVE_DISPOSED) return;
53
+ function runEffect(t, e) {
54
+ if (!t.He || t.ie & REACTIVE_DISPOSED) return;
55
+ // Ownership (#3319): a value computed under a transaction is applied by that
56
+ // transaction's commit. The ordinary effect phase runs with a transaction
57
+ // active only when the flush's finalize ENTERED one (every other path parks
58
+ // or settles first): leave a run owned by a still-held transaction queued —
59
+ // `_modified` stays set — and the next gate stashes it with the owner.
60
+ // Mainline-owned runs (null) apply now. Lanes are exempt by design (they
61
+ // apply their own effects ahead of their transaction — the optimistic view)
62
+ // and mark their runs with LANE_RUN.
63
+
64
+ // Lane exemption has one exception (#3331): a lane runner for an effect that
65
+ // no longer rides a lane — its optimistic source was superseded, so the lane
66
+ // has no optimistic view left to apply, and the value this effect now
67
+ // carries (or will, once its plain recompute lands) belongs to the still-held
68
+ // transaction. Hand the run to the regular queue, where the transaction's
69
+ // gate stashes it with the owner. Lane-less runners with no live owner
70
+ // (reverts, wake-only lanes) apply now.
71
+ if (t._t !== null && !currentTransition(t._t).ft && (e & LANE_RUN ? !t.o?.Oe : activeTransition !== null)) {
72
+ t.C.enqueue(t.Ce, t.rt);
73
+ return;
74
+ }
53
75
  // Error arm (#2840), user effects only: a compute-phase error that is still
54
76
  // the node's settled state at effect time runs the bundle's error handler in
55
77
  // this same imperative, writable scope. Unwrap the StatusError used for
@@ -60,14 +82,14 @@ function runEffect(t) {
60
82
  // Render effects bypass: their errors route to boundaries synchronously in
61
83
  // notifyEffectStatus, and a runner queued by an earlier valueChanged in the
62
84
  // same flush must not be hijacked by a later-arriving error status.
63
- if (t.S & STATUS_ERROR && t.ge === EFFECT_USER) {
85
+ if (t.S & STATUS_ERROR && t.Ce === EFFECT_USER) {
64
86
  const e = unwrapStatusError(t.o?._);
65
- t.At = t.be;
66
- t.tt = false;
87
+ t.Ft = t.me;
88
+ t.He = false;
67
89
  try {
68
- t.Ct ? t.Ct(e, () => {
69
- const e = t.Rt;
70
- t.Rt = undefined;
90
+ t.vt ? t.vt(e, () => {
91
+ const e = t.Ht;
92
+ t.Ht = undefined;
71
93
  e?.();
72
94
  }) : console.error(e);
73
95
  } catch (e) {
@@ -78,14 +100,14 @@ function runEffect(t) {
78
100
  }
79
101
  return;
80
102
  }
81
- const e = t.Rt;
82
- t.Rt = undefined;
103
+ const E = t.Ht;
104
+ t.Ht = undefined;
83
105
  try {
84
- e?.();
85
- const E = t.Ot(t.be, t.At);
86
- if (false && E !== undefined && typeof E !== "function") ;
106
+ E?.();
107
+ const e = t.ht(t.me, t.Ft);
108
+ if (false && e !== undefined && typeof e !== "function") ;
87
109
  // The final cleanup is invoked by disposeChildren at true disposal.
88
- t.Rt = E;
110
+ t.Ht = e;
89
111
  } catch (e) {
90
112
  ext(t)._ = new StatusError(t, e);
91
113
  t.S |= STATUS_ERROR;
@@ -94,12 +116,12 @@ function runEffect(t) {
94
116
  throw e;
95
117
  }
96
118
  } finally {
97
- t.At = t.be;
98
- t.tt = false;
119
+ t.Ft = t.me;
120
+ t.He = false;
99
121
  }
100
122
  }
101
123
 
102
- GlobalQueue.it = runEffect;
124
+ GlobalQueue.ct = runEffect;
103
125
 
104
126
  /**
105
127
  * Internal tracked effect - bypasses heap, goes directly to effect queue.
@@ -107,31 +129,38 @@ GlobalQueue.it = runEffect;
107
129
  * Uses stale reads.
108
130
  */ function trackedEffect(t, e) {
109
131
  const run = () => {
110
- if (!E.tt || E.ie & REACTIVE_DISPOSED) return;
132
+ // `_modified` is NOT redundant with the heap: the heap dedups within a
133
+ // pass, but a held transition's passes each enqueue `_run` into the same
134
+ // user queue, and this gate is what collapses them into one run at commit.
135
+ if (!E.He || E.ie & REACTIVE_DISPOSED) return;
111
136
  try {
112
- E.tt = false;
137
+ E.He = false;
113
138
  recompute(E);
114
139
  } finally {}
115
140
  };
116
141
  const E = computed(() => {
117
- const e = E.Rt;
118
- E.Rt = undefined;
142
+ const e = E.Ht;
143
+ E.Ht = undefined;
119
144
  e?.();
120
- const f = staleValues(t);
121
- E.Rt = f;
145
+ const r = staleValues(t);
146
+ E.Ht = r;
122
147
  }, {
123
148
  ...e,
124
149
  lazy: true
125
150
  });
126
- E.Rt = undefined;
151
+ E.Ht = undefined;
127
152
  E.T = E.T & ~CONFIG_AUTO_DISPOSE | CONFIG_CHILDREN_FORBIDDEN;
128
- E.tt = true;
129
- E.ge = EFFECT_TRACKED;
153
+ E.He = true;
154
+ E.Ce = EFFECT_TRACKED;
130
155
  // Status dispatch rides the SHARED notifier (statusNotifierOf keys off
131
156
  // _type): its error arm is behavior-identical to the closure that used to
132
157
  // live here, without the per-node NodeExtension allocation.
133
- E.yt = run;
134
- E.C.enqueue(EFFECT_USER, run);
158
+ E.Ve = run;
159
+ // The first run rides the heap like every wake (GlobalQueue._update), so a
160
+ // tracked effect created inside a render-effect callback runs after that
161
+ // pass's staged writes commit, not before.
162
+ enqueueSub(E);
163
+ schedule();
135
164
  }
136
165
 
137
166
  // Install the shared effect status notifier (statusNotifierOf serves it to
@@ -64,8 +64,8 @@ function externalUntrack(e) {
64
64
  // removed on reset) so core's null checks stay equivalent to the old
65
65
  // `externalSourceConfig` truthiness checks.
66
66
  function syncExternalHooks() {
67
- GlobalQueue.Pt = externalSourceConfig ? wireExternalSource : null;
68
- GlobalQueue.ht = externalSourceConfig ? externalUntrack : null;
67
+ GlobalQueue.kt = externalSourceConfig ? wireExternalSource : null;
68
+ GlobalQueue.Lt = externalSourceConfig ? externalUntrack : null;
69
69
  }
70
70
 
71
71
  function enableExternalSource(e) {
@@ -1,4 +1,6 @@
1
- import { CONFIG_AUTO_DISPOSE, STATUS_PENDING, REACTIVE_DISPOSED, REACTIVE_ZOMBIE, REACTIVE_RECOMPUTING_DEPS } from "./constants.js";
1
+ import { CONFIG_AUTO_DISPOSE, STATUS_PENDING, REACTIVE_DISPOSED, REACTIVE_ZOMBIE, CONFIG_SLOT_NODE, REACTIVE_RECOMPUTING_DEPS } from "./constants.js";
2
+
3
+ import { slotUnobservedHook } from "./core.js";
2
4
 
3
5
  import { deleteFromHeap, queueFor } from "./heap.js";
4
6
 
@@ -8,15 +10,17 @@ import { bumpNotifyEpoch } from "./scheduler.js";
8
10
 
9
11
  // https://github.com/stackblitz/alien-signals/blob/v2.0.3/src/system.ts#L100
10
12
  function unlinkSubs(e) {
11
- const n = e.ot;
12
- const l = e.lt;
13
- const o = e.ae;
14
- const u = e.en;
15
- if (o !== null) o.en = u; else n._t = u;
16
- if (u !== null) u.ae = o; else {
13
+ const n = e.Se;
14
+ const l = e.ae;
15
+ const o = e.Te;
16
+ const s = e.en;
17
+ if (o !== null) o.en = s; else n.dt = s;
18
+ if (s !== null) s.Te = o; else {
17
19
  n.u = o;
18
20
  if (o === null) {
19
- n.o?.Et?.();
21
+ // Slot nodes (store leaves) dispatch to the ONE shared hook — no
22
+ // per-node unobserved closure, no NodeExtension to hold it.
23
+ if (n.T & CONFIG_SLOT_NODE) slotUnobservedHook(n); else n.o?.Ct?.();
20
24
  // No more subscribers; only tear down if CONFIG_AUTO_DISPOSE is set.
21
25
  // A pending node is exempt: its in-flight async work (or the
22
26
  // transition holding it) is an observer — tearing down would orphan
@@ -31,13 +35,13 @@ function unlinkSubs(e) {
31
35
  }
32
36
 
33
37
  function trimStaleDeps(e) {
34
- const n = e.je;
35
- let l = n !== null ? n.lt : e.ut;
38
+ const n = e.et;
39
+ let l = n !== null ? n.ae : e.fe;
36
40
  if (l !== null) {
37
41
  do {
38
42
  l = unlinkSubs(l);
39
43
  } while (l !== null);
40
- if (n !== null) n.lt = null; else e.ut = null;
44
+ if (n !== null) n.ae = null; else e.fe = null;
41
45
  }
42
46
  }
43
47
 
@@ -46,13 +50,13 @@ function trimStaleDeps(e) {
46
50
  // and skipping early also avoids adding one (hidden-class churn) via the
47
51
  // null-out below.
48
52
  function clearDeps(e) {
49
- let n = e.ut;
53
+ let n = e.fe;
50
54
  if (!n) return;
51
55
  do {
52
56
  n = unlinkSubs(n);
53
57
  } while (n !== null);
54
- e.ut = null;
55
- e.je = null;
58
+ e.fe = null;
59
+ e.et = null;
56
60
  }
57
61
 
58
62
  function unobserved(e) {
@@ -104,20 +108,20 @@ function link(e, n, l = false) {
104
108
  // not relabel the value dependency as probe-only — the value read is what
105
109
  // real-error propagation and affects() coverage key off, regardless of
106
110
  // read order within the computation.
107
- const o = n.je;
108
- if (o !== null && o.ot === e) {
109
- o.ve &&= l;
111
+ const o = n.et;
112
+ if (o !== null && o.Se === e) {
113
+ o.je &&= l;
110
114
  return;
111
115
  }
112
- let u = null;
116
+ let s = null;
113
117
  const t = n.ie & REACTIVE_RECOMPUTING_DEPS;
114
118
  if (t) {
115
- u = o !== null ? o.lt : n.ut;
116
- if (u !== null && u.ot === e) {
117
- u.Ft = n.Ke;
118
- n.je = u;
119
+ s = o !== null ? o.ae : n.fe;
120
+ if (s !== null && s.Se === e) {
121
+ s.yt = n.tt;
122
+ n.et = s;
119
123
  // First touch of this pass: the previous pass's label is stale.
120
- u.ve = l;
124
+ s.je = l;
121
125
  return;
122
126
  }
123
127
  }
@@ -126,24 +130,24 @@ function link(e, n, l = false) {
126
130
  // [deps.._depsTail] prefix — the O(1) equivalent of scanning the dep list
127
131
  // (the old alien-signals `isValidLink` walk, O(n²) when a computation
128
132
  // re-reads earlier deps non-consecutively, e.g. store leaf reads).
129
- const s = e._t;
130
- if (s !== null && s.ce === n && (!t || s.Ft === n.Ke)) {
133
+ const r = e.dt;
134
+ if (r !== null && r.Ie === n && (!t || r.yt === n.tt)) {
131
135
  // Gen-matched during a recompute = repeat touch this pass (AND); outside
132
136
  // a recompute there is no pass boundary, so the latest read labels it.
133
- if (t) s.ve &&= l; else s.ve = l;
137
+ if (t) r.je &&= l; else r.je = l;
134
138
  return;
135
139
  }
136
- const r = n.je = e._t = {
137
- ot: e,
138
- ce: n,
139
- lt: u,
140
- en: s,
141
- ae: null,
142
- Ft: n.Ke,
143
- ve: l
140
+ const u = n.et = e.dt = {
141
+ Se: e,
142
+ Ie: n,
143
+ ae: s,
144
+ en: r,
145
+ Te: null,
146
+ yt: n.tt,
147
+ je: l
144
148
  };
145
- if (o !== null) o.lt = r; else n.ut = r;
146
- if (s !== null) s.ae = r; else e.u = r;
149
+ if (o !== null) o.ae = u; else n.fe = u;
150
+ if (r !== null) r.Te = u; else e.u = u;
147
151
  // New subscriber edge: staged-rewrite skips (§12d) must not miss it.
148
152
  bumpNotifyEpoch();
149
153
  }
@@ -1,6 +1,6 @@
1
1
  import "./core.js";
2
2
 
3
- import { REACTIVE_IN_HEAP, REACTIVE_IN_HEAP_HEIGHT, EFFECT_TRACKED, EFFECT_USER, REACTIVE_ZOMBIE, REACTIVE_RECOMPUTING_DEPS, REACTIVE_MANUAL_WRITE, REACTIVE_CHECK, REACTIVE_DIRTY, CONFIG_FW_CHILDREN } from "./constants.js";
3
+ import { REACTIVE_IN_HEAP, REACTIVE_IN_HEAP_HEIGHT, REACTIVE_ZOMBIE, REACTIVE_RECOMPUTING_DEPS, REACTIVE_MANUAL_WRITE, REACTIVE_CHECK, REACTIVE_DIRTY, CONFIG_FW_CHILDREN } from "./constants.js";
4
4
 
5
5
  import { zombieQueue, dirtyQueue } from "./scheduler.js";
6
6
 
@@ -9,33 +9,27 @@ import { zombieQueue, dirtyQueue } from "./scheduler.js";
9
9
  }
10
10
 
11
11
  /**
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.
12
+ * Schedule one subscriber to re-run on the next flush: inserted into its own
13
+ * (zombie-flag-routed) heap with the `_min` cursor pulled down. Tracked
14
+ * effects ride the heap too the heap visit is their (empty) compute phase,
15
+ * which hands the callback to the user queue once the pass has committed
16
+ * (see GlobalQueue._update, #3291).
15
17
  */ function enqueueSub(e) {
16
- if (e.ge === EFFECT_TRACKED) {
17
- const E = e;
18
- if (!E.tt) {
19
- E.tt = true;
20
- E.C.enqueue(EFFECT_USER, E.yt);
21
- }
22
- return;
23
- }
24
18
  const E = queueFor(e);
25
- if (E.Qe > e.Me) E.Qe = e.Me;
19
+ if (E.Ke > e.Be) E.Ke = e.Be;
26
20
  insertIntoHeap(e, E);
27
21
  }
28
22
 
29
23
  function actualInsertIntoHeap(e, E) {
30
- const t = (e.ke?.Gt ? e.ke.Dt?.Me : e.ke?.Me) ?? -1;
31
- if (t >= e.Me) e.Me = t + 1;
32
- const n = e.Me;
24
+ const t = (e.qe?.gt ? e.qe.bt?.Be : e.qe?.Be) ?? -1;
25
+ if (t >= e.Be) e.Be = t + 1;
26
+ const n = e.Be;
33
27
  const I = E.eE[n];
34
28
  if (I === undefined) E.eE[n] = e; else {
35
- const E = I.ct;
36
- E.rt = e;
37
- e.ct = E;
38
- I.ct = e;
29
+ const E = I.Tt;
30
+ E.Nt = e;
31
+ e.Tt = E;
32
+ I.Tt = e;
39
33
  }
40
34
  if (n > E.EE) E.EE = n;
41
35
  }
@@ -50,12 +44,17 @@ function insertIntoHeap(e, E) {
50
44
  e.ie = t & -4 | REACTIVE_DIRTY | REACTIVE_IN_HEAP;
51
45
  } else {
52
46
  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;
47
+ // An unmarked node entering an already-marked heap is marked on the
48
+ // spot, keeping the markHeap memo valid. `_marked` is only reset by
49
+ // runHeap, so a write between two mid-tick pulls (read-time markHeap +
50
+ // updateIfNecessary) would otherwise leave this node unmarked and every
51
+ // downstream pull stale until the next flush (#2922: the second
52
+ // `latest()` returned the first write's value). Invalidating the memo
53
+ // instead re-walked the WHOLE heap on the next pull — with N effects
54
+ // parked in the heap for a synchronous mount (each row writing a ref
55
+ // signal its effect subscribes to), mounting N rows was O(N²) (#3350).
56
+ // markNode's own guard skips an already-DIRTY node.
57
+ if (E.tE) markNode(e);
59
58
  }
60
59
  if (!(t & REACTIVE_IN_HEAP_HEIGHT)) actualInsertIntoHeap(e, E);
61
60
  }
@@ -71,23 +70,23 @@ function deleteFromHeap(e, E) {
71
70
  const t = e.ie;
72
71
  if (!(t & (REACTIVE_IN_HEAP | REACTIVE_IN_HEAP_HEIGHT))) return;
73
72
  e.ie = t & -25;
74
- const n = e.Me;
75
- if (e.ct === e) E.eE[n] = undefined; else {
76
- const t = e.rt;
73
+ const n = e.Be;
74
+ if (e.Tt === e) E.eE[n] = undefined; else {
75
+ const t = e.Nt;
77
76
  const I = E.eE[n];
78
77
  const o = t ?? I;
79
- if (e === I) E.eE[n] = t; else e.ct.rt = t;
80
- o.ct = e.ct;
78
+ if (e === I) E.eE[n] = t; else e.Tt.Nt = t;
79
+ o.Tt = e.Tt;
81
80
  }
82
- e.ct = e;
83
- e.rt = undefined;
81
+ e.Tt = e;
82
+ e.Nt = undefined;
84
83
  }
85
84
 
86
85
  function markHeap(e) {
87
86
  if (e.tE) return;
88
87
  e.tE = true;
89
88
  for (let E = 0; E <= e.EE; E++) {
90
- for (let t = e.eE[E]; t !== undefined; t = t.rt) {
89
+ for (let t = e.eE[E]; t !== undefined; t = t.Nt) {
91
90
  if (t.ie & REACTIVE_IN_HEAP) markNode(t);
92
91
  }
93
92
  }
@@ -97,16 +96,16 @@ function markNode(e, E = REACTIVE_DIRTY) {
97
96
  const t = e.ie;
98
97
  if ((t & (REACTIVE_CHECK | REACTIVE_DIRTY)) >= E) return;
99
98
  e.ie = t & -4 | E;
100
- for (let E = e.u; E !== null; E = E.ae) {
101
- markNode(E.ce, REACTIVE_CHECK);
99
+ for (let E = e.u; E !== null; E = E.Te) {
100
+ markNode(E.Ie, REACTIVE_CHECK);
102
101
  }
103
102
  // Firewall children (projection machinery only): gate the cold-extension
104
103
  // deref on the config bit — markNode runs per sub edge per write, and an
105
104
  // unconditional _x chase here taxed every propagation (diamond -22%).
106
105
  if (e.T & CONFIG_FW_CHILDREN) {
107
- for (let E = e.o.i; E !== null; E = E.Se) {
108
- for (let e = E.u; e !== null; e = e.ae) {
109
- markNode(e.ce, REACTIVE_CHECK);
106
+ for (let E = e.o.i; E !== null; E = E.Ee) {
107
+ for (let e = E.u; e !== null; e = e.Te) {
108
+ markNode(e.Ie, REACTIVE_CHECK);
110
109
  }
111
110
  }
112
111
  }
@@ -114,11 +113,11 @@ function markNode(e, E = REACTIVE_DIRTY) {
114
113
 
115
114
  function runHeap(e, E) {
116
115
  e.tE = false;
117
- for (e.Qe = 0; e.Qe <= e.EE; e.Qe++) {
118
- let t = e.eE[e.Qe];
116
+ for (e.Ke = 0; e.Ke <= e.EE; e.Ke++) {
117
+ let t = e.eE[e.Ke];
119
118
  while (t !== undefined) {
120
119
  if (t.ie & REACTIVE_IN_HEAP) E(t); else adjustHeight(t, e);
121
- t = e.eE[e.Qe];
120
+ t = e.eE[e.Ke];
122
121
  }
123
122
  }
124
123
  e.EE = 0;
@@ -126,21 +125,21 @@ function runHeap(e, E) {
126
125
 
127
126
  function adjustHeight(e, E) {
128
127
  deleteFromHeap(e, E);
129
- let t = e.Me;
130
- for (let E = e.ut; E; E = E.lt) {
131
- const e = E.ot;
132
- const n = e.st || e;
133
- if (n.oe && n.Me >= t) t = n.Me + 1;
128
+ let t = e.Be;
129
+ for (let E = e.fe; E; E = E.ae) {
130
+ const e = E.Se;
131
+ const n = e.ce || e;
132
+ if (n.oe && n.Be >= t) t = n.Be + 1;
134
133
  }
135
- if (e.Me !== t) {
136
- e.Me = t;
137
- for (let E = e.u; E !== null; E = E.ae) {
134
+ if (e.Be !== t) {
135
+ e.Be = t;
136
+ for (let E = e.u; E !== null; E = E.Te) {
138
137
  // Route each subscriber by its own zombie flag, mirroring the
139
138
  // post-recompute height-adjust path. Inserting into the running `heap`
140
139
  // unconditionally can park a zombie in `dirtyQueue` (or a live node in
141
140
  // `zombieQueue`), breaking the flag/queue invariant `deleteFromHeap`
142
141
  // relies on — the same corruption class as #2759.
143
- insertIntoHeapHeight(E.ce, queueFor(E.ce));
142
+ insertIntoHeapHeight(E.Ie, queueFor(E.Ie));
144
143
  }
145
144
  }
146
145
  }