iebb / F1ManagerSaveReader

F1ManagerSaveReader
https://f1-manager-save-reader.vercel.app
MIT License
4 stars 1 forks source link

In dev mode google ads are added on each reload #1

Closed GingerFitzgerald closed 6 months ago

GingerFitzgerald commented 7 months ago

Description

When running the application by npm run dev the google ads add task seems to be executed on each refresh of the page.

To Reproduce

  1. run the app in dev mode locally and connect to localhost:3000
  2. open the web console
  3. click the reload button of your browser
  4. Now an error pops up stating TagError: adsbygoogle.push() error: All ins elements in the DOM with class=adsbygoogle already have ads in them. image

Notes

this is seems to only affect dev mode

GingerFitzgerald commented 7 months ago

I'm not firm with handling google ads might be resolved (dirty) by adding this in GoogleAd.jsx

      setGoogleInit(setTimeout(() => {
        try {
          if (typeof window !== 'undefined')
            (window.adsbygoogle = window.adsbygoogle || []).push({});
        } catch (e) {
          if (!e.message?.includes('All ins elements in the DOM with class=adsbygoogle already have ads in them')) {
            console.log(e);
          } else {
            // set googleInit to 1 to mark that the ads have been loaded 
          }
        }
      }, timeout));

not sure if setting googleInit to 1 would be the correct code Remark that the catch does not 'handle' the error for other errors that occur here it just prevents it from stopping the application to run

iebb commented 6 months ago

I've removed the ads block :D