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

Update app router revalidate handling on deploy #51062

Merged
merged 1 commit into from
Jun 9, 2023
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
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