marsidev / react-turnstile

Cloudflare Turnstile integration for React.
https://www.npmjs.com/package/@marsidev/react-turnstile
MIT License
414 stars 25 forks source link

Multiple warning logs #32

Closed marsidev closed 1 year ago

marsidev commented 1 year ago
  1. When injectScript is set to false (/manual-script-injection), the following browser warning appears:

image

It seems to be caused because the default callback name (onLoadCallbackName) has changed recently to include the container id (to allow multiple widgets on the same page). To fix it, we should also include the container id on the DEFAULT_ONLOAD_NAME constant.

  1. Sometimes, the script is attempted to be injected multiple times and this log appears: image

We can add an early check on the injectTurnstileScript function to fix it.

  1. Sometimes, the clean-up function cannot remove the widget and the following log appears: image

Seems it happens when a render option of the widget changes (e.g. options.theme) and causes the .remove() method to run twice in two different useEffect. Potentially fixed by checking if the element document.getElementById(widgetId) exists.

Related to #30