WebReflection / WebReflection/linkedom
Incorrect target reported in all MutationRecords of type `childList`
Nobody has claimed this yet.
- Dominant language
- HTML
- Stars
- 2.1k
- Forks
- 104
- PR merge metrics
- No merged PRs in 30d
Description
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).
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in esm/interface/mutation-observer.js at the linked location and run the reproduction using parseHTML and MutationObserver. Verify that a childList MutationRecord reports the parent node of the inserted or removed nodes as its target, so the assertion observes BODY rather than #document.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- web-dev
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 50/100