Skip to content

Commit 881c313

Browse files
authored
Update to use HEAD request for On-Demand ISR (vercel#39038)
* Update to use HEAD request for On-Demand ISR * update test for deploy
1 parent c69d781 commit 881c313

File tree

2 files changed

+62
-50
lines changed

2 files changed

+62
-50
lines changed

packages/next/server/api-utils/node.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ async function revalidate(
316316
try {
317317
if (context.trustHostHeader) {
318318
const res = await fetch(`https://${req.headers.host}${urlPath}`, {
319+
method: 'HEAD',
319320
headers: {
320321
...revalidateHeaders,
321322
cookie: req.headers.cookie || '',

test/e2e/prerender.test.ts

Lines changed: 61 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,6 +2002,67 @@ describe('Prerender', () => {
20022002
})
20032003
}
20042004

2005+
if (!isDev) {
2006+
it('should handle manual revalidate for fallback: blocking', async () => {
2007+
const beforeRevalidate = Date.now()
2008+
const res = await fetchViaHTTP(
2009+
next.url,
2010+
'/blocking-fallback/test-manual-1'
2011+
)
2012+
2013+
if (!isDeploy) {
2014+
await waitForCacheWrite(
2015+
'/blocking-fallback/test-manual-1',
2016+
beforeRevalidate
2017+
)
2018+
}
2019+
const html = await res.text()
2020+
const $ = cheerio.load(html)
2021+
const initialTime = $('#time').text()
2022+
const cacheHeader = isDeploy ? 'x-vercel-cache' : 'x-nextjs-cache'
2023+
2024+
expect(res.headers.get(cacheHeader)).toMatch(/MISS/)
2025+
expect($('p').text()).toMatch(/Post:.*?test-manual-1/)
2026+
2027+
if (!isDeploy) {
2028+
const res2 = await fetchViaHTTP(
2029+
next.url,
2030+
'/blocking-fallback/test-manual-1'
2031+
)
2032+
const html2 = await res2.text()
2033+
const $2 = cheerio.load(html2)
2034+
2035+
expect(res2.headers.get(cacheHeader)).toMatch(/(HIT|STALE)/)
2036+
expect(initialTime).toBe($2('#time').text())
2037+
}
2038+
2039+
const res3 = await fetchViaHTTP(
2040+
next.url,
2041+
'/api/manual-revalidate',
2042+
{
2043+
pathname: '/blocking-fallback/test-manual-1',
2044+
},
2045+
{ redirect: 'manual' }
2046+
)
2047+
2048+
expect(res3.status).toBe(200)
2049+
const revalidateData = await res3.json()
2050+
expect(revalidateData.revalidated).toBe(true)
2051+
2052+
await check(async () => {
2053+
const res4 = await fetchViaHTTP(
2054+
next.url,
2055+
'/blocking-fallback/test-manual-1'
2056+
)
2057+
const html4 = await res4.text()
2058+
const $4 = cheerio.load(html4)
2059+
expect($4('#time').text()).not.toBe(initialTime)
2060+
expect(res4.headers.get(cacheHeader)).toMatch(/(HIT|STALE)/)
2061+
return 'success'
2062+
}, 'success')
2063+
})
2064+
}
2065+
20052066
if (!isDev && !isDeploy) {
20062067
it('should automatically reset cache TTL when an error occurs and build cache was available', async () => {
20072068
await next.patchFile('error.txt', 'yes')
@@ -2056,56 +2117,6 @@ describe('Prerender', () => {
20562117
)
20572118
})
20582119

2059-
it('should handle manual revalidate for fallback: blocking', async () => {
2060-
const beforeRevalidate = Date.now()
2061-
const res = await fetchViaHTTP(
2062-
next.url,
2063-
'/blocking-fallback/test-manual-1'
2064-
)
2065-
await waitForCacheWrite(
2066-
'/blocking-fallback/test-manual-1',
2067-
beforeRevalidate
2068-
)
2069-
const html = await res.text()
2070-
const $ = cheerio.load(html)
2071-
const initialTime = $('#time').text()
2072-
2073-
expect(res.headers.get('x-nextjs-cache')).toMatch(/MISS/)
2074-
expect($('p').text()).toMatch(/Post:.*?test-manual-1/)
2075-
2076-
const res2 = await fetchViaHTTP(
2077-
next.url,
2078-
'/blocking-fallback/test-manual-1'
2079-
)
2080-
const html2 = await res2.text()
2081-
const $2 = cheerio.load(html2)
2082-
2083-
expect(res2.headers.get('x-nextjs-cache')).toMatch(/(HIT|STALE)/)
2084-
expect(initialTime).toBe($2('#time').text())
2085-
2086-
const res3 = await fetchViaHTTP(
2087-
next.url,
2088-
'/api/manual-revalidate',
2089-
{
2090-
pathname: '/blocking-fallback/test-manual-1',
2091-
},
2092-
{ redirect: 'manual' }
2093-
)
2094-
2095-
expect(res3.status).toBe(200)
2096-
const revalidateData = await res3.json()
2097-
expect(revalidateData.revalidated).toBe(true)
2098-
2099-
const res4 = await fetchViaHTTP(
2100-
next.url,
2101-
'/blocking-fallback/test-manual-1'
2102-
)
2103-
const html4 = await res4.text()
2104-
const $4 = cheerio.load(html4)
2105-
expect($4('#time').text()).not.toBe(initialTime)
2106-
expect(res4.headers.get('x-nextjs-cache')).toMatch(/(HIT|STALE)/)
2107-
})
2108-
21092120
it('should not manual revalidate for fallback: blocking with onlyGenerated if not generated', async () => {
21102121
const res = await fetchViaHTTP(
21112122
next.url,

0 commit comments

Comments
 (0)