@solidjs/signals 2.0.0-rc.1 → 2.0.0-rc.11

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 +7155 -0
  2. package/dist/dev.attribution.js +3307 -0
  3. package/dist/dev.js +5765 -4496
  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 +669 -0
  27. package/dist/observe/core/owner.js +353 -0
  28. package/dist/observe/core/scheduler.js +1561 -0
  29. package/dist/observe/core/verdict.js +674 -0
  30. package/dist/observe/index.js +59 -0
  31. package/dist/observe/map.js +507 -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 +500 -104
  61. package/dist/prod/core/owner.js +131 -84
  62. package/dist/prod/core/scheduler.js +1012 -241
  63. package/dist/prod/core/verdict.js +417 -112
  64. package/dist/prod/index.js +20 -8
  65. package/dist/prod/map.js +355 -171
  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 +252 -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,8 +1,8 @@
1
- import { computed, suppressComputedRecompute } from "../../core/core.js";
1
+ import { computed } from "../../core/core.js";
2
2
 
3
- import { getOwner } from "../../core/owner.js";
3
+ import { isDisposed, getOwner } from "../../core/owner.js";
4
4
 
5
- import { setProjectionWriteActive, projectionWriteActive } from "../../core/scheduler.js";
5
+ import { setProjectionWriteActive, projectionWriteActive, scheduleWithheld } from "../../core/scheduler.js";
6
6
 
7
7
  import { handleAsync } from "../../core/async.js";
8
8
 
@@ -10,13 +10,13 @@ import "../../core/verdict.js";
10
10
 
11
11
  import "../../core/effect.js";
12
12
 
13
- import { CONFIG_AUTO_DISPOSE } from "../../core/constants.js";
13
+ import { CONFIG_AUTO_DISPOSE, STATUS_PENDING } from "../../core/constants.js";
14
14
 
15
- import { $TARGET, markRawIngest, STORE_VALUE, setWriteOverride } from "../store.js";
15
+ import { $TARGET, STORE_VALUE, markRawIngest, setWriteOverride } from "../store.js";
16
16
 
17
17
  import { reconcileNextState } from "./reconcile.js";
18
18
 
19
- import { wrapNext, storeSetterNext } from "./store.js";
19
+ import { storeSetterNext, wrapNext, derivedStoreWrite } from "./store.js";
20
20
 
