-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Feature: registerMutationListener should be called with pre-existing DOM #6356
Description
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.