yjs / y-prosemirror

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

'Cannot convert undefined or null to object' in equalAttrs #83

Closed TeemuKoivisto closed 2 years ago

TeemuKoivisto commented 2 years ago

In equalAttrs, yattrs can be null thus crashing when Object.keys(yattrs) is executed.

I suppose this happens because iterating over attribute keys a check is done:

  eq = key === 'ychange' || l === r || (typeof l === 'object' && typeof r === 'object' && equalAttrs(l, r))

Which in case when comparing a regular object {} against null tries to recurse the null because null's typeof is object. A rather unfortunate fact but that's how it is. So maybe a fix could be adding a nullness check in that condition or at the start of the function.

To Reproduce I'll write a reproduction if needed.

Environment Information "y-prosemirror": "^1.0.12",

dmonad commented 2 years ago

Sure, you can create a PR for it.