Skip to content

Commit

Permalink
Fix SPR always revalidating in production
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Oct 16, 2019
1 parent 9308d71 commit 30ade9b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/next/next-server/server/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ export default class Server {

// Complete the response with cached data if its present
const cachedData = await getSprCache(sprCacheKey)

if (cachedData) {
const data = isSprData
? JSON.stringify(cachedData.pageData)
Expand Down
6 changes: 4 additions & 2 deletions packages/next/next-server/server/spr-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const calculateRevalidate = (pathname: string): number | false => {
// in development we don't have a prerender-manifest
// and default to always revalidating to allow easier debugging
const curTime = new Date().getTime()
if (!sprOptions.dev) return curTime
if (sprOptions.dev) return curTime

const { initialRevalidateSeconds } = prerenderManifest.routes[pathname] || {
initialRevalidateSeconds: 1,
Expand Down Expand Up @@ -157,9 +157,11 @@ export async function setSprCache(
}

pathname = normalizePagePath(pathname)
const revalidateAfter = calculateRevalidate(pathname)

cache.set(pathname, {
...data,
revalidateAfter: calculateRevalidate(pathname),
revalidateAfter,
})

// TODO: This option needs to cease to exist unless it stops mutating the
Expand Down

0 comments on commit 30ade9b

Please sign in to comment.