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
- id: C1 claim: connection() indicates that rendering should wait for an incoming user request. source: S1 evidence: "wait for an incoming user request"
- id: C2 claim: Awaiting connection() stops prerendering at that point. source: S1 evidence: "prerendering stops here"
- id: C3 claim: React use() can read a Promise during rendering, which also waits before producing UI. source: S2 evidence: "read a resource during rendering"
Sources
- [S1] connection. Next.js docs. https://nextjs.org/docs/app/api-reference/functions/connection . License: MIT. Accessed 2026-11-19.
- [S2] use. React docs. https://react.dev/reference/react/use . License: CC-BY-4.0. Accessed 2026-11-19.
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
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.},
}
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.
- nextjs-connection.table.json (table; CC-BY-4.0)
- nextjs-connection.schema.json (schema; CC-BY-4.0)
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.