Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 tasks done
milahu opened this issue Oct 22, 2022 · 3 comments
Open
2 tasks done
Assignees
Labels
bug Something isn't working

Comments

@milahu
Copy link

milahu commented Oct 22, 2022

Checklist

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 milahu added the bug Something isn't working label Oct 22, 2022
@marek-baranowski
Copy link

Hey @milahu, did you find some workaround maybe?

@milahu
Copy link
Author

milahu commented Oct 28, 2022

this works

        ySyncPlugin(yXmlFragment, { permanentUserData, colors }),

@marek-baranowski
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants