Repository navigation
Keep the reader where they were when a revision arrives - #802
Conversation
A revision is applied as a patch, and focus survives only on the nodes the patch leaves alone. The Ask a reader is answering is the thing a revision is most likely to restate, and restating it replaces every node inside, so the reader was dropped onto `body` in the same breath as "Updated to Draft". version.js rules focus out of a document replacement because an authored control has no identity a new document can be sure it found again, only a shape. An Ask is not a shape: its id is a declared identity that the inventory, the tray rows, the margin entries and the ask walk already resolve against whichever document is standing. asks/view.js captures that id; version.js restores it after the patch and carries it in the one-use handoff, so the install that opens a fresh document hands back the same standing. An Ask the revision withdraws still leaves the reader on the page. The id is the whole of what crosses, and the Ask itself is the whole of what is handed back. Which control inside it the reader held is not a question this can answer — the controls are the widget's, most carry no id, and the first one that answers the Ask is the walk's landing rule rather than a restore. Handing that back would be the failure version.js names: a reader holding the second option would be given the first, and their next press would choose it. The Ask's opening holds a lent tab stop rather than a decision, so the digits still reach the option they meant and Space decides nothing. Chrome is excluded because it has nothing to restore: a tray row and a margin entry for the same Ask are keyed by that id and keep focus through a patch on their own. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
An install replaces the nodes a revision rewrote, and a widget goes whole because a controller owns its children once it is connected. Everything the reader had put into those nodes went with them: words half typed into a field, the caret in them, a box they had opened, how far they had scrolled inside one, and the focus that says where they are. None of it is in the event log, so no projection could put it back, and the loss arrived in the same breath as "Updated to Draft". What makes it recoverable is the authored id — the identity patchTree matches nodes on, that threads, the diff, `restated`, the tab store and the draft store already key on, and that a version check will not let a revision silently drop. carry.js reads that state off the standing document before the patch and replays it onto same-id elements the install replaced, and only those: a node the patch kept never lost any of this, and writing over it would undo whatever the reader has done since. The other install passes no held nodes, having kept nothing, so the same records ride its handoff and restore whole. Reader-changed state only, wherever the platform says what the author wrote, so a field the reader never touched shows the revision's new text. Where there is no such default the reader's state is the more recent of the two and wins. A select and a contenteditable are left alone, for reasons the module states. The rule this settles is in assets/CLAUDE.md: which of the four routes a fact takes is decided by what the fact is, not by where it was noticed, and a hold is for a gesture that is not a value — a hold postpones a loss rather than preventing it, since the words die when the reader blurs. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Four places read a caret off an element and wrote it onto another by hand: the response bar moved between parents, a conversation seat re-rendered and the same seat retained after a refused view, a thread reconciled, and a replaced document handed back. They are one act — the reader is put back on an element, and where they were inside it comes with them — so `focus.js` owns it, which already owned the other half, and `focusDestination` lands the caret it is given. Also states in the root invariants how long mechanical state lives: as long as the node holding it, recorded in no log and returned by no projection, so whatever replaces a node hands it across under the identity that replacement already keys on. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
leaf-agent
left a comment
There was a problem hiding this comment.
carry.js records <details> disclosure state for every id'd box it sees, not only ones the reader touched, so a revision that opens a box now arrives with it shut.
captureCarry writes record.open unconditionally, and restoreCarry writes it back onto the arriving node. Every other fact is gated on a reader gesture — value against defaultValue, checked against defaultChecked — but details.open has no such platform default, so the outgoing document's state crosses whether or not the reader put it there.
authoring-revisions.md ("Keep the current page current") tells authors to park context a later run still owes inside a collapsed <details>, so "open this box in the next revision" is an ordinary page edit. It now has no effect for any disclosure inside a widget the revision rewrote — and it still works for one outside, because the patch keeps that node and the carry skips it, which makes the outcome depend on whether the box happens to sit in a replaced subtree.
The module header already names the rule this breaks — "Reader-changed state only, wherever the platform says what the author wrote" — and treats details as a case where nothing says it. Something does: authoredSource is a detached clone of the current revision's main that no reader gesture reaches, so captureCarry(live, authoredSource) can record open only where the live node disagrees with its authored counterpart. That also buys carry the authored-id filter skills/leaf/assets/CLAUDE.md already claims for it ("carries nothing for an element the author left unnamed") — today it keys on any id under main, runtime-generated ones included.
Happy to push that if you'd like it; it changes captureCarry's signature and its two call sites in version.js.
Reproduction
Against this head, on the PR's own fixtures — reader never touches the disclosure, revision opens it:
def test_probe_revision_opening_a_disclosure_inside_a_replaced_widget(browser, serve):
opened = LIVE_KEYS_APPARATUS_REWRITTEN.replace(
'<details id="lk-why">', '<details id="lk-why" open>'
)
version_url = serve(LIVE_KEYS_APPARATUS)
page = open_page(browser, live_url(version_url))
assert page.locator("#lk-why").evaluate("el => el.open") is False
(serve.page_dir / "index.html").write_text(opened)
told(page)
page.wait_for_function("document.title === 'Live keys rewritten'")
assert page.locator("#lk-decision h2").inner_text().startswith("Which one, now")
assert page.locator("#lk-why").evaluate("el => el.open") is TrueAssertionError: assert False is True. Commenting out arrived.open = record.open in restoreCarry makes the same case pass, which is what pins the cause here rather than in the patch.
The five new cases in test_render_projection.py pass as written.
A disclosure has no `defaultOpen`, so the carry read the live box and wrote it over the arriving revision: a box the author opens in the next version arrived shut, wherever it sat inside a subtree the install replaced. The baseline is the authored `main` of the revision the reader is standing in — the same side `patchTree` diffs against, and for the reason that module's header gives: the live page differs from the author in everything anything has done to it since it loaded, so the page is never one side of the comparison. The same baseline says which ids are the author's, so state a module made for itself is left to that module to put back. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
This head is not gated — do not merge on the strength of the green checks.
What was and was not run on it:
The checks showing green on this PR are Work on this ground is paused across #801, #802 and #810 while the design converges, so this branch is parked rather than ready.
|
leaf-agent
left a comment
There was a problem hiding this comment.
holdsWords answers true for every <input>, so the failure the new <details> baseline just closed is still open on the other side of the same line: state the reader never put there crosses and overwrites what the arriving revision authored.
value is compared against defaultValue, which reflects the value content attribute. For a text field that is the author's own word, which is what makes the comparison work. For an <input type="checkbox"> the author wrote without one, the platform answers "on" against a defaultValue of ""; for <input type="range"> it answers the midpoint. Both read as reader state on a control nobody touched, and restoreCarry then writes them over the arriving node — so a checkbox also picks up a value attribute the author never wrote on it.
The inline suggestion narrows holdsWords to the types whose defaultValue is the author's word. focus.js already keeps exactly that list as TYPED_TYPES; exporting it rather than keeping a second copy is the better shape if you'd rather take it that way, and I'm happy to push either once the branch is moving again.
One thing the suggestion deliberately does not touch: reveal() in widget-elements.js opens a collapsed <details> on the way to a scroll target, so a box the runtime opened also disagrees with the author and carries as if the reader had opened it. That reads as the right outcome for a reader standing inside the box, but it is not what "only what the reader themselves changed crosses" says — worth a clause in the header either way.
Verdict is withheld on your own note that this branch is parked while #801, #802 and #810 converge, not on anything below.
Measured on 993e217
Both fixtures are the PR's own LIVE_KEYS_APPARATUS pair, with two unvalued controls added inside the widget the revision replaces whole. The reader touches neither; the next revision authors a value on each.
TICK = (
'<p><label for="lk-tick">Also</label>'
' <input id="lk-tick" name="lk-tick" type="checkbox">'
' <input id="lk-dial" name="lk-dial" type="range"></p>'
)
FIRST = LIVE_KEYS_APPARATUS.replace(
'<details id="lk-why">', TICK + '<details id="lk-why">'
)
SECOND = LIVE_KEYS_APPARATUS_REWRITTEN.replace(
'<details id="lk-why">',
TICK.replace('type="checkbox"', 'type="checkbox" value="yes"').replace(
'type="range"', 'type="range" value="80"'
)
+ '<details id="lk-why">',
)
def test_probe_untouched_inputs_take_the_arriving_revisions_values(browser, serve):
page = open_page(browser, live_url(serve(FIRST)))
assert page.locator("#lk-tick").evaluate("el => [el.value, el.defaultValue]") == [
"on",
"",
]
assert page.locator("#lk-dial").evaluate("el => [el.value, el.defaultValue]") == [
"50",
"",
]
(serve.page_dir / "index.html").write_text(SECOND)
told(page)
expect(page).to_have_title("Live keys rewritten")
expect(page.locator("#lk-decision h2")).to_have_text(
"Which one, now the costs are in?"
)
dial = page.locator("#lk-dial").evaluate("el => el.value")
tick = page.locator("#lk-tick").evaluate("el => el.value")
assert (tick, dial) == ("yes", "80")AssertionError: assert ('on', '50') == ('yes', '80') — both carried values won over the revision's. With the inline suggestion applied it passes, and tests/test_render_projection.py -k "apparatus or ask or carry or box or keys" stays at 15 passed. The whole file is green on this head as written: 150 passed.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`defaultValue` is the author's own word for a field whose value is words, and for nothing else in the input family: a tick the author gave no value answers "on", a range answers its midpoint, a colour answers black, each against a `defaultValue` the author left empty. Comparing the two carried every such control as though the reader had set it, over whatever the next revision authored — the disclosure's bug on the other side of the same line. `focus.js` already kept the list of controls whose value is words, inside `takesLetters`. It names it now, and the carry asks it rather than keeping a second copy. Also says what crosses more honestly: not what the reader changed, but what the author did not write, since `reveal` opens a collapsed box on the way to something inside it and that box is the reader's to keep standing in. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
leaf-agent
left a comment
There was a problem hiding this comment.
captureCarry already holds the answer this commit says cannot be had. wrote is the authored node for the id, so wrote.value is the author's own word for every input type, not just the ones whose value is words — read off the detached authored clone on this head, an unvalued range answers "50", one written value="80" answers "80", and a colour answers "#000000".
Narrowing to holdsWords closes the over-crossing by dropping those controls from the carry altogether, so the line now fails the other way: a range the reader dragged to 17 arrives back at 50 across a revision that never touched it. That is the reader's own state, lost in exactly the act the PR exists to prevent.
It also makes the claim the commit adds false where it is most load-bearing. skills/leaf/assets/CLAUDE.md now says the carry reads "so that what crosses is what the author did not write", and holdsWords's own comment says of the rest of the family that "neither question can be asked of them: not what the reader typed, and not what the author wrote". The second one is what wrote answers — the same baseline the <details> fix adopted two paragraphs above, for the same reason, in the same function.
The inline suggestions put the value comparison on that baseline. The type list then does no work in carry.js at all, and holdsWords stays focus.js's own for takesLetters; file is the single exclusion, because its value is a path the page may not write back. The header's "Only where the value is words, though" paragraph is what would need rewording to match.
Measured on f462244
The authored clone's answers, and the reader's own move across a revision — both probes added to tests/test_render_projection.py against the PR's own LIVE_KEYS_APPARATUS pair, with the slider inside the widget the revision replaces whole:
def test_probe_authored_clone_answers_for_range_and_colour(browser, serve):
markup = (
'<p><input id="lk-dial" name="lk-dial" type="range">'
' <input id="lk-dial2" name="lk-dial2" type="range" value="80">'
' <input id="lk-hue" name="lk-hue" type="color"></p>'
)
first = LIVE_KEYS_APPARATUS.replace(
'<details id="lk-why">', markup + '<details id="lk-why">'
)
page = open_page(browser, live_url(serve(first)))
assert page.evaluate(
"""() => {
const clone = document.querySelector('body > main').cloneNode(true);
return [
clone.querySelector('#lk-dial').value,
clone.querySelector('#lk-dial2').value,
clone.querySelector('#lk-hue').value,
];
}"""
) == ["50", "80", "#000000"]
def test_probe_reader_moved_range_crosses(browser, serve):
unvalued = (
'<p><label for="lk-dial">How much</label>'
' <input id="lk-dial" name="lk-dial" type="range"></p>'
)
first = LIVE_KEYS_APPARATUS.replace(
'<details id="lk-why">', unvalued + '<details id="lk-why">'
)
second = LIVE_KEYS_APPARATUS_REWRITTEN.replace(
'<details id="lk-why">', unvalued + '<details id="lk-why">'
)
page = open_page(browser, live_url(serve(first)))
page.locator("#lk-dial").evaluate(
"el => { el.value = '17'; el.dispatchEvent(new Event('input', {bubbles: true})); }"
)
(serve.page_dir / "index.html").write_text(second)
told(page)
expect(page).to_have_title("Live keys rewritten")
expect(page.locator("#lk-decision h2")).to_have_text(
"Which one, now the costs are in?"
)
assert page.locator("#lk-dial").evaluate("el => el.value") == "17"The first passes as written; the second fails AssertionError: assert '50' == '17'. With the three suggestions applied both pass, and uv run pytest tests/test_render_projection.py --run-nightly is 153 passed — the file's own 151 plus these two. Your new test_a_revision_gives_values_to_controls_the_reader_never_touched is among them: an untouched tick and dial still take the arriving revision's yes and 80, because live and authored agree on "on" and "50" and no record is made.
The carry compared a control's value with the platform's `defaultValue`, which is the author's word only where the value is words: a tick the author gave no value answers "on" and a range answers its midpoint, each against an empty default. The last commit kept those from crossing by carrying word-valued controls only, which dropped a range the reader dragged along with the untouched ones. The disclosure fix already had the right baseline in hand. `wrote`, the authored node for the same id, answers `value` and `checked` through the same platform the live node does, so an unvalued range reads its midpoint on both sides and nothing crosses, while one the reader moved reads differently and does. Every fact is now asked of that one node, the type list is gone, and a file input is the single exclusion because its value is a path the page cannot write back. `focus.js` goes back to how it was: `takesLetters` was only split for the carry. Two tests pin it from each side, each failing under one of the two rules it replaces: an untouched tick and range take the arriving revision's values, and a range the reader moved keeps its place. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
leaf-agent
left a comment
There was a problem hiding this comment.
The commit widens what crosses — a range, a date, a colour now carry where only words did — but the two places that draw the family's boundary still argue from the baseline it retired.
carry.js's header keeps <select> out because "its authored default is an attribute on one of its options rather than a property of the control". That was the defaultValue argument. Against the authored node it does not hold: reading value off a clone of main answers the author's selected option while the live control answers the reader's, exactly as it does for a range. All that is left of the exclusion is "no surface in Leaf today", which the same sentence already says — as written it tells the next reader there is an obstacle where there is none.
skills/leaf/assets/CLAUDE.md still names the carry's contents as "a field's words and caret". CLAUDE.md's Working on the repository asks that the implementation and its owning reference stay aligned, and that index entry is what a later reader consults before opening the module.
What the authored clone answers for a <select>
Headless Chromium, the harness's own build. The clone is main.cloneNode(true), which is what initialDocument.source is.
// <select id="s"><option value="a">A</option><option value="b" selected>B</option></select>
// the reader then selects "a"
{ live: "a", clone_taken_at_boot: "b", clone_taken_after_the_gesture: "b" }So wrote.value is the author's word for a <select> under either capture order, and node.value !== wrote.value would record the reader's selection and nothing else — the same reading the rest of the family now gets. Leaf ships no <select> outside carry.js's and version.js's own prose, so this is the sentence rather than the code.
…ed node The header kept `<select>` out because its authored default lives on an option rather than on the control, which was an argument against `defaultValue`. The authored node answers a select's `value` as it answers a range's, so that obstacle is gone; what is left is that `value` names only the first chosen option, which is not the whole of a `multiple` one. The runtime map named the carry's contents as a field's words, when any control's value now crosses. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
When a revision arrives while the reader is standing on an Ask, the install replaces the widget whole — a controller owns its children once it is connected — and everything the reader had put into those nodes goes with them. The page gave back none of it: not the Ask they were answering, not the words half typed into a field, the caret inside them, a box they had opened, or how far they had scrolled in one.
Three things, in order:
patchTreediffs against, so a box the reader opened is carried open while one they never touched is left to the arriving revision to open or shut. Every fact is asked of the authored node for the same id rather than of the platform's defaults, which answer for some controls and not others: an untouched tick or range of any kind is left to the arriving revision, and a range the reader dragged crosses.focus.jsowns it, which already owned the other half, andfocusDestinationlands the caret it is given.The root invariants now say how long mechanical state lives: as long as the node holding it, recorded in no log and returned by no projection, so whatever replaces a node hands it across under the identity that replacement already keys on.
🤖 Generated with Claude Code