Update app router revalidate handling on deploy (#51062)

This ensures we clear the RSC headers during revalidate when deployed so
that the HTML revalidation isn't treated as the RSC revalidation.
This commit is contained in:
JJ Kasper 2023-06-09 13:23:44 -07:00 committed by GitHub
parent 761e372d68
commit 804552590e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 2 deletions

View file

@ -671,8 +671,14 @@ export default abstract class Server<ServerOptions extends Options = Options> {
}
// in minimal mode we detect RSC revalidate if the .rsc
// path is requested
if (this.minimalMode && req.url.endsWith('.rsc')) {
parsedUrl.query.__nextDataReq = '1'
if (this.minimalMode) {
if (req.url.endsWith('.rsc')) {
parsedUrl.query.__nextDataReq = '1'
} else if (req.headers['x-now-route-matches']) {
for (const param of FLIGHT_PARAMETERS) {
delete req.headers[param.toString().toLowerCase()]
}
}
}
req.url = normalizeRscPath(req.url, this.hasAppDir)

View file

@ -0,0 +1,10 @@
export const revalidate = 1
export default function Page() {
return (
<>
<p>/app-blog</p>
<p>Date: {Date.now()}</p>
</>
)
}

View file

@ -0,0 +1,8 @@
export default function Layout({ children }) {
return (
<html>
<head />
<body>{children}</body>
</html>
)
}

View file

@ -9,6 +9,7 @@ import {
findPort,
renderViaHTTP,
initNextServerScript,
fetchViaHTTP,
} from 'next-test-utils'
describe('minimal-mode-response-cache', () => {
@ -80,6 +81,29 @@ describe('minimal-mode-response-cache', () => {
if (server) await killApp(server)
})
it('app router revalidate should work with previous response cache', async () => {
const res1 = await fetchViaHTTP(appPort, '/app-blog', undefined, {
headers: {
'x-matched-path': '/app-blog.rsc',
rsc: '1',
},
})
const content1 = await res1.text()
expect(content1).not.toContain('<html')
expect(content1).toContain('app-blog')
expect(res1.headers.get('content-type')).toContain('text/x-component')
const res2 = await fetchViaHTTP(appPort, '/app-blog', undefined, {
headers: {
'x-matched-path': '/app-blog',
},
})
const content2 = await res2.text()
expect(content2).toContain('<html')
expect(content2).toContain('app-blog')
expect(res2.headers.get('content-type')).toContain('text/html')
})
it('should have correct "Listening on" log', async () => {
expect(output).toContain(`Listening on port`)
expect(output).toContain(`url: http://localhost:${appPort}`)