y-prosemirror icon indicating copy to clipboard operation
y-prosemirror copied to clipboard

TypeError: Cannot read properties of null (reading 'getUserByClientId')

Open milahu opened this issue 3 years ago • 4 comments

Checklist

  • [x] Are you reporting a bug? Use github issues for bug reports and feature requests. For general questions, please use https://discuss.yjs.dev/
  • [x] Try to report your issue in the correct repository. Yjs consists of many modules. When in doubt, report it to https://github.com/yjs/yjs/issues/

Describe the bug

the prosemirror-versions demo throws TypeError when permanentUserData is not passed to ySyncPlugin

To Reproduce

in yjs-demos/prosemirror-versions/prosemirror-versions.js

replace

        ySyncPlugin(yXmlFragment, { permanentUserData, colors }),

with

        ySyncPlugin(yXmlFragment),

edit, create snapshot edit, create snapshot click old snapshot -> error

Expected behavior

better error message or different error handling

Environment Information

[email protected]

Additional context

the error is caused by this call

  editorview.dispatch(editorview.state.tr.setMeta(ySyncPluginKey, { snapshot: Y.decodeSnapshot(version.snapshot), prevSnapshot: prevSnapshot == null ? Y.emptySnapshot : Y.decodeSnapshot(prevSnapshot) }))

which calls

y-prosemirror/src/plugins/sync-plugin.js

  /**
   * @param {Y.Snapshot} snapshot
   * @param {Y.Snapshot} prevSnapshot
   * @param {Object} pluginState
   */
  _renderSnapshot (snapshot, prevSnapshot, pluginState) {
    if (!snapshot) {
      snapshot = Y.snapshot(this.doc)
    }
    // clear mapping because we are going to rerender
    this.mapping = new Map()
    this.mux(() => {
      this.doc.transact((transaction) => {
        // before rendering, we are going to sanitize ops and split deleted ops
        // if they were deleted by seperate users.
        const pud = pluginState.permanentUserData
// pud == null
        if (pud) {
          pud.dss.forEach((ds) => {
            Y.iterateDeletedStructs(transaction, ds, (_item) => {})
          })
        }
        /**
         * @param {'removed'|'added'} type
         * @param {Y.ID} id
         */
        const computeYChange = (type, id) => {
          const user = type === 'added'
            ? pud.getUserByClientId(id.client)
            : pud.getUserByDeletedId(id)
// TypeError: Cannot read properties of null (reading 'getUserByClientId')

milahu avatar Oct 22 '22 16:10 milahu

Hey @milahu, did you find some workaround maybe?

marek-baranowski avatar Oct 28 '22 01:10 marek-baranowski

this works

        ySyncPlugin(yXmlFragment, { permanentUserData, colors }),

milahu avatar Oct 28 '22 08:10 milahu

thank you. will need to tweak a bit as using hocuspocus with tiptap

marek-baranowski avatar Oct 28 '22 08:10 marek-baranowski

thank you. will need to tweak a bit as using hocuspocus with tiptap

@marek-baranowski Hey , Do you have any solutions? I'm also using tiptap

Graperio avatar Jul 03 '25 06:07 Graperio