motiondivision / motion

A modern animation library for React and JavaScript
https://motion.dev
MIT License
25.96k stars 851 forks source link

[BUG] Scroll Progress does not respect layout changes #2718

Open boar-is opened 4 months ago

boar-is commented 4 months ago

1. Read the FAQs šŸ‘‡ āœ…

2. Describe the bug

Changes to element dimensions won't trigger scroll progress. This is problematic for cases where this is forced (like calculating element's height on the client).

3. IMPORTANT: Provide a CodeSandbox reproduction of the bug

https://stackblitz.com/edit/stackblitz-starters-xvjyb4?file=app%2Fpage.tsx

4. Steps to reproduce

Steps to reproduce the behavior:

Go to the reproduction, refresh the result, and observe the actual behavior:

  1. Blue box's height is 50dvh, yellow's one is 0. The progress goes to 1 (nothing to even scroll)
  2. After 1.5s, yellow box's height goes to 300dvh. The progress is still 1, however, it should be 0.
  3. Scroll a bit. You'll see that the progress is recalculated to the correct value and it indeed should have been 0 initially.

5. Expected behavior

Changes to element dimensions should also trigger scroll progress recalculation.

Steps to reproduce is descriptive. Here I'll note that the only "hack" I found out for now is to setTimeout with scrollYProgress.set, which I don't like (the timeout is so indefinite and go up to 500ms).

6. Video or screenshots

N/A, see the reproduction

7. Environment details

Framer Motion 11.2.11, other's N/A