fix: lazyloading issues on about page
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { BrowserRouter, Routes, Route } from 'react-router-dom';
|
import { BrowserRouter, Routes, Route } from 'react-router-dom';
|
||||||
import { LanguageProvider } from './i18n';
|
import { LanguageProvider } from './i18n';
|
||||||
import { Navbar, Footer, FancyCursor } from './components/layout';
|
import { Navbar, Footer, FancyCursor, ScrollToTop } from './components/layout';
|
||||||
import { Home, About, Contact } from './pages';
|
import { Home, About, Contact } from './pages';
|
||||||
import './styles/global.css';
|
import './styles/global.css';
|
||||||
|
|
||||||
@@ -8,6 +8,7 @@ export function App() {
|
|||||||
return (
|
return (
|
||||||
<LanguageProvider>
|
<LanguageProvider>
|
||||||
<BrowserRouter>
|
<BrowserRouter>
|
||||||
|
<ScrollToTop />
|
||||||
<FancyCursor />
|
<FancyCursor />
|
||||||
<Navbar />
|
<Navbar />
|
||||||
<Routes>
|
<Routes>
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
import { render, fireEvent, act } from '@testing-library/react';
|
import { render, fireEvent, act } from '@testing-library/react';
|
||||||
import { FancyCursor } from './FancyCursor';
|
import { FancyCursor } from './FancyCursor';
|
||||||
import { describe, it, expect, vi, beforeAll, afterAll, beforeEach } from 'vitest';
|
import { describe, it, expect, vi, beforeAll, afterAll, beforeEach } from 'vitest';
|
||||||
import React from 'react';
|
|
||||||
|
|
||||||
describe('FancyCursor', () => {
|
describe('FancyCursor', () => {
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ describe('Navbar Performance', () => {
|
|||||||
scrollYGetterSpy = vi.fn(() => 0);
|
scrollYGetterSpy = vi.fn(() => 0);
|
||||||
Object.defineProperty(window, 'scrollY', {
|
Object.defineProperty(window, 'scrollY', {
|
||||||
configurable: true,
|
configurable: true,
|
||||||
get: scrollYGetterSpy,
|
get: scrollYGetterSpy as any,
|
||||||
});
|
});
|
||||||
vi.useFakeTimers();
|
vi.useFakeTimers();
|
||||||
});
|
});
|
||||||
|
|||||||
16
src/components/layout/ScrollToTop.tsx
Normal file
16
src/components/layout/ScrollToTop.tsx
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import { useLayoutEffect } from 'react';
|
||||||
|
import { useLocation } from 'react-router-dom';
|
||||||
|
|
||||||
|
export function ScrollToTop() {
|
||||||
|
const { pathname } = useLocation();
|
||||||
|
|
||||||
|
useLayoutEffect(() => {
|
||||||
|
window.scrollTo({
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
behavior: 'instant'
|
||||||
|
});
|
||||||
|
}, [pathname]);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
export { Navbar } from './Navbar';
|
export { Navbar } from './Navbar';
|
||||||
export { Footer } from './Footer';
|
export { Footer } from './Footer';
|
||||||
export { FancyCursor } from './FancyCursor';
|
export { FancyCursor } from './FancyCursor';
|
||||||
|
export { ScrollToTop } from './ScrollToTop';
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { motion } from 'motion/react';
|
import { motion } from 'motion/react';
|
||||||
|
import { useLocation } from 'react-router-dom';
|
||||||
import { useTranslation } from '../i18n';
|
import { useTranslation } from '../i18n';
|
||||||
import {
|
import {
|
||||||
SiReact,
|
SiReact,
|
||||||
@@ -27,7 +28,7 @@ const containerVariants = {
|
|||||||
hidden: { opacity: 0 },
|
hidden: { opacity: 0 },
|
||||||
visible: {
|
visible: {
|
||||||
opacity: 1,
|
opacity: 1,
|
||||||
transition: { staggerChildren: 0.1 },
|
transition: { staggerChildren: 0.1, delayChildren: 0.6 },
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -42,9 +43,10 @@ const itemVariants = {
|
|||||||
|
|
||||||
export function About() {
|
export function About() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const location = useLocation();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className={styles.about}>
|
<main className={styles.about} key={location.key}>
|
||||||
{/* Hero Section */}
|
{/* Hero Section */}
|
||||||
<section className={styles.hero}>
|
<section className={styles.hero}>
|
||||||
<div className="container">
|
<div className="container">
|
||||||
@@ -65,9 +67,8 @@ export function About() {
|
|||||||
<motion.div
|
<motion.div
|
||||||
className={styles.introContent}
|
className={styles.introContent}
|
||||||
initial={{ opacity: 0, y: 30 }}
|
initial={{ opacity: 0, y: 30 }}
|
||||||
whileInView={{ opacity: 1, y: 0 }}
|
animate={{ opacity: 1, y: 0 }}
|
||||||
viewport={{ once: true }}
|
transition={{ duration: 0.5, delay: 0.2 }}
|
||||||
transition={{ duration: 0.5 }}
|
|
||||||
>
|
>
|
||||||
<p className={styles.introText}>{t.about.intro}</p>
|
<p className={styles.introText}>{t.about.intro}</p>
|
||||||
<p className={styles.introText}>{t.about.experience}</p>
|
<p className={styles.introText}>{t.about.experience}</p>
|
||||||
@@ -81,9 +82,8 @@ export function About() {
|
|||||||
<motion.div
|
<motion.div
|
||||||
className={styles.sectionHeader}
|
className={styles.sectionHeader}
|
||||||
initial={{ opacity: 0, y: 20 }}
|
initial={{ opacity: 0, y: 20 }}
|
||||||
whileInView={{ opacity: 1, y: 0 }}
|
animate={{ opacity: 1, y: 0 }}
|
||||||
viewport={{ once: true }}
|
transition={{ duration: 0.5, delay: 0.4 }}
|
||||||
transition={{ duration: 0.5 }}
|
|
||||||
>
|
>
|
||||||
<h2>{t.about.skills.title}</h2>
|
<h2>{t.about.skills.title}</h2>
|
||||||
<p>{t.about.skills.subtitle}</p>
|
<p>{t.about.skills.subtitle}</p>
|
||||||
@@ -93,8 +93,7 @@ export function About() {
|
|||||||
className={styles.techGrid}
|
className={styles.techGrid}
|
||||||
variants={containerVariants}
|
variants={containerVariants}
|
||||||
initial="hidden"
|
initial="hidden"
|
||||||
whileInView="visible"
|
animate="visible"
|
||||||
viewport={{ once: true }}
|
|
||||||
>
|
>
|
||||||
{techStack.map((tech) => (
|
{techStack.map((tech) => (
|
||||||
<motion.div
|
<motion.div
|
||||||
|
|||||||
Reference in New Issue
Block a user