Strange rendering bug #28076
-
DescriptionThis is kind of tricky, so bear with me. I've built a navigation component that changes its background based on the user's scroll position. This component looks like this:
If I scroll the window and then refresh the page, the What's really strange about this is if log out Here's what I think may be happening:
Steps to reproduce
I've left in a Expected resultGatsby should update the DOM to include the Actual resultGatsby does not update the DOM to include the Environment
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Why would you expect this? You're only setting the class name when scrolling, when Gatsby creates the HTML it doesn't scroll anything. You can either have the class name on the element in the HTML or not, but not both things. A former colleague wrote a great article about this: https://joshwcomeau.com/react/the-perils-of-rehydration/ So similar to libraries like react-headroom you need to handle the case of reloading the page when not at the top of the page yourself and add the logic to change the navigation then. |
Beta Was this translation helpful? Give feedback.
Why would you expect this? You're only setting the class name when scrolling, when Gatsby creates the HTML it doesn't scroll anything. You can either have the class name on the element in the HTML or not, but not both things. A former colleague wrote a great article about this: https://joshwcomeau.com/react/the-perils-of-rehydration/
So similar to libraries like react-headroom you need to handle the case of reloading the page when not at the top of the page yourself and add the logic to change the navigation then.