plans/fix-motion.md
The motion driver (@tamagui/animations-motion) has several issues that need to be fixed. This document tracks the research, bugs, and fixes.
cf54108aa3 - fix(animations-motion): enhance animation handling by adding disableAnimation support and improving state synchronization (#3839)
disableAnimation to useMemo depsupdateFirstAnimationStyle() functionremoveRemovedStyles() with preserve parameter to prevent clearing styles that moved between doAnimate/dontAnimateanimate(scope.current, { ...movedToAnimate }, { duration: 0 })502b549e6c - more safe fix for motion jumps
Date.now() - lastAnimateAt.current < 50) to controls.current?.state === 'running'0e4f08c43a - fix(animations-motion): fix tooltip position jump when interrupting transform animations
[startTransform, targetTransform] for smooth interruption638bb29bb1 - fix(animations-motion): make quick animations faster and snappier
Component: LogoWords.tsx in @tamagui/logo
Symptoms: Moving mouse left/right fast over the TAMAGUI text causes the dot indicator to jitter erratically.
Relevant Code:
<Circle
transition="quicker"
position="absolute"
y={mounted === 'start' ? -30 : -3}
x={x} // Computed from tintIndex
size={4}
backgroundColor="$color12"
/>
Hypothesis: The getComputedStyle fix for tooltip position jumps is incorrectly triggering for this component. The Circle uses transform with translate, and when rapidly changing x values, the position interruption fix is reading stale/wrong computed styles.
Evidence: User says "if we remove the getComputedStyle fix for tooltip jumps it fixes that one"
Component: Header.tsx - HeaderLinksPopover and HeaderLinksPopoverContent
Symptoms:
Relevant Code:
Popover.Content uses enableAnimationForPositionChange and transition="medium"Frame component uses AnimatePresence with custom going prop for enter/exit animationsFrame has enterStyle and exitStyle with x offset based on directionPotential Issues:
going direction calculation may be getting out of syncStatus: Fixed in previous commits but may need more testing
Test: TooltipPositionJump.animated.test.tsx exists
Create test for rapid x position changes on Circle component with motion driver.
Create test for:
Ensure existing tooltip position jump test still passes after fixes.
The current code in createAnimations.tsx:
const isRunning = controls.current?.state === 'running'
const targetTransform = typeof diff.transform === 'string' ? diff.transform : null
// Only apply position fix for translate-only transforms
const isPositionOnlyTransform =
targetTransform &&
targetTransform.includes('translate') &&
!targetTransform.includes('scale') &&
!targetTransform.includes('rotate') &&
!targetTransform.includes('skew') &&
!targetTransform.includes('matrix') &&
!targetTransform.includes('perspective')
if (isRunning && controls.current && isPositionOnlyTransform) {
const currentTransform = getComputedStyle(node).transform
// ... keyframe animation from current to target
}
Problem: This fires for ANY translate-only transform changes when animation is running. This includes:
Potential Fix Approaches:
The fix uses approach #4: element attribute marker to distinguish Popper elements from regular animated elements.
/code/ui/popper/src/Popper.tsx
data-popper-animated="true" attribute to the outer animated TamaguiViewenableAnimationForPositionChange is truedata-placement)/code/core/animations-motion/src/createAnimations.tsx
data-popper-animated attributegetComputedStyle fix when the element has this markerenableAnimationForPositionChange DO have this markerThe key insight is that:
enableAnimationForPositionChange: These are floating-ui positioned elements that jump 100-160px between positions. They NEED the getComputedStyle fix to prevent jumps to origin.getComputedStyle on rapid updates.By using an explicit opt-in marker (data-popper-animated), we can selectively apply the fix only to elements that need it.
All tests pass:
/code/core/animations-motion/src/createAnimations.tsx - Position fix with data-popper-animated check/code/ui/popper/src/Popper.tsx - Added data-popper-animated marker/code/kitchen-sink/tests/TooltipPositionJump.animated.test.tsx - Existing (passes)/code/kitchen-sink/tests/TamaguiSiteMotion.test.ts - Tests against actual tamagui.dev site