vue3-infinite-loading icon indicating copy to clipboard operation
vue3-infinite-loading copied to clipboard

Potential for duplicate observers activation

Open fukasawah opened this issue 2 years ago • 1 comments

The onMounted hook in the infinite-loading component is asynchronous. If the parent component's onMounted process updates the infinite-loading's identifier, the watch function might get triggered first.

Reproduction Code: https://codepen.io/fukasawah/pen/poGjPaG

A suggested fix would be to call observer?.disconnect() in the infinite-loading component's onMounted hook to ensure any existing observer is disconnected before a new one is initiated, reducing the likelihood of having multiple active observers.

onMounted(async () => {
  params.parentEl = await getParentEl(target!);
  observer?.disconnect(); // <= here
  observer = startObserver(params);
});

fukasawah avatar Oct 26 '23 16:10 fukasawah

I was suffering this bug; thanks for the solution.

agm1984 avatar Nov 07 '23 21:11 agm1984