Skip to content

feat: Implement Route-Level Code Splitting (Lazy Loading) for Performance Optimization - #141

Open
sarv-tech wants to merge 3 commits into
SufalBasak:mainfrom
sarv-tech:feat/route-level-code-splitting
Open

feat: Implement Route-Level Code Splitting (Lazy Loading) for Performance Optimization#141
sarv-tech wants to merge 3 commits into
SufalBasak:mainfrom
sarv-tech:feat/route-level-code-splitting

Conversation

@sarv-tech

Copy link
Copy Markdown

Description

This PR implements route-level code splitting using React.lazy() and <Suspense> to significantly optimize the application's initial load performance.

Previously, all major page components were imported synchronously in App.tsx, which forced Vite to bundle the entire application into a single, massive JavaScript chunk. This resulted in a bloated initial payload, negatively impacting Time to Interactive (TTI) and Largest Contentful Paint (LCP) metrics.

By strategically lazily loading all 18+ page-level routes, we have decoupled the heavy views (e.g., Voice Practice, Verbal Game, Practice Hub) from the main bundle. The browser now only fetches the specific JavaScript chunk required for the active route, downloading additional chunks dynamically as the user navigates.

Key Changes

  • Dynamic Imports: Refactored App.tsx to replace all static page imports with React.lazy(() => import('...')).
  • Suspense Boundary: Wrapped the React Router <Routes> layer inside a <Suspense> component to gracefully handle the asynchronous chunk loading.
  • Global Loader Implementation: Created a new, accessible <GlobalLoader /> fallback component (src/components/ui/GlobalLoader.tsx). It features aria-live="polite" and role="status" properties, ensuring screen readers announce the loading transition for visually impaired users.
  • Robust Error Handling: Integrated the <Suspense> boundary directly inside the pre-existing <DebugErrorBoundary>. If a network interruption causes a ChunkLoadError during navigation, the application gracefully degrades to a clean fallback UI rather than crashing.
  • Linting Cleanup: Fixed pre-existing empty interface declarations and resolved unused @ts-expect-error comments in the UI layer without altering the global eslint.config.js.

Performance Impact

  • Initial Bundle Size: Drastically reduced as page logic and dependencies are now correctly code-split.
  • TTI & LCP: Noticeable improvements across all metrics since the browser executes far less JavaScript on the initial render.
  • Network Efficiency: Users on slow connections will only download the specific route they intend to view.

Type of change

  • Performance enhancement (non-breaking change which improves performance)
  • Refactoring (non-breaking change that improves code quality)

Validation and Testing

  • Verified that all routes successfully lazy-load in the development environment.
  • Ran a production build (vite build) and verified that Rollup correctly generates multiple split JavaScript chunks.
  • Confirmed the accessibility of the GlobalLoader fallback during slow 3G network simulation.
  • Passed all 46/46 unit and component tests (npm test).
  • Verified zero TypeScript compilation errors.
  • Confirmed that all critical providers (AuthProvider, QueryClientProvider) remain synchronous and unaffected.

Checklist

  • My code follows the existing style guidelines of this project
  • I have performed a self-review of my own code
  • I have added accessible aria labels where necessary
  • My changes generate no new ESLint warnings or errors

close #140

This implements lazy loading for all page-level routes and introduces an accessible GlobalLoader for the Suspense boundary. It also fixes pre-existing empty interfaces and unused ts-expect-error comments without relaxing the global eslint configuration.
Copilot AI review requested due to automatic review settings July 4, 2026 20:53
@vercel

vercel Bot commented Jul 4, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the Sufal Basak's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces route-level code splitting in the React app by converting page-level route components in src/App.tsx to React.lazy() dynamic imports, wrapped in a global Suspense boundary with an accessible loading fallback. It also includes small UI-layer type cleanups and minor lint-related adjustments.

Changes:

  • Refactored src/App.tsx to lazy-load page routes and render them inside <Suspense fallback={<GlobalLoader />}> (within DebugErrorBoundary).
  • Added a new src/components/ui/GlobalLoader.tsx component to serve as the Suspense fallback UI.
  • Cleaned up a few UI typings (empty interfaces → type aliases) and removed/adjusted TypeScript ignore usage.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tailwind.config.ts Adds an ESLint suppression for the Tailwind plugin require() usage.
src/components/ui/textarea.tsx Replaces an empty props interface with a type alias.
src/components/ui/GlobalLoader.tsx Introduces the global Suspense fallback loader UI.
src/components/ui/command.tsx Replaces an empty props interface with a type alias.
src/components/typing/TypingTest.tsx Removes TS-ignore comments; minor behavior/documentation cleanup needed.
src/App.tsx Implements route-level lazy loading with Suspense + error boundary.
package-lock.json Lockfile updates from dependency resolution/install.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/components/typing/TypingTest.tsx Outdated
Comment thread src/components/ui/GlobalLoader.tsx
Comment thread src/components/ui/GlobalLoader.tsx
sarv-tech and others added 2 commits July 5, 2026 02:26
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@sarv-tech

Copy link
Copy Markdown
Author

Hi @SufalBasak, I've Created a PR kindly review, approve & Add labels

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Enhancement] Implement Route-Level Code Splitting (Lazy Loading) for Performance Optimization

2 participants