Skip to content

Commit 6b6bfcd

Browse files
authored
Polish logging segments of page route (#57834)
Reduce the confusiong of the the logging of pages, make it easier to understand * Removing the trailing `/page`, `/route` suffix * Removing the internal segment like `[[...__metadata__]]` #### After ``` ○ Compiling / ... ○ Compiling /dynamic/[slug]/icon ... ``` #### Before ``` ○ Compiling /page ... ○ Compiling /(group)/dynamic/[slug]/icon-ahg52g/[[...__metadata_id__]]/route ... ``` Closes NEXT-1701
1 parent c3bf735 commit 6b6bfcd

File tree

10 files changed

+156
-19
lines changed

10 files changed

+156
-19
lines changed

packages/next/src/build/output/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,18 @@ export function watchCompilers(
316316
})
317317
}
318318

319+
const internalSegments = ['[[...__metadata_id__]]', '[__metadata_id__]']
319320
export function reportTrigger(trigger: string) {
321+
for (const segment of internalSegments) {
322+
if (trigger.includes(segment)) {
323+
trigger = trigger.replace(segment, '')
324+
}
325+
}
326+
327+
if (trigger.length > 1 && trigger.endsWith('/')) {
328+
trigger = trigger.slice(0, -1)
329+
}
330+
320331
buildStore.setState({
321332
trigger,
322333
})

packages/next/src/server/dev/on-demand-entry-handler.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import { HMR_ACTIONS_SENT_TO_BROWSER } from './hot-reloader-types'
3939
import { isAppPageRouteDefinition } from '../future/route-definitions/app-page-route-definition'
4040
import { scheduleOnNextTick } from '../../lib/scheduler'
4141
import { Batcher } from '../../lib/batcher'
42+
import { normalizeAppPath } from '../../shared/lib/router/utils/app-paths'
4243

4344
const debug = createDebug('next:on-demand-entry-handler')
4445

@@ -832,7 +833,8 @@ export function onDemandEntryHandler({
832833
const hasNewEntry = addedValues.some((entry) => entry.newEntry)
833834

834835
if (hasNewEntry) {
835-
reportTrigger(route.page)
836+
const routePage = isApp ? route.page : normalizeAppPath(route.page)
837+
reportTrigger(routePage)
836838
}
837839

838840
if (entriesThatShouldBeInvalidated.length > 0) {

test/development/basic/barrel-optimization.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ describe('optimizePackageImports', () => {
6161

6262
const modules = [
6363
...logs.matchAll(
64-
/Compiled (\/[\w-]+)*\s*in \d+(\.\d+)?(s|ms) \((\d+) modules\)/g
64+
/Compiled (\/[\w-]*)*\s*in \d+(\.\d+)?(s|ms) \((\d+) modules\)/g
6565
),
6666
]
6767

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
export const fetchCache = 'default-cache'
2+
3+
export default async function Page() {
4+
const dataNoCache = await fetch(
5+
'https://next-data-api-endpoint.vercel.app/api/random?no-cache',
6+
{
7+
cache: 'no-cache',
8+
}
9+
).then((res) => res.text())
10+
11+
const dataForceCache = await fetch(
12+
'https://next-data-api-endpoint.vercel.app/api/random?force-cache',
13+
{
14+
cache: 'force-cache',
15+
}
16+
).then((res) => res.text())
17+
18+
const dataRevalidate0 = await fetch(
19+
'https://next-data-api-endpoint.vercel.app/api/random?revalidate-0',
20+
{
21+
next: {
22+
revalidate: 0,
23+
},
24+
}
25+
).then((res) => res.text())
26+
27+
const dataRevalidateCache = await fetch(
28+
'https://next-data-api-endpoint.vercel.app/api/random?revalidate-3',
29+
{
30+
next: {
31+
revalidate: 3,
32+
},
33+
}
34+
).then((res) => res.text())
35+
36+
const dataRevalidateAndFetchCache = await fetch(
37+
'https://next-data-api-endpoint.vercel.app/api/random?revalidate-3-force-cache',
38+
{
39+
next: {
40+
revalidate: 3,
41+
},
42+
cache: 'force-cache',
43+
}
44+
).then((res) => res.text())
45+
46+
const dataAutoCache = await fetch(
47+
'https://next-data-api-endpoint.vercel.app/api/random?auto-cache'
48+
).then((res) => res.text())
49+
50+
return (
51+
<>
52+
<p>/force-cache</p>
53+
<p id="data-no-cache">"cache: no-cache" {dataNoCache}</p>
54+
<p id="data-force-cache">"cache: force-cache" {dataForceCache}</p>
55+
<p id="data-revalidate-0">"revalidate: 0" {dataRevalidate0}</p>
56+
<p id="data-revalidate-cache">"revalidate: 3" {dataRevalidateCache}</p>
57+
<p id="data-revalidate-and-fetch-cache">
58+
"revalidate: 3 and cache: force-cache" {dataRevalidateAndFetchCache}
59+
</p>
60+
<p id="data-auto-cache">"auto cache" {dataAutoCache}</p>
61+
</>
62+
)
63+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { ImageResponse } from 'next/og'
2+
3+
export default function icon({ params, id }) {
4+
return new ImageResponse(
5+
(
6+
<div
7+
style={{
8+
width: '100%',
9+
height: '100%',
10+
display: 'flex',
11+
alignItems: 'center',
12+
justifyContent: 'center',
13+
fontSize: 88,
14+
background: '#000',
15+
color: '#fafafa',
16+
}}
17+
>
18+
Apple {params.size} {id}
19+
</div>
20+
)
21+
)
22+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default function Layout({ children }) {
2+
return (
3+
<html>
4+
<body>{children}</body>
5+
</html>
6+
)
7+
}
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 'hello world'
3+
}

test/e2e/app-dir/app-static/app-fetch-logging.test.ts renamed to test/e2e/app-dir/logging/index.test.ts

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import path from 'path'
21
import stripAnsi from 'strip-ansi'
32
import { check } from 'next-test-utils'
4-
import { createNextDescribe, FileRef } from 'e2e-utils'
3+
import { createNextDescribe } from 'e2e-utils'
54

65
function parseLogsFromCli(cliOutput: string) {
76
const logs = stripAnsi(cliOutput)
@@ -37,22 +36,14 @@ function parseLogsFromCli(cliOutput: string) {
3736
}
3837

3938
createNextDescribe(
40-
'app-dir - data fetching with cache logging',
39+
'app-dir - logging',
4140
{
4241
skipDeployment: true,
43-
files: {
44-
'app/layout.js': new FileRef(path.join(__dirname, 'app/layout.js')),
45-
'app/default-cache/page.js': new FileRef(
46-
path.join(__dirname, 'app/default-cache/page.js')
47-
),
48-
'next.config.js': `module.exports = {
49-
logging: { fetches: { fullUrl: true } }
50-
}`,
51-
},
42+
files: __dirname,
5243
},
5344
({ next, isNextDev }) => {
54-
function runTests({ hasLogging }: { hasLogging: boolean }) {
55-
if (hasLogging) {
45+
function runTests({ withFetchesLogging }: { withFetchesLogging: boolean }) {
46+
if (withFetchesLogging) {
5647
it('should only log requests in dev mode', async () => {
5748
const outputIndex = next.cliOutput.length
5849
await next.fetch('/default-cache')
@@ -143,10 +134,40 @@ createNextDescribe(
143134
}, 'success')
144135
})
145136
}
137+
138+
if (isNextDev) {
139+
it('should not contain trailing word page for app router routes', async () => {
140+
const logLength = next.cliOutput.length
141+
await next.fetch('/')
142+
143+
await check(() => {
144+
const output = stripAnsi(next.cliOutput.slice(logLength))
145+
expect(output).toContain('/')
146+
expect(output).not.toContain('/page')
147+
148+
return 'success'
149+
}, /success/)
150+
})
151+
152+
it('should not contain metadata internal segments for dynamic metadata routes', async () => {
153+
const logLength = next.cliOutput.length
154+
await next.fetch('/dynamic/big/icon')
155+
156+
await check(() => {
157+
const output = stripAnsi(next.cliOutput.slice(logLength))
158+
expect(output).toContain('/dynamic/[slug]/icon')
159+
expect(output).not.toContain('/(group)')
160+
expect(output).not.toContain('[[...__metadata_id__]]')
161+
expect(output).not.toContain('/route')
162+
163+
return 'success'
164+
}, /success/)
165+
})
166+
}
146167
}
147168

148169
describe('with verbose logging', () => {
149-
runTests({ hasLogging: true })
170+
runTests({ withFetchesLogging: true })
150171
})
151172

152173
describe('with verbose logging for edge runtime', () => {
@@ -160,7 +181,7 @@ createNextDescribe(
160181
await next.start()
161182
})
162183

163-
runTests({ hasLogging: false })
184+
runTests({ withFetchesLogging: false })
164185
})
165186

166187
describe('with default logging', () => {
@@ -170,7 +191,7 @@ createNextDescribe(
170191
await next.start()
171192
})
172193

173-
runTests({ hasLogging: false })
194+
runTests({ withFetchesLogging: false })
174195
})
175196
}
176197
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
logging: {
3+
fetches: {
4+
fullUrl: true,
5+
},
6+
},
7+
}

test/e2e/app-dir/metadata-dynamic-routes/index.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ createNextDescribe(
157157
type: $(el).attr('type'),
158158
}
159159
})
160+
160161
// slug is id param from generateImageMetadata
161162
expect(iconUrls).toMatchObject([
162163
{

0 commit comments

Comments
 (0)