Unverified Commit d07a370d authored by Raphaël Badia's avatar Raphaël Badia Committed by GitHub

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: 's avatarJiachi Liu <inbox@huozhi.im>
parent e1fe0c9a
...@@ -322,18 +322,7 @@ export function watchCompilers( ...@@ -322,18 +322,7 @@ export function watchCompilers(
}) })
} }
const internalSegments = ['[[...__metadata_id__]]', '[__metadata_id__]']
export function reportTrigger(trigger: string, url?: string) { 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({ buildStore.setState({
trigger, trigger,
url, url,
......
...@@ -28,6 +28,19 @@ export type OutputState = ...@@ -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<OutputState>({ export const store = createStore<OutputState>({
appUrl: null, appUrl: null,
bindAddr: null, bindAddr: null,
...@@ -67,7 +80,8 @@ store.subscribe((state) => { ...@@ -67,7 +80,8 @@ store.subscribe((state) => {
if (state.loading) { if (state.loading) {
if (state.trigger) { if (state.trigger) {
trigger = state.trigger trigger = formatTrigger(state.trigger)
console.log('trigger', trigger)
triggerUrl = state.url triggerUrl = state.url
if (trigger !== 'initial') { if (trigger !== 'initial') {
traceSpan = trace('compile-path', undefined, { traceSpan = trace('compile-path', undefined, {
......
...@@ -1061,7 +1061,7 @@ export default class NextNodeServer extends BaseServer { ...@@ -1061,7 +1061,7 @@ export default class NextNodeServer extends BaseServer {
const loggingFetchesConfig = this.nextConfig.logging?.fetches const loggingFetchesConfig = this.nextConfig.logging?.fetches
const enabledVerboseLogging = !!loggingFetchesConfig const enabledVerboseLogging = !!loggingFetchesConfig
const shouldTruncateUrl = loggingFetchesConfig?.fullUrl const shouldTruncateUrl = !loggingFetchesConfig?.fullUrl
if (this.renderOpts.dev) { if (this.renderOpts.dev) {
const { bold, green, yellow, red, gray, white } = const { bold, green, yellow, red, gray, white } =
......
import path from 'path'
import fs from 'fs'
import stripAnsi from 'strip-ansi' import stripAnsi from 'strip-ansi'
import { check } from 'next-test-utils' import { check } from 'next-test-utils'
import { createNextDescribe } from 'e2e-utils' import { createNextDescribe } from 'e2e-utils'
...@@ -42,7 +44,13 @@ createNextDescribe( ...@@ -42,7 +44,13 @@ createNextDescribe(
files: __dirname, files: __dirname,
}, },
({ next, isNextDev }) => { ({ next, isNextDev }) => {
function runTests({ withFetchesLogging }: { withFetchesLogging: boolean }) { function runTests({
withFetchesLogging,
withFullUrlFetches = false,
}: {
withFetchesLogging: boolean
withFullUrlFetches?: boolean
}) {
if (withFetchesLogging) { if (withFetchesLogging) {
it('should only log requests in dev mode', async () => { it('should only log requests in dev mode', async () => {
const outputIndex = next.cliOutput.length const outputIndex = next.cliOutput.length
...@@ -74,8 +82,9 @@ createNextDescribe( ...@@ -74,8 +82,9 @@ createNextDescribe(
log.url.includes('api/random?no-cache') log.url.includes('api/random?no-cache')
) )
// expend full url expect(logs.some((log) => log.url.includes('..'))).toBe(
expect(logs.every((log) => log.url.includes('..'))).toBe(false) !withFullUrlFetches
)
if (logEntry?.cache === 'cache: no-cache') { if (logEntry?.cache === 'cache: no-cache') {
return 'success' return 'success'
...@@ -184,8 +193,28 @@ createNextDescribe( ...@@ -184,8 +193,28 @@ createNextDescribe(
} }
} }
describe('with verbose logging', () => { describe('with fetches verbose logging', () => {
runTests({ withFetchesLogging: true }) 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', () => { describe('with verbose logging for edge runtime', () => {
...@@ -203,11 +232,18 @@ createNextDescribe( ...@@ -203,11 +232,18 @@ createNextDescribe(
}) })
describe('with default logging', () => { describe('with default logging', () => {
const curNextConfig = fs.readFileSync(
path.join(__dirname, 'next.config.js'),
{ encoding: 'utf-8' }
)
beforeAll(async () => { beforeAll(async () => {
await next.stop() await next.stop()
await next.deleteFile('next.config.js') await next.deleteFile('next.config.js')
await next.start() await next.start()
}) })
afterAll(async () => {
await next.patchFile('next.config.js', curNextConfig)
})
runTests({ withFetchesLogging: false }) runTests({ withFetchesLogging: false })
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment