question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] `useViewportScroll` is not updating.

See original GitHub issue

1. Read the FAQs 👇

2. Describe the bug

Give a clear and concise description of what the bug is. scrollYProgress from useViewportScroll hook does not update.

3. IMPORTANT: Provide a CodeSandbox reproduction of the bug

A CodeSandbox minimal reproduction will allow us to quickly follow the reproduction steps. Without one, this bug report won’t be accepted.

4. Steps to reproduce

Steps to reproduce the behavior:

  1. Go to https://codesandbox.io/s/trusting-jepsen-mikfs?file=/src/App.js
  2. Open console
  3. Scroll down
  4. No updated scrollYProgress value

5. Expected behavior

scrollYProgress updates when scroll happens.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:13

github_iconTop GitHub Comments

12reactions
ikupenovcommented, Jan 12, 2021

I ran into this couple of days ago and the issue stems from the fact that I had set the height to 100vh/100%. Try running the following snippet in your browser: document.body.clientHeight - window.innerHeight <= 0. If it returns true you’re probably running into the same issue and will need to use min-height rather than a fixed height for the body element.

5reactions
camsloanftccommented, Nov 12, 2020

The scroll progress happens outside of the react render loop (I believe it is for performance reasons), so you actually need something like this:

  useEffect(() => {
    return scrollYProgress.onChange((v) => console.log(v));
  }, [scrollYProgress]);

I tweaked your demo code example.

I might be misunderstanding the issue though.

From the docs:

MotionValues are used to track the state and velocity of animating values, outside of React’s render lifecycle.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Framer Motion not updating scrollYProgress - Stack Overflow
I think the reason you're not seeing updates is not because of any css. Framer seems to calculate it's state standalone from react....
Read more >
Bountysource
[BUG] useViewportScroll initially not updating. ... Help and Information. Frequently Asked Questions · Bugs and Feature Requests · Fees ...
Read more >
[Solved]-Framer Motion not updating scrollYProgress-Reactjs
Coding example for the question Framer Motion not updating scrollYProgress-Reactjs. ... import React from "react"; import { useViewportScroll } from ...
Read more >
Upgrade guides | Framer for Developers
These will now throw a type error for TypeScript users and should be converted ... This was not a performant approach because all...
Read more >
Page Transitions with React Router and Framer Motion
Framer Crash Course - From UI/UX to Frontend with No Code. DesignCourse ... React & Three.js | Working with Shaders using React Three...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found