Repository navigation
docs: note that getCloudflareContext() in a page/layout requires dynamic rendering - #223
Open
munahartanto-dev wants to merge 1 commit into
Conversation
…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.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.next buildeither fails while trying to prerender it, or succeeds but bakes in a build-time context instead of the incoming request's context.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()) orexport const dynamic = "force-dynamic"before callinggetCloudflareContext()in a page/layout.Test plan