Closed spaceemotion closed 3 months ago
I've been looking at the code and am wondering why the "is the user using a keyboard or a finger/mouse" checks aren't something that's handled on a more global level (unless I misread what the handlers actually do)
I'm willing to work on this.
I think you're absolutely correct @spaceemotion - doesn't seem there's any reason to keep attaching and removing these event handlers per every keystroke and we should just have a global ref that's shared across all "Menu"-like components. From what it seems this was ported as is from Radix UI and never touched after.
Looks like a perfect spot for createSharedComposable
from vueuse.
Environment
Link to minimal reproduction
https://stackblitz.com/edit/hnxppu?file=src%2Fmain.ts (if profiling, check the preview frame, and then you'll find a ton of method calls happening per keydown event)
Steps to reproduce
Type in the input box and see the listener count in the dev tools profiler go up for no good reason.
Describe the bug
In my app I have a lot of potential menus that can be opened. We're talking three digits here. Radix-vue adds one-off event listeners on every keystroke which adds a ton of new event listeners and causes a lot of memory usage (that has to be GCed).
Expected behavior
Radix-Vue not creating that many event listeners. Maybe a shared event pool could help?
Context & Screenshots (if applicable)
From what I can tell the lines that create the event listeners are: https://github.com/radix-vue/radix-vue/blob/562c896ba609028a7fbd5d343aeb70fcde26f211/packages/radix-vue/src/Menu/MenuRoot.vue#L78-L85
Here are some profiler shots, micro view:
and macro view:
The images show a range of around 4k listeners suddenly jumping up to 23k listeners within 3 seconds as I am typing in my app.