twobucks / react-gcaptcha

React component for google reCAPTCHA.
MIT License
25 stars 2 forks source link

race condition where grecaptcha is defined but not loaded #9

Open KaseyPowers opened 6 years ago

KaseyPowers commented 6 years ago

It looks like during the loading process grecaptcha is created as an object with a ready function before it tries calling the onLoad callback.

this means with bad luck, https://github.com/twobucks/react-gcaptcha/blob/master/src/index.js#L24 this will attempt to render before grecaptcha is ready.

I'm not able to recreate locally, so I can't tell if it would be too late to add the callback to window if doing something like if (typeof grecaptcha !== "undefined" && grecapthca.render)

dinodsaurus commented 6 years ago

Thanks for this @KaseyPowers feel free to submit a PR ;)