Repository navigation
fix: register a widget's thread surface as it says lf-connect, so lf-diff keeps its comment controls on return - #7558
Conversation
Since #7542 the host sets `state` again on an element's return, so a LeafElement such as lf-diff runs a Lit update before the arrivals batch re-registers its thread surface. That update read no opener and took each file's Comment control and each line's comment gutter away, and the registration put them back a moment later: the write watch's `unchanged write` on `div.lf-diff-file-actions` and `div.lf-diff-line` that fails test_a_patch_resumes_preparation_on_return_and_keeps_its_finished_rows at teardown. The surface watch now offers a widget as it says `lf-connect`, which registers it before the host's sets for that connection, so the draw they start already reads its opener. A widget keeps its comment controls across a departure and return; nothing else a user sees changes. Closes #7555
leaf-agent
left a comment
There was a problem hiding this comment.
The new header says the surface is registered "before Leaf's sets for that connection", but those sets come first. surfaces.ts imports host/element-integration.js, whose module-level document.addEventListener(CONNECT, …) therefore runs before the listener watchThreadSurfaces adds at startup, and that listener calls host(element), which sets state during the same dispatch. The fix still works because the draw those sets start runs only after the event returns: Lit's update is a microtask, and defineWidget mounts after its dispatchEvent. The contract should state that ordering, since a later widget whose state setter draws synchronously would read the current wording as a promise it doesn't get. I'm pushing the rewording below.
…rface header The host's own lf-connect listener makes its sets first; the registration lands before the draw those sets start, which runs after the event returns.
Since #7542 the host sets
stateagain when an element returns to the page (returnedinhost/element-integration.ts), whichdefineWidgetneeds to mount again. On a LeafElement such aslf-diff, that set starts a Lit update before the arrivals batch re-registers the widget's thread surface. The update reads no opener, soreconcileEntryCommentsremoves each file's Comment control and turns each line's comment gutter back into a plain number; the registration then puts them back. The write watch reports that asunchanged write: children of div.lf-diff-file-actionsanddiv.lf-diff-line, which failstest_a_patch_resumes_preparation_on_return_and_keeps_its_finished_rows[inline]and[bound]at teardown.The thread-surface watch (
records/thread/surfaces.ts) now also offers a widget through its arrival watch as the widget sayslf-connect. The host's sets for the connection run in the same dispatch, but the draw they start runs only once the event returns (Lit's update is a microtask, anddefineWidgetmounts after its dispatch), so that draw already reads the opener. Thelf-connectoffer goes through the same arrival watch and departure still unregisters, so a move within one batch still keeps the registration. #7542 meant the return to setstateagain, and that set still happens. A user who tabbed to a file's Comment control no longer loses it when the diff leaves and comes back; nothing else on screen changes.I chose this over making
lf-diffignore a missing opener, since any widget that readsthreadSurface(owner).openin a draw started on return would hit the same gap. It adds one document listener to the thread-surface owner.Verification:
mainand pass on this branch (2 passed, 2 errors→2 passed).returned = truealone also made them pass, which confirms the trigger. Logging the order showed the return'sstateset, then an update with no opener, then the registration.pnpm run test:runtime(1244) passes, and so dotests/browser/startup/test_thread_surfaces.py,tests/browser/threads/test_seated_threads.py, and the comment, return and thread tests intest_render_diff_controls.pyandtest_leaf_element.py(80 in all).pnpm run check:browserpasses.Closes #7555 — automated triage