fix(shared): preserve decimal precision in string interpolator#2469
Merged
Conversation
Closes #1461. The string interpolator used `output[0]` as both the value at `input = range[0]` and the template for every other input, so trailing zeros (`'0.00'`), explicit signs, and any other format information on later keyframes were dropped on the round-trip through `numberRegex`. As a result, `useSpring({ from: '0.00', to: '1.50' })` rendered `'0'` at rest and `'1.5'` at the goal. Two-part fix: 1. When `input` lands exactly on a `range` value, return that keyframe's `output[k]` verbatim — fixes initial render and at-rest goal for all formats (decimals, signs, locale separators). 2. Per number-position, when every keyframe shares the same non-zero fractional-digit count, `toFixed(n)` the mid-animation result. Gated on `> 0` so whole-number keyframes (e.g. `rgba(…, 0)` → `rgba(…, 1)`) keep their natural sub-frame precision.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 290788c The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This was referenced May 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #1461. Stringified floats lost their precision through
useSpring—'0.00'rendered as'0','1.50'settled at'1.5', and mid-tween values flickered raw IEEE-754 noise. Springs should respect the text the user wrote.Fix
In
createStringInterpolator: return each keyframe verbatim wheninputlands on it (preserves all formatting at start and goal), and pad mid-animation results to the keyframes' shared decimal count when every keyframe opts in to fractional digits. Padding is gated on a non-zero shared count so whole-number keyframes (notably the alpha channel inrgba(…, 0)→rgba(…, 1)) keep their natural sub-frame precision.Out of scope
#1660's
+sign case has a different root cause (AnimatedString lifecycle). Locale separators like'1.500 kr'mid-tween require.to(formatter)—numberRegexcan't disambiguate them.