From 323a5665fed38b62380c324905c86be531ce93f9 Mon Sep 17 00:00:00 2001 From: Mohammed Al-yaseen Date: Wed, 17 Dec 2025 16:36:20 +0300 Subject: [PATCH] fix issue A tree hydrated but some attributes of the server rendered HTML didn't match the client properties. This won't be patched up. This can happen if a SSR-ed Client Component used: - A server/client branch `if (typeof window !== 'undefined')`. - Variable input such as `Date.now()` or `Math.random()` which changes each time it's called. - Date formatting in a user's locale which doesn't match the server. - External changing data without sending a snapshot of it along with the HTML. - Invalid HTML tag nesting. --- src/app/page.tsx | 66 ++++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/src/app/page.tsx b/src/app/page.tsx index 4e1735f..69b90b2 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -8,7 +8,7 @@ import { ProjectOutlined, RocketOutlined, StarOutlined, - TeamOutlined + TeamOutlined, } from "@ant-design/icons"; import { Card, Col, Row, Statistic, Typography } from "antd"; import { useEffect, useState } from "react"; @@ -22,21 +22,26 @@ import styles from "./page.module.css"; const { Title, Paragraph } = Typography; export default function Home() { - const [userPreferences, setUserPreferences] = useState(() => { - try { - const storedPreferences = localStorage.getItem("userPreferences"); - return storedPreferences ? JSON.parse(storedPreferences) : []; - } catch { - return []; - } - }); - - const [showPreferences, setShowPreferences] = useState( - () => userPreferences.length === 0, - ); + // Keep the initial render identical between server and client to avoid hydration mismatches. + // We'll read localStorage after mount. + const [, setUserPreferences] = useState([]); + const [showPreferences, setShowPreferences] = useState(true); const [loading, setLoading] = useState(true); useEffect(() => { + // Reading localStorage can only happen on the client; do it after mount. + try { + const storedPreferences = localStorage.getItem("userPreferences"); + if (storedPreferences) { + /* eslint-disable react-hooks/set-state-in-effect */ + setUserPreferences(JSON.parse(storedPreferences)); + setShowPreferences(false); + /* eslint-enable react-hooks/set-state-in-effect */ + } + } catch { + // ignore invalid JSON / access errors + } + // Simulate loading of resources const timer = setTimeout(() => { setLoading(false); @@ -61,7 +66,7 @@ export default function Home() {
- +
@@ -72,7 +77,7 @@ export default function Home() { Masters
- +
@@ -80,7 +85,7 @@ export default function Home() {
- +
Preparing Your Experience @@ -113,10 +118,11 @@ export default function Home() { Our Services - We offer comprehensive solutions to transform your digital presence and drive business growth + We offer comprehensive solutions to transform your digital + presence and drive business growth
- + @@ -127,7 +133,8 @@ export default function Home() { Web Development - Custom web applications built with modern technologies and best practices for optimal performance and user experience. + Custom web applications built with modern technologies and + best practices for optimal performance and user experience.
  • Responsive Design
  • @@ -137,7 +144,7 @@ export default function Home() {
- +
@@ -147,7 +154,8 @@ export default function Home() { Mobile Development - Native and cross-platform mobile applications that deliver exceptional user experiences across all devices. + Native and cross-platform mobile applications that deliver + exceptional user experiences across all devices.
  • iOS & Android Apps
  • @@ -157,7 +165,7 @@ export default function Home() {
- +
@@ -167,7 +175,8 @@ export default function Home() { UI/UX Design - User-centered design solutions that create intuitive, engaging, and conversion-focused digital experiences. + User-centered design solutions that create intuitive, + engaging, and conversion-focused digital experiences.
  • User Research
  • @@ -189,10 +198,11 @@ export default function Home() { Our Impact - Numbers that speak for themselves - our commitment to excellence in every project + Numbers that speak for themselves - our commitment to excellence + in every project
- +
@@ -207,7 +217,7 @@ export default function Home() { />
- +
@@ -221,7 +231,7 @@ export default function Home() { />
- +
@@ -236,7 +246,7 @@ export default function Home() { />
- +