Skip to content

Potential listener leak on component interaction #8398

@josh-mora-hg

Description

@josh-mora-hg

Provide a general summary of the issue here

I created a barebones/isolated react app to do some performance profiling on react-aria-components. Here is the sandbox link: https://wjwpsh.csb.app/. The only thing being done here is rendering of Button imported from react-aria-components. Based on performance profiling, the number of listeners is increasing on each click, suggesting that old listeners are not being cleaned up. This is leading to an "ascending staircase" graph for listeners:

Image

  • Each "step" is a button click
  • The number of listeners at the start of the recording is 224
  • The number of listeners at the end of the recording is 551

 

Here is the "Call tree" of the recording

Image

🤔 Expected Behavior?

Listener count should not keep climbing as interactions occur

😯 Current Behavior

Listener count is climbing on each button click

💁 Possible Solution

Based on the recording "Call tree," it seems like usePress and/or useGlobalListeners (used by usePress) may need to be evaluated with respect to how listeners are managed.

🔦 Context

Here is a GIF of the profiler recording

Image

🖥️ Steps to Reproduce

  • Go to this sandbox: https://wjwpsh.csb.app/
  • Open up Chrome devtools > Performance tab
  • Check "Memory" checkbox, hit garbage collection brush icon button
  • Hit record
  • Interact with the button (click and/or keyboard interactions) for 10 seconds
  • Stop the recording
  • Note the result "ascending staircase" graph for the number of listeners

Version

react-aria-components@1.10.1

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions