diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-02 06:09:10 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-02 06:09:10 +0300 |
commit | 7580728fc297c86cc5a31fb67e7153217facf1c0 (patch) | |
tree | 59279991d34f28fc1b415a14e77df08d5c11d265 /app/assets/javascripts/captcha | |
parent | d8714cf67ce4db786b26b64f0f0bef50fb6976e6 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/captcha')
-rw-r--r-- | app/assets/javascripts/captcha/init_recaptcha_script.js | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/app/assets/javascripts/captcha/init_recaptcha_script.js b/app/assets/javascripts/captcha/init_recaptcha_script.js index adc69862a85..b9df7604ed1 100644 --- a/app/assets/javascripts/captcha/init_recaptcha_script.js +++ b/app/assets/javascripts/captcha/init_recaptcha_script.js @@ -2,9 +2,6 @@ import { memoize } from 'lodash'; export const RECAPTCHA_API_URL_PREFIX = 'https://www.google.com/recaptcha/api.js'; -/** - * The name which will be used for the reCAPTCHA script's onload callback - */ export const RECAPTCHA_ONLOAD_CALLBACK_NAME = 'recaptchaOnloadCallback'; /** @@ -21,9 +18,7 @@ export const RECAPTCHA_ONLOAD_CALLBACK_NAME = 'recaptchaOnloadCallback'; * */ export const initRecaptchaScript = memoize(() => { - /** - * Appends the the reCAPTCHA script tag to the head of document - */ + // Appends the the reCAPTCHA script tag to the head of document const appendRecaptchaScript = () => { const script = document.createElement('script'); script.src = `${RECAPTCHA_API_URL_PREFIX}?onload=${RECAPTCHA_ONLOAD_CALLBACK_NAME}&render=explicit`; @@ -31,11 +26,14 @@ export const initRecaptchaScript = memoize(() => { document.head.appendChild(script); }; - /** - * Returns a Promise which is fulfilled after the reCAPTCHA script is loaded - */ return new Promise((resolve) => { - window[RECAPTCHA_ONLOAD_CALLBACK_NAME] = resolve; + // This global callback resolves the Promise and is passed by name to the reCAPTCHA script. + window[RECAPTCHA_ONLOAD_CALLBACK_NAME] = (val) => { + // Let's clean up after ourselves. This is also important for testing, because `window` is NOT cleared between tests. + // https://github.com/facebook/jest/issues/1224#issuecomment-444586798. + delete window[RECAPTCHA_ONLOAD_CALLBACK_NAME]; + resolve(val); + }; appendRecaptchaScript(); }); }); |