Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught errors and empty page when loading additional content in JS with Ad Slots on the same page #49

Open
red1 opened this issue Mar 9, 2024 · 1 comment

Comments

@red1
Copy link

red1 commented Mar 9, 2024

Hello I've integrated your module and it works fine until I tried to lazy load some blocks on my app, adding blocks with ResponsiveAdUnit loaded in ReactJS I've got the following errors :
"Uncaught TagError: adsbygoogle.push() error: All ins elements in the DOM with class=adsbygoogle already have ads in them." error
image
image
I think it's due to the init of the library
I've found this that is exactly the same : https://stackoverflow.com/questions/74577652/how-to-solve-uncaught-tagerror-adsbygoogle-push-error-all-ins-elements-in-t
someone is suggesting but it did not worked for me in the main app js
if (adsbygoogle && !adsbygoogle.loaded) (adsbygoogle = (window as any).adsbygoogle || []).push({});

@themre
Copy link

themre commented Dec 2, 2024

this issue is because Ad component pushes ad on each rerender:

useEffect(() => {
    initAd();
  })

solution for me was to use dependency array like so:

useEffect(() => {
    initAd();
  }, []) // or even better [slotId]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants