How to re-render parent node when child changes?

I have a custom node type that can contain other nodes (paragraphs etc.). I want to render a placeholder text inside the custom node if it is empty. Empty means that the parent only contains a single empty paragraph.

In the custom node I check if it is empty. However, when changing the content of the children in the editor, the parent is not re-rendered, thus not triggering the placeholder visibility correctly.

What would be the best way to achieve this? Is there a way to trigger a re-render of the parent if the content of the children changes?

You can do this by giving your node view an update method. The simplest possible one would just do update(newNode) { return this.node.sameMarkup(newNode) }, but you can extend that to something like (assuming we’re in a node view class)…

  update(newNode) {
    if (!this.node.sameMarkup(newNode)) return false
    let empty = newNode.content.length == 0, oldEmpty = this.node.content.length == 0
    if (empty && !oldEmpty)
      this.dom.classList.add("empty-class")
    else if (!empty && oldEmpty)
      this.dom.classList.remove("empty-class")
    this.node = newNode
    return true
  }

That works, thanks for the quick help!