diff --git a/src/components/node.js b/src/components/node.js index dd009bf9b..975191e3f 100644 --- a/src/components/node.js +++ b/src/components/node.js @@ -109,7 +109,7 @@ class Node extends React.Component { // If the node is a block or inline, which can have custom renderers, we // include an extra check to re-render if the node's focus changes, to make // it simple for users to show a node's "selected" state. - if (props.node.kind != 'text') { + if (nextProps.node.kind != 'text') { const hasEdgeIn = props.state.selection.hasEdgeIn(props.node) const nextHasEdgeIn = nextProps.state.selection.hasEdgeIn(nextProps.node) const hasFocus = props.state.isFocused || nextProps.state.isFocused @@ -127,6 +127,14 @@ class Node extends React.Component { if (!nextRanges.equals(ranges)) return true } + // If the node is a text node, and its parent is a block node, and it was + // the last child of the block, re-render to cleanup extra `
` or `\n`. + if (nextProps.node.kind == 'text' && nextProps.parent.kind == 'block') { + const last = props.parent.nodes.last() + const nextLast = nextProps.parent.nodes.last() + if (props.node == last && nextProps.node != nextLast) return true + } + // Otherwise, don't update. return false }