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

Unable to get property 'getAttributeKeys' of undefined or null reference #41

Open
dan-codes-16 opened this issue Aug 17, 2017 · 0 comments

Comments

@dan-codes-16
Copy link

Hello,

We'have observed the following error in react-gpt (Windows 7, IE 11 mostly, but not only in this environment):

  • React renders our component rendering Bling component;
  • Bling.Render checks if gpt scriptLoaded for current component and if not it renders node element instead of script element and adds Bling instance into AdManager (in componentDidMount).
  • Some time later a half of ads get event 'onScriptLoaded' and method Bling.Render is called for Bling instances of these ads. In this time Bling.Render sees scriptLoaded is true and renders script element.
  • So there are two groups of ads in the same time:
  • the first group with scriptLoaded and script element rendered,
  • the second group have only node element rendered (scriptLoaded is false yet for them)
  • Suddenly AdManager.Render method is called (after debounce) and it starts to iterate over all Bling instances and invokes defineSlot() method. After that all Bling instances have got adSlot defined.
  • Next, the second group of ads get event 'onScriptLoaded' and method Bling.Render is called for Bling instances of these ads. Attention! These ads (Bling instances) do not have script element rendered (no _divId) but have adSlot defined. Bling.Render sees scriptLoaded is true and it tries to render script element, but before creating element it destroys the current adSlot if it exists.
    Bling.js, lines 502-507
// clear the current ad if exists
this.clear();
if (this._adSlot) {
    Bling._adManager.googletag.destroySlots([this._adSlot]);
    this._adSlot = null;
}

As a result, the element is created but adSlot is destroyed (adSlot == null).

  • After that, according to our business logic if user scrolls down the page ads are updated. We do this by updating Bling targeting property, e.g. change some timestamp parameter. And when Bling.shouldComponentUpdate is called for the ad with destroyed adSlot, the Bling instance tries to call configureSlot for empty slot and method Bling.setAttributes(adSlot, attributes) throws an exception because of empty adSlot:
    line 270
var attributeKeys = adSlot.getAttributeKeys();

So, why method Bling.Render destroys the current ad if it exists? Could it destroy ad slot only if the Bling instance has divId (script element rendered)?

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

1 participant