diff --git a/workspaces/react/src/contexts/pathname-context.tsx b/workspaces/react/src/contexts/pathname-context.tsx index c138a54e..665dc760 100644 --- a/workspaces/react/src/contexts/pathname-context.tsx +++ b/workspaces/react/src/contexts/pathname-context.tsx @@ -11,7 +11,7 @@ import { type ReactNode, } from "react"; -const INTERVAL_MS = 250; +const INTERVAL_MS = 200; const _usePathname = (): string | undefined => { const [pathname, setPathname] = useState(); @@ -38,7 +38,12 @@ const _usePathname = (): string | undefined => { type IPathnameContext = string | undefined; const PathnameContext = createContext(undefined); -export const usePathname = (): IPathnameContext => useContext(PathnameContext); +export const usePathname = (): IPathnameContext => { + const contextValue = useContext(PathnameContext); + // Avoid accessing window on the server + if (contextValue === undefined) return; + return getPathname(); +}; interface Props { children?: ReactNode;