diff --git a/frontend/src/hooks/useMobile.ts b/frontend/src/hooks/useMobile.ts index 2b0fe1d..4ee2dcf 100644 --- a/frontend/src/hooks/useMobile.ts +++ b/frontend/src/hooks/useMobile.ts @@ -3,7 +3,13 @@ import * as React from "react" const MOBILE_BREAKPOINT = 768 export function useIsMobile() { - const [isMobile, setIsMobile] = React.useState(undefined) + // Read on the first render, not after it: a node on the flow canvas draws + // its handles for the direction this returns, and React Flow measures them + // once. Starting at `false` drew them for a desktop first, so whether an + // edge met its handle depended on which of the two React measured. + const [isMobile, setIsMobile] = React.useState( + () => window.innerWidth < MOBILE_BREAKPOINT, + ) React.useEffect(() => { const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`) @@ -15,5 +21,5 @@ export function useIsMobile() { return () => mql.removeEventListener("change", onChange) }, []) - return !!isMobile + return isMobile }