feat: Responsive calendar, post editor, analytics & settings (Phases 2-4)#1224
Conversation
|
Someone is attempting to deploy a commit to the Listinai Team on Vercel. A member of the Team first needs to authorize it. |
| * Returns true when viewport width is 768px or less | ||
| */ | ||
| export function useMobile() { | ||
| const [isMobile, setIsMobile] = useState(false); |
There was a problem hiding this comment.
Bug: The useMobile hook causes a React hydration mismatch on mobile devices by initializing isMobile to false on the server and only updating it on the client after hydration.
Severity: MEDIUM
Suggested Fix
To prevent the hydration mismatch, ensure the component renders the same content on the server and the initial client render. Defer setting the isMobile state until the component has mounted. One way is to introduce another state variable to track mounting, and only set isMobile based on window.innerWidth inside a useEffect hook. This ensures the mobile-specific view is rendered only after the initial hydration is complete.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: apps/frontend/src/components/hooks/use-mobile.tsx#L10
Potential issue: The `useMobile` hook initializes its state with `const [isMobile,
setIsMobile] = useState(false)`. During server-side rendering (SSR), this causes the
desktop version of components like `WeekView` and `MonthView` to be rendered. On a
mobile device, after the initial client-side hydration, a `useEffect` hook runs and
updates `isMobile` to `true` based on `window.innerWidth`. This change triggers a
re-render with a different component tree (e.g., `MobileWeekView`), causing a React
hydration mismatch error. This results in a visual flash as the UI switches from the
desktop to the mobile layout and can lead to temporarily broken user interactions on
initial page load for mobile users.
Did we get this right? 👍 / 👎 to inform future reviews.
|
Hi @travelsatsargentina thank you for putting work onto this! I hope this work gets prioritized. Mobile capabilities would be very great for Postiz |
👋 Hey Postiz team!
Continuing our responsive design work from PR #1223 (Phase 1 - Sidebar + Navigation).
What this PR does
Mobile Calendar List View
Time Table Fix
max-w-[400px]to responsive withmobile:max-w-fullNew Files
apps/frontend/src/components/hooks/use-mobile.tsx— reusable viewport detection hookDesign Principles
Part of our responsive design contribution series. More phases coming!
Contributed by the Travelsats team (@travelsatsargentina) 🇦🇷