-
Notifications
You must be signed in to change notification settings - Fork 79
[Dropdown]: stale closure in onValueChange and onClose callbacks #3011
Copy link
Copy link
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Steps to Reproduce
- Open this sandbox. It uses UUI v.5.9.1
- Click on the "Open dropdown" button
- Click on the "Example 1" option. This will update the local state's value and close the dropdown using the
bodyProps.onClosecallback- The state's update is wrapped in
flushSyncto ensure that the update happens before the dropdown is closed
- The state's update is wrapped in
- Check the console
- Change the version of UUI packages in
package.jsonto 6.0.0 or later and reinstall dependencies via console (pnpm install) - Repeat steps 2-4
Actual result
In the 5.9.1 version, when the dropdown is closed, the onValueChange and onClose callbacks of the Dropdown component have access to the latest value of the local state. Thus, they log to the console "example-1".
In the 6.0.0 or later versions, when the dropdown is closed, the onValueChange and onClose callbacks of the Dropdown component have access only to the initial value of the local state. Thus, they log to the console undefined.
Expected result
The behavior should be the same as in 5.9.1.
Additional information
- Similar bug, but in a different component
- In 6.0.0,
Dropdownhas been migrated to a function component
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Type
Projects
Status
Closed