Skip to content

Keep the user's place in every move, and drop the render wrapper, named-control hardening and unread exports - #2509

Merged
max-sixty merged 10 commits into
mainfrom
agent-a09212ab3feaa9079
Oct 12, 2026
Merged

max-sixty merged 10 commits into
mainfrom
agent-a09212ab3feaa9079

Conversation

@max-sixty

@max-sixty max-sixty commented Oct 12, 2026 •

Copy link
Copy Markdown
Owner

Every retained-node move now keeps the user standing in the moved node, in every browser, because the move primitive holds focus itself. That retires the focus-holding render wrapper, the partial protection against form controls named after DOM methods, and the widget-api exports no module reads.

Review item 21: two renders kept focus differently. In a browser without moveBefore (Safari, or Chrome with it disabled), a keyed reorder rendered with Lit's own render, which about 27 runtime modules use, left a focused editor's focus on body. Packages got a wrapper that held focus around the whole render instead.

  • move() in runtime/dom-move.js now holds the user's place across its insertBefore branch (holdFocus). It holds only for elements, since the text, comments and fragments Lit inserts for every new row can't contain focus.
  • Every mover goes through move(): patched Lit, Sortable, setChildren/orderChildren and lf-board. The response bar's seats (composing/surface.js, moveFab/seatFab) now do too. They used append plus a hold of their own, which blurred the editor even in Chrome; move() uses moveBefore there.
  • The wrapper is deleted and widget-api re-exports Lit's render. lf-board's and moveFab's own holds around moves go.
  • focus.js is a runtime primitive and imports no mover, so dom-move.js → focus.js adds no cycle. On served pages focus.js already loads before Lit.
  • holdFocus's "dropped place" reading now checks containment before it asks checkVisibility.
  • The three copies of this contract in module-authoring.md are now one statement, under "Template rendering".
  • Behavior change on the fallback path: a template's focus/focusin handlers now run between repeat's moves rather than after render returns. A detached node the user was dropped from, with no input since, takes them back when it is reinserted.

Review item 22: partial named-control hardening. A <form> control named insertBefore, getRootNode or moveBefore shadows that method. The prototype calls only covered chosen sites: firstChild and parentNode are shadowed too, and Lit's insertPart still called insertBefore directly. This removes the root-marker seam from build/browser/build.mjs and every Node.prototype.getRootNode.call site, and uses plain method calls. Inside such a form, moves and root readings now throw in every engine, move() included where moveBefore is shadowed. This is accepted rather than guarded: no page check refuses these names, because nobody has hit this and the partial guard could not make such a form work.

Review item 29: widget-api exported names no behavior module reads.

  • widget-api drops LitElement, svg, mathml, noChange, ifDefined, createRef and when. The facade drops svg, mathml, ifDefined and when, which nothing imports; build.test.mjs pins the new list.
  • test_every_widget_api_export_has_a_behavior_module_reader counted a name's mention in the export list as a reader, so the list kept every name alive. The list now sits on its own under ### Lit exports in module-authoring.md, and the test leaves that section out. Every export needs an importer or a reference that teaches it elsewhere. A control fails as it should: an unread mathml export, listed only under "Lit exports".
  • The Leaf helpers documented in prose stay as extension points for packages outside the tree (mountThreadViews, openLayer, clockValue, …). None of them is mentioned only in the list.
  • With LitElement gone, no widget can have an updateComplete. So widget-controller.js no longer reads it, and test_render_projection.py drops the "async" mode that faked one. Two test widgets that extended LitElement are now HTMLElement widgets painting with render.

Hand-written source lines, excluding tests, vendored bundles and Markdown (git diff main --numstat):

Review item Files Added Removed
21 dom-children.js, widget-upgrade.js, lf-board.js, composing/surface.js 8 21
21 and 22 dom-move.js (the hold, plain calls), focus.js (heldIn, plain calls) 32 26
22 build.mjs, passages.js, shadow.js, shadow-tree.js, arrivals.js 15 31
29 widget-api.js, index.ts, widget-controller.js 4 16
Total 59 94

Tests: 67 added, 134 removed. test_retained_moves_keep_native_editor_and_frame_state drops the named inputs and the caller's own focus holds. It uses Lit's render, and makes the cross-parent move in both modes. Against main's runtime its two fallback cases fail ("Locator expected to be focused"); on this branch all four pass. test_named_form_controls_leave_shadow_scroll_and_standing_readings_available tested the removed hardening, so it is deleted. Lit now loads focus.js through dom-move.js, so the focus paint's mutation observer also queues work in arrivals.test.mjs's process, as it does on every page. The departure test there now counts only its own frame's job.

Checks run:

  • the retained-move test;
  • tests/runtime/dom-children.test.mjs and lit-refs.test.mjs;
  • the interact-layer export test;
  • the 21 application-boundary tests and the export test that load the rewritten widgets;
  • the projection test's two remaining modes;
  • the response bar's shadow seating, diff-outlet and floating-face tests;
  • node build/browser/build.mjs --check and build/browser/build.test.mjs;
  • pre-commit on the changed files.

