b-fuze / deno-dom

Browser DOM & HTML parser in Deno
https://jsr.io/@b-fuze/deno-dom
MIT License
426 stars 46 forks source link

Setting `node.nodeValue` does not update the HTML #93

Closed DrParanoia closed 2 years ago

DrParanoia commented 2 years ago

Hi! Let's say I have this code:

const doc = new DOMParser().parseFromString("<div>Hello world</div>", "text/html");

function convertNode(node: any) {
    if (!node.childNodes) {
        return;
    }

    node.childNodes.forEach((childNode: Node) => {
        if (childNode.nodeType === NodeType.TEXT_NODE && childNode.textContent.trim()) {
            childNode.nodeValue = 'foo';
        }
        convertNode(childNode);
    });
}

if (doc) {
    convertNode(doc);
    console.log(doc.body.innerHTML, doc.body.innerText);
}

So as a result doc.body.innerHTML will still be <div>Hello world</div> while doc.body.innerText will correctly be foo which is incorrect. The new HTML value should be <div>foo</div>.

I feel like this is quite a critical issue 😢

b-fuze commented 2 years ago

Thanks for reporting this. Hopefully I'll have a fix for this in the next two weeks or so