Force nodes of specific type to re-render

I’ve got it working with NodeView and Decoration.

Updating my variable values through a Transaction updates related Decorations which in turn updates related NodeViews. All encapsulated nicely in a Plugin and the variable values are now part of the state of my Plugin. The respective NodeSpec is also defined by the Plugin and accessed using plugin.nodeSpecs.

But I still have to access a variable’s value in NodeSpec.toDOM() for copy & paste to work properly. Unfortunately I’ve only got access to the Node and not the EditorState, so I cannot access the variable values from my Plugin’s state.

There are multiple potential paths forward now:

  1. I find a way to access a Plugin’s state from within NodeSpec.toDOM().
    I don’t think there is a proper one.
  2. I maintain a reference the EditorView from within my NodeSpec in order to access the current EditorState.
    That doesn’t sound clean.
  3. I allow my Plugin to provide a DOMSerializer that can serialize my NodeSpec. The problem here is the same as with toDOM() though: I don’t have access to the EditorState.
    So also not clean.
  4. I put all state of a variable (label, value, etc.) directly into all Nodes that reference it. I replace these Nodes every that state changes.
    That doesn’t sound right either. The node is only a simple variable reference with a name. Adding the value and other information to it shouldn’t be necessary.

It’s basically similar to the issue that I already have with state-sensitive text serialization, just with HTML this time:

Desired HTML output:

<span data-variable="varname">varvalue</span>

(varname is a Node attribute, varvalue is Plugin state)

Desired text output:

varvalue

Am I missing something here or is there no good solution to that problem?