perf: optimize framer-motion bundle size and memoize dictionary fetching

- Wrap getDictionary with React cache to prevent redundant JSON parsing on the server
- Create MotionProvider to globally initialize framer-motion LazyMotion with domAnimation
- Replace standard 'motion' imports with 'm' across all animated client components (HomeClient, Navbar, GaleriClient, SSSClient, card, text-reveal) to drastically reduce First Load JS size
This commit is contained in:
mstfyldz
2026-06-04 12:50:23 +03:00
parent e1d8bae5a4
commit acf01c81fa
9 changed files with 59 additions and 44 deletions
+11
View File
@@ -0,0 +1,11 @@
"use client";
import { LazyMotion, domAnimation } from "framer-motion";
export function MotionProvider({ children }: { children: React.ReactNode }) {
return (
<LazyMotion features={domAnimation}>
{children}
</LazyMotion>
);
}
+3 -3
View File
@@ -5,7 +5,7 @@ import Link from "next/link";
import Image from "next/image";
import { usePathname } from "next/navigation";
import { Menu, X, Globe } from "lucide-react";
import { motion, AnimatePresence } from "framer-motion";
import { m, AnimatePresence } from "framer-motion";
import { Locale } from "../dictionaries";
export default function Navbar({ lang, dict }: { lang: Locale; dict: any }) {
@@ -91,7 +91,7 @@ export default function Navbar({ lang, dict }: { lang: Locale; dict: any }) {
{/* Mobile Nav */}
<AnimatePresence>
{mobileMenuOpen && (
<motion.div
<m.div
initial={{ opacity: 0, y: -20 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: -20 }}
@@ -114,7 +114,7 @@ export default function Navbar({ lang, dict }: { lang: Locale; dict: any }) {
<Link href={switchLanguage('en')} onClick={() => setMobileMenuOpen(false)} className={`text-sm ${lang === 'en' ? 'text-[var(--color-moy-gold)] font-bold' : ''}`}>English</Link>
</div>
</div>
</motion.div>
</m.div>
)}
</AnimatePresence>
</header>
+3 -3
View File
@@ -2,7 +2,7 @@
import * as React from "react"
import Image from "next/image"
import { motion } from "framer-motion";
import { m } from "framer-motion";
import { cn } from "@/lib/utils";
/* ── Base Card ── */
@@ -15,7 +15,7 @@ interface CardProps {
export function Card({ children, hover = true, glass = false, className }: CardProps) {
return (
<motion.div
<m.div
whileHover={hover ? { y: -6 } : undefined}
transition={{ duration: 0.35, ease: [0.16, 1, 0.3, 1] }}
className={cn(
@@ -27,7 +27,7 @@ export function Card({ children, hover = true, glass = false, className }: CardP
)}
>
{children}
</motion.div>
</m.div>
);
}
+3 -3
View File
@@ -1,6 +1,6 @@
"use client";
import { motion, useInView } from "framer-motion";
import { m, useInView } from "framer-motion";
import { useRef } from "react";
import { cn } from "@/lib/utils";
@@ -26,7 +26,7 @@ export function TextReveal({
return (
<span ref={ref} className={cn("inline", className)}>
{words.map((word, i) => (
<motion.span
<m.span
key={i}
className="inline-block mr-[0.28em] last:mr-0"
initial={{ opacity: 0, y: 22, filter: "blur(4px)" }}
@@ -42,7 +42,7 @@ export function TextReveal({
}}
>
{word}
</motion.span>
</m.span>
))}
</span>
);