Repository: next.js
Issue: Framer Motion AnimatePresence PopLayout
Labels: bug

### Verify canary release

- [X] I verified that the issue exists in the latest Next.js canary release

### Provide environment information

```bash
Local
```


### Which area(s) of Next.js are affected? (leave empty if unsure)

App Router

### Link to the code that reproduces this issue or a replay of the bug

NA

### To Reproduce

export default function Carousel({ images, autoDirection }: { images: string[]; autoDirection: number }) {
  const [[page, direction], setPage] = useState([0, autoDirection]);
  const [mounted, setMounted] = useState(false);

  // We only have 3 images, but we paginate them absolutely (ie 1, 2, 3, 4, 5...) and
  // then wrap that within 0-2 to find our image ID in the array below. By passing an
  // absolute page index as the `motion` component's `key` prop, `AnimatePresence` will
  // detect it as an entirely new image. So you can infinitely paginate as few as 1 images.
  const imageIndex = wrap(0, images?.length, page);
  //console.log(imageIndex);
  const paginate = (newDirection: number) => {
    return setPage([page + newDirection, newDirection]);
  };
  useEffect(() => {
    if (!mounted) {
      setMounted(true);
      return;
    }
    const intervalId = setInterval(() => {
      paginate(autoDirection);
    }, 8000);
    return () => clearInterval(intervalId);
  });

  return (
    <>
      <AnimatePresence  mode="popLayout" initial={false} custom={direction}>
        <motion.img
          key={page}
          src={images[imageIndex] ?? ''}
          width={1600}
          height={900}
          alt="carousel"

          className="object-cover rounded-lg shadow-lg"
          custom={direction}
          variants={variants}
          initial="enter"

          animate="center"
          exit="exit"
          transition={{
            x: { type: "spring", stiffness: 150, damping: 30 },
            opacity: { duration: 0.1 },
          }}
          drag="x"
          dragConstraints={{ left: 0, right: 0 }}
          dragElastic={1}

          onDragEnd={(e, { offset, velocity }) => {
            const swipe = swipePower(offset.x, velocity.x);

            if (swipe < -swipeConfidenceThreshold) {
              paginate(1);
            } else if (swipe > swipeConfidenceThreshold) {
              paginate(-1);
            }
          }}/>

      </AnimatePresence>
    </>
  );
}


### Describe the Bug

NotFoundError: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.

Call Stack
eval
node_modules/framer-motion/dist/es/components/AnimatePresence/PopChild.mjs (65:0)
safelyCallDestroy
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (19747:0)
commitDeletionEffectsOnFiber
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21051:0)
recursivelyTraverseDeletionEffects
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (20904:0)
commitDeletionEffectsOnFiber
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21132:0)
recursivelyTraverseDeletionEffects
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (20904:0)
commitDeletionEffectsOnFiber
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21079:0)
commitDeletionEffects
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (20891:0)
recursivelyTraverseMutationEffects
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21291:0)
commitMutationEffectsOnFiber
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21327:0)
recursivelyTraverseMutationEffects
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21305:0)
commitMutationEffectsOnFiber
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21327:0)
recursivelyTraverseMutationEffects
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21305:0)
commitMutationEffectsOnFiber
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21473:0)
recursivelyTraverseMutationEffects
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21305:0)
commitMutationEffectsOnFiber
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21473:0)
recursivelyTraverseMutationEffects
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21305:0)
commitMutationEffectsOnFiber
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21473:0)
recursivelyTraverseMutationEffects
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21305:0)
commitMutationEffectsOnFiber
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21473:0)
recursivelyTraverseMutationEffects
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21305:0)
commitMutationEffectsOnFiber
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21473:0)
recursivelyTraverseMutationEffects
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21305:0)
commitMutationEffectsOnFiber
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21473:0)
recursivelyTraverseMutationEffects
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21305:0)
commitMutationEffectsOnFiber
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21327:0)
recursivelyTraverseMutationEffects
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21305:0)
commitMutationEffectsOnFiber
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21758:0)
recursivelyTraverseMutationEffects
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21305:0)
commitMutationEffectsOnFiber
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21327:0)
recursivelyTraverseMutationEffects
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21305:0)
commitMutationEffectsOnFiber
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21758:0)
recursivelyTraverseMutationEffects
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21305:0)
commitMutationEffectsOnFiber
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21758:0)
recursivelyTraverseMutationEffects
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21305:0)
commitMutationEffectsOnFiber
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21327:0)
recursivelyTraverseMutationEffects
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21305:0)
commitMutationEffectsOnFiber
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21366:0)
recursivelyTraverseMutationEffects
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21305:0)
commitMutationEffectsOnFiber
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21327:0)
recursivelyTraverseMutationEffects
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21305:0)
commitMutationEffectsOnFiber
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21366:0)
recursivelyTraverseMutationEffects
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21305:0)
commitMutationEffectsOnFiber
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21327:0)
recursivelyTraverseMutationEffects
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21305:0)
commitMutationEffectsOnFiber
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21668:0)
recursivelyTraverseMutationEffects
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21305:0)
commitMutationEffectsOnFiber
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21602:0)
recursivelyTraverseMutationEffects
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21305:0)
commitMutationEffectsOnFiber
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (21327:0)

### Expected Behavior

Framer Motion AnimatePresence with only one child motion.image carousel removing child correctly

### Which browser are you using? (if relevant)

Chrome Canary release

### How are you deploying your application? (if relevant)

_No response_