8000 diffApply array bug · Issue #590 · angus-c/just · GitHub
[go: up one dir, main page]

Skip to content

diffApply array bug #590

Open
Open

Description

@letzabelin

There is a bug in diffApply function from just-diff-apply package

import { diff } from 'just-diff'
import { diffApply } from 'just-diff-apply'

const source = { a: [ 1, 2, 3, 4, 5 ] }

const newSource = { a: [ 1, 2, 5 ] }

const changes = diff(source, newSource) // [{ op: 'remove', path: ['a', 4] }, { op: 'remove', path: ['a', 3] }, { op: 'replace', path: ['a', 2], value: 5 }]

console.log(changes)

// Expected value is newSource, but got only the array [1, 2, 5]
const appliedChanges = diffApply(source, changes) // [1, 2, 5]

console.log(appliedChanges)

If I replace return subObject in diffApply function with return obj I will get correct result

Activity

  1. alvindev111 commented on Oct 16, 2026

    @alvindev111

    Confirmed on current master at d8c5dd18941062d8db7e9310ecc8f53fd607df54 (checked 2026-10-17): the current implementation still returns subObject.

    git clone --depth 1 --branch master https://github.com/angus-c/just.git
    cd just
    test "$(git rev-parse HEAD)" = d8c5dd18941062d8db7e9310ecc8f53fd607df54
    node <<'NODE'
    const {diff} = require('./packages/collection-diff/index.cjs');
    const {diffApply} = require('./packages/collection-diff-apply/index.cjs');
    const source = {a: [1, 2, 3, 4, 5]};
    const expected = {a: [1, 2, 5]};
    const returned = diffApply(source, diff(source, expected));
    console.log({returned, source, returnedIsSource: returned === source});
    NODE

    Expected: returned is the patched root {a: [1, 2, 5]} and returnedIsSource is true.

    Actual: source is patched, but returned is [1, 2, 5] and returnedIsSource is false. The path walk changes subObject to the nested array, so the final return subObject returns that container; returning obj would preserve the root result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0