Skip to content

feat: render lf-diff through @pierre/diffs 1.7.1 - #7432

Merged
leaf-agent merged 1 commit into
mainfrom
fix/issue-7430
Nov 27, 2026
Merged

leaf-agent merged 1 commit into
mainfrom
fix/issue-7430

Conversation

@leaf-agent

Copy link
Copy Markdown
Collaborator

@pierre/diffs 1.7 removed the unifiedContentAST that lf-diff rendered from. Its renderer now returns row specs (columns.unified). lf-diff renders each row spec's content element instead, and gets the same rows 1.6.1 produced. A static render of a patch with changed words, a hunk separator and no-newline markers gives identical HTML on both versions except for two things. First, 1.7.1 still emits the icon sprite, which lf-diff already removes. Second, deletion, separator and no-newline rows now carry contenteditable="false", which Pierre's editor uses.

With 1.7.1 and the old lf-diff, every diff failed with Cannot read properties of undefined (reading 'type'). With this change, test_a_diff_marks_changed_words_only_where_the_line_mostly_stayed, test_a_diff_shows_native_file_metadata_without_empty_disclosures, test_the_widget_reads_the_diff_patch_table and the rest of the diff tests in test_render_anchors.py pass. So do the diff export and lazy-loading tests, a selection of test_render_diff_controls.py, and pnpm run check.

The other API changes:

  • Parse options. parsePatchFiles now takes { throwOnError: true } instead of positional arguments. ParseDiffOptions now lists @pierre/patches' keys, which have no comparator. Pierre still passes options through to jsdiff, so the file-type replacement now names preferredDiffLib: "jsdiff" and types its options as Pierre's plus jsdiff's. The existing comparator augmentation in browser/types/native-modules.d.ts covers jsdiff's type.
  • Build seam. The changed-word distance adaptation in build/vendor.mjs moves to utils/computeLineDiffRanges.js and returns NO_RANGES.
  • Deck swipe. lf-deck's touch-swipe guard ignored a press on any [contenteditable] element, so a swipe begun on a diff's deletion row inside a card would no longer move the card. The guard now skips only editable content ([contenteditable]:not([contenteditable=false])), which is how control-selectors.js already treats it. test_a_swipe_begun_on_read_only_text_moves_the_card fails without the change and passes with it.

Bytes: the renderer bundle, which loads only once a diff draws its rows, grows from 823 KB to 1071 KB. Most of that is @pierre/highlights' inlined WASM, which grows from 244 KB to 405 KB of base64 between 0.2.0 and 0.5.2. The parser grows from 22 KB to 37 KB, since it now bundles @pierre/patches even though Leaf parses with jsdiff.

Something this change doesn't do: 1.7 adds disableLineMatching, which "preserves the patch's change blocks and line order without similarity realignment". That may let joinChangeRuns go. It needs its own check against the rewrite case that function's comment describes.

Closes #7430 — automated triage

@pierre/diffs 1.7 replaced the renderer's unifiedContentAST with row specs
(columns.unified). lf-diff now renders each row spec's content element, which
produces the same row markup as 1.6.1's content AST. Pierre also adds
contenteditable="false" to deletion, separator and no-newline rows.

- parsePatchFiles takes { throwOnError } in place of positional arguments.
- The file-type replacement names jsdiff explicitly and types its comparator
  as jsdiff's option, since ParseDiffOptions now lists @pierre/patches' keys.
- The changed-word distance seam moves to utils/computeLineDiffRanges.js and
  returns NO_RANGES.
- lf-deck's touch-swipe guard skipped any [contenteditable] target, so a
  swipe begun on a diff row in a card stopped moving the card. It now skips
  only editable content, as Leaf's control selectors already do.

Behaviour change: none intended on screen. The renderer bundle grows from
823 KB to 1071 KB, mostly @pierre/highlights' WASM (0.2.0 -> 0.5.2), and the
parser from 22 KB to 37 KB, which now carries @pierre/patches.

Closes #7430
@leaf-agent
leaf-agent merged commit fbdac63 into main Nov 27, 2026
8 checks passed
@leaf-agent
leaf-agent deleted the fix/issue-7430 branch November 27, 2026 20:07
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.

Port lf-diff to the @pierre/diffs 1.7 renderer API

1 participant