Skip to content

Bug: triggering an update from an mutation/update listener can lead to Yjs document corruption #7709

@james-atticus

Description

@james-atticus

Lexical version: 0.33.1

Steps To Reproduce

  1. Register a mutation/update listener which triggers another editor update.
  2. Register a mutation listener which calls editor.read()
  3. Do an action which triggers the first mutation/update listener.

Example failing test: 635cb9665

The current behavior

The read() from the second mutation listener calls $commitPendingUpdates which triggers update listeners. However, update listeners from the first update may not have not yet been called. This can lead to corruption of the Yjs document.

Image

The expected behavior

Update listeners are called in-order and Yjs is not corrupted.

Impact of fix

For Yjs specifically, these updates being called out of order can lead to data loss or complete failure to load the document (Expected shared type to include type attribute).

Acknowledge that triggering an update from an update listener is an anti-pattern, but reporting this anyway given the impact.

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