react-spectrum: Performance degradation in `onPress`

Provide a general summary of the issue here

After updating react-aria-components to the latest version (1.8.0) we faced a significant performance degradation, increasing passiveMountOnFiber duration from roughly 200ms to 1.8s(!)

After digging into the issue we found that the root cause is in usePress hook: https://github.com/adobe/react-spectrum/blob/main/packages/%40react-aria/interactions/src/usePress.ts#L821 caused by: https://github.com/adobe/react-spectrum/pull/8047

Here’s a recording from chrome devtools:

Trace-20250412T155902.json

Here’s a screenshot, you can see that usePress schedules over 2000 style recalculations.

Image

🤔 Expected Behavior?


😯 Current Behavior


💁 Possible Solution


🔦 Context


🖥️ Steps to Reproduce


Version

1.8.0

What browsers are you seeing the problem on?

Chrome

If other, please specify.

No response

What operating system are you using?

MacOS

🧢 Your Company/Team

No response

🕷 Tracking Issue

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 3
  • Comments: 18 (6 by maintainers)

Most upvoted comments

@MrFlashAccount Thanks for the repro 👍

While I can observe the forced reflow now, on my machine, the commitPassiveMountEffects only takes ~120ms?

That’s a lot, don’t you think?

@devongovett Shouldn’t the override in #8047 also be running on every render, making this degradation possibly worse? Currently the useEffect is dependent on domRef, but what if touch-action: auto were to apply conditionally?

@MrFlashAccount Unfortunately I can’t reproduce the degradation just by rendering 2000 <Button />'s.

Maybe it makes sense to add a data-pressable attribute on each element instead? Optionally, we could then inject a global style with low specificity so user styles would still override. Ideally users would still just set <meta name="viewport" content="width=device-width"> whenever possible.