Skip to content

Commit 07d926b

Browse files
ryansolidClaude via Cursorcursoragent
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]>
1 parent 4b62bc2 commit 07d926b

16 files changed

Lines changed: 772 additions & 62 deletions
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@solidjs/signals": patch
3+
"solid-js": patch
4+
---
5+
6+
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.

‎documentation/solid-2.0/02-signals-derived-ownership.md‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ In 2.0, a root created inside an existing owned scope is itself owned by that pa
2020

2121
```js
2222
function Widget() {
23-
createRoot((dispose) => {
23+
createRoot(dispose => {
2424
const [count, setCount] = createSignal(0);
25-
const id = setInterval(() => setCount((c) => c + 1), 1000);
25+
const id = setInterval(() => setCount(c => c + 1), 1000);
2626
onCleanup(() => clearInterval(id));
2727
});
2828
return null;
@@ -32,7 +32,7 @@ function Widget() {
3232

3333
#### Disposal order is unwind
3434

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).
3636

3737
#### Detaching is explicit: `runWithOwner(null, ...)`
3838

@@ -90,7 +90,7 @@ const [todos, { addTodo }] = useContext(TodosContext);
9090

9191
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.
9292

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.
9494
9595
**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.
9696

@@ -110,6 +110,8 @@ const [cached, setCached] = createSignal((prev = props.something) => prev);
110110
// setValue(...) writes like a normal signal; the compute receives prev on recompute.
111111
```
112112

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.
114+
113115
#### Function-form `createStore` (derived/projection store)
114116

115117
`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
118120

119121
```js
120122
// Example: derived store that only flips the active key
121-
const [selected, setSelected] = createStore((draft) => {
123+
const [selected, setSelected] = createStore(draft => {
122124
const id = selectedId();
123125
draft[id] = true;
124126
if (draft._prev != null) delete draft[draft._prev];
@@ -157,10 +159,10 @@ If you used `createComputed` to “write back”:
157159

158160
## Removals
159161

160-
| Removed | Replacement |
161-
|--------|-------------|
162-
| `createComputed` | `createEffect` (split), function-form `createSignal`/`createStore`, or `createMemo` |
163-
| `Context.Provider` | Use the context directly as the provider component (`<Context value={...}>`) |
162+
| Removed | Replacement |
163+
| ------------------ | ----------------------------------------------------------------------------------- |
164+
| `createComputed` | `createEffect` (split), function-form `createSignal`/`createStore`, or `createMemo` |
165+
| `Context.Provider` | Use the context directly as the provider component (`<Context value={...}>`) |
164166

165167
## Alternatives considered
166168

0 commit comments

Comments
 (0)