diffDOM
diffDOM copied to clipboard
Work with jsdom without global values
Trying to use diff-dom in non-test Node.js project with jsdom, I noticed the document option that allows manually specifying the value, but that option along does not work.
The issue is caused by DiffFInder doing a global typeof Element check that prevents the expected nodeToObj() conversion:
https://github.com/fiduswriter/diffDOM/blob/8f19b20a5e8e1f8d1db488a8b9e26e1fc745ec34/src/diffDOM/virtual/diff.ts#L42C1-L43
Workaround:
dd.diff(nodeToObj(elementA), nodeToObj(elementB));
Please provide minimal example @vilicvane
Got an error with that too.
The check here:
https://github.com/fiduswriter/diffDOM/blob/08d4f15d4c1ab7c55d477fb5a668e984e75a7184/src/diffDOM/helpers.ts#L35
assumes that element.ownerDocument is live.
However document.cloneNode().defaultView == null.
The test should fall back to nodeToObj in that case, cause it is impossible to check inheritance in that case.