webiny / webiny-js

Open-source serverless enterprise CMS. Includes a headless CMS, page builder, form builder, and file manager. Easy to customize and expand. Deploys to AWS.
https://www.webiny.com
Other
7.22k stars 588 forks source link

fix(form): register field in the current animation frame #4177

Closed Pavel910 closed 2 weeks ago

Pavel910 commented 2 weeks ago

Changes

This PR ensures that form fields are registered into the form as soon as the useBind is executed, within the same render cycle. Previously, form fields were registered within a requestAnimationFrame callback. In most cases, that was not an issue, until we ran into a very interesting use case, where we would call bind.onChange, and it would not be able to set the value, because the field was not yet registered into the form.

How Has This Been Tested?

Manually. Unfortunately, I was unable to simulate this bug using Jest and React Testing Library, because the bug only manifests itself on the first render cycle.