Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix incorrect (sync) getCloudflareContext error message #404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/warm-lizards-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@opennextjs/cloudflare": patch
---

fix incorrect (sync) `getCloudflareContext` error message

currently `getCloudflareContext` run in sync mode at the top level of a not static route
gives a misleading error message saying that the function needs to be run in a not static
route, the changes here correct this error message clarifying that the problem actually is
10 changes: 5 additions & 5 deletions packages/cloudflare/src/api/cloudflare-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ function getCloudflareContextSync<
// normal global state so we throw with a helpful error message.
if (inSSG()) {
throw new Error(
`\n\nERROR: \`getCloudflareContext\` has been called in a static route,` +
` that is not allowed, this can be solved in different ways:\n\n` +
` - call \`getCloudflareContext({async: true})\` to use the \`async\` mode\n` +
` - avoid calling \`getCloudflareContext\` in the route\n` +
` - make the route non static\n`
`\n\nERROR: \`getCloudflareContext\` has been called in sync mode in either a static route or at the top level of a non-static one,` +
` both cases are not allowed but can be solved by either:\n` +
` - make sure that the call is not at the top level and that the route is not static\n` +
` - call \`getCloudflareContext({async: true})\` to use the \`async\` mode\n` +
` - avoid calling \`getCloudflareContext\` in the route\n`
);
}

Expand Down