Skip to content

fix: update useMotionRef to properly handle externalRef changes#3366

Merged
mattgperry merged 3 commits into
motiondivision:mainfrom
AmitSingh-5600:fix/motion-ref-update-bug
Sep 16, 2025
Merged

fix: update useMotionRef to properly handle externalRef changes#3366
mattgperry merged 3 commits into
motiondivision:mainfrom
AmitSingh-5600:fix/motion-ref-update-bug

Conversation

@AmitSingh-5600
Copy link
Copy Markdown
Contributor

Description

Fixes issue where motion components don't update refs when externalRef changes.

Root Cause

The useMotionRef function wasn't including externalRef in the useCallback dependency array, causing the ref callback to not update when the external ref changes.

Changes

  • Add externalRef to the dependency array in useMotionRef
  • Add test case to verify ref changes work correctly
  • Update CHANGELOG.md with the fix

Testing

Files Changed

  • packages/framer-motion/src/motion/utils/use-motion-ref.ts
  • packages/framer-motion/src/motion/__tests__/ref-change.test.tsx
  • CHANGELOG.md

Fixes #3361

- Add externalRef to useCallback dependency array
- Fixes issue where motion components don't update refs when externalRef changes
- Add test case to verify ref swapping works correctly
- Resolves motiondivision#3361
…ivision#3361

& Test verifies that refs are properly cleared and updated when externalRef changes
…te refs when externalRef changes. The function now properly includes in the dependency array to ensure ref callbacks update when the external ref changes.

## [12.23.12] 2025-07-29
@mattgperry
Copy link
Copy Markdown
Collaborator

Thanks for the PR!

@mattgperry mattgperry merged commit d9b4133 into motiondivision:main Sep 16, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Updating the ref to a motion element does not work

2 participants