Skip to content

Feature: registerMutationListener should be called with pre-existing DOM #6356

@etrepum

Description

@etrepum

Description

See also #6349 (comment)

Typically when registerMutationListener is called, code is not written to check for any initial state. However, it's possible and sometimes desirable to do this lazily (e.g. lazy initialization of plug-ins, plug-ins registered after the initial state is rendered, etc.). Other listener features have this type of support, e.g. registerNodeTransform marks all nodes as dirty, registerRootListener immediately calls its listener, etc.

The rare case when you may not want this to happen can be handled with an additional option. One such case might be the TableOfContentsPlugin, which already handles lazy initialization correctly and has an efficient implementation. I haven't done any benchmarking on the pair of HeadingNode and TextNode mutation listeners that implement the continuous updates, but it's clearly much worse than a single traversal of the root's children.

Impact

It will be easier to correctly implement mutation listeners correctly. You can be certain that every lexical node in the DOM has a corresponding 'created' either when the mutation listener was registered, or when it was initially reconciled.

For performance sensitive use cases where this is not desired, a skipInitialization option will be available.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementImprovement over existing feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions