Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: login recaptcha #4876

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

alexevladgabriel
Copy link

The token state was not updating on verification process immediately, instead using useState was replaced with useRef.

@matthewpi
Copy link
Member

I believe I noticed this when I had reCaptcha enabled but I always disable it in my dev environments for obvious reasons, but I'm wondering why this change is required for develop but not 1.0-develop. Both have identical code; could it be due to React 18 running hooks twice? If so, this change should go into 1.0-develop, then develop assuming it doesn't break 1.0.

@alexevladgabriel
Copy link
Author

alexevladgabriel commented Oct 3, 2023

I believe I noticed this when I had reCaptcha enabled but I always disable it in my dev environments for obvious reasons, but I'm wondering why this change is required for develop but not 1.0-develop. Both have identical code; could it be due to React 18 running hooks twice? If so, this change should go into 1.0-develop, then develop assuming it doesn't break 1.0.

What I had observed was that when calling onVerify function the state to update the token was not running concurrently and being later executed. Setting a timeout for the submitForm function would solve the problem without using refs, but doesn't feel a good practice for me.

Found this:
Much like .setState() in class components created by extending React.Component or React.PureComponent, the state update using the updater provided by useState hook is also asynchronous, and will not be reflected immediately.

Also, the main issue here is not just the asynchronous nature but the fact that state values are used by functions based on their current closures, and state updates will reflect in the next re-render by which the existing closures are not affected, but new ones are created. Now in the current state, the values within hooks are obtained by existing closures, and when a re-render happens, the closures are updated based on whether the function is recreated again or not.

@Danieljunek17
Copy link

btw this does fix the problem in the development branch and should be merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 👀 In review
Development

Successfully merging this pull request may close these issues.

None yet

3 participants