marsidev / react-turnstile

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

Failure to load script is not handled #40

Closed IanVS closed 10 months ago

IanVS commented 10 months ago

Do you want to request a feature or report a bug? Somewhere in between a bug and feature

What is the current behavior? If https://challenges.cloudflare.com/turnstile/v0/api.js cannot be loaded, such as during the Cloudflare outage yesterday, there seems to be no way to catch the failure and show a fallback UI or handle the failure. In my case, I'd like to "fail open" and proceed even if turnstile cannot load. However, when the script fails to load, the onError callback of the component is not triggered.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than React. Paste the link to your CodeSandbox example below:

This can be reproduced by blocking the request to https://challenges.cloudflare.com/turnstile/v0/api.js in the network tab, and observe what happens.

What is the expected behavior? I expected onError to be triggered.

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React? I don't think this has anything to do with React/browser/OS, it's due to the way that the script is injected, and then the rest of the code expects turnstile to be on window, without any way to handle an error.