You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 0be1f6d
Browse filesBrowse the repository at this point in the historyBrowse files
fix(signals): a projection run's own draft writes arm the flush they withheld (#3585 follow-on)
A derive body only runs outside a flush at creation. Its own draft writes
made schedule() withhold the microtask (projectionWriteActive) and, for a
sync derive, nothing ever re-armed it: a projection created in a top-level
createRoot left `scheduled` set with no microtask, so its root's effects and
every unrelated write anywhere waited for an explicit flush(). Pre-existing
on `next`; fixed here in the same mechanism as the late-write arming by
dropping the run-returned gate on scheduleWithheld.
Arming mid-body is safe: the microtask fires after the synchronous slice,
when the body has returned or parked, and an initial async run's pre-await
half drains before its landing exactly as it already does when the creation
ran inside a flush — nothing reads it before the landing (the node is
uninitialized, proj R23). Reruns are flush-driven, so the withhold never
applies to them. Pinned: sync top-level projection no longer strands; an
async one with a pre-await write no longer holds unrelated work until its
landing, and the landing still reveals both halves together.
Size: -13 B minified in projection.js; `every store family` brotli moved
+105 on that removal (layout), cap 31.0 -> 31.1 KB with audit note;
re-measured against the rebased `next`.
Co-authored-by: Claude via Cursor <[email protected]>
Copy file name to clipboardExpand all lines: .changeset/projection-draft-valid-until-superseded.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,4 +2,4 @@
2
2
"@solidjs/signals": patch
3
3
---
4
4
5
-
Behavior change: a `createProjection` / `createStore(fn, seed)` / `createOptimisticStore(fn)` draft now stays valid until it is superseded by the next run of the derive or its owner is disposed — no longer "until no longer in flight" (#3585). A subscription set up inside a sync derive can write through the draft from its callback without the never-resolving-Promise workaround; the write applies, notifies subscribers, and arms the flush itself when no async run is in flight to do so (the scheduler used to strand on such writes). Writes through a superseded or disposed draft are dropped silently, so a previous run's leaked callback can no longer write into the current run's state (it did before, whenever nothing had read the projection yet).
5
+
Behavior change: a `createProjection` / `createStore(fn, seed)` / `createOptimisticStore(fn)` draft now stays valid until it is superseded by the next run of the derive or its owner is disposed — no longer "until no longer in flight" (#3585). A subscription set up inside a sync derive can write through the draft from its callback without the never-resolving-Promise workaround; the write applies, notifies subscribers, and arms the flush itself when no async run is in flight to do so (the scheduler used to strand on such writes). Also fixes the pre-existing strand where a sync projection created in a top-level `createRoot` outside any flush left the scheduler armed with no microtask — its effects and every unrelated write waited for an explicit `flush()`. Writes through a superseded or disposed draft are dropped silently, so a previous run's leaked callback can no longer write into the current run's state (it did before, whenever nothing had read the projection yet).
Copy file name to clipboardExpand all lines: packages/signals/docs/RULES-INDEX.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -178,7 +178,7 @@ Status legend: **live** stated and standing · **ruled** carries an explicit rul
178
178
| CS-R34 | live |`docs/rules-mining/core-store.md:151`| store.ts×1 | visibility-oracle-store.states.ts×1 |~~Optimistic writes visible immediately at write time (before flush)~~, never touch base raw; ambient (non-action) optimistic writes auto-revert at flush end.**_Visibility superseded 2026-09-10 by A2… |
179
179
| CS-R35 | live |`docs/rules-mining/core-store.md:156`| — | — | Mid-refetch optimistic overlays are consumed when data lands — identical via direct reads, mapArray, wrapper views, Object.keys, snapshot.**|
180
180
| CS-R36 | live |`docs/rules-mining/core-store.md:160`| — | — | An active optimistic hold on a wrapper view masks inner-store changes for the view's subscribers: mid-hold inner refresh landing causes ZERO re-runs of the view's structural subscribers; the reveal re… |
181
-
| CS-R37 | live |`docs/rules-mining/core-store.md:165`| — |createProjection.draft-lifetime-3585.test.ts×1 visibility-oracle-store.states.ts×3 | Setting store state from effect callbacks and promise resolutions works, applying next flush.**|
181
+
| CS-R37 | live |`docs/rules-mining/core-store.md:165`| — | visibility-oracle-store.states.ts×3 | Setting store state from effect callbacks and promise resolutions works, applying next flush.**|
182
182
| CS-R38 | live |`docs/rules-mining/core-store.md:171`| — | — | Shallow stores: root keys reactive (per-key nodes, membership, length), values served raw by identity at every depth, arrays and objects.**|
183
183
| CS-R39 | live |`docs/rules-mining/core-store.md:175`| — | visibility-oracle-store.states.ts×1 | Shallow setter-scope reads serve raws; in-place mutation of a served raw is reactively inert — records replaced, never edited.**|
184
184
| CS-R40 | live |`docs/rules-mining/core-store.md:179`| — | — | Shallow reconcile is positional: per-index effects only where the reference changed; reference-identical rows skip entirely; length propagates; `key` option moot.** Aligned: unowned-reference skip rul… |
@@ -317,7 +317,7 @@ Status legend: **live** stated and standing · **ruled** carries an explicit rul
317
317
| PJ-R20 | live |`docs/rules-mining/projections.md:70`| — | — | Chained backing works for array roots** (structural + row-level edits flow). |
318
318
| PJ-R21 | live |`docs/rules-mining/projections.md:72`| — | — |`createStore(fn, seed)` is the same projection mechanism and chains identically.**|
319
319
| PJ-R22 | live |`docs/rules-mining/projections.md:74`| — | — |`snapshot()` of a chained projection returns plain data equal to the current view and detached from future source writes.**|
320
-
| PJ-R23 | live |`docs/rules-mining/projections.md:80`| store.ts×2 | createProjection.draft-lifetime-3585.test.ts×1 | The seed is a draft for the derive, never observable (#2897)**: until first settle/yield, every read — tracked, untracked, enumeration/spread — throws NotReadyError. |
320
+
| PJ-R23 | live |`docs/rules-mining/projections.md:80`|projection.ts×1 store.ts×2 | createProjection.draft-lifetime-3585.test.ts×1 | The seed is a draft for the derive, never observable (#2897)**: until first settle/yield, every read — tracked, untracked, enumeration/spread — throws NotReadyError. |
321
321
| PJ-R24 | live |`docs/rules-mining/projections.md:83`| — | — | Draft writes during an in-flight async run are invisible until that run settles** (per-run atomic visibility). |
322
322
| PJ-R25 | live |`docs/rules-mining/projections.md:86`| — | — | Async generators publish one snapshot per yield**: bare `yield` publishes accumulated draft mutations; `yield value` replaces the entire state (no merge); each yield transforms again. |
323
323
| PJ-R26 | live |`docs/rules-mining/projections.md:88`| projection.ts×1 | createProjection.draft-lifetime-3585.test.ts×1 | Latest-run-wins supersession**: superseded runs' later yields and pending draft writes are discarded entirely; if no run ever landed, stays NotReady. |
@@ -331,7 +331,7 @@ Status legend: **live** stated and standing · **ruled** carries an explicit rul
331
331
| PJ-R34 | live |`docs/rules-mining/projections.md:104`| — | — | Errored derives follow async memo rules**: after rejection ALL readers (settle-time, late tracked, untracked) throw the error (StatusError-wrapped; boundaries unwrap). Seed never served uninitialized;… |
332
332
| PJ-R35 | live |`docs/rules-mining/projections.md:107`| — | — | A genuine tracked read on a later cycle retries an errored derive** (memo parity: never untracked, never inside isPending probe, at most once per cycle); successful retry serves fresh value. |
333
333
| PJ-R36 | live |`docs/rules-mining/projections.md:111`| — | — | Disposing the owning root stops the projection** (no recomputes, no notifications afterward). |
334
-
| PJ-R37 | ruled |`docs/rules-mining/projections.md:113`| scheduler.ts×2 projection.ts×3 target.ts×1 | createProjection.draft-lifetime-3585.test.ts×1| A draft is valid from the start of its run until it is superseded or its owner is disposed — not "until no longer in flight" (#3585, ruled 2026-09-22).** The draft handed to a run stays writable after… |
334
+
| PJ-R37 | ruled |`docs/rules-mining/projections.md:113`| scheduler.ts×2 projection.ts×3 target.ts×1 | createProjection.draft-lifetime-3585.test.ts×3| A draft is valid from the start of its run until it is superseded or its owner is disposed — not "until no longer in flight" (#3585, ruled 2026-09-22).** The draft handed to a run stays writable after… |
335
335
## R — reconcile-snapshot (`RS-R<n>`)
336
336
337
337
| id | status | defined | cited in src | cited in tests | statement (at definition) |
**R36 — Disposing the owning root stops the projection** (no recomputes, no notifications afterward).
112
112
113
113
**R37 — A draft is valid from the start of its run until it is superseded or its owner is disposed — not "until no longer in flight" (#3585, ruled 2026-09-22).** The draft handed to a run stays writable after the derive returns — sync or async, whatever it returned — until (a) the NEXT run of the derive starts (including a run that throws NotReady or is parked on an `await`; latest-run-wins, R26), or (b) the projection's owner is disposed. This is the contract behind `createProjection(draft => { subscribe(id, item => draft.push(item)); onCleanup(unsubscribe) })` working without a never-resolving-Promise workaround; it applies equally to `createStore(fn, seed)` and `createOptimisticStore(fn)` drafts.
114
-
- Late writes take the authoritative override channel (pending-backing write, per-op notification, fold at the next flush). When no flight is up to drain them at its landing, the write arms the drain itself (`scheduleWithheld`) — `schedule()` withholds its microtask under projectionWriteActive precisely because a landing normally follows, and a drain BEFORE the landing tears the run's pre- and post-`await` halves apart (async "notifies only changed paths", spec A22). A late write inside an `action` is stamped to that transaction and commits atomically with it.
114
+
- Late writes take the authoritative override channel (pending-backing write, per-op notification, fold at the next flush). When no flight is up to drain them at its landing, the write arms the drain itself (`scheduleWithheld`) — `schedule()` withholds its microtask under projectionWriteActive precisely because a landing normally follows, and a drain BEFORE the landing tears the run's pre- and post-`await` halves apart (async "notifies only changed paths", spec A22). The run's own writes arm the same way: a derive body only runs outside a flush at creation, and a sync projection created in a top-level `createRoot` used to leave `scheduled` set with no microtask — its root's effects and every unrelated write stranded until an explicit `flush()` (pre-existing, fixed with R37). A late write inside an `action` is stamped to that transaction and commits atomically with it.
115
115
- A write to a superseded or disposed draft is dropped silently — same fate as a superseded async run's pending draft writes (R26); no diagnostic (a stale `.then` continuation landing after supersession is the ordinary latest-run-wins race, not an authoring error).
116
116
- Carve-out: a loading-window run (`seedLoadingValue`) works a detached shadow of the seed, not the draft (#2988). A callback that closes over the shadow writes into a dead clone once the window has closed (first commit). Ruled acceptable for now; a redirecting shadow would remove the carve-out.
117
117
- The pre-R37 gate (`!settled || owner._x?._inFlight === result`) was timing-dependent: a sync derive's `undefined` result equalled a never-installed `_x`'s `undefined``_inFlight`, so the "dead" draft was live exactly while nothing had read the projection, and a superseded run's leaked callback kept writing into the NEXT run's state. Nothing pinned it.
0 commit comments