From f703985b4cce72e9fdf5e9c44e7f04c0c8d74d94 Mon Sep 17 00:00:00 2001 From: Kai Gritun Date: Mon, 9 Feb 2026 21:13:27 -0500 Subject: [PATCH] fix: prevent duplicate MutationObserver when autoAnimate called twice When autoAnimate() is called multiple times on the same element (e.g., in React StrictMode which renders components twice), a new MutationObserver was being created each time. This caused child-added animations to fail because multiple observers were interfering with each other. Now we check if a MutationObserver already exists for the element before creating a new one. This ensures idempotent behavior when autoAnimate() is called repeatedly on the same element. Fixes #232 --- src/index.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index 772b21f..e6d1cb2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -905,9 +905,11 @@ export default function autoAnimate( ...(config as Partial), }) } - const mo = new MutationObserver(handleMutations) - mo.observe(el, { childList: true }) - mutationObservers.set(el, mo) + if (!mutationObservers.has(el)) { + const mo = new MutationObserver(handleMutations) + mo.observe(el, { childList: true }) + mutationObservers.set(el, mo) + } parents.add(el) } }