chenglou / chenglou/react-motion
Setting Motion props in onRest callback won't start new animation
- Dominant language
- JavaScript
- Stars
- 21.9k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
I'm not sure if this is a bug, but it bit me today.
In my code, a Motion onRest callback triggers a re-render of my React component, which sets new props for that Motion component, which are then ignored because the animationID has not yet been set to null [here](https://github.com/chenglou/react-motion/blob/master/src/Motion.js#L105) which means no new animation is created [here](https://github.com/chenglou/react-motion/blob/master/src/Motion.js#L214).
Expected behavior: a new animation is created, Motion works as usual.
Possible fix: call onRest after animation state has been reset.
Alternate fix: in development, React-Motion could detect it's inside an onRest callback, and print warnings if calls are made that can't be handled at that time.
There is a workaround [here](https://github.com/chenglou/react-motion/issues/224#issuecomment-218277983) using a setTimeout with 0.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in src/Motion.js around lines 105 and 214, tracing how animationID is reset relative to the onRest callback. Reproduce the callback-triggered prop update described in the issue, then verify that a new animation starts without the setTimeout workaround. The issue does not mention a test file.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100