Skip to content

fix: register a widget's thread surface as it says lf-connect, so lf-diff keeps its comment controls on return - #7558

Merged
max-sixty merged 2 commits into
mainfrom
fix/issue-7555
Nov 28, 2026
Merged

max-sixty merged 2 commits into
mainfrom
fix/issue-7555

Conversation

@leaf-agent

@leaf-agent leaf-agent commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Since #7542 the host sets state again when an element returns to the page (returned in host/element-integration.ts), which defineWidget needs to mount again. On a LeafElement such as lf-diff, that set starts a Lit update before the arrivals batch re-registers the widget's thread surface. The update reads no opener, so reconcileEntryComments removes 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 as unchanged write: children of div.lf-diff-file-actions and div.lf-diff-line, which fails test_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 says lf-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, and defineWidget mounts after its dispatch), so that draw already reads the opener. The lf-connect offer 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 set state again, 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-diff ignore a missing opener, since any widget that reads threadSurface(owner).open in a draw started on return would hit the same gap. It adds one document listener to the thread-surface owner.

Verification:

  • Both parametrizations error on main and pass on this branch (2 passed, 2 errors → 2 passed).
  • Reverting returned = true alone also made them pass, which confirms the trigger. Logging the order showed the return's state set, then an update with no opener, then the registration.
  • pnpm run test:runtime (1244) passes, and so do tests/browser/startup/test_thread_surfaces.py, tests/browser/threads/test_seated_threads.py, and the comment, return and thread tests in test_render_diff_controls.py and test_leaf_element.py (80 in all).
  • pnpm run check:browser passes.

Closes #7555 — automated triage

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 leaf-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.
@max-sixty
max-sixty merged commit 741d533 into main Nov 28, 2026
8 checks passed
@max-sixty
max-sixty deleted the fix/issue-7555 branch November 28, 2026 22:14
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.

test_a_patch_resumes_preparation_on_return_and_keeps_its_finished_rows: lf-diff redraws unchanged rows at teardown since #7542

2 participants