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
Batch async state updates #2006
base: main
Are you sure you want to change the base?
Conversation
This pull request is being automatically deployed with ZEIT Now (learn more). 🔍 Inspect: https://zeit.co/jared/formik-docs/3dgqckx05 |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 200cdee:
|
These warnings are causing a lot of clutter in our test output. Looks like this issue is related: #1543 |
any updates on this? |
any updates? |
I don't think the React-redux does it like this to support React Native: https://github.com/reduxjs/react-redux/blob/v7.2.3/src/utils/reactBatchedUpdates.js export { unstable_batchedUpdates } from 'react-dom'; https://github.com/reduxjs/react-redux/blob/v7.2.3/src/utils/reactBatchedUpdates.native.js export { unstable_batchedUpdates } from 'react-native'; The file structure would need to be preserved for this trick to work though, or you would have to output a separate bundle for RN. Alternatively, using some sort of dependency injection based on the entry point could also do it (formik-dom/formik-native?) |
Async validations trigger
act
warnings during testing:When validating, the next error state is updated at the earliest at the end of the current tick. These will cause act warnings unless they take place during the window of an async
act
call. It's hard to know the timing of these, so it should be Formik's responsiblity to prevent these warnings.What
act
does is basically forcing updates to be batched. React automatically batches updates in event handlers and component lifecycles/effects, but for other updates we need to useunstable_batchedUpdates
. Unfortunately it's not exported by React itself so we need to use some requires with fallbacks to support different renderers.