motiondivision / motion

A modern animation library for React and JavaScript
https://motion.dev
MIT License
25.67k stars 843 forks source link

[BUG] NaN in point animation when using spring animations #2791

Open cheald opened 2 months ago

cheald commented 2 months ago

Describe the bug

When animating a <polygon> point list with a "spring" animation, at various points in the animation, the computed pointlist contains NaNs and throws console errors.

image

CodeSandbox reproduction of the bug

https://codesandbox.io/p/sandbox/pensive-khayyam-5mwd29?file=%2Fsrc%2FApp.js%3A9%2C68&workspaceId=5c31fde4-86cd-4353-99cd-cbe570ccc4aa

Steps to reproduce

  1. Define an SVG with a polygon element.
  2. Animate the points of the element, and use a spring animation.
  3. Observe that you get a bunch of complaints about NaNs in your error console.

When the animation type is not "spring", the NaN errors are not thrown (though one "expected number, 'undefined'" message is thrown per polygon element).

Expected behavior

When an SVGPointList would produce NaNs, it should not incorrectly attempt to set the pointlist with NaNs on the element.

Environment details

Reproduced in Brave v 1.69.153 (Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36)