Skip to content

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

@Yonom

Description

@Yonom

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

  1. Mount the component above.
  2. Check the console logs.
  3. 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
Image

7. Environment details

  • motion version: \12.23.12
  • React version: \19.1.1
  • Browser: \Chrome

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions