adobe / react-spectrum

A collection of libraries and tools that help you build adaptive, accessible, and robust user experiences.
https://react-spectrum.adobe.com
Apache License 2.0
12.73k stars 1.09k forks source link

The onAction handler is called twice when passed to MenuItem. #6643

Closed GuoXiaoyang closed 2 months ago

GuoXiaoyang commented 3 months ago

Provide a general summary of the issue here

After we upgraded our react-aria to 3.33.1, the onAction handler which passed to MenuItem directly was broken. It is called twice but not once only.

I noticed the change was introduced in this pull request: https://github.com/adobe/react-spectrum/pull/5874/files#diff-2237da4ee227fcc1c1be60b57ee78479c8cbac8679abfc5de478689e90e0adaf. And the added test case is passed unexpectedly: https://github.com/adobe/react-spectrum/pull/5874/files#r1658273241

πŸ€” Expected Behavior?

The onAction handler is called only once when passed to MenuItem.

😯 Current Behavior

The onAction handler is called twice when passed to MenuItem.

πŸ’ Possible Solution

No response

πŸ”¦ Context

No response

πŸ–₯️ Steps to Reproduce

https://github.com/adobe/react-spectrum/pull/5874/files#r1658273241

image

Version

3.33.1

What browsers are you seeing the problem on?

Chrome

If other, please specify.

No response

What operating system are you using?

macOS 14.5

🧒 Your Company/Team

No response

πŸ•· Tracking Issue

No response

snowystinger commented 3 months ago

Thanks for reporting, it looks like

item.props.onAction
&&
props.onAction

We should check if any of the other collections suffer from this. We may just be missing some prioritization on calling them, an else if, instead of just an if.

https://github.com/adobe/react-spectrum/blob/b46d23b9919eaec8ab1f621b52beced82e88b6ca/packages/%40react-aria/menu/src/useMenuItem.ts#L135