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.
This commit is contained in:
dong.nguyen committed 2026-10-18 23:45:47 +07:00
1 parent 0c4aea32b5
commit 63afc1b505
8 files changed
+71 -41

No files matched your search

+27 -21
View File
@@ -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() {
<ThemeProvider>
<LanguageProvider>
<Layout>
<Routes>
<Route path="/" element={<HomePage />} />
<Route path="/about" element={<AboutPage />} />
<Route path="/experience" element={<ExperiencePage />} />
<Route path="/projects" element={<ProjectsListPage />} />
<Route path="/projects/:id" element={<ProjectDetailPage />} />
<Route path="/philosophy" element={<PhilosophyPage />} />
<Route path="/contact" element={<ContactPage />} />
</Routes>
</Layout>
</LanguageProvider>
</ThemeProvider>
{/* A null fallback keeps the shell (nav, footer) painted without reserving a
box that would shift the page when the route chunk lands. */}
<Suspense fallback={null}>
<Routes>
<Route path="/" element={<HomePage />} />
<Route path="/about" element={<AboutPage />} />
<Route path="/experience" element={<ExperiencePage />} />
<Route path="/projects" element={<ProjectsListPage />} />
<Route path="/projects/:id" element={<ProjectDetailPage />} />
<Route path="/philosophy" element={<PhilosophyPage />} />
<Route path="/contact" element={<ContactPage />} />
</Routes>
</Suspense>
</Layout>
</LanguageProvider>
</ThemeProvider>
</BrowserRouter>
)
}