Skip to content

"Detached Elements" does not show nodes that were never attached #190

Open
@warpech

Description

@warpech

Hi, Thanks for a great tool!

I discovered one problem with it that I think should be treated as a bug. Or, probably the docs need a clarification.


The announcement blog post (https://blogs.windows.com/msedgedev/2021/12/09/debug-memory-leaks-detached-elements-tool-devtools/) gives 2 valid reasons why elements can be unattached (numbering mine):

Usually, we create DOM nodes in JavaScript to insert them somewhere in the page to display them. But it is possible to create nodes and
(1) never attach them or
(2) remove nodes from the page and keep references to them in JavaScript.

The announcement blog post explains it as if the "Detached Elements" tab was able to detect cases (1) and (2), but, in fact, it only detects case (2).

I think both cases are valid. It would be useful for this tool to support both. Ideally with some button to filter the kind you're interested in.

Reproduction

Run the following code as index.html:

<script type="module">
  const cache = [];

  const detachedSection = document.createElement("section");
  cache.push(detachedSection);

  const detachedArticle = document.createElement("article");
  document.body.appendChild(detachedArticle);
  detachedArticle.remove();
  cache.push(detachedArticle);

  console.log("Disconnected elements", cache);
</script>

This script creates two nodes, but only one (article) is reported by the tool, as seen on the screenshot below:

Screenshot 2023-10-13 at 4 18 46 PM


Edge version: 120.0.2158.0 (Official build) Canary (arm64)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions