Skip to content

Commit 09772c3

Browse files
authored
[cache components] add cache components indicator to dev start (#85069)
Missed the plumbing for this in `dev`.
1 parent 34a40fd commit 09772c3

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed

packages/next/src/server/lib/start-server.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,17 +367,20 @@ export async function startServer(
367367
// Only load env and config in dev to for logging purposes
368368
let envInfo: string[] | undefined
369369
let experimentalFeatures: ConfiguredExperimentalFeature[] | undefined
370+
let cacheComponents: boolean | undefined
370371
try {
371372
if (isDev) {
372373
const startServerInfo = await getStartServerInfo({ dir, dev: isDev })
373374
envInfo = startServerInfo.envInfo
375+
cacheComponents = startServerInfo.cacheComponents
374376
experimentalFeatures = startServerInfo.experimentalFeatures
375377
}
376378
logStartInfo({
377379
networkUrl,
378380
appUrl,
379381
envInfo,
380382
experimentalFeatures,
383+
cacheComponents,
381384
logBundler: isDev,
382385
})
383386

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export default function RootLayout({
2+
children,
3+
}: {
4+
children: React.ReactNode
5+
}) {
6+
return (
7+
<html>
8+
<body>{children}</body>
9+
</html>
10+
)
11+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function Page() {
2+
return <p>Hello, World!</p>
3+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { nextTestSetup } from 'e2e-utils'
2+
const { version: nextVersion } = require('next/package.json')
3+
4+
const cacheComponentsEnabled = process.env.__NEXT_CACHE_COMPONENTS === 'true'
5+
6+
describe('dev-output', () => {
7+
const { next, isTurbopack } = nextTestSetup({
8+
files: __dirname,
9+
})
10+
11+
it('shows Cache Components indicator when enabled', async () => {
12+
const preamble = getPreambleOutput(next.cliOutput)
13+
14+
if (cacheComponentsEnabled) {
15+
if (isTurbopack) {
16+
expect(preamble).toContain('Next.js')
17+
expect(preamble).toContain('Turbopack')
18+
expect(preamble).toContain('Cache Components')
19+
} else {
20+
expect(preamble).toContain('Next.js')
21+
expect(preamble).toContain('webpack')
22+
expect(preamble).toContain('Cache Components')
23+
}
24+
} else {
25+
// When cache components env is not set, should not show the indicator
26+
expect(preamble).toContain('Next.js')
27+
if (isTurbopack) {
28+
expect(preamble).toContain('Turbopack')
29+
} else {
30+
expect(preamble).toContain('webpack')
31+
}
32+
expect(preamble).not.toContain('Cache Components')
33+
}
34+
})
35+
})
36+
37+
function getPreambleOutput(cliOutput: string): string {
38+
const lines: string[] = []
39+
40+
for (const line of cliOutput.split('\n')) {
41+
// Capture lines up to and including the "Local:" line
42+
lines.push(line.replace(nextVersion, 'x.y.z'))
43+
44+
if (line.includes('Local:')) {
45+
break
46+
}
47+
}
48+
49+
return lines.join('\n').trim()
50+
}

0 commit comments

Comments
 (0)