Skip to content

Keep a frame in a diff thread loaded through revisions in WebKit - #3852

Merged
max-sixty merged 3 commits into
mainfrom
grind/s-diff-rows
Oct 27, 2026
Merged

max-sixty merged 3 commits into
mainfrom
grind/s-diff-rows

Conversation

@max-sixty

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

Copy link
Copy Markdown
Owner

In WebKit, a frame in a diff line thread now keeps its document when the patch changes. Before this, every revision unloaded it: the iframe stayed connected but its contentWindow went to null. Chromium and Firefox were never affected.

#4014, "Stop moving live content between parents", blamed this on lf-diff moving thread outlets beside redrawn rows. That isn't what happens on current main. I watched the diff's shadow root with a MutationObserver through several kinds of revision: one that redraws the thread's own line, one that adds a line after it, and one that puts another file before it, each for a line thread and a file thread, from both an inline patch and a manifest. In every case the outlet kept its node identity and no childList record removed it. replaceFileContent already patches the existing .lf-diff-rows, and setChildren leaves the outlet in place. An outlet only moved when its datum disappeared (a line inserted above it shifted the numbers, or the file became metadata-only). There the thread has to leave its line anyway, so I didn't build the rows-stable refactor; it would change no behavior.

The frame was unloaded by show() calling this.replaceChildren() on the host every time it rendered, to drop the authored <pre> placeholder. I patched DOM methods to find the call after which contentWindow went null, and it was this one. In Playwright WebKit 26.6, replaceChildren() on a shadow host unloads every iframe in its shadow tree, even when the host has no children. textContent = "" does the same when it has some. Removing each child with remove() keeps the frames. Chromium 153 and Firefox 155 keep them in all three cases (minimal repro across the three engines, 2026-10-24). lf-diff now removes its light children one by one.

Changes:

  • packages/diff/widgets/lf-diff.js: the host's light DOM is cleared child by child instead of with replaceChildren().
  • tests/browser/widgets/test_diffs.py: new test_a_diff_revision_leaves_a_line_thread_where_it_stands, run in Chromium and WebKit. It sets up a line thread whose agent reply holds an iframe, then sends a revision that redraws that line and adds a file before it. It asserts that the outlet is the same node, the frame's window is the same, and no load event fired. With the fix reverted, WebKit fails it ([True, None, 0] != [True, True, 0]) and Chromium passes.
  • notes/browser-support.md: a known-gap entry for the WebKit behaviour.

Calls Max may reverse:

  • I didn't build the rows-stable refactor the item proposed (one .lf-diff-rows per file for its whole life, a details kept across rendering states), because the measurements found no outlet move for it to remove.
  • I didn't change the other replaceChildren() call sites. They run on hosts without a shadow root, or once at setup before anything stands in the stage. The source === null path in lf-diff clears the stage anyway.

Ran: the new test before and after the fix, tests/browser/widgets/test_diffs.py and tests/browser/test_render_diff_controls.py in full (52 passed), and the -k "diff or patch" selection of tests/browser/threads/test_seated_threads.py, tests/browser/test_render_anchors.py, tests/browser/projection/test_code_review.py and tests/browser/projection/test_revision_patches.py (73 passed).

Not verified: Safari itself (only Playwright's WebKit build), and selections across a revision in WebKit.

Part of #4014: lf-diff leaves its list of places that move live nodes, and three remain.

On landing, update #4014: "Four places" becomes three; drop the lf-diff clause.

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

Each revision of a diff unloaded any iframe in its line threads in WebKit:
the frame stayed connected with a null contentWindow. `show()` cleared the
host's light DOM with `this.replaceChildren()` on every rendering, and
WebKit's `replaceChildren()` on a shadow host unloads every frame in its
shadow tree, even with no child to remove. Removing each child with
`remove()` keeps them, as Chromium and Firefox do in every form.

The TODO blamed this on lf-diff moving outlets beside redrawn rows. A
MutationObserver over the diff's shadow root showed the outlet of a
surviving datum keeps its node and parent through a redrawn own line, an
added line and a file inserted before it; outlets move only when their
datum disappears. So lf-diff leaves that TODO item's list, and the
WebKit gap is recorded in notes/browser-support.md.

test_a_diff_revision_leaves_a_line_thread_where_it_stands runs in
Chromium and WebKit; WebKit fails it with the old clear.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
max-sixty and others added 2 commits October 25, 2026 12:27
Takes main's TODO.md, whose backlog moved to GitHub issues in #4090.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@max-sixty
max-sixty marked this pull request as ready for review October 27, 2026 05:15
@max-sixty
max-sixty merged commit 7a59831 into main Oct 27, 2026
5 checks passed
@max-sixty
max-sixty deleted the grind/s-diff-rows branch October 27, 2026 05:28
max-sixty added a commit that referenced this pull request Oct 27, 2026
Resolves lf-diff.js and notes/browser-support.md against #3852's squashed copy by
keeping this branch's side: shadowStage clears the host, so lf-diff's local
child-by-child clear goes. Rebuilds dist/kernel from main's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
max-sixty added a commit that referenced this pull request Oct 27, 2026
`shadowStage` now clears the host's light children itself, child by
child. Three widgets cleared their own host with `replaceChildren()`; in
WebKit that unloads every iframe in the host's shadow tree (#3852 fixed
only `lf-diff`). The `replaceChildren()` calls in `lf-diff.js`,
`lf-file-editor.js` and `lf-file-tree.js` are gone, along with #3852's
local workaround in `lf-diff`, so a widget has nothing to remember.
`notes/browser-support.md` now names `shadowStage` as the one place a
host is cleared. `dist/kernel` is rebuilt for `shadow-stage.js`.

Call (reversible): the clear is unconditional (option a). An `x-shadow`
widget slots none of its authored children, and sparing slotted ones
depended on a slot existing at stage time, which the documented
stage-a-container-then-render pattern breaks.
`skills/leaf/references/module-authoring.md` ("Shadow stages and
styles") now says the stage removes authored children, so a widget reads
them first. Every in-tree caller already does: the three widgets above,
the runtime's failure box for a staged widget (`widget-upgrade.js`), and
the feature gallery's `lf-conversation-workspace`, which authors no
children.

Tests: the two `passage-boundaries` tests that slot content now add it
after staging, and the first asserts the words exist so its
`doesNotMatch` is not vacuous.

Ran after merging main: `pnpm run check` (runtime 668 pass),
`tests/browser/widgets/test_diffs.py -k line_thread_where_it_stands`
(Chromium and WebKit), and the file-editor, file-tree and diff-revision
selections of `test_render_files.py`, `test_render_diff_controls.py` and
`test_diffs.py`. Not run: a WebKit test for `lf-file-editor` or
`lf-file-tree` frames.

> _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