Skip to content

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

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

[react-strict-animated] Fix incorrect error message for invalid mass in SpringAnimation#499
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.


Reopening this. I closed it by accident during a bulk cleanup of my stale forks and cannot reopen the original because the fork was deleted, so this is the same branch restored. Sorry for the noise @MoOx.

…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).
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.

1 participant