Repository navigation
Give focus back to a keyed control in a widget's shadow root after a revision - #6785
Merged
Merged
Conversation
… what a revision keeps under lfPatch A package written from the shipped references alone (`lf-ranking`, a list whose `lf-rank-item` members the user reorders, each item drawing its grip in a declared shadow root) reported that every revision replaced its list and items though its class declared `lfPatch`, that the kept widget then showed the authored order, and that focus came back to an item's host rather than its grip. Run against `main`, each has its own cause. **Focus (a defect, fixed).** `carry.js` read the focused control and its owner in the page's own tree, where a control in a shadow root is its host. So a `data-lf-carry` key on a control in a declared shadow root carried nothing, and focus went back to the host. Capture now reads the focused control in whichever tree holds it and finds its owner through the shadow root (`closestAcross`), and restore looks for the key in the owner's shadow root as well as its own tree. A control in the widget's own tree carries as before. The bundled board gave its grips no key, so a revision that reworded one card dropped a user on another card's grip to `body`. Each grip now carries `data-lf-carry="grip"`. **What `lfPatch` keeps (the reference was wrong).** `module-authoring.md`, "Revisions", said Leaf "edits inside those children in place". It patches the widget's markup as it patches the page's, which has three limits the reference left out, each confirmed on the trial package: - a widget inside, with a module of its own, is still replaced when its markup changes unless its class declares `lfPatch` too; - an element that has lost a node its author wrote is kept or replaced whole (`atomic` in `dom-children.js`), and `setChildren` removes the whitespace between the members it orders, which is what replaced the trial's list and every item on each reword; - the patch puts each element's children back in the revision's order and doesn't redraw the kept widget, so a module that orders its members showed the authored order after any revision, one that changed only the page's heading included. The section now says so, says a module that moves its members declares nothing, as the board does, and names the `MutationObserver` that "reads them again" meant. "Retained nodes" says `setChildren` removes every other child. `package-data.md` says a position record's container is an element inside the widget, never the widget: both runtimes read it that way (`initialState` in `projection/authored.js`, `recorded_owner` in `projection.py`) and `package check` passes a `within` naming the widget's own tag, whose state then holds no container. A reader given only the two references and the trial's design chose not to declare `lfPatch` and predicted which nodes each choice keeps. Tests: a new `test_a_replaced_widget_gives_focus_back_to_the_grip_its_module_drew` (the shadow arm waited out its timeout before the fix, and the board's grip read `body`); the revision-patch, draft-revision, pane, reading position, board and activity tests that cross a revision with focus held; the render gate on `triage-board`; `pnpm run check`. > _This was written by Claude Code on behalf of max-sixty_
#6777 holds every reference correction from the package-author trials, and two of the files this branch edited sit at the size the skill's test allows there. The edits go onto that branch, and this one keeps the runtime fix and its test.
leaf-agent
approved these changes
Nov 22, 2026
max-sixty
added a commit
that referenced
this pull request
Nov 23, 2026
Agents that wrote packages from the shipped references alone were left stuck or guessing in places where the references were silent, wrong or pointed nowhere. This corrects those places, from two rounds: six faults that two earlier trials found, and the documentation gaps from a trial in which six agents each wrote a different kind of package (a widget that asks, one bound to data, a reordered list, a drawing with parts, a theme, a widget that also runs off Leaf). What an author now finds: the shape of a target's `placement`, of `consumeAnnotations`' entries and items, and of the `placePageThreads` handle (`module-annotations.md`); `keeps-first-box` and how to reserve a first box, what `verbatim` says, how `--package` reads a path, and where the install keeps the files these references link to (`packages.md`); that a `value` record's attribute is a string, which keywords a verb's `detail` takes, what a position record's container is and what page state gives for it, and that a stamp records a `restated` retraction (`package-data.md`); where the user undoes, when a widget calls `defer()`, and what `this.state` does off Leaf (`module-state.md`); what a revision keeps in a widget that declares `lfPatch`, which the text overstated (`module-authoring.md`, "Revisions"); and how to try a theme while writing it and see its dark scheme (`package-themes.md`). Three statements in #6161's wording, which first carried four of these corrections, are false on `main` and are left out: that every thread with a place arrives as a target, that `update()` can be awaited, and that `reveal` is a callback passed at registration. To stay under the 30,000 characters the skill's size test allows a file, the last commit moves the `views` helpers from `module-authoring.md` to `module-state.md` word for word and cuts ten sentences that repeated a neighbour or described a helper's internals; its message quotes each. `module-input.md` is seven characters under. Three sentences follow fixes to Leaf's own code that have merged: a keyed control in a shadow root belongs to its widget (#6785), `themes.toml` may name `reading` as its default, and `m` leaves a question's premise out only where the premise stands outside the widget (both #6781). Other faults the trial found in Leaf's code are not fixed here. Max hasn't read this. A subagent wrote it and confirmed most added statements by running them with `leaf-dev probe` or the command concerned, and its commit messages say which it only read; a fresh agent then answered seventeen author questions from the skill alone, sixteen from the text. I read both diffs. Tests: the reference tests in `tests/model/test_interact_layer.py`, `tests/model/test_theme_tokens.py`, `tests/runtime/widget-api.test.mjs`, and pre-commit. > _This was written by Claude Code on behalf of max-sixty_
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A revision that replaces a widget gives focus back to a control the widget's module keyed with
data-lf-carry, but not when the module draws that control into the widget's shadow root: focus landed on the widget's host, or onbody. An agent writing a reordered list from the references hit this with a grip in each item's shadow root.captureCarryread the focused element in the page's own tree, which for a shadow control is the host, andrestoreCarrysearched only the owner's light tree. Capture now reads the focused control in whichever tree holds it and finds its owner out through the shadow root, and restore also looks in the owner's shadow root. The board's grips gaindata-lf-carry="grip": with focus on one card's grip, a revision that reworded another card dropped focus tobody.The same investigation found that the references promised more in-place patching under
lfPatchthan the runtime does; that correction is in #6777, and the runtime is unchanged there.Max hasn't read this. A subagent wrote it after reproducing ten cases of the ranking widget through revisions; I read the diff. Tests:
test_a_replaced_widget_gives_focus_back_to_the_grip_its_module_drew, whose shadow arm fails onmain; sixteen browser tests by node id that hold focus across a revision;pnpm run check.