Skip to content

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

Open
damian-rodriguez-imi wants to merge 1 commit into
masterfrom
damian/fix-state-race-condition
Open

fix(state): isApiReady state update race condition#421
damian-rodriguez-imi wants to merge 1 commit 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

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
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.

1 participant