Closed glassesUSA closed 9 months ago
@glassesUSA good day :)
I'm not sure if the same thing happening on my end.. The scroll offset seems to be always 0 after navigation:
https://github.com/KingSora/OverlayScrollbars/assets/12936317/7bef7121-c120-4e50-afc6-8d94b3159c86
Apologies - I sent the wrong link! https://optimaxdev.github.io/optimaxeyewear/vendors/glassesusa - This is the new site that has the issue
@glassesUSA there seems to be an issue with the initialization because the body
elements initialization is a bit special. Are you able to share your code with me?
At this point I'm fairly certain that you're doing something like this:
<OverlayScrollbarsComponent element="body">
</OverlayScrollbarsComponent>
To initialized OverlayScrollbars to / as the body
element. The problem here is that the OverlayScrollbarsComponent
wasn't really designed to do that. Its intended usecase is to use it for everything besides the body
element.
Please use the useOverlayScrollbars
hook for the initialization instead:
const MyComponent = () => {
const bodyRef = useRef(null);
const [initialize, osInstance] = useOverlayScrollbars({ options, events, defer });
useEffect(() => {
const { current: body } = bodyRef;
if (body) {
initialize(body);
return () => osInstance()?.destroy();
}
}, [initialize, osInstance])
return (<body ref={bodyRef} data-overlayscrollbars-initialize="">
content
</body>);
}
I could adapt the component to be also able to initialize the body
element properly, but thats the current workaround I recommend.
Perfect thank you!
Describe the bug When scrolling down and hitting a Link component, the page navigates slightly scrolled down
To Reproduce
Expected behavior Window should be at the top of the page
Examples Please create a small example of the bug. To do this you can use online platforms like JSFiddle, CodeSandbox or StackBlitz. You can also create a separate Github repository which I can clone.
Environment
Additional context NextJS latest version