diff --git a/packages/next/src/server/next-server.ts b/packages/next/src/server/next-server.ts index 87e0cc79726485..113ddb8e6d43dd 100644 --- a/packages/next/src/server/next-server.ts +++ b/packages/next/src/server/next-server.ts @@ -1132,12 +1132,14 @@ export default class NextNodeServer extends BaseServer { 'originalResponse' in _res ? _res.originalResponse : _res const reqStart = Date.now() + const isMiddlewareRequest = req.headers['x-middleware-invoke'] const reqCallback = () => { // we don't log for non-route requests - const isRouteRequest = getRequestMeta(req).match + const routeMatch = getRequestMeta(req).match + const isRSC = isRSCRequestCheck(req) - if (!isRouteRequest || isRSC) return + if (!routeMatch || isRSC || isMiddlewareRequest) return const reqEnd = Date.now() const fetchMetrics = normalizedReq.fetchMetrics || [] diff --git a/test/e2e/app-dir/logging/app/page.js b/test/e2e/app-dir/logging/app/page.js index 5560657841caf8..0583904f6fc69f 100644 --- a/test/e2e/app-dir/logging/app/page.js +++ b/test/e2e/app-dir/logging/app/page.js @@ -1,3 +1,9 @@ +import Link from 'next/link' + export default function Page() { - return 'hello world' + return ( + <> + /link + + ) } diff --git a/test/e2e/app-dir/logging/fetch-logging.test.ts b/test/e2e/app-dir/logging/fetch-logging.test.ts index d17221311de63d..87d662713a9e71 100644 --- a/test/e2e/app-dir/logging/fetch-logging.test.ts +++ b/test/e2e/app-dir/logging/fetch-logging.test.ts @@ -4,7 +4,7 @@ import stripAnsi from 'strip-ansi' import { retry } from 'next-test-utils' import { nextTestSetup } from 'e2e-utils' -const cahceReasonRe = /Cache (missed|skipped) reason: / +const cacheReasonRegex = /Cache (missed|skipped) reason: / interface ParsedLog { method: string @@ -17,13 +17,13 @@ interface ParsedLog { function parseLogsFromCli(cliOutput: string) { const logs = stripAnsi(cliOutput) .split('\n') - .filter((log) => cahceReasonRe.test(log) || log.includes('GET')) + .filter((log) => cacheReasonRegex.test(log) || log.includes('GET')) return logs.reduce((parsedLogs, log) => { - if (cahceReasonRe.test(log)) { + if (cacheReasonRegex.test(log)) { // cache miss/skip reason // Example of `log`: "│ │ Cache skipped reason: (cache: no-cache)" - const reasonSegment = log.split(cahceReasonRe, 3)[2].trim() + const reasonSegment = log.split(cacheReasonRegex, 3)[2].trim() const reason = reasonSegment.slice(1, -1) parsedLogs[parsedLogs.length - 1].cache = reason } else { @@ -162,8 +162,10 @@ describe('app-dir - logging', () => { await browser.elementByCss('a').click() await browser.waitForElementByCss('h2') const logs = stripAnsi(next.cliOutput.slice(outputIndex)) - expect(logs).not.toContain('GET /_next/static') - expect(logs).not.toContain('GET /foo?_rsc') + expect(logs).not.toContain('/_next/static') + expect(logs).not.toContain('?_rsc') + // Only show `GET /` once + expect(logs.split('GET /').length).toBe(2) }) } } else {