The reason for this issue is due to the document being called on the server side.
To resolve this, you can disable the preload on the server by using a dynamic call:
import dynamic from "next/dynamic";
const StarrySky = dynamic(() => import("@/app/components/starry-sky"), {
ssr: false,
});
export default function Home() {
return <StarrySky />;
}
Note that I have moved all the code to another component in order to simplify the solution. It was simply copied and pasted here for clarity.
You may also consider checking if the document (and window) exist and attempt to address the issue in that manner. I tried this approach but it did not yield the desired behavior.
For further guidance related to your problem, you can refer to this answer with helpful references: other answer here
Additionally, you can find more information about next/dynamics at this link: next/dynamic