21
21
  /**
22
22
  * Store rewrite — projections (§7/§7b): a projection is a computed store.
@@ -33,68 +33,119 @@ import { wrapNext, storeSetterNext } from "./store.js";
33
33
  * loading windows, handleAsync landings, commit-through-setter) on next
34
34
  * primitives; the generic draft write-traps are reused from the legacy
35
35
  * module unchanged.
36
- */ function createWriteTraps(e, t) {
37
- // Save/restore, never hard-reset: the draft can be driven from inside an
38
- // enclosing authoritative-write scope (next-store optimistic derives), and
39
- // a hard `false` would clobber it mid-derive.
40
- const r = {
41
- get(e, t) {
42
- let o;
43
- const i = projectionWriteActive;
36
+ */
37
+ /**
38
+ * Wrap a store proxy as a projection DRAFT: every operation carries the write
39
+ * override (the derive is the author — its ops must not hit the §6c firewall
40
+ * gate, even in a continuation after an `await`/`yield` where the sync write
41
+ * scope has closed).
42
+ *
43
+ * FAKE TARGET, not the store proxy itself (#3060): after a proxy trap
44
+ * returns, the engine runs spec invariant validation against the proxy's
45
+ * TARGET — [[OwnPropertyKeys]] after ownKeys, [[GetOwnProperty]] after
46
+ * set/getOwnPropertyDescriptor/defineProperty. With the store proxy as
47
+ * target those checks re-enter the store's traps OUTSIDE the override
48
+ * bracket (the trap's finally has already run), so `Object.keys(state)` in
49
+ * a derive continuation fired the firewall gate and re-threw the
50
+ * projection's own pending NotReadyError into the derive. A dummy of
51
+ * matching kind (array/object, same trick as the store's own TargetShape)
52
+ * keeps invariant validation away from the store entirely; the traps
53
+ * forward to the closed-over inner proxy inside the bracket.
54
+ *
55
+ * Save/restore projectionWriteActive, never hard-reset: the draft can be
56
+ * driven from inside an enclosing authoritative-write scope (next-store
57
+ * optimistic derives), and a hard `false` would clobber it mid-derive.
58
+ */ function wrapDraft(e, t, r, o, i) {
59
+ // One bracket for the three mutating traps. A write to a superseded or
60
+ // disposed draft is dropped silently (proj R37 — the same fate as a
61
+ // superseded async run's pending draft writes, R26). `afterWrite` runs
62
+ // once the bracket has closed — outside it, so the scheduler's
63
+ // projectionWriteActive guard no longer applies — and only for the
64
+ // outermost bracket (a draft driven from inside an enclosing authoritative
65
+ // scope, the optimistic derive, leaves scheduling to that scope's caller).
66
+ const mutate = e => {
67
+ if (!t()) return true;
68
+ const o = projectionWriteActive;
69
+ setWriteOverride(true);
70
+ setProjectionWriteActive(true);
71
+ try {
72
+ r ? r(e) : e();
73
+ } finally {
74
+ setWriteOverride(false);
75
+ setProjectionWriteActive(o);
76
+ }
77
+ if (!o && i) i();
78
+ return true;
79
+ };
80
+ const n = {
81
+ get(n, c) {
82
+ let s;
83
+ const l = projectionWriteActive;
44
84
  setWriteOverride(true);
45
85
  setProjectionWriteActive(true);
46
86
  try {
47
- o = e[t];
87
+ s = e[c];
48
88
  } finally {
49
89
  setWriteOverride(false);
50
- setProjectionWriteActive(i);
90
+ setProjectionWriteActive(l);
51
91
  }
52
- if (t === $TARGET) return o;
53
- return typeof o === "object" && o !== null ? new Proxy(o, r) : o;
92
+ // A shallow store's leaves are raw by contract (#3498): no draft proxy
93
+ // over them, so identity holds and a frozen leaf is never trapped.
94
+ return !o && typeof s === "object" && s !== null && c !== $TARGET ? wrapDraft(s, t, r, false, i) : s;
54
95
  },
55
- has(e, t) {
56
- let r;
57
- const o = projectionWriteActive;
96
+ has(t, r) {
97
+ let o;
98
+ const i = projectionWriteActive;
58
99
  setWriteOverride(true);
59
100
  setProjectionWriteActive(true);
60
101
  try {
61
- r = t in e;
102
+ o = r in e;
62
103
  } finally {
63
104
  setWriteOverride(false);
64
- setProjectionWriteActive(o);
105
+ setProjectionWriteActive(i);
65
106
  }
66
- return r;
107
+ return o;
67
108
  },
68
- set(r, o, i) {
69
- if (e && !e()) return true;
70
- const n = projectionWriteActive;
109
+ set: (t, r, o) => mutate(() => {
110
+ e[r] = o;
111
+ }),
112
+ deleteProperty: (t, r) => mutate(() => {
113
+ delete e[r];
114
+ }),
115
+ ownKeys() {
116
+ const t = projectionWriteActive;
71
117
  setWriteOverride(true);
72
118
  setProjectionWriteActive(true);
73
119
  try {
74
- r[o] = i;
75
- t?.();
120
+ return Reflect.ownKeys(e);
76
121
  } finally {
77
122
  setWriteOverride(false);
78
- setProjectionWriteActive(n);
123
+ setProjectionWriteActive(t);
79
124
  }
80
- return true;
81
125
  },
82
- deleteProperty(r, o) {
83
- if (e && !e()) return true;
126
+ getOwnPropertyDescriptor(t, r) {
127
+ let o;
84
128
  const i = projectionWriteActive;
85
129
  setWriteOverride(true);
86
130
  setProjectionWriteActive(true);
87
131
  try {
88
- delete r[o];
89
- t?.();
132
+ o = Reflect.getOwnPropertyDescriptor(e, r);
90
133
  } finally {
91
134
  setWriteOverride(false);
92
135
  setProjectionWriteActive(i);
93
136
  }
94
- return true;
95
- }
137
+ // The dummy target doesn't hold the key, so a non-configurable report
138
+ // would violate the proxy invariant. Store descriptors are already
139
+ // normalized configurable; enforce it for raw leaves too.
140
+ if (o) o.configurable = true;
141
+ return o;
142
+ },
143
+ defineProperty: (t, r, o) => mutate(() => {
144
+ Reflect.defineProperty(e, r, o);
145
+ })
96
146
  };
97
- return r;
147
+ // Matching-kind dummy so Array.isArray(draft) answers like the store.
148
+ return new Proxy(Array.isArray(e) ? [] : {}, n);
98
149
  }
99
150
 
100
151
  function createProjectionNextInternal(e, t, r) {
@@ -118,7 +169,7 @@ function createProjectionNextInternal(e, t, r) {
118
169
  if (!o.node) o.node = getOwner();
119
170
  runProjectionComputedNext(i, e, r?.key === undefined ? "id" : r.key);
120
171
  }, n);
121
- c.T &= ~CONFIG_AUTO_DISPOSE;
172
+ c.C &= ~CONFIG_AUTO_DISPOSE;
122
173
  o.node = c;
123
174
  return {
124
175
  store: i,
@@ -132,39 +183,73 @@ function createProjectionNext(e, t, r) {
132
183
 
133
184
  /** Derived writable store (legacy parity): a projection whose public setter
134
185
  * masks the recompute for the tick (core R31 — the manual write wins over a
135
- * same-flush dependency change). */ function createStoreDerivedNext(e, t, r) {
186
+ * same-flush dependency change). Across a hold the write is not a proposal:
187
+ * a leaf another transaction holds as the fold's result re-runs the fold
188
+ * under it, the write being the draft's prior state (A34 amendment, #3612;
189
+ * core derivedWrite). */ function createStoreDerivedNext(e, t, r) {
136
190
  const {store: o, node: i} = createProjectionNextInternal(e, t, r);
137
- return [ o, e => {
138
- // Mark the projection as manually written before notifying nodes.
139
- suppressComputedRecompute(i);
140
- storeSetterNext(o, e);
141
- } ];
191
+ return [ o, e => derivedStoreWrite(i, o, e) ];
192
+ }
193
+
194
+ // A detached copy of projection state: the root container alone for a shallow
195
+ // store — its leaves are raw references by contract and stay so (#3498) — the
196
+ // whole tree otherwise.
197
+ function cloneState(e, t) {
198
+ return t ? Array.isArray(e) ? e.slice() : {
199
+ ...e
200
+ } : JSON.parse(JSON.stringify(e));
142
201
  }
143
202
 
144
203
  function runProjectionComputedNext(e, t, r, o, i) {
145
204
  const n = getOwner();
146
- let c = false;
147
- let s;
205
+ const c = e[$TARGET];
206
+ const s = c.fam;
207
+ // Draft validity is per run (R37): live from here until the NEXT run starts
208
+ // — this counter moves, whatever that run does (lands, throws NotReady,
209
+ // awaits) — or the owner is disposed. Not "until no longer in flight": a
210
+ // sync derive that subscribes to an external source and pushes into the
211
+ // draft from the callback (#3585) is the model use, and the old gate
212
+ // (`owner._x?._inFlight === result`) only admitted it by accident — while
213
+ // nothing had read the projection yet (no `_x`), `undefined === undefined`.
214
+ const l = s.run = (s.run || 0) + 1;
215
+ let u;
148
216
  // Open loading window (seedLoadingValue): the observable store IS commit #0
149
217
  // for the whole first flight — the derive works a detached shadow of the
150
218
  // seed so draft writes cannot tear through to readers (#2988). Every commit
151
- // point reconciles the shadow through the normal commit path.
152
- const u = n.Ee ? JSON.parse(JSON.stringify(e[$TARGET][STORE_VALUE])) : null;
153
- const l = new Proxy(e, createWriteTraps(() => !c || n.Te === s, i));
154
- storeSetterNext(l, i => {
155
- s = t(u ?? i);
156
- c = true;
219
+ // point reconciles the shadow through the normal commit path. (A callback
220
+ // that closes over the shadow writes into a dead clone once the window has
221
+ // closed — the one carve-out from R37's one-draft-per-run model.)
222
+ const a = n.ve ? cloneState(c[STORE_VALUE], c.s) : null;
223
+ const f = wrapDraft(e, () => s.run === l && !isDisposed(n), i, c.s,
224
+ // A write after the run returned takes the override channel (pending
225
+ // backing + per-op notify + fold) and arms the drain itself when no
226
+ // landing will: a flight still up — pending, or the loading window's
227
+ // first flight — drains at its landing, and must not be drained early.
228
+ // Not gated on the run having returned: the body's own writes withhold
229
+ // the microtask too, and a derive body only ever runs outside a flush at
230
+ // creation (reruns are flush-driven) — a top-level sync projection in a
231
+ // createRoot stranded the scheduler until an explicit flush(). Arming
232
+ // mid-body is safe: the microtask fires after this synchronous slice,
233
+ // when the body has returned or parked, and an initial async run's
234
+ // pre-await half drains before its landing exactly as it does when the
235
+ // creation ran inside a flush — nothing reads it before the landing
236
+ // (the node is uninitialized, proj R23).
237
+ () => {
238
+ if (!(n.h & STATUS_PENDING) && !n.ve) scheduleWithheld();
239
+ });
240
+ storeSetterNext(f, i => {
241
+ u = t(a ?? i);
157
242
  const commit = t => {
158
243
  // Shadow run: commit a detached snapshot, never the shadow itself
159
244
  // (adoption takes the value by identity — handing it the live shadow
160
245
  // would fuse the draft to the observable store).
161
- if (u && (t === undefined || t === u)) t = JSON.parse(JSON.stringify(u));
246
+ if (a && (t === undefined || t === a)) t = cloneState(a, c.s);
162
247
  if (t === i || t === undefined) return;
163
248
  const write = () => storeSetterNext(e, e => reconcileNextState(t, e, r, true), false);
164
- o ? o(write) : write();
249
+ o ? o(write, t) : write();
165
250
  };
166
- const l = handleAsync(n, s, commit);
167
- if (!n.Ee) commit(l);
251
+ const s = handleAsync(n, u, commit);
252
+ if (!n.ve) commit(s);
168
253
  }, false);
169
254
  return n;
170
255
  }