hCaptcha/react-hcaptcha

Creating a 2nd Captcha before the API scripts loads causes 2nd script to load

TylerDixon opened this issue · 0 comments

This is best explained by an example:

  1. User is on Page A which has a Captcha A
  2. Captcha A mounts, putting an API script tag on the page.
  3. User Navigates to Page B which has a Captcha B
  4. Captcha B resets the captchaScriptCreated flag, then mounts which places another API script tag on the page.

This is most prevalent in scenarios where the user has a slow connection. I have also created a scenario to test this out there here.

Expected Behavior

API script should only attempt to be loaded once.

Current Behavior

API script is loaded more than once.

Possible Solution

Remove the check from the constructor here, and instead update this line to be

const captchaScriptCreated = typeof hcaptcha !== 'undefined';

Workaround

Load the script with a <script> tag before your page loads.