-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix NaN in spring-animated SVG polygon points (#2791) #3757
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -215,6 +215,20 @@ function getSpringOptions(options: SpringOptions) { | |||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||
| * Guard against non-positive or non-finite stiffness/mass. These divide | ||||||||||||||||||||||||||
| * and feed Math.sqrt() during resolution, so a 0 (or an explicit | ||||||||||||||||||||||||||
| * `undefined` that clobbers the default via the spread above) produces NaN | ||||||||||||||||||||||||||
| * spring values — which corrupt any animated value, e.g. an SVG polygon's | ||||||||||||||||||||||||||
| * points list. See https://github.com/motiondivision/motion/issues/2791 | ||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||
| if (!(springOptions.stiffness > 0)) { | ||||||||||||||||||||||||||
| springOptions.stiffness = springDefaults.stiffness | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| if (!(springOptions.mass > 0)) { | ||||||||||||||||||||||||||
| springOptions.mass = springDefaults.mass | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
Comment on lines
+225
to
+230
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| return springOptions | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
damping: undefinednot guarded — same NaN path as the fixed bugstiffnessandmassare guarded, butdampinggoes through the exact same spread-clobber mechanism and isn't protected. If a caller passestransition={{ damping: optionalProp }}whereoptionalPropisundefined, the...optionsspread clobbersspringDefaults.damping(10), leavingspringOptions.damping = undefined. ThendampingRatio = undefined / (2 * Math.sqrt(stiffness * mass))evaluates toNaN, which makes every branch comparison (NaN < 1,NaN === 1) false, so the overdamped path runs with aNaNdampedAngularFreq— producingNaNoutputs for every frame.A guard like
if (!(springOptions.damping >= 0)) springOptions.damping = springDefaults.dampingwould coverundefined,NaN, and negative damping (note:>= 0rather than> 0because zero damping is a valid underdamped spring). The new test suite would benefit from adamping: undefinedcase as well.