Repository navigation
Description
One of a series of small proposals, in order; the tracking issue lists them. Depends on: none beyond upstream PR solidjs#69.
Summary
peek e reads e once, without subscribing (E-5). When the peek sits in an expression that is kept and read again, and nothing else in that expression changes, the expression never recomputes, so every reader keeps the first value of e. If e can change, that is almost always a bug. This RFC makes it a compile error, SNAPSHOT_KEPT (E-5a), checked one module at a time.
Motivation
In ReactiveScript an equation (x = …) is a derived value (a Solid memo); a view's {…} is a live read. peek exists for samples: read a value at the moment something else makes the expression recompute. Used alone, it quietly freezes:
export default component App() {
source n := 1
shown = peek n // 1 forever
<p>{shown}</p>
<button onClick={() => { n := n + 1 }}>+</button>
}
The same happens with a provision: provide page = peek data, where data loads and is refreshed, hands every consumer the first value. In Solid this is untrack(data) in a memo with no other source, or <Ctx value={untrack(data)}>. Upstream accepts both without a word, and at run time nothing fails: the page just stops updating.
Proposal
E-5a (A kept peek of what changes). A peek is kept when its expression is kept and read again:
- an equation; a provision or a context's default;
- what a view reads (a
{…}, an attribute, anifcondition, aforlist); - a component's argument; a
refargument.
Not kept: a source's seed (E-4) and a value argument (E-10), which are snapshots by rule; an effect's compute half; a closure, which reads when called.
A kept peek e is refused with SNAPSHOT_KEPT (bin S, a compile error) when nothing else in the expression changes and e can change: a source that is written, guessed, refreshed or affected; something that awaits; a ref parameter; a JS reader or a field declared to hold; a field read through the instance a declared primitive made (peek size.width), or an equation bound to one; a field read through a for row (peek r.x) whose list can change. The row and the instance themselves never change (peek r is accepted, as is a method called on an instance), but a row's fields are written by path or reconciled by key while the row lives, and an instance's fields track.
Accepted:
twice = n * 2 + peek n // a sample: n * 2 changes, so peek n is read again
source draft := peek props.start // a named snapshot (E-4)
fixed = peek label // label is an equation that never changes
The fix the message suggests: drop peek to read live, or name the snapshot, source saved := peek e.
Per module. Writes to a source are always in its own module (MO-2), and a context is read-only beneath its provision (RG-7c). What one module cannot see is who applies its components, who provides its contexts, and what an imported .rx export does. Checked one module at a time (the default), each of those counts as changing:
// show.rx: refused when checked alone, whoever applies Show
export component Show(props: { value: number }) {
<b>{peek props.value}</b>
}
RFC 35 proposes a whole-program mode that decides these from every application and provision.
Drawbacks and alternatives
- It refuses some correct programs: a
peekof a prop that every caller passes a constant (above). The per-module default is conservative on purpose; RFC 35 is the escape. - A prop is assumed to change for the
peek, but does not count as "something else that changes" for the rest of the expression. Sov = props.k + peek nwithnwritten is refused per module, even thoughprops.kmay well change. This keeps the check one-sided (it never accepts a freeze it cannot see past), at the cost of more refusals. - Alternative: a warning. Under CN-1a there is no warning tier, so a bin-S rule is an error or nothing.
- Alternative: forbid
peekoutside samples entirely. That would refusefixed = peek label, which is harmless, and named snapshots, which are the point.
Prototype
Branch claude/magical-bell-pfhb1w of yumemi-thomas/reactivescript: commit 8b62574 (the per-module check in ref/src/check.ts and compiler/src/check.rs). Spec rule E-5a in spec/02-core.md; SNAPSHOT_KEPT in spec/99-diagnostics.md and guide/diagnostics.md. Scenario scenarios/S-surface-6.md: the accepted program (a sample, a named snapshot, a peek of a constant equation, with frames) and rejected variants for an equation, a provision of loaded data, and a prop peeked in another module.
Open questions
- Should a prop on the other side of the expression (
props.k + peek n) count as changing per module, making thepeeka sample? The prototype says no. - Resolved in f031b0b (both checkers, S-surface-8): a kept
peekof a field of a primitive's instance, and of a field of aforrow whose list can change, were accepted and froze. A row's field counts as changing whenever its list does, which also refuses a list that is only ever replaced whole with untouched rows; dropping thepeekthere costs nothing. Should that case be told apart? - Not covered: the same field read as a value argument (
createLabel(r.x)in a row, E-10) or a source's seed is still read once without a diagnostic for a row; for an instance RFC 14 refuses it.
Revised after the second review (2026-11-21, cdc00d4)
RFC 34, after the second review. Aligned with RFC 14's bounded exemption: a kept peek inst.m() of a method the primitive does not declare in methods(…) is SNAPSHOT_KEPT, as the same call in an argument is SNAPSHOT_ARGUMENT (S-module-20).
Activity