[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

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

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

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.

Description

area: core kind: bug
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

Dominant language
TypeScript
Stars
29.3k
Forks
1.2k
Avg merge
3d 15h
Merged PRs (30d)
17

Getting set up

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.

More from pmndrs/react-spring

All issues in pmndrs/react-spring

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.