Skip to content

Commit 00129d0

Browse files
committed
[cache components]: show when cache components is enabled
1 parent fff99fa commit 00129d0

File tree

4 files changed

+63
-67
lines changed

4 files changed

+63
-67
lines changed

packages/next/src/build/index.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,18 +1115,20 @@ export default async function build(
11151115
)
11161116

11171117
// Always log next version first then start rest jobs
1118-
const { envInfo, experimentalFeatures } = await getStartServerInfo({
1119-
dir,
1120-
dev: false,
1121-
debugPrerender,
1122-
})
1118+
const { envInfo, experimentalFeatures, cacheComponents } =
1119+
await getStartServerInfo({
1120+
dir,
1121+
dev: false,
1122+
debugPrerender,
1123+
})
11231124

11241125
logStartInfo({
11251126
networkUrl: null,
11261127
appUrl: null,
11271128
envInfo,
11281129
experimentalFeatures,
11291130
logBundler: true,
1131+
cacheComponents,
11301132
})
11311133

11321134
const typeCheckingOptions: Parameters<typeof startTypeChecking>[0] = {

packages/next/src/server/lib/app-info-log.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,37 @@ export function logStartInfo({
1414
envInfo,
1515
experimentalFeatures,
1616
logBundler,
17+
cacheComponents,
1718
}: {
1819
networkUrl: string | null
1920
appUrl: string | null
2021
envInfo?: string[]
2122
experimentalFeatures?: ConfiguredExperimentalFeature[]
2223
logBundler: boolean
24+
cacheComponents?: boolean
2325
}) {
24-
let bundlerSuffix = ''
26+
let versionSuffix = ''
2527
if (logBundler) {
28+
const parts = []
2629
if (process.env.TURBOPACK) {
27-
bundlerSuffix = ' (Turbopack)'
30+
parts.push('Turbopack')
2831
} else if (process.env.NEXT_RSPACK) {
29-
bundlerSuffix = ' (Rspack)'
32+
parts.push('Rspack')
3033
} else {
31-
bundlerSuffix = ' (webpack)'
34+
parts.push('webpack')
3235
}
36+
37+
if (cacheComponents) {
38+
parts.push('Cache Components')
39+
}
40+
41+
versionSuffix = ` (${parts.join(', ')})`
3342
}
3443

3544
Log.bootstrap(
3645
`${bold(
3746
purple(`${Log.prefixes.ready} Next.js ${process.env.__NEXT_VERSION}`)
38-
)}${bundlerSuffix}`
47+
)}${versionSuffix}`
3948
)
4049
if (appUrl) {
4150
Log.bootstrap(`- Local: ${appUrl}`)
@@ -91,9 +100,11 @@ export async function getStartServerInfo({
91100
}): Promise<{
92101
envInfo?: string[]
93102
experimentalFeatures?: ConfiguredExperimentalFeature[]
103+
cacheComponents?: boolean
94104
}> {
95105
let experimentalFeatures: ConfiguredExperimentalFeature[] = []
96-
await loadConfig(
106+
let cacheComponents = false
107+
const config = await loadConfig(
97108
dev ? PHASE_DEVELOPMENT_SERVER : PHASE_PRODUCTION_BUILD,
98109
dir,
99110
{
@@ -107,6 +118,8 @@ export async function getStartServerInfo({
107118
}
108119
)
109120

121+
cacheComponents = !!config.cacheComponents
122+
110123
// we need to reset env if we are going to create
111124
// the worker process with the esm loader so that the
112125
// initial env state is correct
@@ -119,5 +132,6 @@ export async function getStartServerInfo({
119132
return {
120133
envInfo,
121134
experimentalFeatures,
135+
cacheComponents,
122136
}
123137
}

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -364,21 +364,25 @@ export async function startServer(
364364
process.env.__NEXT_EXPERIMENTAL_HTTPS = '1'
365365
}
366366

367-
// Only load env and config in dev to for logging purposes
367+
// Load env and config for logging purposes
368368
let envInfo: string[] | undefined
369369
let experimentalFeatures: ConfiguredExperimentalFeature[] | undefined
370+
let cacheComponents: boolean | undefined
370371
try {
371-
if (isDev) {
372-
const startServerInfo = await getStartServerInfo({ dir, dev: isDev })
373-
envInfo = startServerInfo.envInfo
374-
experimentalFeatures = startServerInfo.experimentalFeatures
375-
}
372+
const startServerInfo = await getStartServerInfo({ dir, dev: isDev })
373+
envInfo = isDev ? startServerInfo.envInfo : undefined
374+
experimentalFeatures = isDev
375+
? startServerInfo.experimentalFeatures
376+
: undefined
377+
cacheComponents = startServerInfo.cacheComponents
378+
376379
logStartInfo({
377380
networkUrl,
378381
appUrl,
379382
envInfo,
380383
experimentalFeatures,
381384
logBundler: isDev,
385+
cacheComponents,
382386
})
383387

384388
Log.event(`Starting...`)

test/production/app-dir/build-output-prerender/build-output-prerender.test.ts

Lines changed: 26 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -18,59 +18,49 @@ describe('build-output-prerender', () => {
1818

1919
beforeAll(() => next.build())
2020

21-
// TODO: Re-enable this test once we move the cache components flag
22-
it.skip('prints only the user-selected experimental flags (and the ones enabled via env variable)', async () => {
21+
it('prints only the user-selected experimental flags (and the ones enabled via env variable)', async () => {
2322
if (cacheComponentsEnabled) {
2423
if (isTurbopack) {
2524
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
26-
"▲ Next.js x.y.z (Turbopack)
25+
"▲ Next.js x.y.z (Turbopack, Cache Components)
2726
- Experiments (use with caution):
2827
✓ cacheComponents
2928
✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`)"
3029
`)
3130
} else {
3231
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
33-
"▲ Next.js x.y.z (webpack)
32+
"▲ Next.js x.y.z (webpack, Cache Components)
3433
- Experiments (use with caution):
35-
✓ cacheComponents
3634
✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`)"
3735
`)
3836
}
3937
} else if (pprEnabled) {
4038
if (isTurbopack) {
4139
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
42-
"▲ Next.js x.y.z (Turbopack)
40+
"▲ Next.js x.y.z (Turbopack, Cache Components)
4341
- Experiments (use with caution):
44-
✓ cacheComponents
4542
✓ ppr (enabled by \`__NEXT_EXPERIMENTAL_PPR\`)"
4643
`)
4744
} else {
4845
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
49-
"▲ Next.js x.y.z (webpack)
46+
"▲ Next.js x.y.z (webpack, Cache Components)
5047
- Experiments (use with caution):
51-
✓ cacheComponents
5248
✓ ppr (enabled by \`__NEXT_EXPERIMENTAL_PPR\`)"
5349
`)
5450
}
5551
} else {
5652
if (isTurbopack) {
57-
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
58-
"▲ Next.js x.y.z (Turbopack)
59-
- Experiments (use with caution):
60-
✓ cacheComponents"
61-
`)
53+
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(
54+
`"▲ Next.js x.y.z (Turbopack, Cache Components)"`
55+
)
6256
} else if (isRspack) {
6357
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
64-
"▲ Next.js x.y.z (Rspack)
65-
- Experiments (use with caution):
66-
✓ cacheComponents"
58+
"▲ Next.js x.y.z (Rspack, Cache Components)"
6759
`)
6860
} else {
69-
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
70-
"▲ Next.js x.y.z (webpack)
71-
- Experiments (use with caution):
72-
✓ cacheComponents"
73-
`)
61+
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(
62+
`"▲ Next.js x.y.z (webpack, Cache Components)"`
63+
)
7464
}
7565
}
7666
})
@@ -116,15 +106,13 @@ describe('build-output-prerender', () => {
116106

117107
beforeAll(() => next.build())
118108

119-
// TODO: Re-enable this test once we move the cache components flag
120-
it.skip('prints a warning and the customized experimental flags', async () => {
109+
it('prints a warning and the customized experimental flags', async () => {
121110
if (cacheComponentsEnabled) {
122111
if (isTurbopack) {
123112
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
124113
"⚠ Prerendering is running in debug mode. Note: This may affect performance and should not be used for production.
125-
▲ Next.js x.y.z (Turbopack)
114+
▲ Next.js x.y.z (Turbopack, Cache Components)
126115
- Experiments (use with caution):
127-
✓ cacheComponents
128116
⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
129117
✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`)
130118
✓ serverSourceMaps (enabled by \`--debug-prerender\`)
@@ -133,9 +121,8 @@ describe('build-output-prerender', () => {
133121
} else {
134122
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
135123
"⚠ Prerendering is running in debug mode. Note: This may affect performance and should not be used for production.
136-
▲ Next.js x.y.z (webpack)
124+
▲ Next.js x.y.z (webpack, Cache Components)
137125
- Experiments (use with caution):
138-
✓ cacheComponents
139126
⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
140127
✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`)
141128
⨯ serverMinification (disabled by \`--debug-prerender\`)
@@ -146,9 +133,8 @@ describe('build-output-prerender', () => {
146133
if (isTurbopack) {
147134
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
148135
"⚠ Prerendering is running in debug mode. Note: This may affect performance and should not be used for production.
149-
▲ Next.js x.y.z (Turbopack)
136+
▲ Next.js x.y.z (Turbopack, Cache Components)
150137
- Experiments (use with caution):
151-
✓ cacheComponents
152138
✓ ppr (enabled by \`__NEXT_EXPERIMENTAL_PPR\`)
153139
⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
154140
✓ serverSourceMaps (enabled by \`--debug-prerender\`)
@@ -157,9 +143,8 @@ describe('build-output-prerender', () => {
157143
} else {
158144
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
159145
"⚠ Prerendering is running in debug mode. Note: This may affect performance and should not be used for production.
160-
▲ Next.js x.y.z (webpack)
146+
▲ Next.js x.y.z (webpack, Cache Components)
161147
- Experiments (use with caution):
162-
✓ cacheComponents
163148
✓ ppr (enabled by \`__NEXT_EXPERIMENTAL_PPR\`)
164149
⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
165150
⨯ serverMinification (disabled by \`--debug-prerender\`)
@@ -170,29 +155,26 @@ describe('build-output-prerender', () => {
170155
if (isTurbopack) {
171156
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
172157
"⚠ Prerendering is running in debug mode. Note: This may affect performance and should not be used for production.
173-
▲ Next.js x.y.z (Turbopack)
158+
▲ Next.js x.y.z (Turbopack, Cache Components)
174159
- Experiments (use with caution):
175-
✓ cacheComponents
176160
⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
177161
✓ serverSourceMaps (enabled by \`--debug-prerender\`)
178162
⨯ turbopackMinify (disabled by \`--debug-prerender\`)"
179163
`)
180164
} else if (isRspack) {
181165
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
182166
"⚠ Prerendering is running in debug mode. Note: This may affect performance and should not be used for production.
183-
▲ Next.js x.y.z (Rspack)
167+
▲ Next.js x.y.z (Rspack, Cache Components)
184168
- Experiments (use with caution):
185-
✓ cacheComponents
186169
⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
187170
⨯ serverMinification (disabled by \`--debug-prerender\`)
188171
✓ serverSourceMaps (enabled by \`--debug-prerender\`)"
189172
`)
190173
} else {
191174
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
192175
"⚠ Prerendering is running in debug mode. Note: This may affect performance and should not be used for production.
193-
▲ Next.js x.y.z (webpack)
176+
▲ Next.js x.y.z (webpack, Cache Components)
194177
- Experiments (use with caution):
195-
✓ cacheComponents
196178
⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
197179
⨯ serverMinification (disabled by \`--debug-prerender\`)
198180
✓ serverSourceMaps (enabled by \`--debug-prerender\`)"
@@ -241,21 +223,18 @@ describe('build-output-prerender', () => {
241223

242224
beforeAll(() => next.build())
243225

244-
// TODO: Re-enable this test once we move the cache components flag
245-
it.skip('prints no experimental flags (unless enabled via env variable)', async () => {
226+
it('prints no experimental flags (unless enabled via env variable)', async () => {
246227
if (cacheComponentsEnabled) {
247228
if (isTurbopack) {
248229
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
249-
"▲ Next.js x.y.z (Turbopack)
230+
"▲ Next.js x.y.z (Turbopack, Cache Components)
250231
- Experiments (use with caution):
251-
✓ cacheComponents (enabled by \`__NEXT_CACHE_COMPONENTS\`)
252232
✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`)"
253233
`)
254234
} else {
255235
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
256-
"▲ Next.js x.y.z (webpack)
236+
"▲ Next.js x.y.z (webpack, Cache Components)
257237
- Experiments (use with caution):
258-
✓ cacheComponents (enabled by \`__NEXT_CACHE_COMPONENTS\`)
259238
✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`)"
260239
`)
261240
}
@@ -300,15 +279,13 @@ describe('build-output-prerender', () => {
300279

301280
beforeAll(() => next.build())
302281

303-
// TODO: Re-enable this test once we move the cache components flag
304-
it.skip('prints a warning and the customized experimental flags', async () => {
282+
it('prints a warning and the customized experimental flags', async () => {
305283
if (cacheComponentsEnabled) {
306284
if (isTurbopack) {
307285
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
308286
"⚠ Prerendering is running in debug mode. Note: This may affect performance and should not be used for production.
309-
▲ Next.js x.y.z (Turbopack)
287+
▲ Next.js x.y.z (Turbopack, Cache Components)
310288
- Experiments (use with caution):
311-
✓ cacheComponents (enabled by \`__NEXT_CACHE_COMPONENTS\`)
312289
⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
313290
✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`)
314291
✓ serverSourceMaps (enabled by \`--debug-prerender\`)
@@ -317,9 +294,8 @@ describe('build-output-prerender', () => {
317294
} else {
318295
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
319296
"⚠ Prerendering is running in debug mode. Note: This may affect performance and should not be used for production.
320-
▲ Next.js x.y.z (webpack)
297+
▲ Next.js x.y.z (webpack, Cache Components)
321298
- Experiments (use with caution):
322-
✓ cacheComponents (enabled by \`__NEXT_CACHE_COMPONENTS\`)
323299
⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
324300
✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`)
325301
⨯ serverMinification (disabled by \`--debug-prerender\`)

0 commit comments

Comments
 (0)