Problem/Motivation

CKEditor 5 saves content as a single, minified HTML string without line breaks (as tracked in Core issues #3351660 and #3361617). Because we cannot rely on a Core-level database formatting fix anytime soon, we must handle this formatting within the Diff module to prevent two major regressions:

  • Split & Unified Fields: Because these use a line-by-line algorithm, feeding them a single line of HTML causes the engine to mark the entire field as one massive change. The diff becomes unreadable.
  • Visual Inline: The engine struggles to parse and group massive, unbroken HTML strings. This causes severe performance issues on large revisions and even false positives based on some reports.

Steps to reproduce

  1. Draft multiple paragraphs in a CKEditor field, preferably large samples
  2. Edit the content and modify the content, again preferably with large samples
  3. Compare the revisions and test the different comparison modes

Proposed resolution

Format the HTML and optimizes the engines:

  • Add a formatHtmlForDiff() helper that injects a \n after closing block-level tags.
  • Fix Visual Inline performance and accuracy by disabling setGroupDiffs. This forces the library to diff word-by-word instead of doing complex block grouping. Bypassing the grouping logic completely resolves the severe performance bottlenecks on large node revisions and eliminates the chunks of false highlights.
  • Disable Purifier (may need further review). Disabling setPurifierEnabled helps reduce processing time in large samples. Because Drupal's Renderer pipeline already guarantees XSS safety before the Diff module sees the HTML, running HTMLPurifier again inside the diff library is redundant..

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork diff-3627092

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

cballenar created an issue. See original summary.

cballenar’s picture

Status: Active » Needs review

MR 182 submitted with the proposed items as separate commits for easy review.

cballenar’s picture

I've pushed an amended commit that resolves the original HTML diff spacing issues, along with fixing the linting and static analysis complaints.

  • HTML Spacing Fixes: improved newline logic to prevent empty trailing lines.
  • Addressed SlevomatCodingStandard requirements by prefixing global PHP functions with a backslash and resolved the PHPStan complaints.

Note: the pipeline will likely show as failed due to out-of-scope Drupal 11 deprecations. I've left these out, but wanted to flag why the pipeline won't be fully green. The MR is otherwise ready for review!