vue3-infinite-loading
vue3-infinite-loading copied to clipboard
Potential for duplicate observers activation
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);
});
I was suffering this bug; thanks for the solution.