pmndrs / pmndrs/react-spring

[bug]: Decimal prop values under 1, without 0 as a prefix, don't work

Open
#1,910 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area: core kind: bug
Dominant language
TypeScript
Stars
29.1k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

Which react-spring target are you using?
  • @react-spring/web
  • @react-spring/three
  • @react-spring/native
  • @react-spring/konva
  • @react-spring/zdog
What version of react-spring are you using?

9.4.5

What's Wrong?

The regex parser of the react-spring doesn't accurately read numbers inside a string which are under 1 and don't have a leading 0 in front of them, i.e. .5 fails, but 0.5 works. I am trying it inside transform: scale(.5)

I am not entirely sure how valid in the CSS world not adding the 0 in front of the decimal point is.

I am semi-embarrassed over how long I spent on this bug, because I could have circumvented it much earlier. But so that someone else doesn't end up on the tumultuous journey I did.

To Reproduce
const props = useSpring({
  // Works.
  // transform: state ? `scale(1)` : `scale(0.5)`

  // Doesn't work
  transform: state ? `scale(1)` : `scale(.5)`
});
Expected Behaviour

Spring animations working just fine regardless of the leading 0.

If I were more familiar with the codebase, I'd submit a PR with a test.

Link to repo

https://codesandbox.io/s/optimistic-fire-wzsg1d?file=/src/App.js

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue in the linked CodeSandbox and locate the react-spring regex parser used by the @react-spring/web target. Check how decimal values such as .5 are read inside transform strings, then add regression coverage showing that both .5 and 0.5 animate correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
frontend, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.