motiondivision / motiondivision/motion
[BUG] `popLayout` position incorrectly calculated
Nobody has claimed this yet.
- 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
Steps to reproduce
- Observe the motion of the disappearing elements with the
fixedcheckbox not checked. - Check the
fixedcheckbox. - Observe the motion of the disappearing elements with the
fixedcheckbox 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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