Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

TypeError: node.dataset is undefined #17

Open
nbfritch opened this issue Apr 30, 2023 · 0 comments
Open

TypeError: node.dataset is undefined #17

nbfritch opened this issue Apr 30, 2023 · 0 comments

Comments

@nbfritch
Copy link

I noticed this extension logs an error whenever an element containing only text is updated.
This issue appears to be Firefox only. I observed this issue in v112.

The problem comes from this section of content.js line 154-156

mutations.every((mutation) =>
  Array.from(mutation.addedNodes).every((node) => node.dataset.demodal)
)

In firefox, when a node containing just text is updated, node.dataset is null, and the attempt to read .demodal causes a type error.

I think the above code could be changed as follows to filter out text-only mutations.

mutations.every((mutation) =>
  Array.from(mutation.addedNodes).every((node) => node.dataset == null || node.dataset.demodal)
)

Here is a minimal html file which triggers the issue once per second.
npx http-server --port 8000 and navigate to http://localhost:8000/issue.html

<html>
<head>
  <script>
    document.addEventListener('DOMContentLoaded', () => {
      const content = document.getElementById("content");
      let count = 0;
      setInterval(() => {
        count++;
        content.innerText = `Some Content ${count}`;
      }, 1000);
    });
  </script>
</head>

<body>
  <div id="content">Some Content 0</div>
</body>
</html>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant