react-spring icon indicating copy to clipboard operation
react-spring copied to clipboard

'onRest' not fired when two 'start' calls are too close

Open iyinchao opened this issue 3 years ago • 0 comments

🐛 Bug Report

To Reproduce

I use the spring API like this:

const [props, api] = useSpring(() => ({
  opacity: 0,
  onRest: {
    opacity: (v) => {
      if (v.value === 0) {
        // do something
      }
    },
  },
}));

Then user interaction will start opacity animation between value 0~1.

// user trigger
api.start({ opacity: 1 });

// user untrigger
api.start({ opacity: 0 });

When users move too fast, the trigger ---> untrigger calls are too close, e.g. about less than a single animation frame, the onRest sometimes will not called.

Expected behavior

onRest be called whenever start is called, even when 2 start calls are too close.

Link to repro

https://codesandbox.io/s/tippy-js-react-spring-forked-hl3vd?file=/src/App.js

image The button click simulates the 2 close start calls. Sometimes console log will not show, (the click count is not equal to the log count)

Environment

  • react-spring v9.3.1
  • react v17.0.2

iyinchao avatar Dec 24 '21 03:12 iyinchao