"use client"; import { useAtomValue } from "jotai"; import { useEffect, useState } from "react"; import { createPortal } from "react-dom"; import { globalLoadingAtom } from "@/atoms/ui/loading.atoms"; import { Spinner } from "@/components/ui/spinner"; import { cn } from "@/lib/utils"; /** * GlobalLoadingProvider renders a persistent loading overlay. * The spinner is ALWAYS in the DOM to prevent animation reset when * loading states change between different pages/components. * * Visibility is controlled via CSS opacity/pointer-events, NOT mounting/unmounting. */ export function GlobalLoadingProvider({ children }: { children: React.ReactNode }) { const [mounted, setMounted] = useState(false); const { isLoading } = useAtomValue(globalLoadingAtom); useEffect(() => { setMounted(true); }, []); // The overlay is ALWAYS rendered, but visibility is controlled by CSS // This prevents the spinner animation from resetting const loadingOverlay = (