Skip to content

docs: note that getCloudflareContext() in a page/layout requires dynamic rendering - #223

Open
munahartanto-dev wants to merge 1 commit into
opennextjs:mainfrom
munahartanto-dev:docs/getcloudflarecontext-requires-dynamic-rendering
Open

munahartanto-dev wants to merge 1 commit into
opennextjs:mainfrom
munahartanto-dev:docs/getcloudflarecontext-requires-dynamic-rendering

Conversation

@munahartanto-dev

Copy link
Copy Markdown

Summary

  • getCloudflareContext() works fine in route handlers (already covered by the existing SSG/async-mode callout), but when called in a page or layout component it silently requires the route to render dynamically.
  • If Next.js is able to statically prerender that route, next build either fails while trying to prerender it, or succeeds but bakes in a build-time context instead of the incoming request's context.
  • This isn't currently documented anywhere in the bindings page, so it's easy to hit without understanding the cause.

Change

Adds a callout to pages/cloudflare/bindings.mdx (right after the existing SSG async-mode callout) showing how to force dynamic rendering via a Next.js Dynamic API (headers()) or export const dynamic = "force-dynamic" before calling getCloudflareContext() in a page/layout.

Test plan

  • Previewed the rendered Callout locally for MDX syntax correctness
  • Maintainer review for accuracy/preferred phrasing

…mic rendering

Calling getCloudflareContext() in a page or layout (not a route
handler) is only safe when the route renders dynamically. If
Next.js can statically prerender the route, next build will try
to do so and fail, or the context will reflect build time rather
than the incoming request.
@munahartanto-dev
munahartanto-dev requested review from a team and james-elicx as code owners November 6, 2026 09:06

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant