Skip to content

Fix diff engine missing added properties and array element changes #93

@andypalmi

Description

@andypalmi

Summary

getItemDifferences in the compare diff engine has two bugs that cause it to silently miss changes:

  1. Object comparison only iterates keys from the old value — properties that were added in the new version are never compared and produce no change entries
  2. Array comparison only iterates the old array's length — if the new array has additional elements, they are ignored

This means nodes with newly added properties or longer arrays are detected as changed by generateDiff but produce zero change entries from getItemDifferences, making them invisible in the compare output despite being rendered on the SVG canvas.

Additional: allChanges option

A new allChanges render option was added to compare(). When true, position-changed nodes also get their full property diff instead of being short-circuited by otherChanges = false. This allows getting a complete set of change entries with highlight() functions for every changed node.

Fix

  • getItemDifferences (objects): iterate the union of both objects' keys instead of only Object.keys(value1)
  • getItemDifferences (arrays): use Math.max of both array lengths instead of value1.length
  • compare() / diffProcessor / getTabChanges: accept and forward allChanges option

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions