When updating a ref on a motion component (e.g., m.div), the old ref is not cleared and the new ref is not set. This results in stale references when swapping between ref objects after mount.
3. IMPORTANT: Provide a CodeSandbox reproduction of the bug
https://codesandbox.io/p/sandbox/dxzgcp
4. Steps to reproduce
- Mount the component above.
- Check the console logs.
- Observe that
ref1.current is still populated, and ref2.current is null.
5. Expected behavior
- Before swap:
ref1.current should point to the div, ref2.current should be null.
- After swap:
ref1.current should be null, ref2.current should point to the div.
6. Video or screenshots

7. Environment details
- motion version: \12.23.12
- React version: \19.1.1
- Browser: \Chrome
When updating a
refon amotioncomponent (e.g.,m.div), the old ref is not cleared and the new ref is not set. This results in stale references when swapping between ref objects after mount.3. IMPORTANT: Provide a CodeSandbox reproduction of the bug
https://codesandbox.io/p/sandbox/dxzgcp
4. Steps to reproduce
ref1.currentis still populated, andref2.currentisnull.5. Expected behavior
ref1.currentshould point to thediv,ref2.currentshould benull.ref1.currentshould benull,ref2.currentshould point to thediv.6. Video or screenshots

7. Environment details