Skip to content

Commit 1a4e865

Browse files
committed
[cache components]: show when cache components is enabled
1 parent 85c3d20 commit 1a4e865

File tree

5 files changed

+66
-77
lines changed

5 files changed

+66
-77
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/config.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,15 +1784,6 @@ function enforceExperimentalFeatures(
17841784
(isDefaultConfig && !config.cacheComponents))
17851785
) {
17861786
config.cacheComponents = true
1787-
1788-
if (configuredExperimentalFeatures) {
1789-
addConfiguredExperimentalFeature(
1790-
configuredExperimentalFeatures,
1791-
'cacheComponents',
1792-
true,
1793-
'enabled by `__NEXT_CACHE_COMPONENTS`'
1794-
)
1795-
}
17961787
}
17971788

17981789
// TODO: Remove this once using the debug channel is the default.

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

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,40 @@ 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 = ''
27+
const parts = []
28+
2529
if (logBundler) {
2630
if (process.env.TURBOPACK) {
27-
bundlerSuffix = ' (Turbopack)'
31+
parts.push('Turbopack')
2832
} else if (process.env.NEXT_RSPACK) {
29-
bundlerSuffix = ' (Rspack)'
33+
parts.push('Rspack')
3034
} else {
31-
bundlerSuffix = ' (webpack)'
35+
parts.push('webpack')
3236
}
3337
}
3438

39+
if (cacheComponents) {
40+
parts.push('Cache Components')
41+
}
42+
43+
if (parts.length > 0) {
44+
versionSuffix = ` (${parts.join(', ')})`
45+
}
46+
3547
Log.bootstrap(
3648
`${bold(
3749
purple(`${Log.prefixes.ready} Next.js ${process.env.__NEXT_VERSION}`)
38-
)}${bundlerSuffix}`
50+
)}${versionSuffix}`
3951
)
4052
if (appUrl) {
4153
Log.bootstrap(`- Local: ${appUrl}`)
@@ -91,9 +103,11 @@ export async function getStartServerInfo({
91103
}): Promise<{
92104
envInfo?: string[]
93105
experimentalFeatures?: ConfiguredExperimentalFeature[]
106+
cacheComponents?: boolean
94107
}> {
95108
let experimentalFeatures: ConfiguredExperimentalFeature[] = []
96-
await loadConfig(
109+
let cacheComponents = false
110+
const config = await loadConfig(
97111
dev ? PHASE_DEVELOPMENT_SERVER : PHASE_PRODUCTION_BUILD,
98112
dir,
99113
{
@@ -107,6 +121,8 @@ export async function getStartServerInfo({
107121
}
108122
)
109123

124+
cacheComponents = !!config.cacheComponents
125+
110126
// we need to reset env if we are going to create
111127
// the worker process with the esm loader so that the
112128
// initial env state is correct
@@ -119,5 +135,6 @@ export async function getStartServerInfo({
119135
return {
120136
envInfo,
121137
experimentalFeatures,
138+
cacheComponents,
122139
}
123140
}

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 & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -18,59 +18,48 @@ 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):
28-
✓ cacheComponents
2927
✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`)"
3028
`)
3129
} else {
3230
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
33-
"▲ Next.js x.y.z (webpack)
31+
"▲ Next.js x.y.z (webpack, Cache Components)
3432
- Experiments (use with caution):
35-
✓ cacheComponents
3633
✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`)"
3734
`)
3835
}
3936
} else if (pprEnabled) {
4037
if (isTurbopack) {
4138
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
42-
"▲ Next.js x.y.z (Turbopack)
39+
"▲ Next.js x.y.z (Turbopack, Cache Components)
4340
- Experiments (use with caution):
44-
✓ cacheComponents
4541
✓ ppr (enabled by \`__NEXT_EXPERIMENTAL_PPR\`)"
4642
`)
4743
} else {
4844
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
49-
"▲ Next.js x.y.z (webpack)
45+
"▲ Next.js x.y.z (webpack, Cache Components)
5046
- Experiments (use with caution):
51-
✓ cacheComponents
5247
✓ ppr (enabled by \`__NEXT_EXPERIMENTAL_PPR\`)"
5348
`)
5449
}
5550
} else {
5651
if (isTurbopack) {
57-
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
58-
"▲ Next.js x.y.z (Turbopack)
59-
- Experiments (use with caution):
60-
✓ cacheComponents"
61-
`)
52+
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(
53+
`"▲ Next.js x.y.z (Turbopack, Cache Components)"`
54+
)
6255
} else if (isRspack) {
6356
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
64-
"▲ Next.js x.y.z (Rspack)
65-
- Experiments (use with caution):
66-
✓ cacheComponents"
57+
"▲ Next.js x.y.z (Rspack, Cache Components)"
6758
`)
6859
} else {
69-
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
70-
"▲ Next.js x.y.z (webpack)
71-
- Experiments (use with caution):
72-
✓ cacheComponents"
73-
`)
60+
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(
61+
`"▲ Next.js x.y.z (webpack, Cache Components)"`
62+
)
7463
}
7564
}
7665
})
@@ -116,15 +105,13 @@ describe('build-output-prerender', () => {
116105

117106
beforeAll(() => next.build())
118107

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 () => {
108+
it('prints a warning and the customized experimental flags', async () => {
121109
if (cacheComponentsEnabled) {
122110
if (isTurbopack) {
123111
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
124112
"⚠ 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)
113+
▲ Next.js x.y.z (Turbopack, Cache Components)
126114
- Experiments (use with caution):
127-
✓ cacheComponents
128115
⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
129116
✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`)
130117
✓ serverSourceMaps (enabled by \`--debug-prerender\`)
@@ -133,9 +120,8 @@ describe('build-output-prerender', () => {
133120
} else {
134121
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
135122
"⚠ 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)
123+
▲ Next.js x.y.z (webpack, Cache Components)
137124
- Experiments (use with caution):
138-
✓ cacheComponents
139125
⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
140126
✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`)
141127
⨯ serverMinification (disabled by \`--debug-prerender\`)
@@ -146,9 +132,8 @@ describe('build-output-prerender', () => {
146132
if (isTurbopack) {
147133
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
148134
"⚠ 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)
135+
▲ Next.js x.y.z (Turbopack, Cache Components)
150136
- Experiments (use with caution):
151-
✓ cacheComponents
152137
✓ ppr (enabled by \`__NEXT_EXPERIMENTAL_PPR\`)
153138
⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
154139
✓ serverSourceMaps (enabled by \`--debug-prerender\`)
@@ -157,9 +142,8 @@ describe('build-output-prerender', () => {
157142
} else {
158143
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
159144
"⚠ 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)
145+
▲ Next.js x.y.z (webpack, Cache Components)
161146
- Experiments (use with caution):
162-
✓ cacheComponents
163147
✓ ppr (enabled by \`__NEXT_EXPERIMENTAL_PPR\`)
164148
⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
165149
⨯ serverMinification (disabled by \`--debug-prerender\`)
@@ -170,29 +154,26 @@ describe('build-output-prerender', () => {
170154
if (isTurbopack) {
171155
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
172156
"⚠ 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)
157+
▲ Next.js x.y.z (Turbopack, Cache Components)
174158
- Experiments (use with caution):
175-
✓ cacheComponents
176159
⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
177160
✓ serverSourceMaps (enabled by \`--debug-prerender\`)
178161
⨯ turbopackMinify (disabled by \`--debug-prerender\`)"
179162
`)
180163
} else if (isRspack) {
181164
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
182165
"⚠ 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)
166+
▲ Next.js x.y.z (Rspack, Cache Components)
184167
- Experiments (use with caution):
185-
✓ cacheComponents
186168
⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
187169
⨯ serverMinification (disabled by \`--debug-prerender\`)
188170
✓ serverSourceMaps (enabled by \`--debug-prerender\`)"
189171
`)
190172
} else {
191173
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
192174
"⚠ 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)
175+
▲ Next.js x.y.z (webpack, Cache Components)
194176
- Experiments (use with caution):
195-
✓ cacheComponents
196177
⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
197178
⨯ serverMinification (disabled by \`--debug-prerender\`)
198179
✓ serverSourceMaps (enabled by \`--debug-prerender\`)"
@@ -241,21 +222,18 @@ describe('build-output-prerender', () => {
241222

242223
beforeAll(() => next.build())
243224

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 () => {
225+
it('prints no experimental flags (unless enabled via env variable)', async () => {
246226
if (cacheComponentsEnabled) {
247227
if (isTurbopack) {
248228
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
249-
"▲ Next.js x.y.z (Turbopack)
229+
"▲ Next.js x.y.z (Turbopack, Cache Components)
250230
- Experiments (use with caution):
251-
✓ cacheComponents (enabled by \`__NEXT_CACHE_COMPONENTS\`)
252231
✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`)"
253232
`)
254233
} else {
255234
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
256-
"▲ Next.js x.y.z (webpack)
235+
"▲ Next.js x.y.z (webpack, Cache Components)
257236
- Experiments (use with caution):
258-
✓ cacheComponents (enabled by \`__NEXT_CACHE_COMPONENTS\`)
259237
✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`)"
260238
`)
261239
}
@@ -300,15 +278,13 @@ describe('build-output-prerender', () => {
300278

301279
beforeAll(() => next.build())
302280

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 () => {
281+
it('prints a warning and the customized experimental flags', async () => {
305282
if (cacheComponentsEnabled) {
306283
if (isTurbopack) {
307284
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
308285
"⚠ 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)
286+
▲ Next.js x.y.z (Turbopack, Cache Components)
310287
- Experiments (use with caution):
311-
✓ cacheComponents (enabled by \`__NEXT_CACHE_COMPONENTS\`)
312288
⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
313289
✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`)
314290
✓ serverSourceMaps (enabled by \`--debug-prerender\`)
@@ -317,9 +293,8 @@ describe('build-output-prerender', () => {
317293
} else {
318294
expect(getPreambleOutput(next.cliOutput)).toMatchInlineSnapshot(`
319295
"⚠ 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)
296+
▲ Next.js x.y.z (webpack, Cache Components)
321297
- Experiments (use with caution):
322-
✓ cacheComponents (enabled by \`__NEXT_CACHE_COMPONENTS\`)
323298
⨯ prerenderEarlyExit (disabled by \`--debug-prerender\`)
324299
✓ reactDebugChannel (enabled by \`__NEXT_EXPERIMENTAL_DEBUG_CHANNEL\`)
325300
⨯ serverMinification (disabled by \`--debug-prerender\`)

0 commit comments

Comments
 (0)