Back to all reviewers

Next.js async behavior

elie222/inbox-zero
Based on 3 comments
TSX

Understand and correctly implement the asynchronous behavior of Next.js APIs and components. Follow these guidelines: 1. Add `` boundaries around components that use hooks that can trigger suspense, such as `useSearchParams` in the Next.js App Router:

Next TSX

Reviewer Prompt

Understand and correctly implement the asynchronous behavior of Next.js APIs and components. Follow these guidelines:

  1. Add <Suspense> boundaries around components that use hooks that can trigger suspense, such as useSearchParams in the Next.js App Router:
<Suspense>
  <ComponentUsingSearchParams />
</Suspense>
  1. Don’t await synchronous Next.js functions. For example, cookies() from ‘next/headers’ returns a synchronous object:
// Incorrect
const cookieStore = await cookies();

// Correct
const cookieStore = cookies();
  1. Next.js page props like searchParams are regular objects, not Promises - handle them correctly:
// Incorrect
export default async function Page(props: {
  searchParams: Promise<{ param?: string }>;
}) {
  const searchParams = await props.searchParams;
  // ...
}

// Correct
export default async function Page({ 
  searchParams 
}: {
  searchParams: { param?: string };
}) {
  // ...
}

Correctly identifying when to use asynchronous patterns like Suspense and await improves application stability and performance.

3
Comments Analyzed
TSX
Primary Language
Next
Category

Source Discussions