Prosemirror First typing in paragraph IME bug

binding: y-prosemirror
detail:

When typing in a paragraph block while using an IME Chinese input method, it ends up in the first character.

It seems like that as long as the two user cursor are at the same position, this would happen.

I doubted it is caused by my ‘placeholder’ plugin, but I found some other same situation without placeholder widget.

I can give a gif screen shot later…

As you can see, I got a crash flash when I typing the first character… but if there are contents inside a paragraph block, my input method just work as expected…

What’s the problem?

Also, if the paragraph is empty, first typing would cause this bug… but it didn’t occur everytime…

kinda weird

Hi @ShenQingchuan,

does this also occur without Yjs? I.e. can you add a ProseMirror widget to the last position of the document and reproduce the issue? y-prosemirror only interacts with ProseMirror through the ProseMirror API. The y-prosemirror cursor plugin simply adds a widget to the ProseMirror editor.

我遇到了同样的问题,发现是这个插件的原因
Machine translation: I encountered the same problem and found that it was the reason for this plugin

// @tiptap-pro/extension-unique-id

...
  // check initial content for missing ids
  onCreate() {
    // Don’t do this when the collaboration extension is active
    // because this may update the content, so Y.js tries to merge these changes.
    // This leads to empty block nodes.
    // See: https://github.com/ueberdosis/tiptap/issues/2400
    if (this.editor.extensionManager.extensions.find((extension) => extension.name === 'collaboration')) {
      return
    }

新文档的一个节点没有 id
Machine translation: A node in the new document does not have an ID

<p data-placeholder="请输入内容" class="is-empty"><br class="ProseMirror-trailingBreak"></p>

当开始打字时插件会做以操作导致节点重绘
Machine translation: When starting typing, the plugin will do something to cause the node to redraw

    tr.setNodeMarkup(pos, undefined, {
      ...node.attrs,
      [attributeName]: generateID()
    })

My solution:

  // check initial content for missing ids
  onCreate() {
    const { types, attributeName, generateID } = this.options 
    if (this.editor.extensionManager.extensions.find((extension) => extension.name === 'collaboration')) {
      // ydoc data loaded
      this.editor.on('initSuccess', () => {
        const { tr, doc } = this.editor.state
        const node = doc.childCount === 1 ? doc.firstChild : null
        if (!node || !!node.attrs[attributeName] || node.content.size > 0) return

        tr.setNodeMarkup(0, undefined, { ...node.attrs, [attributeName]: generateID() })
        tr.setMeta('addToHistory', false)
        this.editor.view.dispatch(tr)
      })
      return
    }