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

Ensure minimalMode previousCache expire time is capped #35954

Merged
merged 3 commits into from Apr 7, 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
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
@@ -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>
</>
)
}