Strange behavior with whitespace and decorations

I’m creating a proofreading software through websockets. Basically, the frontend sends the recent steps to the server, server applies these steps and checks the slices of text that were affected. It worked well until I discovered a strange behavior with trailing whitespace. When I end a list item with a trailing whitespace and hit enter, it creates a second list item, but that trailing whitespace suddenly disappears. The server doesn’t have any idea that it disappeared, as a result, we have one position shifted decorations, causing off-by-one error. What might be a problem?

I could create a workaround in a server. When it serializes a textblock, it removes any trailing whitespace from its text representation. I doubt it is a viable solution - the problem is with how decorations are created. Instead of relying on the inherent structure of the document, they seem to rely on the visible innerText of editor, that’s why trailing whitespaces are not considered when creating inline decorations.

This is definitely not the case. All programmatic addressing in ProseMirror works in terms of the document structure.

Also, I do not see the editor deleting trailing space in list items when I press enter in the demo editor on

Ah. Sorry, my bad. I found the bug. I was converting JSON serialized doc into html this way:

 * Converts Prosemirror JSON format to HTML Fragment
 * @param schema
 * @param json
export function fromJSONtoHTML(schema, json): string {
  const pmNode = ProsemirrorNode.fromJSON(schema, json)
  const node = DOMSerializer

  const div = document.createElement('div');

  return div.innerHTML

This approach was deleting trailing whitespace. I’d better initialize the EditorView with the EditorState using nodeFromJSON(). I don’t understand why I didn’t do it in the first place. Thank you for your response, it helped a lot :slight_smile: