-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Open
Labels
Description
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
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a VueUse issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion.
- The provided reproduction is a minimal reproducible example of the bug.