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 07d926b
Browse filesBrowse the repository at this point in the historyBrowse files
committed
fix(signals): a held derivation is not a proposal — mainline writes become prev for the re-derivation (#3612)
#2692's "manual write wins" precedence applies within a synchronous frame.
Across a hold, a held derivation is not a proposal: a mainline write to a
node whose held staging is a pass result (stamped by another transaction,
REACTIVE_MANUAL_WRITE not set on the node or its _firewall) becomes `prev`
for the transaction's re-derivation and does not suppress it. The write
still joins T per A34(1) — the writer's tick reveals with T, no intermediate
mainline commit. Writes made inside the transaction keep last-write-wins.
Applies to createSignal(fn) and createStore(fn) (CS-R31).
Mechanism: `setMemo` asks `heldDerivation` before the write, resolves an
updater against the committed value on a hit, takes the A34 join, and
`rederiveHeld`s (DIRTY + enqueue) instead of masking. The derived store
setter is wrapped by `derivedStoreWrite`, which records a held leaf whose
`_firewall` is the setter's node in `notifyWrites` and decides in its
`finally`. `updateIfNecessary`'s post-pull flag wipe now preserves
REACTIVE_MANUAL_WRITE: the mask is state, not scheduling, and a `latest()`
probe must not turn a proposal into a pass result.
Co-authored-by: Claude via Cursor <[email protected]>
Co-authored-by: Cursor <[email protected]>
A held derivation is not a proposal (#3612). A mainline write to a writable memo (`createSignal(fn)`) or function-form store (`createStore(fn)`) whose staging is a pass result held by another transaction no longer suppresses that transaction's re-derivation: the write still joins the transaction (A34), and the derivation re-runs under the hold with the written value as `prev`. Same-frame "manual write wins" (#2692) and last-write-wins for writes made inside the transaction are unchanged.
Copy file name to clipboardExpand all lines: documentation/solid-2.0/02-signals-derived-ownership.md
+11-9Lines changed: 11 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,9 +20,9 @@ In 2.0, a root created inside an existing owned scope is itself owned by that pa
20
20
21
21
```js
22
22
functionWidget() {
23
-
createRoot((dispose)=> {
23
+
createRoot(dispose=> {
24
24
const [count, setCount] =createSignal(0);
25
-
constid=setInterval(() =>setCount((c)=> c +1), 1000);
25
+
constid=setInterval(() =>setCount(c=> c +1), 1000);
26
26
onCleanup(() =>clearInterval(id));
27
27
});
28
28
returnnull;
@@ -32,7 +32,7 @@ function Widget() {
32
32
33
33
#### Disposal order is unwind
34
34
35
-
Cleanups run in unwind order: an owner's children are disposed before its own cleanups, and within one owner later registrations run before earlier ones (the same LIFO rule 1.x had). In production a component body shares its enclosing owner rather than getting one of its own, so a parent that registers `onCleanup` before rendering its children tears down after them — the same order the dev build's per-component owner gives. Register cleanup before creating children when the order between them matters; a parent that registers `onCleanup`*after* creating its children runs before them in production (and after them in dev).
35
+
Cleanups run in unwind order: an owner's children are disposed before its own cleanups, and within one owner later registrations run before earlier ones (the same LIFO rule 1.x had). In production a component body shares its enclosing owner rather than getting one of its own, so a parent that registers `onCleanup` before rendering its children tears down after them — the same order the dev build's per-component owner gives. Register cleanup before creating children when the order between them matters; a parent that registers `onCleanup`_after_ creating its children runs before them in production (and after them in dev).
36
36
37
37
#### Detaching is explicit: `runWithOwner(null, ...)`
The default form `createContext<T>(defaultValue)` is unchanged: `useContext` falls back to `defaultValue` outside any Provider. Reserved for primitive fallbacks (theme, locale, frozen config). For any context carrying reactive state, prefer the default-less form.
92
92
93
-
> If you want truly app-wide state, **don't use Context** — a module-scope signal/store *is* a global. Context is for scoping state to a subtree, which is why a Provider is mandatory in the default-less form.
93
+
> If you want truly app-wide state, **don't use Context** — a module-scope signal/store _is_ a global. Context is for scoping state to a subtree, which is why a Provider is mandatory in the default-less form.
94
94
95
95
**Migration:** drop `useX`-with-throw wrappers and call `useContext` directly. If you actively relied on `useContext(ctx)` returning `undefined` for a default-less context, either pass an explicit default to `createContext` or wrap the call in a try/catch.
// setValue(...) writes like a normal signal; the compute receives prev on recompute.
111
111
```
112
112
113
+
Within a synchronous frame the write wins over a recompute queued in the same tick (either order). Across a hold it is not a proposal: while a transaction holds a value the compute derived (an async dependent of the source is still in flight), a write from outside that transaction joins it and becomes the `prev` of the transaction's re-derivation instead of replacing it — the frame that reveals is `fn(inputs)`, never a value the writer computed against the old frame. Writes made inside the transaction keep last-write-wins. The same holds for the derived `createStore` below.
`createStore(fn, seed, options?)` creates a derived store driven by mutation in `fn(draft)` (and may also return a value / Promise / async iterable). It’s the store analogue for derived shapes and underpins patterns like “selector-like” updates without notifying everything.
@@ -118,7 +120,7 @@ Unlike memo/effect `prev`, the second argument here is a real backing host objec
118
120
119
121
```js
120
122
// Example: derived store that only flips the active key
0 commit comments