linkedom icon indicating copy to clipboard operation
linkedom copied to clipboard

Incorrect target reported in all MutationRecords of type `childList`

Open jed opened this issue 1 year ago • 3 comments

Running this code:

import { parseHTML } from "linkedom";
const { document, MutationObserver } = parseHTML(
  "<!doctype html><html><head></head><body>",
);

let mo = new MutationObserver((records) => {
  let { nodeName } = records[0].target;
  console.assert(nodeName === "BODY", `Expected BODY, got ${nodeName}.`);
});

mo.observe(document, { subtree: true, childList: true });

document.body.appendChild(document.createTextNode(""));

results in this error:

Assertion failed: Expected BODY, got #document.

If I'm reading it correctly, it looks like the target for a mutation is always reported as the node passed to observe (at least for childList) which is incorrect; for the childList MutationRecord type, the target should be the parentNode of the inserted/removed node(s).

jed avatar Feb 10 '25 16:02 jed

it looks to me you're capable of landing MRs on that esm folder by now ... I am really sorry but I am not using this project daily and I am not using this project for my current daily tasks so that if you need speedy changes in here, you better go ahead and file a PR where I can spend the "non-existent-time" I have for non related tasks these days ... if that works for you, I can try helping out with directions around how to proceed with tests too, so that coverage keeps being useful. I did ask for help in here stating I don't have time needed to keep this updated, but one of the main possible candidates to take it over disappeared 🤷\

edit see https://github.com/WebReflection/linkedom/issues/300#issuecomment-2648550569

WebReflection avatar Feb 10 '25 16:02 WebReflection

I totally understand, will take a look to see if I can figure out a reliable way of reflecting the correct target.

jed avatar Feb 10 '25 16:02 jed

mandatory context needed in here too: https://github.com/WebReflection/linkedom/issues/247

relevant up to its latest comment: https://github.com/WebReflection/linkedom/issues/247#issuecomment-1904087838

WebReflection avatar Feb 10 '25 16:02 WebReflection