Skip to content

[Dropdown]: stale closure in onValueChange and onClose callbacks #3011

@vasilii-kovalev

Description

@vasilii-kovalev

Steps to Reproduce

  1. Open this sandbox. It uses UUI v.5.9.1
  2. Click on the "Open dropdown" button
  3. Click on the "Example 1" option. This will update the local state's value and close the dropdown using the bodyProps.onClose callback
    • The state's update is wrapped in flushSync to ensure that the update happens before the dropdown is closed
  4. Check the console
  5. Change the version of UUI packages in package.json to 6.0.0 or later and reinstall dependencies via console (pnpm install)
  6. 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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status

Closed

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions