nfl / react-gpt

A React display ad component using Google Publisher Tag
MIT License
145 stars 84 forks source link

hasOwnProperty returns a false negative #83

Open Paul-Hess opened 6 years ago

Paul-Hess commented 6 years ago

Current behavior:

The render method in createManager.js checks if any instance of adSlot has own property 'getServices'. If it does not it creates a dummy ad to enable publisher services with. The hasOwnProperty method returns a false negative sometimes. This results in extraneous use of the dummyAdSlot implementation. Consequently the googletag console shows errors concerning defineSlot being called without an accompanying call to render, which can inflate unfilled slot numbers.

Bugfix:

Replacing the use of "hasOwnProperty" with a check that adSlot is truthy, adSlot.getServices is truthy, and that adSlot.getServices is a function before calling it fixes the issue. Possibly overkill, but it is certainly safe and more reliable than "hasOwnProperty". This may be due to the general unreliability of "hasOwnProperty" https://github.com/eslint/eslint/issues/7071 or because in the reference to adSlot, getServices has been renamed to some abstracted random key, or a little of both.

Accompanying PR: https://github.com/nfl/react-gpt/pull/84

Cheers!

react-gpt -v 2.10.2 node -v 8.5.0 npm -v 5.3.0