Skip to content

useEventBus causes memory leaks in some scenarios #3498

@Renhor

Description

@Renhor

Describe the bug

Combination with pinia storeToRefs + SSR (nuxt3) + useEventBus().on causes memory leaks.

I'm not sure it directly related to useEventBust or storeToRefs pinia or the way i use them together ;(

index.vue

const store = useSomeStore();
const { form } = storeToRefs(store);

// ok
// useSomeComponentLogic(store.form);

// cause leaks
useSomeComponentLogic(form);

useSomeComponentLogic.ts

export const useSomeComponentLogic = (_ref: MaybeRef<{ data: string }>) => {
  const bus = useAppEventBus(AppEvent.Test);
  const ref = computed(() => unref(_ref));

  // causes leak

  bus.on(() => {
    ref.value.data = 'test';
    console.log('im bus');
  });

  // ok

  // onMounted(() => {
  //   bus.on(() => {
  //     ref.value.data = 'test';
  //     console.log('im bus');
  //   });
  // })
};

Reproduction

https://github.com/Renhor/useEventBus-leak

System Info

System:
    OS: macOS 14.0
    CPU: (10) arm64 Apple M1 Max
    Memory: 6.37 GB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.17.1 - ~/.nvm/versions/node/v18.17.1/bin/node
    npm: 9.6.7 - ~/.nvm/versions/node/v18.17.1/bin/npm
  Browsers:
    Chrome: 118.0.5993.88
    Safari: 17.0
  npmPackages:
    @vueuse/core: ^10.5.0 => 10.5.0 
    @vueuse/nuxt: ^10.5.0 => 10.5.0 
    vue: ^3.3.6 => 3.3.6

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy