Unverified Commit 80455259 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

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.
parent 761e372d
...@@ -671,8 +671,14 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -671,8 +671,14 @@ export default abstract class Server<ServerOptions extends Options = Options> {
} }
// in minimal mode we detect RSC revalidate if the .rsc // in minimal mode we detect RSC revalidate if the .rsc
// path is requested // path is requested
if (this.minimalMode && req.url.endsWith('.rsc')) { if (this.minimalMode) {
parsedUrl.query.__nextDataReq = '1' 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) req.url = normalizeRscPath(req.url, this.hasAppDir)
......
export const revalidate = 1
export default function Page() {
return (
<>
<p>/app-blog</p>
<p>Date: {Date.now()}</p>
</>
)
}
export default function Layout({ children }) {
return (
<html>
<head />
<body>{children}</body>
</html>
)
}
...@@ -9,6 +9,7 @@ import { ...@@ -9,6 +9,7 @@ import {
findPort, findPort,
renderViaHTTP, renderViaHTTP,
initNextServerScript, initNextServerScript,
fetchViaHTTP,
} from 'next-test-utils' } from 'next-test-utils'
describe('minimal-mode-response-cache', () => { describe('minimal-mode-response-cache', () => {
...@@ -80,6 +81,29 @@ describe('minimal-mode-response-cache', () => { ...@@ -80,6 +81,29 @@ describe('minimal-mode-response-cache', () => {
if (server) await killApp(server) 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 () => { it('should have correct "Listening on" log', async () => {
expect(output).toContain(`Listening on port`) expect(output).toContain(`Listening on port`)
expect(output).toContain(`url: http://localhost:${appPort}`) expect(output).toContain(`url: http://localhost:${appPort}`)
......
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