Skip to content
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

[Component] - Select onValueChange bug #2062

Closed
acd02 opened this issue Apr 19, 2024 · 0 comments · Fixed by #2063
Closed

[Component] - Select onValueChange bug #2062

acd02 opened this issue Apr 19, 2024 · 0 comments · Fixed by #2063
Assignees
Labels
Component: select Related to alert-dialog component Component Related to a component Type: Bug A bug to fix

Comments

@acd02
Copy link
Contributor

acd02 commented Apr 19, 2024

While using the Select component in controlled mode, two issues have been observed:

  1. The onValueChange prop is executed on initial render, even though the value has not been changed.
  2. Each time the value changes, the onValueChange prop is executed twice.

Repro ➡ https://stackblitz.com/edit/stackblitz-starters-ulfsq2?file=pagesContent%2Findex.tsx

The problem seems to originate from packages/components/select/src/SelectContext.tsx, specifically this piece of code:

useEffect(() => {
  if (valueProp) setValue(valueProp)
}, [valueProp, setValue])

The weird thing is, when we comment out what's inside the useEffect, all the tests still pass. And even when we interact with the component in the browser (in both controlled and uncontrolled modes), it doesn't seem to break anything

@acd02 acd02 added this to the 2024 Q2 - Sprint 2 milestone Apr 19, 2024
@acd02 acd02 added Type: Bug A bug to fix Component Related to a component Component: select Related to alert-dialog component labels Apr 19, 2024
@acd02 acd02 self-assigned this Apr 19, 2024
acd02 added a commit that referenced this issue Apr 19, 2024
… prop

remove code causing excessive calls to the onValueChange prop

#2062
@acd02 acd02 linked a pull request Apr 19, 2024 that will close this issue
9 tasks
acd02 added a commit that referenced this issue Apr 22, 2024
… prop

remove code causing excessive calls to the onValueChange prop

#2062
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: select Related to alert-dialog component Component Related to a component Type: Bug A bug to fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants