-
Notifications
You must be signed in to change notification settings - Fork 1.2k
useNumberField: old value flash after blur in controlled mode #2870
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
Comments
Seems like this issue is still occurring. See working codesandbox and broken codesandbox. See reproduction above. |
Hey, so it looks like you're seeing an issue with StrictMode. If you remove that, your NumberField works perfectly. I'm not sure about the difference between 3.0.4 and 3.0.5 off the top of my head. When we tackle StrictMode, hopefully this will help though. |
Yes indeed, thanks! We came across a second issue that was "caused" by StrictMode (and React 18 related). Anyway thanks for these awesome libraries ( |
I'm also finding that only every second arrow key press works in Repro: https://codesandbox.io/s/practical-lake-47ptck?file=/src/App.js Is it worth creating an issue for this? Should I comment on #779? |
@peteragarclover I've made a comment so we know there is a second reported issue here. Thanks for reporting. |
🐛 Bug Report
When consuming
useNumberField
in controlled mode the previously set value will be visible briefly after blurring the input.🤔 Expected Behavior
The input should not display the "old" value after blurring.
😯 Current Behavior
After entering a new value in controlled mode and blurring the input the previous value will flash up for a second before the new value from props is applied again.
💁 Possible Solution
The visual bug seems to be related to this
useEffect
inuseNumberFieldState
:https://github.com/adobe/react-spectrum/blob/main/packages/@react-stately/numberfield/src/useNumberFieldState.ts#L103
Switching the effect to a
useLayoutEffect
removes the visual glitch as the updated value is set before the browser repaints.However, the input will still have one render cycle with the old value again (can be seen in code sample)
💻 Code Sample
Codepen showing the issue: https://codesandbox.io/s/amazing-oskar-zb73h8?file=/src/App.js
(based on controlled example in docs, glitch is also visible there)
To reproduce:
console.log
shows the single render cycle with the old value after blurring🌍 Your Environment
The text was updated successfully, but these errors were encountered: