fix: play nav intro animation once per page load
Deploy React Site / build-and-deploy (push) Successful in 10s
Deploy React Site / build-and-deploy (push) Successful in 10s
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).
This commit is contained in:
@@ -52,6 +52,8 @@ const PillNav: React.FC<PillNavProps> = ({
|
|||||||
const logoRef = useRef<HTMLAnchorElement | HTMLElement | null>(null);
|
const logoRef = useRef<HTMLAnchorElement | HTMLElement | null>(null);
|
||||||
|
|
||||||
const isInitialMount = useRef(true);
|
const isInitialMount = useRef(true);
|
||||||
|
const hasPlayedIntro = useRef(false);
|
||||||
|
const [introTick, setIntroTick] = useState(0);
|
||||||
|
|
||||||
// --- 1. Gestion du Menu Mobile avec GSAP ---
|
// --- 1. Gestion du Menu Mobile avec GSAP ---
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -207,7 +209,8 @@ const PillNav: React.FC<PillNavProps> = ({
|
|||||||
document.fonts.ready.then(layout).catch(() => {});
|
document.fonts.ready.then(layout).catch(() => {});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (initialLoadAnimation) {
|
if (initialLoadAnimation && !hasPlayedIntro.current) {
|
||||||
|
hasPlayedIntro.current = true;
|
||||||
const logo = logoRef.current;
|
const logo = logoRef.current;
|
||||||
const navItems = navItemsRef.current;
|
const navItems = navItemsRef.current;
|
||||||
if (logo) {
|
if (logo) {
|
||||||
@@ -221,7 +224,18 @@ const PillNav: React.FC<PillNavProps> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return () => window.removeEventListener("resize", onResize);
|
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 handleEnter = (i: number) => {
|
||||||
const tl = tlRefs.current[i];
|
const tl = tlRefs.current[i];
|
||||||
|
|||||||
Reference in New Issue
Block a user