yjs / y-prosemirror

ProseMirror editor binding for Yjs
https://demos.yjs.dev/prosemirror/prosemirror.html
MIT License
328 stars 115 forks source link

remirror is broken after y-prosemirror@1.2.4 #155

Closed usman-web-dev closed 2 months ago

usman-web-dev commented 2 months ago

Checklist

Describe the bug Before 1.2.4, remirror was working fine, but as soon as I updated to 1.2.4 it's breaking. It says Cannot read properties of undefined (reading 'state')

To Reproduce Steps to reproduce the behavior:

  1. Clone this repo
  2. Run npm i and then npm run dev to serve
  3. There will be a blank page and if you open the console, there will be an error saying Cannot read properties of undefined (reading 'state')

Expected behavior The app should run as it runs on 1.2.3

Screenshots

image

Environment Information

Additional context From what I have figured out that the error is occurring due to this change, if we put back the timeout, it will start working again.

Possible workaround Hardcode y-prosemirror to 1.2.3 using npm i y-prosemirror@1.2.3

dmonad commented 2 months ago

I think removing the timeout was the right choice. The initial content shouldn't be populated in a timeout - it should happen synchronously. This also fixes other issues, that we can't fix any other way. I'm sorry that this breaks remirror. @ifiokjr let me know if you need help on this.

If you populate the initial ProseMirror state with the Yjs content, no state change is triggered. This avoids an unnecessary update and is generally the recommended way to instantiate ProseMirror state. Please check the demo in this repository to see how to do that. But I think remirror could also support the synchronous state change.

const { doc, mapping } = initProseMirrorDoc(type, schema)
const prosemirrorView = new EditorView(editor, {
  state: EditorState.create({
    doc,
    schema,
    plugins: [
      ySyncPlugin(type, { mapping }),
      yCursorPlugin(provider.awareness),
      yUndoPlugin(),
      keymap({
        'Mod-z': undo,
        'Mod-y': redo,
        'Mod-Shift-z': redo
      })
    ].concat(exampleSetup({ schema }))
  })
})