Skip to content

fix: new ISR cache handling to resolve regression in 13.4 #2165

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 12 commits into from
Jun 16, 2023
Merged
Changes from 1 commit
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
11 changes: 7 additions & 4 deletions packages/runtime/src/templates/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,14 @@ const getNetlifyNextServer = (NextServer: NextServerType) => {
return
}

// force Next to revalidate all ODB revalidation requests so that we always have fresh content...
// setting this header to the preview mode ID is how Next knows to revalidate
// force Next to revalidate all requests so that we always have fresh content
// for our ODBs and middleware is disabled at the origin
// but ignore in preview mode (prerender_bypass is set to true in preview mode)
// because otherwise revalidate will override preview mode
// eslint-disable-next-line no-underscore-dangle
if (headers['x-nf-builder-cache'] === 'revalidate' && !headers.__prerender_bypass) {
console.log(`Revalidating ${url}`)
if (!headers.__prerender_bypass) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gah, I realized last night that if we only revalidate when an ODB sends that header, then middleware will still be enabled for all other requests (because we're now relying on revalidate mode to disable middleware at the origin). This commit reverts that, so we now revalidate on every request and will have to find a different way to serve the initial static content (but perhaps that's for a separate PR, like you said).

// this header controls whether Next.js will revalidate the page
// and needs to be set to the preview mode id to enable it
headers['x-prerender-revalidate'] = this.renderOpts.previewProps.previewModeId
}

Expand Down