Skip to content

Commit

Permalink
fix: form-control concurrent mode issues
Browse files Browse the repository at this point in the history
  • Loading branch information
segunadebayo committed Mar 26, 2021
1 parent a58b724 commit 3cc77ce
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/soft-flowers-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@chakra-ui/form-control": patch
---

Fix concurrent mode issue with setting state in focus event handler. We use
`withFlushSync` helper to achieve this.
4 changes: 2 additions & 2 deletions packages/form-control/src/form-control.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
useStyles,
HTMLChakraProps,
} from "@chakra-ui/system"
import { createContext, cx, __DEV__ } from "@chakra-ui/utils"
import { createContext, cx, withFlushSync, __DEV__ } from "@chakra-ui/utils"
import * as React from "react"

export interface FormControlOptions {
Expand Down Expand Up @@ -107,7 +107,7 @@ function useFormControlProvider(props: FormControlContext) {
isReadOnly: !!isReadOnly,
isDisabled: !!isDisabled,
isFocused: !!isFocused,
onFocus: setFocus.on,
onFocus: withFlushSync(setFocus.on),
onBlur: setFocus.off,
hasFeedbackText,
setHasFeedbackText,
Expand Down

0 comments on commit 3cc77ce

Please sign in to comment.