motiondivision / motion

A modern animation library for React and JavaScript
https://motion.dev
MIT License
25.96k stars 851 forks source link

[BUG] NextJs Link and page transition animations breaks and adds several pages. #2693

Closed J4v4Scr1pt closed 4 months ago

J4v4Scr1pt commented 5 months ago

I'm trying to animate transition between pages in a NextJs application (app router). All works fine but if you click the links back and forth a bit to fast AnimatePresence will have two animation.div's. I can't find a good solution on how to handle this.

1c5a9002ffb4587a4ee42f5f6d15a493

React tree without bugg: image

React tree with bugg: image

It can even add several pages: image

Steps to reproduce:

Stackblitz: https://stackblitz.com/edit/stackblitz-starters-xnrzd1?file=package.json,app%2Flayout.tsx,app%2FPageTransitionEffect.tsx