Upon loading the page or when the user updates it, there seems to be an issue with smooth scrolling to the desired position on the site (lower than needed).
How can this be resolved so that everything functions correctly even after the page has finished rendering?
"use client";
import React from "react";
import { Link } from "react-scroll";
interface ButtonNavigationProps {
navigateTo: string;
children: React.ReactNode;
}
const ButtonNavigation: React.FC<ButtonNavigationProps> = ({
navigateTo,
children,
}) => {
return (
<Link
smooth={true}
spy={true}
isDynamic={true}
to={navigateTo}
offset={-130}
duration={650}
className="flex items-center gap-x-2 px-8 py-3"
>
{children}
<svg
xmlns="http://www.w3.org/2000/svg"
height="24"
viewBox="0 -960 960 960"
width="24"
fill="currentColor"
>
<path d="m560-240-56-58 142-142H160v-80h486L504-662l56-58 240 240-240 240Z" />
</svg>
</Link>
);
};
export default ButtonNavigation;
There are two scenarios in which the scrolling bug does not occur:
If the user manually scrolls through the site or uses link navigation for a second time (the first attempt did not scroll correctly), then the navigation operates as intended.
If the link lacks smooth behavior, everything works properly upon initial page rendering. However, smooth scrolling is preferred and alternatives have not been found.
This abnormal behavior is likely related to a smooth scrolling bug. Confirming full page load before attempting to scroll did not provide a solution.