Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] problems with useMotionValue and useSpring to make an object follow the cursor after v11. #2610

Open
tebafu opened this issue Apr 7, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@tebafu
Copy link

tebafu commented Apr 7, 2024

1. Read the FAQs 馃憞

Done.

2. Describe the bug

I use useMotionValue and useSpring to track the cursors position and animate a div to follow it, worked fine with the last v10 version. After upgrading to v11 I noticed two specific bugs.

  1. If I click while moving my cursor the animated div will accelerate in the direction it was facing while the click happened. it is very easy to reproduce by spamming click while making circles with the cursor in the codeSandbox I provide below.

  2. when I have dev tools open the animation is glitchy.

3. IMPORTANT: Provide a CodeSandbox reproduction of the bug

https://codesandbox.io/p/sandbox/framer-motion-cursor-lag-khssjf?file=%2Fsrc%2FApp.js%3A9%2C52

4. Steps to reproduce

Steps to reproduce the behavior:

  1. create two motion values with useMotionValue().
  2. update them with a useEffect and a window.addEventListener("mousemove", handleMouseMove). handleMouseMove just sets the two previous motion values to event.clientX and event.clientY respectively.
  3. pass the motion values through a useSpring each.
  4. use the values returned from the two useSpring in the style prop of a motion.div for the x and y.
    1. bug 1, while making circular movements with the cursor, spam click. the animated div should soon gain speed and move outside the page and the expected path it should follow .
    2. bug 2, inspect the page and open the dev tools. while they are open move the cursor. it doesn't move smoothly anymore.

5. Expected behavior

bug 1 - it should work like pre v11, clicking should not affect the movement/velocity of the element.

bug 2 - it should not be laggy with dev tools open.

6. Video or screenshots

CodeSandbox reproduction.

2024-04-08.00-00-04.mp4

and locally with a clean Next.js project.

2024-04-07.23-49-28.mp4

7. Environment details

Windows 11 Education 23H2.

Chrome Version 123.0.6312.106 (Official Build) (64-bit).

8. Extra question

In the docs it is mentioned that using motion values inside the style prop does not make use of hardware acceleration.

Is there a better way to implement the functionality I want? what would be the best way to track the cursors position and animate an element?

@tebafu tebafu added the bug Something isn't working label Apr 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant