question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

React rerender causing multiple captcha solves

See original GitHub issue

Following the Example in the Documentation#react-example, we are seeing issues with auto-solving captchas following re-renders from react.

Calling destroy() instead of reset() seems to fix the problem, but I feel like either the js implementation in the friendly-challenge lib is somewhat irregular or the documentation/example for react is incorrect. I also say “seems”, because I fear side effects caused by calling functions not clearly defining their side effects. (What is destroy anyway, and why do we need it explicitly (compared to a captcha in a “solved” state)?)

I think the re-render issue stems from this line in the reset() function, especially in connection with startMode="auto", as it immediately restarts the solving process: https://github.com/FriendlyCaptcha/friendly-challenge/blob/87282feb6f494a9dfd1fd2378f9abc097411c740/src/captcha.ts#L294

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
MauriceArikoglucommented, Mar 10, 2022

Thank you @merlinfuchs

0reactions
merlinfuchscommented, Mar 10, 2022

I think using .destroy() instead of .reset() in the cleanup function is actually the correct thing to do. We are not re-using the same Widget instance so using .reset() will start solving a puzzle in the old Widget instance which isn’t attached to the DOM anymore. This can also lead to doneCallback being called multiple times. (once from the old instance and once from the new instance)

I’m pretty sure this isn’t a bug in the widget implementation, the react example is just using the wrong function to do the job. (vue example, and nextjs examples as well btw) We should either re-use the same widget instance or replace reset with destroy in the examples. There isn’t really a benefit in re-using the same widget instance atm (the workers are terminated anway) so I would suggest to just use .destroy().

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: ReCAPTCHA has already been rendered in ... - GitHub
I am trying to use the captcha.reset() function, but it doesn't seem to be doing what I expect. I have tried the reset()...
Read more >
react-google-recaptcha re-rendering when setstate
This is happening because of setEmail(email) in handleEmailBlur function. If I comment out setEmail(email), Captcha does not re-render itself.
Read more >
How to solve too many re-renders error in ReactJS?
“Too many re-renderers” is a React error that happens after you have reached an infinite render loop, typically caused by code that in...
Read more >
Google recaptcha hides after changing component via react ...
Coding example for the question Google recaptcha hides after changing component via react-router-Reactjs.
Read more >
I'm Not a Robot! So Why Won't Captchas Believe Me? - WIRED
The goal of captcha is to create tests or puzzles that humans can solve but bots can't—so you, a mere mortal, might have...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found