The widget-list-keeps-focus eval was not rescored: the reference still requires holdFocus for hiding and replacement, and only the move case changed.

This was written by Claude Code on behalf of max-sixty

max-sixty and others added 10 commits October 11, 2026 22:25
…, unread exports

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ateComplete)

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts:
#	skills/leaf/assets/runtime/composing/surface.js
Lit now loads focus.js through dom-move.js, so the focus paint's mutation observer queues work in this test's process, as it does on every page.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new direct DOM calls break accepted pages containing form controls named after DOM methods. In Chromium, <form><input name="moveBefore"></form> makes form.moveBefore a truthy input element, so move() calls it and throws; getRootNode and insertBefore are shadowed the same way. The direct getRootNode() calls added in focus.js, arrivals.js, and passage reading also fail on such forms. The former coverage for these names is deleted, while page check still accepts them. This needs one consistent contract: preserve method access across the affected readers and movers, or reject the conflicting names at the authored-markup boundary.

@max-sixty
max-sixty merged commit 5a36c24 into main Oct 12, 2026
3 checks passed
@max-sixty
max-sixty deleted the agent-a09212ab3feaa9079 branch October 12, 2026 06:38
max-sixty added a commit that referenced this pull request Oct 12, 2026
…h a native move (#2545)

Review item 52 of the Lit follow-up round: a lint rule now refuses
re-parenting a placed node with a plain insertion, every site it finds
goes through `move()`, and a focused comment box keeps its caret through
a native move, which it lost in Chrome on `main`.

**The rule (`architecture/moves`, eslint.config.mjs)**
- `insertBefore` and `moveBefore` are refused outside `dom-move.js`,
unless the node is made in the same expression (`createElement`,
`cloneNode`, ...).
- `append`, `prepend`, `before`, `after`, `appendChild`,
`replaceChildren` and `replaceWith` are refused only where a condition
around the call asks where the node stands: its parent or a sibling, or
whether something contains it. The variants, measured on `main` over the
runtime and packages:

| Variant for the append family | Sites flagged | Real re-parents |
| --- | --- | --- |
| every call with a non-literal argument | 282 | mostly new nodes |
| minus nodes made in the expression, a local binding, or `el`/`offer` |
159 | mostly new nodes |
| a `holdFocus` in the same function | 9 | 4 |
| a condition reads where the node stands (chosen) | 12 | 11 |

The 12th, in `lf-trace`, appended its fresh replacement under the old
name and now names it.
- The rule sits beside `architecture/placements` and has a row in
`skills/leaf/assets/AGENTS.md`'s owner table.
`tests/runtime/moves-rule.test.mjs` pins what it refuses and admits.

**What the rule found, fixed through `move()` or `setChildren`**
- 20 `insertBefore` sites and 11 guarded appends across the runtime, the
annotation overlay and the default widgets.
- The key chip's seat and a failed diff file's body use `setChildren`.
The diff's `replaceChildren` re-inserted the file's summary, which
blurred it if focused.
- Moves that held focus themselves now call `move()`: the margin rows'
lane, carrier and motion-layer moves (`moveHolding`, `moveHost` and the
rows' `move` option are deleted), the inline contributions' host, and
the floating composer's motion frames.

**Behaviour change: a focused `leaf-text` kept focus but lost its caret
on a native move.** `moveBefore` collapses the selection inside the
field's closed shadow tree, and CodeMirror read it back a few frames
later as a caret at the start, so the next keystroke landed there. The
field's reparent hold restored the caret on the first `selectionchange`,
which came before CodeMirror's read. `leaf-text` now defines
`connectedMoveCallback`, so a native move is no disconnection, and puts
its recorded selection back as it lands
(`LeafEditorView.placeSelection`, split out of `focus()`). The hold and
the test that called `connectedCallback` directly are deleted.

**Response-bar test.**
`test_the_comment_box_keeps_the_user_typing_as_it_takes_its_seat_again`
folds and reopens a diff file while the user writes a line comment, so
the bar is re-seated in the line's outlet, then types. With `moveBefore`
it fails on `main` (the words land at the start, 3 of 3 runs) and with
the pre-#2509 `append` seat (the editor blurs). Without `moveBefore`,
the hold path keeps focus and caret.

| Lines (`git diff --numstat`) | Added | Removed |
| --- | --- | --- |
| Hand-written source, excluding tests, vendored bundles and Markdown |
223 | 154 |
| of which the lint rule | 125 | 0 |
| Tests | 117 | 34 |

Checks run: eslint over the runtime and packages, pre-commit on the
changed files, `pnpm run test:runtime`, and the focused browser tests
for the response bar, retained moves, diff outlets and seating, code
copy, the margin's lane and focus cases, floating composers and the
touched widgets.

> _This was written by Claude Code on behalf of max-sixty_

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants