Skip to content

Incorrect target reported in all MutationRecords of type childList #300

Description

@jed

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).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions