Skip to main content
These 16 rules are automatically enabled when React Doctor detects a Next.js project. They catch Next.js-specific issues and enforce framework best practices.

Rules

Severity: warn
Rule ID: react-doctor/nextjs-no-img-element
Requires using next/image instead of plain <img> tags for automatic optimization.Why it’s bad:
  • No automatic optimization
  • No lazy loading by default
  • No responsive srcset generation
  • Larger cumulative layout shift
Bad:
Good:
This rule is disabled in OG image routes (/app/og/route.tsx) where you need raw <img> for OpenGraph image generation.
Severity: error
Rule ID: react-doctor/nextjs-async-client-component
Prevents marking client components as async. Client components cannot be async functions.Bad:
Good:
Severity: warn
Rule ID: react-doctor/nextjs-no-a-element
Requires using next/link for internal navigation to enable client-side routing and prefetching.Bad:
Good:
Severity: warn
Rule ID: react-doctor/nextjs-no-use-search-params-without-suspense
Requires wrapping useSearchParams() in a Suspense boundary to prevent the entire page from falling back to client-side rendering.Why it’s bad:
  • Entire page renders on client instead of server
  • Slower initial page load
  • Loses benefits of server components
Bad:
Good:
Severity: warn
Rule ID: react-doctor/nextjs-no-client-fetch-for-server-data
Prevents using useEffect + fetch in page/layout files. Data should be fetched server-side.Bad:
Good:
Severity: warn
Rule ID: react-doctor/nextjs-missing-metadata
Requires page files to export metadata or generateMetadata for SEO.Bad:
Good:
This rule ignores internal routes like /app/(dashboard)/, /app/admin/, etc.
Severity: warn
Rule ID: react-doctor/nextjs-no-client-side-redirect
Suggests using redirect() in server components or middleware instead of client-side redirects.Bad:
Good:
Severity: warn
Rule ID: react-doctor/nextjs-no-redirect-in-try-catch
Prevents calling redirect() inside try-catch blocks. redirect() throws a special error that Next.js handles internally.Bad:
Good:
Severity: warn
Rule ID: react-doctor/nextjs-image-missing-sizes
Requires sizes attribute on images with fill prop for responsive behavior.Bad:
Good:
Severity: warn
Rule ID: react-doctor/nextjs-no-native-script
Requires using next/script instead of plain <script> for loading strategy optimization.Bad:
Good:
Severity: warn
Rule ID: react-doctor/nextjs-inline-script-missing-id
Requires id attribute on inline <Script> components for Next.js tracking.Bad:
Good:
Severity: warn
Rule ID: react-doctor/nextjs-no-polyfill-script
Next.js includes automatic polyfills for modern JavaScript features. External polyfill scripts are unnecessary.Bad:
Good: Remove the script - Next.js handles polyfills automatically.
Severity: error
Rule ID: react-doctor/nextjs-no-head-import
next/head is not supported in the App Router. Use the Metadata API instead.Bad:
Good:
Severity: error
Rule ID: react-doctor/nextjs-no-side-effect-in-get-handler
Prevents side effects in GET route handlers to prevent CSRF and unintended prefetch triggers.Why it’s bad:
  • GET requests should be safe (no side effects)
  • Next.js prefetches routes automatically
  • CSRF attacks can trigger GET requests
Bad:
Good:
Side effects detected:
  • Database writes (insert, update, delete)
  • User logout/signout in route path
  • State mutations

Server vs Client Components

Next.js App Router uses server components by default:

When to use client components:

  • Event handlers (onClick, onChange)
  • React hooks (useState, useEffect)
  • Browser APIs
  • Third-party interactive components

When to use server components:

  • Data fetching
  • Direct database access
  • Server-only code
  • Reducing bundle size