Back to Blog

Visual Regression Testing for React and Next.js Apps

Visual Regression Testing for React and Next.js Apps

React and Next.js apps have unique visual testing challenges: component hydration, client-side routing, dynamic imports, suspense boundaries, and server-rendered content that can differ from client-rendered output.

Why React Apps Need Visual Testing

CSS-in-JS Side Effects: Change a utility class and 40 components shift. Functional tests won't catch it.

Component Composition: A padding change to <Card> affects every page using it.

Hydration Mismatches: If server and client output differ, visual testing catches the final rendered state.

Two-column comparison of reviewing a shared React component change: raw snapshot files (open every PNG by hand, pixel-only false fails, commit binaries to git) versus the Lastest dashboard (all diffs side by side, SSIM plus Butteraugli ignore font noise, AI flags intentional vs unintended)
When a shared component changes dozens of routes, raw snapshot files mean manual PNG triage while Lastest's dashboard plus three diff engines and AI classification collapse the review.

What to Test

  • Each route - homepage, dashboard, settings, profile
  • Auth states - login page vs logged-in
  • Empty states - pages with no data
  • Error states - API failures, 404
  • Responsive breakpoints - mobile (375×812), tablet (768×1024), desktop (1440×900)

Handling React-Specific Challenges

Client-Side Routing: Lastest's DOM stability detector waits for React to finish rendering. No manual waitForTimeout.

Dynamic Imports: Network idle waiting + DOM stability detection ensures all lazy chunks load before capture.

Suspense: Configure network idle wait so all data fetching completes before screenshots.

Pipeline flow showing a React route change passing through DOM stability detection, network-idle waiting for Suspense and lazy chunks, and clock-freeze/random-seed before producing a deterministic screenshot with no waitForTimeout
Lastest chains DOM-stability, network-idle, and clock/random freezing so React renders settle before capture, with no manual waits.
Recording settings

Stabilization

  • Timestamps: Freeze Date.now()
  • Random values: Seed Math.random()
  • Animations: Disable CSS transitions during tests
  • Third-party: Block chat widgets, analytics

Template Selection

App TypeTemplateWhy
SaaS dashboardSaaS / DashboardTimestamp freezing, dynamic masking
Marketing siteMarketing WebsiteThird-party blocking, multiple viewports
Design tool (Canvas)Canvas / DrawingGPU headless, coordinate selectors
E-commerceE-commercePrice/image mocking
Docs (MDX)DocumentationLightweight, high parallelism

Getting Started

  1. Deploy Lastest: docker-compose up -d
  2. Add your React/Next.js app as a repository
  3. Select the right template
  4. Run the AI Play Agent
  5. Review and approve baselines
  6. Add to CI with GitHub Action