GoogleWebComponents / google-apis

Web components for loading Google's JavaScript Libraries
https://elements.polymer-project.org/elements/google-apis
Other
87 stars 64 forks source link

Race condition on google-client-loader #75

Open softkot opened 8 years ago

softkot commented 8 years ago

It looks like the code in ready hook may not works properly and event js-api-load could be fired earlier than it is listned so the client is never loaded.

  this._loader = document.createElement('google-js-api');
        this.listen(this._loader, 'js-api-load', '_loadClient');

Tested on Google Chrome 52.0.2743.82 (64-bit)

softkot commented 8 years ago

Pull request to workaround https://github.com/GoogleWebComponents/google-apis/pull/76

ebidel commented 8 years ago

Can you post a jsbin that repos the race condition. I'd like to understand whst caused the problem instead of hacking around it.

softkot commented 8 years ago

I just create a jsbin https://jsbin.com/koquvi/9/edit?html,output but if works just fine because refer to polymer-cdn where https://github.com/Download/polymer-cdn/blob/master/lib/google-apis/google-client-loader.html use

 <template>
    <google-js-api on-js-api-load="_loadClient"></google-js-api>
  </template>

instead ready hook in latest repo. If you change it to latest https://github.com/GoogleWebComponents/google-apis/blob/master/google-client-loader.html it will fail to race conditions.

softkot commented 8 years ago

This was broken in https://github.com/GoogleWebComponents/google-apis/issues/72

tjmonsi commented 8 years ago

Actually I am having problems on it as well, especially on slow internet speeds. The quick hack on #76 did the trick.

dmurph commented 7 years ago

This happens for me every time.

mrabdallah commented 7 years ago

I tried setting interval in ready function like this var intervalId = setInterval(function(){ if(gapi.client){ var clients = that.querySelectorAll("google-client-loader"); for (var i = 0; i < clients.length; i++) { clients[i]._loadClient(); } clearInterval(intervalId); } else gapi.load('client', function(){}); }, 3000); and it worked for me

peterfortuin commented 5 years ago

I'm using the 2.x version of this element and have the same race condition. For me it happend because I have 10 times the google-client-loader element in my dom tree with different endpoints to connect to. The fix mentioned in #76 fixed my problems.

peterfortuin commented 5 years ago

I have created a pull request (#99) to solve this for the 2.x branch.