motion icon indicating copy to clipboard operation
motion copied to clipboard

[BUG] PresenceContext seems not to pass down custom prop to entire component tree

Open patricknick opened this issue 6 years ago • 1 comments

1. Read the FAQs 👇

2. Describe the bug

When using the custom prop on AnimatePresence, these values are passed down to unmounting motion components and can be used in dynamic variants. But if you wrap the animating component with another motion component, plus you specify initial, animate and exit, the propagation stops. You can only avoid this if you specify these three properties on the inner motion comp.

3. IMPORTANT: Provide a CodeSandbox reproduction of the bug

Repro: https://codesandbox.io/s/framer-motion-image-gallery-boj95?file=/src/Example.tsx Working example: https://codesandbox.io/s/framer-motion-image-gallery-oiyec?file=/src/Example.tsx

4. Steps to reproduce

Steps to reproduce the behavior:

  1. In the slideshow, press the arrow keys.
  2. The animation is confusing, as images exit in the wrong directions.

5. Expected behavior

From the documentation I expect the custom values available on every level of the component tree, no matter where I specify the initial, animate and exit props.

6. Video or screenshots

--

7. Environment details

framer-motion: 1.11.1

FAQs

AnimatePresence isn't working

Have all of its immediate children got a unique key prop that remains the same for that component every render?

// Bad: The index could be given to a different component if the order of items changes
<AnimatePresence>
  {items.map((item, index) => <Component key={index} />)}
</AnimatePresence>
// Good: The item ID is unique to each component
<AnimatePresence>
  {items.map((item, index) => <Component key={item.id} />)}
</AnimatePresence>

Is the AnimatePresence correctly outside of the controlling conditional? AnimatePresence must be rendered whenever you expect an exit animation to run - it can't do so if it's unmounted!

// Bad: AnimatePresence is unmounted - exit animations won't run
{isVisible && (
  <AnimatePresence>
    <Component />
  </AnimatePresence>
)}
// Good: Only the children are unmounted - exit animations will run
<AnimatePresence>
  {isVisible && <Component />}
</AnimatePresence>

patricknick avatar Jun 22 '20 17:06 patricknick

Seems to work as expected in later versions

mattgperry avatar Mar 03 '21 15:03 mattgperry