Repository navigation
Keep the user's place in every move, and drop the render wrapper, named-control hardening and unread exports - #2509
Merged
Merged
Conversation
…, 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
reviewed
Oct 12, 2026
leaf-agent
left a comment
Collaborator
There was a problem hiding this comment.
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
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]>
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.
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
renderwrapper, 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 withoutmoveBefore(Safari, or Chrome with it disabled), a keyed reorder rendered with Lit's ownrender, which about 27 runtime modules use, left a focused editor's focus onbody. Packages got a wrapper that held focus around the whole render instead.move()inruntime/dom-move.jsnow holds the user's place across itsinsertBeforebranch (holdFocus). It holds only for elements, since the text, comments and fragments Lit inserts for every new row can't contain focus.move(): patched Lit, Sortable,setChildren/orderChildrenandlf-board. The response bar's seats (composing/surface.js,moveFab/seatFab) now do too. They usedappendplus a hold of their own, which blurred the editor even in Chrome;move()usesmoveBeforethere.render.lf-board's andmoveFab's own holds around moves go.focus.jsis a runtime primitive and imports no mover, sodom-move.js → focus.jsadds no cycle. On served pagesfocus.jsalready loads before Lit.holdFocus's "dropped place" reading now checks containment before it askscheckVisibility.module-authoring.mdare now one statement, under "Template rendering".focus/focusinhandlers now run betweenrepeat's moves rather than afterrenderreturns. 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 namedinsertBefore,getRootNodeormoveBeforeshadows that method. The prototype calls only covered chosen sites:firstChildandparentNodeare shadowed too, and Lit'sinsertPartstill calledinsertBeforedirectly. This removes the root-marker seam frombuild/browser/build.mjsand everyNode.prototype.getRootNode.callsite, and uses plain method calls. Inside such a form, moves and root readings now throw in every engine,move()included wheremoveBeforeis 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.
LitElement,svg,mathml,noChange,ifDefined,createRefandwhen. The facade dropssvg,mathml,ifDefinedandwhen, which nothing imports;build.test.mjspins the new list.test_every_widget_api_export_has_a_behavior_module_readercounted 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 exportsinmodule-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 unreadmathmlexport, listed only under "Lit exports".mountThreadViews,openLayer,clockValue, …). None of them is mentioned only in the list.LitElementgone, no widget can have anupdateComplete. Sowidget-controller.jsno longer reads it, andtest_render_projection.pydrops the "async" mode that faked one. Two test widgets that extendedLitElementare nowHTMLElementwidgets painting withrender.Hand-written source lines, excluding tests, vendored bundles and Markdown (
git diff main --numstat):dom-children.js,widget-upgrade.js,lf-board.js,composing/surface.jsdom-move.js(the hold, plain calls),focus.js(heldIn, plain calls)build.mjs,passages.js,shadow.js,shadow-tree.js,arrivals.jswidget-api.js,index.ts,widget-controller.jsTests: 67 added, 134 removed.
test_retained_moves_keep_native_editor_and_frame_statedrops the named inputs and the caller's own focus holds. It uses Lit'srender, and makes the cross-parent move in both modes. Againstmain'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_availabletested the removed hardening, so it is deleted. Lit now loadsfocus.jsthroughdom-move.js, so the focus paint's mutation observer also queues work inarrivals.test.mjs's process, as it does on every page. The departure test there now counts only its own frame's job.Checks run:
tests/runtime/dom-children.test.mjsandlit-refs.test.mjs;node build/browser/build.mjs --checkandbuild/browser/build.test.mjs;The
widget-list-keeps-focuseval was not rescored: the reference still requiresholdFocusfor hiding and replacement, and only the move case changed.