Skip to content

scrollTop is not set when from & to are equal #1185

@kernelwhisperer

Description

@kernelwhisperer

from @aleclarson on discord:

You need to provide a start value: from: { scrollTop: 0 }

This fixes it, yes, thanks! 😄 (I guess on v8.0.27 the lib used to do that automatically.)

To achieve my behavior of a initial scrollTop I have to do this now:

  const { scrollTop } = useSpring({
   from: { scrollTop: 0 }
   to: { scrollTop: 100 },
   immediate: true
});

And then to set immediate: false on subsequent calls.

I can live with this... hovever I would still consider this a bug, and expect this expression to work as an equivalent, just like it does in v8.0.27:

  const { scrollTop } = useSpring({
    from: { scrollTop: 100 }
  });

and this should be possible too:

  const { scrollTop } = useSpring({
    from: { scrollTop: 100 }
    to: { scrollTop: 100 }
  });

It works with animated.span so this is most likely an issue in animated.div's scrollTop handling:
https://codesandbox.io/s/react-spring-v9-scrolltop-bug-forked-7h3vf?file=/src/App.js

Originally posted by @0x6431346e in #985 (comment)

Metadata

Metadata

Assignees

Labels

kind: bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions