react-native-recaptcha-that-works
react-native-recaptcha-that-works copied to clipboard
Update and optimize reCAPTCHA script loading
This PR introduces an optimized approach to load reCAPTCHA.
I was having issues where the recaptcha component would hang indefinitely. I dug into the source code to resolve the issue, and noticed there was no way to tell if the loading of the recaptcha script failed. In addition, the reliance on setInterval
and setTimeout
raised concerns for potential race conditions at worst, and poorly optimized code at bets.
Guided by Google’s documentation on loading reCAPTCHA, this update focuses on event-driven execution and improved race condition handling. This alignment with Google’s documentation enhances the library’s loading efficiency and aims to give better insight into potential errors.
Benchmarks
For these benchmarks I measured the time between calling open
and onVerify
.
Value 1 | Value 2 | Value 3 | Value 4 | Value 5 | Average | |
---|---|---|---|---|---|---|
New Code | 1109 | 1320 | 827 | 789 | 807 | 970.4 |
Old Code | 1922 | 1794 | 2024 | 1861 | 1784 | 1877 |
@douglasjunior I look forward to any feedback or critique you have!