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 Explain the App Router file conventions: page, layout, loading, error, not-found, template and route.

    page.tsx defines a route's UI; layout.tsx wraps child segments and persists across navigation; loading.tsx is an automatic Suspense fallback; error.tsx is an error boundary (must be a Client…

  2. Most asked How does data fetching work in the App Router?

    Server Components can be async and fetch data directly with fetch or any database/ORM client. Next.js adds caching and revalidation options on top: fetch(url, { next: { revalidate: 60, tags:…

  3. Most asked How did caching defaults change in Next.js 15?

    Next.js 15 made caching opt-in: fetch requests are no longer cached by default, GET Route Handlers are not cached by default, and the client Router Cache no longer reuses page segments (stale time…

  4. Most asked Explain SSR, SSG, ISR and CSR in Next.js.

    SSG pre-renders pages at build time; ISR (Incremental Static Regeneration) re-generates static pages in the background after a revalidation period or on demand; SSR renders on every request; CSR…

  5. Most asked What happens, step by step, when a request reaches a Next.js App Router application?

    next.config headers, redirects and rewrites apply; the proxy (middleware.ts before Next.js 16) runs for matched paths and may redirect, rewrite or respond; routing serves static assets directly or…

  6. Most asked How do dynamic routes, catch-all and optional catch-all segments work?

    [slug] matches one segment, [...slug] matches one or more segments (array), and [[...slug]] also matches the parent path with no segments. Params arrive in the page's params prop.

  7. Most asked How does streaming with Suspense work in Next.js?

    The server sends HTML in chunks: the shell (layout plus fast parts) is sent immediately, and slower components wrapped in <Suspense fallback={...}> stream in when their data resolves, without…

  8. Most asked How do `revalidatePath` and `revalidateTag` work?

    revalidatePath('/posts') invalidates cached data and rendered output for a path; revalidateTag('posts') invalidates all cached fetches/entries tagged posts. Both are called from Server Actions or…

  9. Most asked How do environment variables work in Next.js, and what is exposed to the browser?

    Variables in .env* files are available on the server via process.env. Only variables prefixed with NEXT_PUBLIC_ are inlined into the client bundle at build time, so never put secrets in NEXT_PUBLIC_…

  10. Most asked How do `getServerSideProps`, `getStaticProps` and `getStaticPaths` work in the Pages Router?

    getServerSideProps runs on every request and passes props to the page (SSR); getStaticProps runs at build time (with optional revalidate for ISR); getStaticPaths lists dynamic paths to pre-render,…

  11. How can a Client Component render Server Component content?

    Pass the Server Component as children (or another prop) from a Server Component parent. The server renders it, and the Client Component just places the already-rendered result.

  12. Describe the caching layers in the Next.js App Router.

    There are four layers: Request Memoization (dedupes identical fetches within one render), the Data Cache (persists fetch results across requests and deploys until revalidated), the Full Route Cache…

  13. How does navigation work with `<Link>` and `useRouter` in the App Router?

    <Link href='/about'> performs client-side navigation and prefetches routes in the viewport (in production). useRouter() from next/navigation provides push, replace, refresh, back and prefetch for…

  14. How does error handling work in the App Router?

    error.tsx (a Client Component receiving error and reset) acts as a React error boundary for its segment; global-error.tsx handles root layout errors; notFound() renders not-found.tsx; and redirect()…

  15. How does `next/dynamic` work and when do you use it?

    next/dynamic lazy-loads a component (code splitting) with an optional loading fallback; with ssr: false (only allowed inside Client Components in recent versions) it skips server rendering for…

  16. How do redirects, rewrites and headers work in `next.config`?

    redirects() returns permanent (308) or temporary (307) redirects, rewrites() maps a request path to another path or external URL without changing the browser URL (e.g., proxying an API), and…

  17. How does state management change with Server Components?

    Much 'state' becomes server data fetched in Server Components and refreshed via revalidation, so global client stores shrink. Use URL search params for shareable UI state, React state/context for…

  18. How does React 19's `use()` hook help with data in Next.js?

    use(promise) lets a Client Component read a Promise passed from a Server Component, suspending until it resolves; it can also read context conditionally.

  19. How are static assets served in Next.js?

    Files in public/ are served from the site root (/logo.png) without processing. Imported assets (import logo from './logo.png') get hashed filenames and can be optimized with next/image.

  20. How do `redirect()`, `permanentRedirect()` and `notFound()` work?

    They throw special errors that Next.js catches: redirect() sends a 307 (or 303 from Server Actions), permanentRedirect() sends 308, and notFound() renders the nearest not-found.tsx with a 404…

  21. How does Next.js support TypeScript?

    Next.js has built-in TypeScript support: it creates tsconfig.json and next-env.d.ts, type-checks during next build, supports next.config.ts, and offers typed routes (typedRoutes) for compile-time…

  22. How should errors in Server Actions be handled for good UX?

    Return structured results for expected errors (validation, business rule failures) and render them via useActionState; let unexpected errors throw so the nearest error.tsx boundary handles them, and…

  23. How do you make a Route Handler's GET response static or cached?

    In Next.js 15+, GET Route Handlers are dynamic by default; opt into static generation with export const dynamic = 'force-static' (or revalidate), or set HTTP caching headers (Cache-Control) for CDN…

  24. How do you stream a response (e.g., AI tokens) from a Route Handler?

    Return a Response wrapping a ReadableStream (or use helpers like the Vercel AI SDK's toDataStreamResponse) with appropriate headers, and consume it in the client with fetch +…

  25. How does image optimization work when self-hosting Next.js?

    next start includes the image optimizer, which resizes on demand and caches results on disk (.next/cache/images); in multi-instance or serverless setups, use a shared cache or offload to an image…

  26. How do you call a Server Action from an event handler instead of a form?

    Import the action into a Client Component and call it like an async function, usually inside startTransition (via useTransition) so React tracks the pending state and can update the UI after…

  27. How do you handle runtime configuration that changes per environment without rebuilding?

    Read server-side process.env values at request time in Server Components/Route Handlers (which are evaluated at runtime for dynamic routes), and pass the needed public values down as props, rather…

  28. How does Next.js protect against XSS and where can you still introduce it?

    React escapes values rendered in JSX by default. XSS can still come from dangerouslySetInnerHTML with unsanitized content, href/src values like javascript: URLs from user input, unsafe Markdown…

Was this page helpful?

Report a mistake