← All notes

Wait for a Next.js request with connection() before request-time work

Answer: The connection() function in next/server allows you to indicate rendering should wait for an incoming user request before continuing. Awaiting it stops prerendering at that line. React's use() is a different wait: it reads a Promise or context during rendering.

When to call connection()

It is useful when a component does not use Request-time APIs such as cookies or headers, yet still needs different output per request, for example Math.random() or new Date(). The example is await connection() in a page, then code that only runs at request time. Queries from synchronous database drivers can complete during prerendering. Call connection() before such a query if you are not already using a Request-time API.

Waiting with use()

use lets you read a resource during rendering, such as a Promise or context. connection() waits for the incoming user request. Use use() when the component reads a Promise or context value.

| connection() | use() | |---|---| | connection() | Wait for an incoming user request | | prerendering | Stops at await connection() | | cookies and headers | Request-time APIs | | use() | Reads a Promise or context during render |

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Next.js docs, connection; React docs, use. MIT; CC-BY-4.0. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Next.js docs, connection; React docs, use. MIT; CC-BY-4.0.

Cite this

Permanent ID: iil:note:dacg8yw0

iinventedlight. 2026. "Wait for a Next.js request with connection() before request-time work." iinventedlight Library, iil:note:dacg8yw0, version of 2026-11-19. https://iinventedlight.com/library/notes/nextjs-connection/. License: CC-BY-4.0.

@misc{iil_note_dacg8yw0,
  author = {{iinventedlight}},
  title = {{Wait for a Next.js request with connection() before request-time work}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-19},
  url = {https://iinventedlight.com/library/notes/nextjs-connection/},
  note = {Permanent ID iil:note:dacg8yw0. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/nextjs-connection.md.