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>
This commit is contained in:
Raphaël Badia 2023-12-07 20:54:34 +01:00 committed by GitHub
parent e1fe0c9a14
commit d07a370dfa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 57 additions and 18 deletions

View file

@ -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,

View file

@ -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>({
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, {

View file

@ -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 } =

View file

@ -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 })
})