Skip to content

Diffing RenderedElem trees to produce VDomPatch#3104

Merged
sawka merged 3 commits intomainfrom
copilot/implement-diff-algorithm
Mar 22, 2026
Merged

Diffing RenderedElem trees to produce VDomPatch#3104
sawka merged 3 commits intomainfrom
copilot/implement-diff-algorithm

Conversation

Copy link
Contributor

Copilot AI commented Mar 22, 2026

Pull request created by AI Agent

Copilot AI and others added 3 commits March 22, 2026 18:19
}
continue
}
insertions[oldPtr] = append(insertions[oldPtr], newIdx)
Copy link
Contributor

Choose a reason for hiding this comment

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

CRITICAL: Consecutive insertions after a matched element are incorrectly assigned to the same position.

The oldPtr is not incremented after processing an unmatched element (insertion). When there are multiple consecutive unmatched elements in the new array after a matched element, they all get assigned to the same insertion position.

Example: old=["a", "b"], new=["a", "x", "y", "b"]

  • Expected: insert "x" at position 1, insert "y" at position 2
  • Actual: both "x" and "y" inserted at position 1

Fix: Add oldPtr++ after line 330:

insertions[oldPtr] = append(insertions[oldPtr], newIdx)
oldPtr++

@kilo-code-bot
Copy link
Contributor

kilo-code-bot bot commented Mar 22, 2026

Code Review Summary

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 1
WARNING 0
SUGGESTION 0
Issue Details (click to expand)

CRITICAL

File Line Issue
tsunami/rpctypes/diff.go 330 Consecutive insertions bug in computePhase1ArrayChanges - insertion positions incorrectly collapse to same index
Files Reviewed (2 files)
  • tsunami/rpctypes/diff.go - 1 issue
  • tsunami/rpctypes/diff_test.go - no issues

The PR implements a virtual DOM diffing algorithm for RenderedElem trees. The algorithm is well-structured with clear phase separation (phase 1 for insertions/deletions, phase 2 for updates/swaps). The bug found is a logical error in the insertion position calculation that would cause incorrect patches when multiple new elements are inserted between matched elements.


Reviewed by minimax-m2.5-20260211 · 448,028 tokens

@sawka sawka merged commit 4a28c4b into main Mar 22, 2026
6 checks passed
@sawka sawka deleted the copilot/implement-diff-algorithm branch March 22, 2026 20:51
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