diff --git a/packages/next/src/build/output/index.ts b/packages/next/src/build/output/index.ts index a304daa454b46..10745f2e1ae28 100644 --- a/packages/next/src/build/output/index.ts +++ b/packages/next/src/build/output/index.ts @@ -322,18 +322,7 @@ export function watchCompilers( }) } -const internalSegments = ['[[...__metadata_id__]]', '[__metadata_id__]'] export function reportTrigger(trigger: string, url?: string) { - for (const segment of internalSegments) { - if (trigger.includes(segment)) { - trigger = trigger.replace(segment, '') - } - } - - if (trigger.length > 1 && trigger.endsWith('/')) { - trigger = trigger.slice(0, -1) - } - buildStore.setState({ trigger, url, diff --git a/packages/next/src/build/output/store.ts b/packages/next/src/build/output/store.ts index e15d566c5e8de..3b25d0557f463 100644 --- a/packages/next/src/build/output/store.ts +++ b/packages/next/src/build/output/store.ts @@ -28,6 +28,19 @@ export type OutputState = } )) +const internalSegments = ['[[...__metadata_id__]]', '[__metadata_id__]'] +export function formatTrigger(trigger: string) { + for (const segment of internalSegments) { + if (trigger.includes(segment)) { + trigger = trigger.replace(segment, '') + } + } + if (trigger.length > 1 && trigger.endsWith('/')) { + trigger = trigger.slice(0, -1) + } + return trigger +} + export const store = createStore({ appUrl: null, bindAddr: null, @@ -67,7 +80,8 @@ store.subscribe((state) => { if (state.loading) { if (state.trigger) { - trigger = state.trigger + trigger = formatTrigger(state.trigger) + console.log('trigger', trigger) triggerUrl = state.url if (trigger !== 'initial') { traceSpan = trace('compile-path', undefined, { diff --git a/packages/next/src/server/next-server.ts b/packages/next/src/server/next-server.ts index acb6abf0c95c7..c02af8fd254eb 100644 --- a/packages/next/src/server/next-server.ts +++ b/packages/next/src/server/next-server.ts @@ -1061,7 +1061,7 @@ export default class NextNodeServer extends BaseServer { const loggingFetchesConfig = this.nextConfig.logging?.fetches const enabledVerboseLogging = !!loggingFetchesConfig - const shouldTruncateUrl = loggingFetchesConfig?.fullUrl + const shouldTruncateUrl = !loggingFetchesConfig?.fullUrl if (this.renderOpts.dev) { const { bold, green, yellow, red, gray, white } = diff --git a/test/e2e/app-dir/logging/fetch-logging.test.ts b/test/e2e/app-dir/logging/fetch-logging.test.ts index 885fd61241ab3..8402bc50868d8 100644 --- a/test/e2e/app-dir/logging/fetch-logging.test.ts +++ b/test/e2e/app-dir/logging/fetch-logging.test.ts @@ -1,3 +1,5 @@ +import path from 'path' +import fs from 'fs' import stripAnsi from 'strip-ansi' import { check } from 'next-test-utils' import { createNextDescribe } from 'e2e-utils' @@ -42,7 +44,13 @@ createNextDescribe( files: __dirname, }, ({ next, isNextDev }) => { - function runTests({ withFetchesLogging }: { withFetchesLogging: boolean }) { + function runTests({ + withFetchesLogging, + withFullUrlFetches = false, + }: { + withFetchesLogging: boolean + withFullUrlFetches?: boolean + }) { if (withFetchesLogging) { it('should only log requests in dev mode', async () => { const outputIndex = next.cliOutput.length @@ -74,8 +82,9 @@ createNextDescribe( log.url.includes('api/random?no-cache') ) - // expend full url - expect(logs.every((log) => log.url.includes('..'))).toBe(false) + expect(logs.some((log) => log.url.includes('..'))).toBe( + !withFullUrlFetches + ) if (logEntry?.cache === 'cache: no-cache') { return 'success' @@ -184,8 +193,28 @@ createNextDescribe( } } - describe('with verbose logging', () => { - runTests({ withFetchesLogging: true }) + describe('with fetches verbose logging', () => { + runTests({ withFetchesLogging: true, withFullUrlFetches: true }) + }) + + describe('with fetches default logging', () => { + const curNextConfig = fs.readFileSync( + path.join(__dirname, 'next.config.js'), + { encoding: 'utf-8' } + ) + beforeAll(async () => { + await next.stop() + await next.patchFile( + 'next.config.js', + curNextConfig.replace('fullUrl: true', 'fullUrl: false') + ) + await next.start() + }) + afterAll(async () => { + await next.patchFile('next.config.js', curNextConfig) + }) + + runTests({ withFetchesLogging: true, withFullUrlFetches: false }) }) describe('with verbose logging for edge runtime', () => { @@ -203,11 +232,18 @@ createNextDescribe( }) describe('with default logging', () => { + const curNextConfig = fs.readFileSync( + path.join(__dirname, 'next.config.js'), + { encoding: 'utf-8' } + ) beforeAll(async () => { await next.stop() await next.deleteFile('next.config.js') await next.start() }) + afterAll(async () => { + await next.patchFile('next.config.js', curNextConfig) + }) runTests({ withFetchesLogging: false }) })