Skip to content

Replace custom LCS word-diff with @sanity/diff-match-patch#101

Merged
tomasz-tomczyk merged 1 commit intomainfrom
migrate-to-sanity-diff-match-patch
Apr 25, 2026
Merged

Replace custom LCS word-diff with @sanity/diff-match-patch#101
tomasz-tomczyk merged 1 commit intomainfrom
migrate-to-sanity-diff-match-patch

Conversation

@tomasz-tomczyk
Copy link
Copy Markdown
Owner

Summary

  • Replaces the custom tokenize + computeTokenLCS (O(m×n) DP) word-diff implementation with @sanity/diff-match-patch
  • Uses makeDiff + cleanupSemantic for word-boundary-aligned highlights
  • ESM import — works directly with Phoenix's esbuild pipeline
  • applyWordDiffToHtml and all guard clauses unchanged — return type { oldRanges, newRanges } preserved

Why: Google's diff-match-patch is archived. @sanity/diff-match-patch is a maintained TypeScript rewrite (~492K weekly npm downloads) that merges bugfixes Google never accepted.

Companion PR: tomasz-tomczyk/crit#347 (pending)

Test plan

  • CI passes (mix compile, mix test, esbuild bundle)
  • Visual check: word-level highlights in shared reviews render correctly

🤖 Generated with Claude Code

The custom tokenize+computeTokenLCS implementation used O(m*n) dynamic
programming on word tokens. Replace it with @sanity/diff-match-patch's
diff algorithm + semantic cleanup, which produces better word-boundary
highlights with less code. The return type ({ oldRanges, newRanges })
and all guard clauses are preserved.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@tomasz-tomczyk tomasz-tomczyk merged commit 725f38c into main Apr 25, 2026
2 checks passed
@tomasz-tomczyk tomasz-tomczyk deleted the migrate-to-sanity-diff-match-patch branch April 25, 2026 19:42
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.

1 participant