Skip to content
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

Firing animateChanges in useLayoutEffect if we have optimised animations to handoff #1840

Merged
merged 2 commits into from Dec 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/framer-motion/src/motion/utils/use-visual-element.ts
@@ -1,5 +1,5 @@
import * as React from "react"
import { useContext, useEffect, useRef } from "react"
import { useContext, useRef } from "react"
import { PresenceContext } from "../../context/PresenceContext"
import { MotionProps } from "../../motion/types"
import { useVisualElementContext } from "../../context/MotionContext"
Expand Down Expand Up @@ -48,7 +48,12 @@ export function useVisualElement<Instance, RenderState>(
visualElement && visualElement.render()
})

useEffect(() => {
/**
* If we have optimised appear animations to handoff from, trigger animateChanges
* from a synchronous useLayoutEffect to ensure there's no flash of incorrectly
* styled component in the event of a hydration error.
*/
useIsomorphicLayoutEffect(() => {
if (visualElement && visualElement.animationState) {
visualElement.animationState.animateChanges()
}
Expand Down