Skip to content

fix(state): isApiReady state update race condition - #421

Merged
damian-rodriguez-imi merged 3 commits into
masterfrom
damian/fix-state-race-condition
Aug 25, 2026
Merged

fix(state): isApiReady state update race condition#421
damian-rodriguez-imi merged 3 commits into
masterfrom
damian/fix-state-race-condition

Conversation

@damian-rodriguez-imi

@damian-rodriguez-imi damian-rodriguez-imi commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Description:

This fix addressed some edge cases where integrators' React implementation might defer committing the isApiReady state update. Since the existing hCaptcha's rendering logic was passed as a setState callback, delaying the commit also delayed hCaptcha rendering and the onLoad callback.

By using flushSync we force React to commit the state update synchronously, preventing present React scheduling or batching in the integrator from deferring it. The rendering logic then runs immediately after flushSync preserving this way the original order: commit isApiReady, render hCaptcha then call onLoad.

References:

https://react.dev/reference/react-dom/flushSync

@damian-rodriguez-imi
damian-rodriguez-imi marked this pull request as ready for review August 21, 2026 20:06
@damian-rodriguez-imi
damian-rodriguez-imi requested a review from a team as a code owner August 21, 2026 20:06
@damian-rodriguez-imi damian-rodriguez-imi self-assigned this Aug 21, 2026
@damian-rodriguez-imi
damian-rodriguez-imi merged commit 0f25fe3 into master Aug 25, 2026
4 checks passed
@damian-rodriguez-imi
damian-rodriguez-imi deleted the damian/fix-state-race-condition branch August 25, 2026 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants