Skip to content

Commit

Permalink
Ensure minimalMode previousCache expire time is capped (#35954)
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Apr 7, 2022
1 parent 0164ac6 commit 26aacb0
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
5 changes: 1 addition & 4 deletions packages/next/server/response-cache.ts
Expand Up @@ -187,10 +187,7 @@ export default class ResponseCache {
this.previousCacheItem = {
key,
entry: cacheEntry,
expiresAt:
typeof cacheEntry.revalidate !== 'number'
? Date.now() + 1000
: Date.now() + cacheEntry?.revalidate * 1000,
expiresAt: Date.now() + 1000,
}
} else {
await this.incrementalCache.set(
Expand Down
24 changes: 24 additions & 0 deletions test/production/required-server-files.test.ts
Expand Up @@ -211,6 +211,30 @@ describe('should set-up next', () => {
expect(props4.gspCalls).toBe(props3.gspCalls)
})

it('should cap de-dupe previousCacheItem expires time', async () => {
const res = await fetchViaHTTP(appPort, '/gsp-long-revalidate', undefined, {
redirect: 'manual',
})
expect(res.status).toBe(200)
const $ = cheerio.load(await res.text())
const props = JSON.parse($('#props').text())
expect(props.gspCalls).toBeDefined()

await waitFor(1000)

const res2 = await fetchViaHTTP(
appPort,
`/_next/data/${next.buildId}/gsp-long-revalidate.json`,
undefined,
{
redirect: 'manual',
}
)
expect(res2.status).toBe(200)
const { pageProps: props2 } = await res2.json()
expect(props2.gspCalls).not.toBe(props.gspCalls)
})

it('should set correct SWR headers with notFound gsp', async () => {
await waitFor(2000)
await next.patchFile('standalone/data.txt', 'show')
Expand Down
37 changes: 37 additions & 0 deletions test/production/required-server-files/pages/gsp-long-revalidate.js
@@ -0,0 +1,37 @@
import fs from 'fs'
import path from 'path'

let gspCalls = 0

export async function getStaticProps() {
const data = await fs.promises.readFile(
path.join(process.cwd(), 'data.txt'),
'utf8'
)
gspCalls += 1

if (data.trim() === 'hide') {
return {
notFound: true,
revalidate: 1,
}
}

return {
props: {
hello: 'world',
data,
gspCalls,
},
revalidate: 100,
}
}

export default function Page(props) {
return (
<>
<p id="gsp">getStaticProps page</p>
<p id="props">{JSON.stringify(props)}</p>
</>
)
}

0 comments on commit 26aacb0

Please sign in to comment.