Child added animation is not working in react StrictMode (or in any other case where autoAnimate() is called twice)

Author: Zachary3234Created Jan 11, 2026Updated Apr 26, 2026
I found that auto-animate not working in react StrictMode initially, which renders component twice to help find bugs. So I tested and found that add animation will fail if autoAnimate is called twice (remove animation is fine). Here’s a minimal example: >
  • 1
  • 2
  • 3
I resolved it by checking whether the element already exists in mutationObservers before creating a new MutationObserver. Here's the relevant change: > if (!isDisabledDueToReduceMotion) { enabled.add(el) if (getComputedStyle(el).position === "static") { Object.assign(el.style, { position: "relative" }) } forEach(el, updatePos, poll, (element) => resize?.observe(element)) if (isPlugin(config)) { options.set(el, config as AutoAnimationPlugin) } else { options.set(el, { duration: 250, easing: "ease-in-out", ...(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) }