From 63afc1b505c8c1f2eafb64dacaf49b9c9b601fd5 Mon Sep 17 00:00:00 2001 From: "dong.nguyen" Date: Sun, 18 Oct 2026 23:45:47 +0700 Subject: [PATCH] fix(a11y): reduced motion, screen-reader text and route-level splitting Typewriter reads useReducedMotion: under reduced motion the timer never starts and the first role renders whole, while a screen-reader-only span exposes the full role list once instead of one keystroke at a time. BackToTop scrolls instantly under reduced motion and is labelled in the active language; the nav landmark and the mode toggle stop being English-only. The hero photo declares its measured 1200x1600 canvas plus fetch priority so the box is reserved before the 898 kB image decodes. HomePage stays eagerly imported because it owns the LCP; the other six routes lazy-load behind one Suspense boundary, which is also why the pages barrel is gone. --- src/App.tsx | 48 ++++++++++++++++------------ src/components/layout/Navigation.tsx | 6 ++-- src/components/sections/Hero.tsx | 5 ++- src/components/ui/BackToTop.tsx | 10 ++++-- src/components/ui/Typewriter.tsx | 20 ++++++++---- src/i18n/strings.ts | 4 +++ src/index.css | 12 +++++++ src/pages/index.ts | 7 ---- 8 files changed, 71 insertions(+), 41 deletions(-) delete mode 100644 src/pages/index.ts diff --git a/src/App.tsx b/src/App.tsx index 334c972..f7ef41a 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,17 +1,19 @@ import './App.css' +import { lazy, Suspense } from 'react' import { BrowserRouter, Routes, Route } from 'react-router' import { ThemeProvider } from '@/hooks/useTheme' import { Layout } from '@/components/layout/Layout' import { LanguageProvider } from '@/hooks/useLanguage' -import { - HomePage, - AboutPage, - ExperiencePage, - ProjectsListPage, - ProjectDetailPage, - PhilosophyPage, - ContactPage, -} from '@/pages' +import { HomePage } from '@/pages/HomePage' + +// HomePage stays eager: it is the landing route and owns the LCP, so its code must +// already be in the entry chunk. The other six split out and load on navigation. +const AboutPage = lazy(() => import('@/pages/AboutPage').then((m) => ({ default: m.AboutPage }))) +const ExperiencePage = lazy(() => import('@/pages/ExperiencePage').then((m) => ({ default: m.ExperiencePage }))) +const ProjectsListPage = lazy(() => import('@/pages/ProjectsListPage').then((m) => ({ default: m.ProjectsListPage }))) +const ProjectDetailPage = lazy(() => import('@/pages/ProjectDetailPage').then((m) => ({ default: m.ProjectDetailPage }))) +const PhilosophyPage = lazy(() => import('@/pages/PhilosophyPage').then((m) => ({ default: m.PhilosophyPage }))) +const ContactPage = lazy(() => import('@/pages/ContactPage').then((m) => ({ default: m.ContactPage }))) function App() { return ( @@ -19,18 +21,22 @@ function App() { - - } /> - } /> - } /> - } /> - } /> - } /> - } /> - - - - + {/* A null fallback keeps the shell (nav, footer) painted without reserving a + box that would shift the page when the route chunk lands. */} + + + } /> + } /> + } /> + } /> + } /> + } /> + } /> + + + + + ) } diff --git a/src/components/layout/Navigation.tsx b/src/components/layout/Navigation.tsx index 4f60483..d72d68d 100644 --- a/src/components/layout/Navigation.tsx +++ b/src/components/layout/Navigation.tsx @@ -57,7 +57,7 @@ export function Navigation() { return ( <> -