TypeError: Cannot read properties of null (reading 'getUserByClientId')
milahu opened this issue · 3 comments
milahu commented
Checklist
- Are you reporting a bug? Use github issues for bug reports and feature requests. For general questions, please use https://discuss.yjs.dev/
- 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
y-prosemirror@1.2.0
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')
marek-baranowski commented
Hey @milahu, did you find some workaround maybe?
milahu commented
this works
ySyncPlugin(yXmlFragment, { permanentUserData, colors }),
marek-baranowski commented
thank you. will need to tweak a bit as using hocuspocus
with tiptap