Skip to content

[react-strict-animated] Fix incorrect error message for invalid mass in SpringAnimation#485

Closed
adityasingh2400 wants to merge 1 commit into
react:mainfrom
adityasingh2400:fix-spring-mass-error-message
Closed

[react-strict-animated] Fix incorrect error message for invalid mass in SpringAnimation#485
adityasingh2400 wants to merge 1 commit into
react:mainfrom
adityasingh2400:fix-spring-mass-error-message

Conversation

@adityasingh2400

Copy link
Copy Markdown

Summary

The mass validation in the SpringAnimation constructor throws the wrong error message. It reports a damping problem when an invalid mass is supplied, because the message was copy-pasted from the preceding damping check.

if (this.#damping <= 0) {
  throw new Error('Damping value must be greater than 0');
}
if (this.#mass <= 0) {
  throw new Error('Damping value must be greater than 0'); // should be Mass
}

A user passing mass: 0 (or a negative mass) gets told their damping value is wrong, which points them at the wrong config field. React Native's equivalent SpringAnimation throws 'Mass value must be greater than 0' here.

Fix

Use the correct message for the mass check.

Test

Added SpringAnimation-test.js covering all three constructor validations (stiffness, damping, mass). The mass case fails on main (asserts 'Mass value must be greater than 0') and passes with the fix.

flow check and eslint are clean.

…in SpringAnimation

The mass validation in the SpringAnimation constructor threw 'Damping value
must be greater than 0', a copy-paste of the preceding damping check. It now
reports 'Mass value must be greater than 0', matching the field being
validated (and the equivalent check in React Native's SpringAnimation).
@MoOx

MoOx commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

@adityasingh2400 Care to comment about closing something that could help ?

@adityasingh2400

Copy link
Copy Markdown
Author

Sorry @MoOx, same story as #484, this was an accidental close during a bulk fork cleanup, not a decision about the fix. The fork was deleted so I could not reopen it, so I restored the branch and opened #499 to carry it forward. Glad to iterate on it there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants