fix: Reduce component flashing on page load and scroll
Some checks failed
Production Deployment (Zero Downtime) / deploy-production (push) Has been cancelled
Some checks failed
Production Deployment (Zero Downtime) / deploy-production (push) Has been cancelled
- Remove mounted state checks that return null (Hero, About, Projects) - Reduce animation delays and durations for faster initial render - Change viewport margins from -100px to -50px for earlier trigger - Reduce initial animation distances (y: 40 -> 20, y: 30 -> 20) - Use requestAnimationFrame for Header mount to prevent flash - Always render components instead of returning null to prevent layout shift - Optimize Framer Motion transitions for smoother scrolling
This commit is contained in:
@@ -7,12 +7,12 @@ import Link from "next/link";
|
||||
import Image from "next/image";
|
||||
|
||||
const fadeInUp: Variants = {
|
||||
hidden: { opacity: 0, y: 40 },
|
||||
hidden: { opacity: 0, y: 20 },
|
||||
visible: {
|
||||
opacity: 1,
|
||||
y: 0,
|
||||
transition: {
|
||||
duration: 0.8,
|
||||
duration: 0.5,
|
||||
ease: [0.25, 0.1, 0.25, 1],
|
||||
},
|
||||
},
|
||||
@@ -44,11 +44,9 @@ interface Project {
|
||||
}
|
||||
|
||||
const Projects = () => {
|
||||
const [mounted, setMounted] = useState(false);
|
||||
const [projects, setProjects] = useState<Project[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
setMounted(true);
|
||||
const loadProjects = async () => {
|
||||
try {
|
||||
const response = await fetch(
|
||||
@@ -58,7 +56,7 @@ const Projects = () => {
|
||||
const data = await response.json();
|
||||
setProjects(data.projects || []);
|
||||
}
|
||||
} catch (error) {
|
||||
} catch (error) {
|
||||
if (process.env.NODE_ENV === "development") {
|
||||
console.error("Error loading projects:", error);
|
||||
}
|
||||
@@ -67,8 +65,6 @@ const Projects = () => {
|
||||
loadProjects();
|
||||
}, []);
|
||||
|
||||
if (!mounted) return null;
|
||||
|
||||
return (
|
||||
<section
|
||||
id="projects"
|
||||
@@ -78,7 +74,7 @@ const Projects = () => {
|
||||
<motion.div
|
||||
initial="hidden"
|
||||
whileInView="visible"
|
||||
viewport={{ once: true, margin: "-100px" }}
|
||||
viewport={{ once: true, margin: "-50px" }}
|
||||
variants={fadeInUp}
|
||||
className="text-center mb-20"
|
||||
>
|
||||
@@ -94,7 +90,7 @@ const Projects = () => {
|
||||
<motion.div
|
||||
initial="hidden"
|
||||
whileInView="visible"
|
||||
viewport={{ once: true, margin: "-100px" }}
|
||||
viewport={{ once: true, margin: "-50px" }}
|
||||
variants={staggerContainer}
|
||||
className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8"
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user