Possible issue with a MutationRecord object?
Darkle opened this issue · comments
Hi, I'm having some issues getting an object property with dot-prop and I'm not sure why it's not working. Here's the code:
const dotProp = require('dot-prop')
const lodashGet = require('lodash.get')
const mainDiv = document.createElement('div')
mainDiv.setAttribute('id', 'main')
document.body.appendChild(mainDiv)
const mainElem = document.querySelector('#main')
const testerObj = {
foo: 'bar'
}
console.log(dotProp.get(testerObj, 'foo'))
console.log(lodashGet(testerObj, 'foo'))
const observer = new MutationObserver(mutations => {
mutations.forEach(mutation => {
console.log(mutation)
console.log(dotProp.get(mutation, 'addedNodes'))
console.log(lodashGet(mutation, 'addedNodes'))
})
})
observer.observe(
mainElem,
{
childList: true,
subtree: true,
attributes: false,
characterData: false,
attributeOldValue: false,
characterDataOldValue: false
}
)
const newP = document.createElement('p')
mainElem.appendChild(newP)
I get the following output on the console:
bar
bar
MutationRecord { type: "childList", target: <div#main>, addedNodes: NodeList[1], removedNodes: NodeList[0], previousSibling: null, nextSibling: null, attributeName: null, attributeNamespace: null, oldValue: null }
undefined
NodeList [ <p> ]
If you want an easy way to try the code above, copy and paste it into https://esnextb.in/ and open the browser console to see the output.
Cheers.
This requires the DOM tree. Is there an easier/minimal way to replicate the issue?
It looks like some earlier versions of jsdom had some MutationObserver support, so maybe you could try that: jsdom/jsdom#639
What I meant is if there's a minimal way to replicate the issue? introducing MutationObserver
makes it hard to demonstrate the issue
I believe the issue is probably caused by MutationObserver
. If you could prove the issue is caused by this module please comment :)