Unverified Commit a1633948 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Add warning for edge with force-static (#50182)

Currently the edge runtime does not support static generation so this adds a warning when `force-static` is leveraged with `edge-runtime` as it will cause unexpected behavior. Support is being investigated so this isn't a hard error at the moment. 

x-ref: [slack thread](https://vercel.slack.com/archives/C03S8ED1DKM/p1684783403551589)
parent 91e3c007
...@@ -1384,8 +1384,9 @@ export async function isPageStatic({ ...@@ -1384,8 +1384,9 @@ export async function isPageStatic({
let prerenderFallback: boolean | 'blocking' | undefined let prerenderFallback: boolean | 'blocking' | undefined
let appConfig: AppConfig = {} let appConfig: AppConfig = {}
let isClientComponent: boolean = false let isClientComponent: boolean = false
const pathIsEdgeRuntime = isEdgeRuntime(pageRuntime)
if (isEdgeRuntime(pageRuntime)) { if (pathIsEdgeRuntime) {
const runtime = await getRuntimeContext({ const runtime = await getRuntimeContext({
paths: edgeInfo.files.map((file: string) => path.join(distDir, file)), paths: edgeInfo.files.map((file: string) => path.join(distDir, file)),
env: edgeInfo.env, env: edgeInfo.env,
...@@ -1503,6 +1504,12 @@ export async function isPageStatic({ ...@@ -1503,6 +1504,12 @@ export async function isPageStatic({
{} {}
) )
if (appConfig.dynamic === 'force-static' && pathIsEdgeRuntime) {
Log.warn(
`Page "${page}" is using runtime = 'edge' which is currently incompatible with dynamic = 'force-static'. Please remove either "runtime" or "force-static" for correct behavior`
)
}
if (appConfig.dynamic === 'force-dynamic') { if (appConfig.dynamic === 'force-dynamic') {
appConfig.revalidate = 0 appConfig.revalidate = 0
} }
......
...@@ -1270,6 +1270,12 @@ createNextDescribe( ...@@ -1270,6 +1270,12 @@ createNextDescribe(
expect($2('#page-data').text()).toBe(pageData) expect($2('#page-data').text()).toBe(pageData)
return 'success' return 'success'
}, 'success') }, 'success')
if (isNextStart) {
expect(next.cliOutput).toContain(
`Page "/variable-revalidate-edge/revalidate-3" is using runtime = 'edge' which is currently incompatible with dynamic = 'force-static'. Please remove either "runtime" or "force-static" for correct behavior`
)
}
}) })
it('should honor fetch cache correctly (edge)', async () => { it('should honor fetch cache correctly (edge)', async () => {
......
import { cache, use } from 'react' import { cache, use } from 'react'
export const runtime = 'experimental-edge' export const runtime = 'experimental-edge'
export const dynamic = 'force-static'
export default function Page() { export default function Page() {
const getData = cache(() => const getData = cache(() =>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment