From 34bf764c8959359052018dcdf2b0bb46ea46e2f1 Mon Sep 17 00:00:00 2001 From: Ivan Jager Date: Mon, 19 Jun 2017 10:57:53 -0500 Subject: [PATCH] Fix race on execute() Previously, if the call to execute() happened before the script is asynchnonously loaded and fully rendered, the Captcha would never execute. --- src/recaptcha.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/recaptcha.js b/src/recaptcha.js index 2746f7b..9f06c42 100644 --- a/src/recaptcha.js +++ b/src/recaptcha.js @@ -22,6 +22,8 @@ export default class ReCAPTCHA extends React.Component { if (grecaptcha && widgetId !== undefined) { return grecaptcha.execute(widgetId); + } else { + this._executeRequested = true; } } @@ -56,6 +58,10 @@ export default class ReCAPTCHA extends React.Component { widgetId: id, }, cb); } + if (this._executeRequested && this.props.grecaptcha && this.state.widgetId !== undefined) { + this._executeRequested = false; + this.execute(); + } } componentDidMount() {