Interview Q&A · questions with model answers

Next.js Developer Interview Questions

Part of the study plan for: Frontend Engineer · Full Stack Engineer

Ordered by how often they're asked. Most-asked answers are free to read in full; members see every answer and can rate their confidence on each.

  1. Most asked How do you manage metadata and SEO in the App Router?

    Export a static metadata object or an async generateMetadata() from layouts and pages; Next.js merges them down the tree and renders <title>, meta descriptions, Open Graph and Twitter tags. Use…

  2. Most asked How do you implement authentication in a Next.js App Router app?

    Use a library such as Auth.js (NextAuth v5), Clerk, Better Auth or a custom session system: store sessions in HttpOnly cookies, read the session in Server Components/Actions/Route Handlers via…

  3. Most asked What causes hydration mismatch errors and how do you fix them?

    Hydration errors occur when the HTML rendered on the server differs from what React renders on the client's first pass, e.g. from using Date.now(), Math.random(), window/localStorage,…

  4. Most asked How do you optimize Core Web Vitals in a Next.js app?

    Minimize client JavaScript (keep components on the server, push 'use client' down the tree), optimize the LCP image with next/image priority, use next/font, stream slow content with Suspense, avoid…

  5. How do you build forms with Server Actions, validation and pending states?

    Pass a Server Action to <form action>; use useActionState(action, initialState) to get the returned state (errors, messages) and a pending flag; use useFormStatus inside a submit button to disable…

  6. How do you load third-party scripts efficiently in Next.js?

    Use next/script with a loading strategy: beforeInteractive (critical, rare), afterInteractive (default, e.g., tag managers), lazyOnload (idle time, e.g., chat widgets) or worker (experimental,…

  7. How do you design good loading states in the App Router?

    Use loading.tsx for instant route-level skeletons on navigation, granular <Suspense> boundaries for slow sections, useFormStatus/useActionState pending states for mutations, and useTransition for…

  8. How do you implement internationalization in the App Router?

    Use a [locale] dynamic segment (e.g., app/[locale]/...), detect the preferred locale in middleware/proxy (Accept-Language or cookie) and redirect, load dictionaries in Server Components, and…

  9. How do you test a Next.js application?

    Unit test components and utilities with Vitest or Jest plus React Testing Library, test Server Actions and data functions as plain async functions, and run end-to-end tests with Playwright against a…

  10. How do you add a Content Security Policy to a Next.js app?

    Set CSP headers in next.config headers() for static policies, or generate a per-request nonce in middleware/proxy, set the CSP header with that nonce, and read it in the layout (headers()) to pass…

  11. How do you add observability to a Next.js app?

    Use instrumentation.ts (with register()) to initialize OpenTelemetry (@vercel/otel) or APM SDKs at server startup, onRequestError to report server errors, Sentry's Next.js SDK for errors and…

  12. How do you access a database from Next.js safely and efficiently?

    Query the DB directly from Server Components, Server Actions and Route Handlers using an ORM (Prisma, Drizzle) inside a server-only data layer; reuse a single client instance (avoid creating clients…

  13. How would you migrate a large Next.js app from the Pages Router to the App Router?

    Migrate incrementally: create the app/ directory with a root layout replacing _app/_document, move routes one at a time (both routers coexist), convert data fetching from…

  14. How do you read and set cookies and headers in the App Router?

    Use cookies() and headers() from next/headers (async in Next.js 15+). Read cookies in Server Components; set or delete cookies only in Server Actions, Route Handlers or middleware, since Server…

  15. How do you avoid request waterfalls in Server Components?

    Start independent requests at the same time (Promise.all, or create promises before awaiting), move slow, independent data into separately suspended components, and preload data with a preload()…

  16. How do you add real-time features to a Next.js app?

    Next.js route handlers don't host long-lived WebSocket servers on serverless platforms, so use a managed real-time service (Pusher, Ably, Supabase Realtime, Liveblocks) or a separate WebSocket…

  17. How do you structure a Next.js app in a monorepo?

    Use a workspace manager (pnpm/npm/yarn workspaces) with Turborepo or Nx, put shared UI, config and types in packages, and set transpilePackages in next.config for internal packages that ship…

  18. How do you find and reduce large client bundles in Next.js?

    Run @next/bundle-analyzer (or the build output's size report), move heavy logic to Server Components, lazy-load rarely used client components with next/dynamic, use optimizePackageImports for large…

  19. How do you generate dynamic Open Graph images in Next.js?

    Add an opengraph-image.tsx (or a Route Handler) that returns new ImageResponse(<JSX/>, { width: 1200, height: 630 }) from next/og, rendering JSX with a subset of CSS to a PNG at request or build time.

  20. How do you colocate non-route files inside the `app` directory?

    Any file or folder inside app/ is safe to colocate because only page and route files create public routes; prefixing a folder with _ (e.g., _components) explicitly opts it out of routing and signals…

  21. How do you read query parameters in a Server Component page?

    Pages receive a searchParams prop (a Promise in Next.js 15+), so you await searchParams and read values; layouts don't receive searchParams because they don't re-render on navigation.

  22. How would you implement pagination and filters in the App Router?

    Keep filter and page state in the URL search params, read them in the page Server Component to fetch data on the server, and update them from client controls with router.replace()/<Link> (often…

  23. How do you implement a URL-addressable modal in the App Router?

    Combine a parallel route slot (@modal) in the layout with an intercepting route (@modal/(.)photos/[id]/page.tsx) that renders the modal during client navigation, while photos/[id]/page.tsx renders…

  24. How should you handle third-party webhooks in Next.js?

    Use a Route Handler, read the raw body with await req.text(), verify the signature with the provider's SDK or HMAC before parsing, process idempotently using the event ID, and respond quickly…

  25. How can you preload critical resources in the App Router?

    Use React DOM's resource APIs such as preload(), preconnect() and prefetchDNS() from react-dom in Server Components, plus next/font and the priority image prop, which emit preload hints automatically.

  26. How do you debug unexpected stale data in a Next.js App Router app?

    Identify which cache is serving it: check whether the route is static (build output ○ vs ƒ), whether fetches are cached (cache/revalidate options), whether data is in unstable_cache/'use cache', and…

  27. How do you investigate a production-only error that shows 'An error occurred in the Server Components render'?

    Use the error digest shown to the client to find the full error in server logs or your error tracker (Sentry via instrumentation.ts/onRequestError), because Next.js hides server error messages from…

  28. What should you consider for focus management during client-side navigation in Next.js?

    Next.js announces route changes for screen readers and scrolls to the top (or to hash targets) by default; you should ensure each page has a clear <h1>, manage focus for modals and dynamic content,…

Was this page helpful?

Report a mistake