From 1c445fdcd29bda3f3b5ee7d9f82e8bdc5ce2a485 Mon Sep 17 00:00:00 2001 From: xEsiah Date: Mon, 19 Oct 2026 21:41:07 +0200 Subject: [PATCH] fix: play nav intro animation once per page load Guard the initial load animation with a ref so it no longer replays on client-side route changes. Replay it when the page is restored from the back-forward cache (pageshow persisted). --- src/components/PillNav.tsx | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/components/PillNav.tsx b/src/components/PillNav.tsx index 2e6ca1a..2e60b98 100644 --- a/src/components/PillNav.tsx +++ b/src/components/PillNav.tsx @@ -52,6 +52,8 @@ const PillNav: React.FC = ({ const logoRef = useRef(null); const isInitialMount = useRef(true); + const hasPlayedIntro = useRef(false); + const [introTick, setIntroTick] = useState(0); // --- 1. Gestion du Menu Mobile avec GSAP --- useEffect(() => { @@ -207,7 +209,8 @@ const PillNav: React.FC = ({ document.fonts.ready.then(layout).catch(() => {}); } - if (initialLoadAnimation) { + if (initialLoadAnimation && !hasPlayedIntro.current) { + hasPlayedIntro.current = true; const logo = logoRef.current; const navItems = navItemsRef.current; if (logo) { @@ -221,7 +224,18 @@ const PillNav: React.FC = ({ } return () => window.removeEventListener("resize", onResize); - }, [items, ease, initialLoadAnimation]); + }, [items, ease, initialLoadAnimation, introTick]); + + useEffect(() => { + const onPageShow = (event: PageTransitionEvent) => { + if (event.persisted) { + hasPlayedIntro.current = false; + setIntroTick((t) => t + 1); + } + }; + window.addEventListener("pageshow", onPageShow); + return () => window.removeEventListener("pageshow", onPageShow); + }, []); const handleEnter = (i: number) => { const tl = tlRefs.current[i];