Conversation
When a single value is supplied, we should do an extra check to ensure the label is not empty. This reduces the likelihood of infinite loops when consumers supply incorrect values to Autocomplete v2.
An example of an invalid label is an empty string:
```tsx
value={{label: '' }}
```
This case above is a realistic case where the consumer did not have a selection, and instead should have supplied `undefined` in this case.
Checking for a valid label is just an extra precaution we're putting in place to prevent bad loops caused by our useAutocomplete internal hook logic.
jdeichert
commented
Jan 21, 2026
|
|
||
| describe("invalid value handling", () => { | ||
| describe("when inputValue is empty and value has empty label", () => { | ||
| it("does not call onChange", async () => { |
Contributor
Author
There was a problem hiding this comment.
This test was added before the fix, and was failing as expected. Now passing 👍
Deploying atlantis with
|
| Latest commit: |
8e8da81
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://738c45df.atlantis.pages.dev |
| Branch Preview URL: | https://job-148590-prevent-potential.atlantis.pages.dev |
ZakaryH
reviewed
Jan 21, 2026
ZakaryH
reviewed
Jan 27, 2026
ZakaryH
approved these changes
Jan 30, 2026
Contributor
ZakaryH
left a comment
There was a problem hiding this comment.
LGTM
while I would prefer consumers not provide values such as an empty label string, I understand RHF and default, empty states can complicate that.
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.
Motivations
This PR introduces an extra safety check for the Autocomplete v2
valueprop.There's a case in consumer code where they supplied an empty label (equivalent to this
value={{ label: "" }}) instead of supplyingundefinedwhen nothing is selected. This empty label can lead to an infinite loop due tovaluebeing non-null,useAutocompletewas treating that ashasSelection=truewhich then led to an effect running unnecessarily, to clear the value withonChange(undefined). The consumer code then did the exact same thing in response to thatonChangecall, supplying an empty label, thus causing the loop.This is now fixed by treating an empty/nullish
value.labelas an invalid value, making it match the unselected case just like ifvaluewasundefined. This prevents consumer code from accidentally triggering this code path leading to an infinite loop.Ideally consumers don't supply invalid labels. However, it's possibly due to the fact that ReactHookForm does not allow passing
undefinedto the controller, so consumers are working around that in their own ways. Regardless, adding this precaution is a pretty cheap and effective way to avoid potential infinite loops that end up coming back to us for investigation.Changes
Fixed
Testing
docs/components/Autocomplete/WebV2.stories.tsxTemplateFlatto the code example belowChanges can be tested via Pre-release
In Atlantis we use Github's built in pull request reviews.