-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
fix(Select): HiddenSelect Component Auto-Completion Issue #7670
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e752670
address autofill issue
igorlima 8cdc137
lint
igorlima 4a2615e
remove unnecessary change
igorlima bffedc9
Update packages/@react-aria/select/src/HiddenSelect.tsx
igorlima d9293d3
remove unnecessary variable declaration
igorlima 9224e82
Merge branch 'main' into issue-7660
reidbarber File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reading from a ref during render is typically unsafe and unfortunately it's hard to tell when it potentially breaks React's concurrent mode since they don't expose any of that for tests.
We should try to find another way to handle this.
does the hidden select fire an onChange that we aren't listening to? I'm worried that the state doesn't know about this value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for raising this concern!
This repository already has a lint rule to detect issues related to reading from refs during rendering. In my initial proposal, the lint failed because it did indeed read from a ref during render. However, I addressed this, and the lint has now passed.
screenshot lint fixed
Regarding the use of
selectRef
, there are existing references to it in this function:useFormValidation
and passesselectRef
as a parameter. WithinuseFormValidation
,ref
is heavily used to access the ref's value.@snowystinger given that the lint passes for this case and considering the function's existing use of refs, I believe it’s safe to use
selectRef
here. 🙏There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The concern that the state might not be aware of the value is valid. I added a
debugger
to the demo link to check everything is still working as intended. By opening the DevTools and triggering the native browser autocomplete, we can see that the value is set. Additionally, we can check all values when we submit the form.screenshots
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I had a chance today to look into this. I think the behavior is actually related to the controlled value being initially set. I'm making a recommendation below for how to handle it so we don't need to read the ref during render and we can rely on the state itself.
the
onChange
fired by autofill will have asvalue
whatever 'controlled' value is already there. It doesn't fire an onChange with the new value.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything seems to work as intended, and the code looks much more straightforward and cleaner now. Thanks for the help!