ProseMirror / prosemirror

The ProseMirror WYSIWYM editor
http://prosemirror.net/
MIT License
7.61k stars 336 forks source link

Attribute change on parent node always recreates child NodeView instances #1366

Closed jhnsnc closed 1 year ago

jhnsnc commented 1 year ago

Simple attribute changes (either via setNodeAttribute or setNodeMarkup) on any node destroys/recreates all child nodeView instances. The NodeView is not destroyed if the setNodeAttribute is called for the node itself.

This is unexpected because in most (or perhaps all?) cases, a simple attribute change on the parent is irrelevant to the rendering of its contentDOM. If the attribute change were directly on the node with the NodeView, we have the update() callback to decide if the NodeView can successfully handle the change or not, but there is no such mechanism for changes on parent/ancestor nodes.

Repro demo: https://glitch.com/edit/#!/vivacious-whispering-ocarina

We noticed this in our editor because user IME compositions were getting disrupted when we set an attribute on a container node to track which user last touched that node's content and it destroyed/recreated our NodeView containing the text node where the IME was happening, breaking the composition.

marijnh commented 1 year ago

See https://github.com/ProseMirror/prosemirror-view/commit/47be3c32b9fd2238a4bffd7435ada713cee64750 . But I expect IME will still be disrupted even with that patch, since without a node view for the parent node, there's no way in which ProseMirror can update it without recreating the DOM nodes.

jhnsnc commented 1 year ago

Thanks, Marijn!