Skip to content

Commit d07a370

Browse files
raphaelbadiahuozhi
andauthored
fixes the logging by showing full URLs only on demand (#58088)
<!-- Thanks for opening a PR! Your contribution is much appreciated. To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below. Choose the right checklist for the change(s) that you're making: ## For Contributors ### Fixing a bug - Related issues linked using `fixes #number` - Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ### Adding a feature - Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. (A discussion must be opened, see https://github.com/vercel/next.js/discussions/new?category=ideas) - Related issues/discussions are linked using `fixes #number` - e2e tests added (https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) - Documentation added - Telemetry added. In case of a feature if it's used or not. - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ## For Maintainers - Minimal description (aim for explaining to someone not on the team to understand the PR) - When linking to a Slack thread, you might want to share details of the conclusion - Link both the Linear (Fixes NEXT-xxx) and the GitHub issues - Add review comments if necessary to explain to the reviewer the logic behind a change ### What? ### Why? ### How? Closes NEXT- Fixes #58087 --> fixes #58087 Currently in Next 14, everyone has fullURL flag turned to true, this PR reverts the condition. --------- Co-authored-by: Jiachi Liu <inbox@huozhi.im>
1 parent e1fe0c9 commit d07a370

File tree

4 files changed

+57
-18
lines changed

4 files changed

+57
-18
lines changed

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -322,18 +322,7 @@ export function watchCompilers(
322322
})
323323
}
324324

325-
const internalSegments = ['[[...__metadata_id__]]', '[__metadata_id__]']
326325
export function reportTrigger(trigger: string, url?: string) {
327-
for (const segment of internalSegments) {
328-
if (trigger.includes(segment)) {
329-
trigger = trigger.replace(segment, '')
330-
}
331-
}
332-
333-
if (trigger.length > 1 && trigger.endsWith('/')) {
334-
trigger = trigger.slice(0, -1)
335-
}
336-
337326
buildStore.setState({
338327
trigger,
339328
url,

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ export type OutputState =
2828
}
2929
))
3030

31+
const internalSegments = ['[[...__metadata_id__]]', '[__metadata_id__]']
32+
export function formatTrigger(trigger: string) {
33+
for (const segment of internalSegments) {
34+
if (trigger.includes(segment)) {
35+
trigger = trigger.replace(segment, '')
36+
}
37+
}
38+
if (trigger.length > 1 && trigger.endsWith('/')) {
39+
trigger = trigger.slice(0, -1)
40+
}
41+
return trigger
42+
}
43+
3144
export const store = createStore<OutputState>({
3245
appUrl: null,
3346
bindAddr: null,
@@ -67,7 +80,8 @@ store.subscribe((state) => {
6780

6881
if (state.loading) {
6982
if (state.trigger) {
70-
trigger = state.trigger
83+
trigger = formatTrigger(state.trigger)
84+
console.log('trigger', trigger)
7185
triggerUrl = state.url
7286
if (trigger !== 'initial') {
7387
traceSpan = trace('compile-path', undefined, {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ export default class NextNodeServer extends BaseServer {
10611061

10621062
const loggingFetchesConfig = this.nextConfig.logging?.fetches
10631063
const enabledVerboseLogging = !!loggingFetchesConfig
1064-
const shouldTruncateUrl = loggingFetchesConfig?.fullUrl
1064+
const shouldTruncateUrl = !loggingFetchesConfig?.fullUrl
10651065

10661066
if (this.renderOpts.dev) {
10671067
const { bold, green, yellow, red, gray, white } =

test/e2e/app-dir/logging/fetch-logging.test.ts

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import path from 'path'
2+
import fs from 'fs'
13
import stripAnsi from 'strip-ansi'
24
import { check } from 'next-test-utils'
35
import { createNextDescribe } from 'e2e-utils'
@@ -42,7 +44,13 @@ createNextDescribe(
4244
files: __dirname,
4345
},
4446
({ next, isNextDev }) => {
45-
function runTests({ withFetchesLogging }: { withFetchesLogging: boolean }) {
47+
function runTests({
48+
withFetchesLogging,
49+
withFullUrlFetches = false,
50+
}: {
51+
withFetchesLogging: boolean
52+
withFullUrlFetches?: boolean
53+
}) {
4654
if (withFetchesLogging) {
4755
it('should only log requests in dev mode', async () => {
4856
const outputIndex = next.cliOutput.length
@@ -74,8 +82,9 @@ createNextDescribe(
7482
log.url.includes('api/random?no-cache')
7583
)
7684

77-
// expend full url
78-
expect(logs.every((log) => log.url.includes('..'))).toBe(false)
85+
expect(logs.some((log) => log.url.includes('..'))).toBe(
86+
!withFullUrlFetches
87+
)
7988

8089
if (logEntry?.cache === 'cache: no-cache') {
8190
return 'success'
@@ -184,8 +193,28 @@ createNextDescribe(
184193
}
185194
}
186195

187-
describe('with verbose logging', () => {
188-
runTests({ withFetchesLogging: true })
196+
describe('with fetches verbose logging', () => {
197+
runTests({ withFetchesLogging: true, withFullUrlFetches: true })
198+
})
199+
200+
describe('with fetches default logging', () => {
201+
const curNextConfig = fs.readFileSync(
202+
path.join(__dirname, 'next.config.js'),
203+
{ encoding: 'utf-8' }
204+
)
205+
beforeAll(async () => {
206+
await next.stop()
207+
await next.patchFile(
208+
'next.config.js',
209+
curNextConfig.replace('fullUrl: true', 'fullUrl: false')
210+
)
211+
await next.start()
212+
})
213+
afterAll(async () => {
214+
await next.patchFile('next.config.js', curNextConfig)
215+
})
216+
217+
runTests({ withFetchesLogging: true, withFullUrlFetches: false })
189218
})
190219

191220
describe('with verbose logging for edge runtime', () => {
@@ -203,11 +232,18 @@ createNextDescribe(
203232
})
204233

205234
describe('with default logging', () => {
235+
const curNextConfig = fs.readFileSync(
236+
path.join(__dirname, 'next.config.js'),
237+
{ encoding: 'utf-8' }
238+
)
206239
beforeAll(async () => {
207240
await next.stop()
208241
await next.deleteFile('next.config.js')
209242
await next.start()
210243
})
244+
afterAll(async () => {
245+
await next.patchFile('next.config.js', curNextConfig)
246+
})
211247

212248
runTests({ withFetchesLogging: false })
213249
})

0 commit comments

Comments
 (0)