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

Failed to execute 'unobserve' on 'IntersectionObserver': parameter 1 is not of type 'Element'. #276

Open
mrkam2 opened this issue Jan 25, 2023 · 0 comments

Comments

@mrkam2
Copy link

mrkam2 commented Jan 25, 2023

I have a react app that is used with google analytics and autotrack plugin and it fires this error a lot:

Uncaught TypeError: Failed to execute 'unobserve' on 'IntersectionObserver': parameter 1 is not of type 'Element'. 
at impression-tracker.js:329:43 
at Array.forEach (<anonymous>) 
at ye.handleDomElementRemoved (impression-tracker.js:327:16) 
at ye.walkNodeTree (impression-tracker.js:251:7) 
at ye.handleDomMutations (impression-tracker.js:234:14)

Here is how google analytics is configured:

  ga("require", "impressionTracker", {
    elements: [
      {
        id: "my-id",
        threshold: 0.5,
      }, ...]});

I found that this component is currently controlled in react so that it appears and disappears based on the data:

<div>
  {data && <div id="my-id>...</div>}
</div>

When I caught this exception in Dev Tools, I found that the element that is passed to the unobserve function is actually div#my-id, so I'm not sure why it is complaining that it is not of a type 'Element`.

Here is the corresponding line in impression-tracker.js where the exception is thrown:

        this.thresholdMap[item.threshold].unobserve(element);

It looks like this issue is happening to others as well even without react involvement:

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