Skip to content

Calling destroy() on a nested editor leads to dangling objects in its parent and makes core editor unusable #1693

@hatelamers

Description

@hatelamers

Given a construct like this

const editor = new JSONEditor(element, {
    schema: {
        type: "object",
        properties: {
            field1: {
                type: "string"
            },
            field2: {
                type: "string"
            }
        }
    },
    startval: {
        field1: "value 1",
        field2: "value 2"
    }
});

const button = document.createElement("button");
button.type = "button";
button.textContent = "Delete field2";
button.onclick = () => {
    const fieldEditor = editor.getEditor("root.field2");
    fieldEditor.destroy();
};
const div = document.createElement("div");
div.appendChild(div);
document.body.appendChild(div);

After click on "Delete field2" the field editor is removed from the GUI and the core editor, however the parent editor still has "fieled2" in its editors list, this causes exceptions upon any subsequent action (like modifying the remaining field f.i.).

Applicable workaround is deleting child editor manually from its parent like this

button.onclick = () => {
    const fieldEditor = editor.getEditor("root.field2");
    delete fieldEditor.parent.editors[fieldEditor.key];
    fieldEditor.destroy();
};

Such clean-up should be responsiblity of AbstractEditor.destroy.

Metadata

Metadata

Assignees

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