-
-
Notifications
You must be signed in to change notification settings - Fork 344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using a cached NodeView causes a null error when updating decorations in some cases #1495
Comments
Your caching scheme is causing multiple nodes to use the same DOM element, which isn't supported and will break the editor in precisely the way you are seeing here. I verified by adding this loop to the start of let set = new Set
for (let ch of descs) {
if (set.has(ch.dom)) throw new Error("Duplicate")
set.add(ch.dom)
} |
Thanks for the quick response! Based on my understanding, my caching scheme always returns the same NodeView instance and DOM element for the same node instance, but not for different node instances. What's interesting to me is that adding an Based on all this, I don't think there is a bug in |
Nodes are compared by content/type, not by identity. Using them as cache keys isn't going to be safe. |
Thanks for clearing that up, that explains the issue. |
Since ProseMirror can often recreate a NodeView in cases where this is not wanted for my use case, I have implemented logic which allows me to cache and reuse NodeViews. The primary motivation is that a node view should keep its state as long as the same node is shown in the editor (e.g. wrapping an existing node in a list should not destroy and recreate the node view and make it lose its state).
One specific example is that a node view, which renders an iframe, should not reload the iframe when editing the document.
This is the first time I'm running into an issue with the custom node view caching and it was relatively difficult to reproduce. Here is the smallest possible reproduction I was able to come up with. Please note that this does not contain all of the node view caching logic, only what was needed to reproduce the issue. The code can directly be run here: https://glitch.com/edit/#!/mica-closed-lint?path=index.js
This is the error I get when updating the decorations in a specific way:
The issue only occurs when reusing the cached node view. My guess is that it has to be somehow related to the
dom
property of the node view and how it gets created or attached to the DOM.The text was updated successfully, but these errors were encountered: