Skip to content

Commit

Permalink
Merge pull request #2852 from framer/fix/double-mount-update
Browse files Browse the repository at this point in the history
Fix double `.update()` call on mount
  • Loading branch information
mergetron[bot] authored Oct 31, 2024
2 parents c02ec5a + c3593da commit f3468b3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/framer-motion/src/motion/utils/use-visual-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,15 @@ export function useVisualElement<Instance, RenderState>(
)
}

const isMounted = useRef(false)
useInsertionEffect(() => {
visualElement && visualElement.update(props, presenceContext)
/**
* Check the component has already mounted before calling
* `update` unnecessarily. This ensures we skip the initial update.
*/
if (visualElement && isMounted.current) {
visualElement.update(props, presenceContext)
}
})

/**
Expand All @@ -91,6 +98,7 @@ export function useVisualElement<Instance, RenderState>(
useIsomorphicLayoutEffect(() => {
if (!visualElement) return

isMounted.current = true
window.MotionIsMounted = true

visualElement.updateFeatures()
Expand Down

0 comments on commit f3468b3

Please sign in to comment.