Skip to content

Commit

Permalink
Update app router revalidate handling on deploy (#51062)
Browse files Browse the repository at this point in the history
This ensures we clear the RSC headers during revalidate when deployed so
that the HTML revalidation isn't treated as the RSC revalidation.
  • Loading branch information
ijjk committed Jun 9, 2023
1 parent 761e372 commit 8045525
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/next/src/server/base-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const revalidate = 1

export default function Page() {
return (
<>
<p>/app-blog</p>
<p>Date: {Date.now()}</p>
</>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default function Layout({ children }) {
return (
<html>
<head />
<body>{children}</body>
</html>
)
}
24 changes: 24 additions & 0 deletions test/production/standalone-mode/response-cache/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
findPort,
renderViaHTTP,
initNextServerScript,
fetchViaHTTP,
} from 'next-test-utils'

describe('minimal-mode-response-cache', () => {
Expand Down Expand Up @@ -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}`)
Expand Down

0 comments on commit 8045525

Please sign in to comment.