fix parentNode binding in case parent doesn't fire MO

This commit is contained in:
Kevin Jahns 2018-05-07 11:41:45 +02:00
parent 6336064516
commit 1ace7f4b73

View File

@ -90,21 +90,20 @@ export default function domObserver (mutations, _document) {
mutations.forEach(mutation => { mutations.forEach(mutation => {
const dom = mutation.target const dom = mutation.target
const yxml = this.domToType.get(dom) const yxml = this.domToType.get(dom)
if (yxml === false || yxml === undefined || yxml.constructor === YXmlHook) { if (yxml === undefined) { // In case yxml is undefined, we double check if we forgot to bind the dom
// dom element is filtered let parent
if (yxml === undefined) { // In case yxml is undefined, we double check if we forgot to bind the dom let yParent
console.error('Yjs DomBinding: Reconstructing DomBinding, please report how to reproduce this.') do {
let parent parent = dom.parentNode
let yParent yParent = this.domToType.get(parent)
do { } while (yParent === undefined && parent !== null)
parent = dom.parentNode if (yParent !== false && yParent !== undefined && yParent.constructor !== YXmlHook) {
yParent = this.domToType.get(parent) diffChildren.add(parent)
} while (yParent === undefined)
if (yParent !== false && yParent !== undefined && yParent.constructor !== YXmlHook) {
diffChildren.add(parent)
}
} }
return return
} else if (yxml === false || yxml.constructor === YXmlHook) {
// dom element is filtered / a dom hook
return
} }
switch (mutation.type) { switch (mutation.type) {
case 'characterData': case 'characterData':