You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you update examples/playground/api/env as follow:
import{getCloudflareContext}from"@opennextjs/cloudflare";// the output.exportconstdynamic="force-dynamic";console.log(getCloudflareContext());exportasyncfunctionGET(){returnnewResponse(JSON.stringify(process.env));}
Note: calling getCloudflareContext is not actually supported at top level but I'm working on adding support for that.
It would log an incorrect message (the route is dynamic):
ERROR: `getCloudflareContext` has been called in a static route, that is not allowed, this can be solved in different ways:
- call `getCloudflareContext({async: true})` to use the `async` mode
- avoid calling `getCloudflareContext` in the route
- make the route non static
This is not a static route
getCloudflareContext({async: true}) seem to work
We should first fix the error message.
It would also be nice that we could make {async: false} work here if possible
The text was updated successfully, but these errors were encountered:
I've just investigate this and it's my bad for the wrong error message, sorry about that π
Basically the {async: false} version of the function cannot work at the top level regardless on whether the route is dynamic or not, so I do need to update the error message to reflect that
The problem is that Next.js seems to always import and so a SSG-like processing even if you force the route to be dynamic, there is a long standing issue/discussion in their repo about this: vercel/next.js#35534
To clarify, see this hello api route I created in a brand new create-next-app application:
As you can see from the log the top level logic is run even if the route is fully dynamic, and I can't seem to find a way to prevent Next.js from doing that π
PS: what's worse if that Next.js does this in the same way it does standard SSG, so we can't discern between the two cases and provide different error messages in case the route is actually SSG'd or not π
If you update
examples/playground/api/env
as follow:Note: calling
getCloudflareContext
is not actually supported at top level but I'm working on adding support for that.It would log an incorrect message (the route is dynamic):
getCloudflareContext({async: true})
seem to workWe should first fix the error message.
It would also be nice that we could make
{async: false}
work here if possibleThe text was updated successfully, but these errors were encountered: