Skip to content

applyChange() possibly modifies change object #142

Closed
@soulmerge

Description

@soulmerge

The current implementation of applyChange() copies a reference to the change object's rhs property in line 379. Any changes to the target object also changes the change object afterwards. Example:

const target = {};
const change1 = { kind: "N": path: ["foo"], rhs: {} };
const change2 = { kind: "N": path: ["foo", "bar"], rhs: "bug" };
applyChange(target, true, change1);
applyChange(target, true, change2);
console.log(change1.rhs.bar) // prints "bug"

I am currently working around this issue by deep-cloning my change objects before applying them.

I would issue a pull request using clone-deep, but I'm not sure if that is in the best interest of this library, as it has no dependencies at the moment.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions