Migrating React SPA, Vite, or Create React App
Inventory first​
List routes, loaders, API clients, environment variables, asset rules, CSS ownership, authentication, browser-only libraries, tests, and deployment assumptions. Record behavior before changing architecture.
Incremental strategy​
- Create an App Router shell and root layout.
- Move static assets and global CSS.
- Recreate routes one vertical slice at a time.
- Keep browser-only features in narrow Client Components.
- Move privileged data access to server-only modules.
- Replace client routing and document metadata with Next.js APIs.
- Add server-side authorization, error boundaries, and loading UI.
- Compare bundle size, Web Vitals, status codes, and SEO.
Environment variables​
Vite's VITE_* and CRA's REACT_APP_* variables do not map automatically. Public Next.js variables use NEXT_PUBLIC_*; private values remain server-only. Audit every variable before renaming because public prefixes embed values into browser bundles.
API calls​
A SPA often calls a separate backend from the browser. Keep that architecture when appropriate, but move secret-bearing or aggregation calls into Server Components or Route Handlers. Preserve timeouts and error contracts.
Browser-only dependencies​
Do not mark the whole route 'use client'. Wrap the incompatible component, dynamically load it when necessary, and provide an accessible server-rendered shell.
Rollout​
Use route-level traffic control or a reverse proxy when old and new applications must coexist. Maintain deep-link behavior, cookies, canonical URLs, and analytics identifiers during the transition.