Skip to content

First render after useLayoutEffect is ignored if animated value evaluated as 0 #1638

Description

@Eliav2

🐛 Bug Report

well, it's quite strange but this is probably a bug.
the title describes the issue exactly.

I'm working on new major release for react-xarrows and wanted to move from svg animation to react-spring animation.

if one of the following conditions would met the issue would not appear:

  • if you will change the effect hook from useLayoutEffect to useEffect .
  • if you would change the initial value of the animated value to be truthy (==true) value. for example, set prop1 to 0.01 instead of 0 and refresh.

Unfortunately, react-xarrows updates the UI on useLayoutEffec phase to the best user experience. Changing the default value is not possible either.

To Reproduce

just go to sandbox

Expected behavior

the animation starts after useLayoutEffect fire with the new value, even after refresh(first render).

Link to repro (highly encouraged)

code sandbox: https://codesandbox.io/s/react-spring-issue-g4xkl

look at the console. you can see useSpring receives 20 but the UI stays on 0.

example description: MyComponent is a component with expensive to parse props. useParseProps parse the props whenever prop from user was changed and MyCompoenet consumes parsed props from the hook. this is how react-xarrows is written.

Environment

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind: bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions