Skip to content

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

@iyinchao

Description

@iyinchao

🐛 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: corerelates to core classes // parts of the librarykind: bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions