Unverified Commit 26aacb04 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Ensure minimalMode previousCache expire time is capped (#35954)

parent 0164ac60
...@@ -187,10 +187,7 @@ export default class ResponseCache { ...@@ -187,10 +187,7 @@ export default class ResponseCache {
this.previousCacheItem = { this.previousCacheItem = {
key, key,
entry: cacheEntry, entry: cacheEntry,
expiresAt: expiresAt: Date.now() + 1000,
typeof cacheEntry.revalidate !== 'number'
? Date.now() + 1000
: Date.now() + cacheEntry?.revalidate * 1000,
} }
} else { } else {
await this.incrementalCache.set( await this.incrementalCache.set(
......
...@@ -211,6 +211,30 @@ describe('should set-up next', () => { ...@@ -211,6 +211,30 @@ describe('should set-up next', () => {
expect(props4.gspCalls).toBe(props3.gspCalls) 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 () => { it('should set correct SWR headers with notFound gsp', async () => {
await waitFor(2000) await waitFor(2000)
await next.patchFile('standalone/data.txt', 'show') await next.patchFile('standalone/data.txt', 'show')
......
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>
</>
)
}
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