-
-
Notifications
You must be signed in to change notification settings - Fork 829
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure AnimatePresence executes exiting animations in sequence #2477
Conversation
|
||
const exitingChildren = useRef( | ||
new Map<ComponentKey, ReactElement<any> | undefined>() | ||
).current | ||
|
||
// Keep a living record of the children we're actually rendering so we | ||
// can diff to figure out which are entering and exiting | ||
const presentChildren = useRef(childrenToRender) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed presentChildren
for clarity - filteredChildren
, exitingChildren
and allChildren
are enough to maintain the status quo
@mattgperry |
In the past, I've written PR to fix errors in this regard. I'm linking because I think it would be good to refer to! |
Thanks @JaeSeoKim! Just had a quick look-through, and it seems like there are two main problems the PR was trying to solve - (1) bringing This PR tries to solve a different problem where a quick waterfall of existing elements do not exit in sequence (i.e. elements exit in quick succession, but in different times), instead of how the exiting/current/entering elements should be rendered - though it seems like a pretty interesting problem to solve 🦄 |
Thanks for the excellent PR and apologises it's taken a while to get to. I'll merge and publish today. |
Ah apologises. I had to revert this PR because of these lines: const filteredChildren = useRef(onlyElements(children))
filteredChildren.current = onlyElements(children) The intention here is to update Therefore, it's only safe to assign a const filteredChildren = useRef(null)
if (!filteredChildren.current)
filteredChildren.current = onlyElements(children) (Which obviously isn't the intent of this line) Otherwise what we have is a situation where React could prospectively render something with a |
Another issue - or maybe it's been fixed in the meantime? - is I ported the tests in this PR to |
This PR fixes #2462.
It also fixes 3 tests (i.e. "Only renders one child at a time if mode === 'wait'", "Fast animations with wait render the child content correctly", "Fast animations with wait render the child content correctly (strict mode disabled)") where not enough leeway is given for exiting elements to completely exit from the DOM.
Before
framer-motion-bug.mov
Now
Screen.Recording.2024-01-06.at.00.54.36.mov