Fix: Wrap commit() in flushSync on Enter in NumberField#9683
Open
tariqrasheed172001 wants to merge 2 commits intoadobe:mainfrom
Open
Fix: Wrap commit() in flushSync on Enter in NumberField#9683tariqrasheed172001 wants to merge 2 commits intoadobe:mainfrom
tariqrasheed172001 wants to merge 2 commits intoadobe:mainfrom
Conversation
… is pressed in NumberField, commit() was called without flushSync, unlike the blur handler which wraps commit() in flushSync. This caused controlled form libraries reading React state immediately after Enter to receive stale values instead of the committed value. The browser synthesizes a trusted click on the form's submit button when Enter is pressed, firing onSubmit before the unguarded commit() has flushed to React state. This change wraps commit() in flushSync on Enter, making it consistent with the blur behavior and ensuring the value is flushed synchronously before any consumer reads form state. Fixes adobe#9671
Member
|
@tariqrasheed172001 Hi, thanks for the PR! Would you mind signing the CLA as mentioned here? |
Author
|
@LFDanLu Sure. |
Author
|
Just closed/re-open switch for Adobe CLA re-check. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the inconsistency where
commit()is wrapped influshSyncon blur but not on Enter keydown inuseNumberField.Closes #9671
Problem
When a user types a value in NumberField and presses Enter:
commit()withoutflushSynconSubmitfires beforecommit()has flushed to React stateThis works correctly with native HTML forms because they read from the hidden input after
commit()has updatedstate.numberValue. But controlled form libraries that read React state directly are exposed to this race condition.Solution
Wrap
commit()influshSync()on Enter, consistent with how the blur handler already does it. This ensures the value is flushed synchronously before any consumer reads form state.✅ Pull Request Checklist:
📝 Test Instructions:
Before the fix:
defaultValue(e.g., 1)After the fix:
Existing behavior preserved:
🧢 Your Project:
Cryptlex (SaaS license management platform)