Skip to content
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

Fix revalidate during dev #41772

Merged
merged 5 commits into from Oct 25, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -10,7 +10,7 @@ export function staticGenerationBailout(reason: string) {
if (staticGenerationStore?.isStaticGeneration) {
// TODO: honor the dynamic: 'force-static'
if (staticGenerationStore) {
staticGenerationStore.revalidate = 0
staticGenerationStore.fetchRevalidate = 0
}
throw new DynamicServerError(reason)
}
Expand Down
22 changes: 12 additions & 10 deletions packages/next/server/app-render.tsx
Expand Up @@ -238,13 +238,13 @@ function patchFetch(ComponentMod: any) {
) {
staticGenerationStore.fetchRevalidate = next.revalidate

// TODO: ensure this error isn't logged to the user
// seems it's slipping through currently
throw new DynamicServerError(
`revalidate: ${next.revalidate} fetch ${input}${
pathname ? ` ${pathname}` : ''
}`
)
if (next.revalidate === 0) {
throw new DynamicServerError(
`revalidate: ${next.revalidate} fetch ${input}${
pathname ? ` ${pathname}` : ''
}`
)
}
}
if (hasNextConfig) delete init.next
}
Expand Down Expand Up @@ -735,7 +735,9 @@ export async function renderToHTMLOrFlight(
supportsDynamicHTML,
} = renderOpts

patchFetch(ComponentMod)
if (process.env.NODE_ENV === 'production') {
patchFetch(ComponentMod)
}
const generateStaticHTML = supportsDynamicHTML !== true

const staticGenerationAsyncStorage = ComponentMod.staticGenerationAsyncStorage
Expand Down Expand Up @@ -1619,9 +1621,9 @@ export async function renderToHTMLOrFlight(

;(renderOpts as any).pageData = filteredFlightData
;(renderOpts as any).revalidate =
typeof staticGenerationStore?.revalidate === 'undefined'
typeof staticGenerationStore?.fetchRevalidate === 'undefined'
? defaultRevalidate
: staticGenerationStore?.revalidate
: staticGenerationStore?.fetchRevalidate

return new RenderResult(htmlResult)
}
Expand Down
5 changes: 4 additions & 1 deletion test/e2e/app-dir/app-static/app/blog/[author]/page.js
Expand Up @@ -2,7 +2,10 @@ import Link from 'next/link'

export const dynamicParams = false

export default function Page({ params }) {
export default async function Page({ params }) {
await fetch('https://example.vercel.sh', {
next: { revalidate: 10 },
})
return (
<>
<p id="page">/blog/[author]</p>
Expand Down