motiondivision / motiondivision/motion

[BUG] `popLayout` position incorrectly calculated

Open
#2,348 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
33.7k
Forks
1.4k
Avg merge
1d 10h
Merged PRs (30d)
14

Description

Bug description

When in the popLayout mode of AnimatePresence, the locations of the absolute-positioned, exiting elements are incorrectly calculated if their container is not position: static. This is because the absolutely-positioned top and left are calculated in relation to the window, but after applied, they're relative to the non-static container.

Note: The bug is not visible if the non-static container's top is aligned with the top edge of the window.

CodeSandbox repro

https://codesandbox.io/s/framer-motion-animatepresence-poplayout-mode-forked-8lyz9x?file=/src/App.tsx

Steps to reproduce

  1. Observe the motion of the disappearing elements with the fixed checkbox not checked.
  2. Check the fixed checkbox.
  3. Observe the motion of the disappearing elements with the fixed checkbox checked.

Note the difference of direction toward which the exiting element disappears: it's toward its center in a static container and towards bottom in fixed container.

Expected behavior

Regardless of the position of the container, elements should disappear to their center instead of drop down.

Video or screenshots

https://github.com/framer/motion/assets/6209244/2d622be2-c873-4aae-a101-452ba9639b37

Additional notes

Contrary to the first impression, the described conditions in which this bug reveals itself are not really a big edge case: bottom right corner of the window is the most popular location for all sorts of toast / notification components, so implementing such a list with sleek presence and layout animations using Motion is potentially quite a popular use case.

Regardles, Motion is fantastic - I love its superpowers, great job guys 🏅

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked CodeSandbox reproduction at src/App.tsx and compare AnimatePresence behavior with the container's position set to fixed and left unset. Trace the popLayout positioning entry point in the Motion source, then verify that exiting elements disappear toward their center regardless of the container position.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.