Skip to content

Conversation

@lux-v
Copy link
Contributor

@lux-v lux-v commented Jun 27, 2025

I've seen a few places in UCLA that they forgot to remove event listener when component unmounts, which can lead to memory leaks etc.

I added a simple composable that automatically adds/removes event listener using onMount/onBeforeUnmount which can be useful for us as well.

Since we are using Vite with our Nuxt3 apps, Vite will perform tree shaking when building a project and get rid of unused code (including custom composables as well) and will not include them in the final bundle

@lux-v lux-v requested review from dChiamp and drewbaker June 27, 2025 11:44
@drewbaker
Copy link
Member

When are you using an event listener manually? Rather than just using the Vue @click events?

the only time I can think you’d need an event handler is for some global event like a key press. In that case, use VueUse not a manual event handler.

Not sure if UCLA users VueUse or not, but we include it.

@lux-v
Copy link
Contributor Author

lux-v commented Jun 27, 2025

When are you using an event listener manually? Rather than just using the Vue @click events?

the only time I can think you’d need an event handler is for some global event like a key press. In that case, use VueUse not a manual event handler.

Not sure if UCLA users VueUse or not, but we include it.

Yes, it's exactly for that purpose: keypress, resize, scroll etc.

What do you mean by saying 'use VueUse' in that case? Does VueUse already provide this exact composable?

@drewbaker
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants