Skip to content

updateUploadHistory throws an error when undos is empty #4803

@devnaumov

Description

@devnaumov

Description

There is the media placeholder example in the: docs. Inside media-placeholder-node component, there’s a call to updateUploadHistory.
In this function, we try to find an index by iterating over editor.history.undos. If undos is empty, or if we can’t find the item with batch.operations.some, index will be -1.
Currently, the code does:

const batch = editor.history.undos[index];
for (const operation of batch.operations) { ... }

When index is -1, batch is undefined, and for (const operation of batch.operations) throws an error.

I think we should check that index is not -1 before proceeding.

Also, can someone clarify the purpose of this function?

Reproduction URL

No response

Reproduction steps

1. Try to insert image
2. Error appears

Plate version

52.0.1

Slate React version

52.0.1

Screenshots

Logs

TypeError: Cannot read properties of undefined (reading 'operations')

Browsers

Chrome

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions