Files
next.js/test/e2e/app-dir/cache-components-errors/cache-components-console-patch.test.ts
Tim NeutkensGitHubVercel <vercel[bot]@users.noreply.github.com>
fd2bd2952e Move Ready in time before handler initialization (#88235)
## Move "Ready in X" log before config loading and eliminate duplicate
`loadConfig` calls

### What?

Reorder the dev server startup flow so the "Ready in X" log appears
before loading the user's `next.config.js`, and eliminate duplicate
`loadConfig` calls in both dev and build paths.

### Why?

Previously, the "Ready in X" time included the time spent loading and
evaluating the user's `next.config.js` file. This made the framework
appear slower than it actually is, especially for projects with complex
config files or slow config evaluation.

Additionally, config was being loaded twice:
- **Dev server**: Once in `getStartServerInfo()` just for logging, then
again in `getRequestHandlers()`
- **Build**: Once for the main build, then again in
`getStartServerInfo()` just for logging

### How?

**Before:**
```
1. getStartServerInfo() → loadConfig #1 (slow - blocks on next.config.js)
2. logStartInfo() → logs version, URLs, experimental features
3. "Ready in X" ← time includes config loading
4. getRequestHandlers() → loadConfig #2
```

**After:**
```
1. logStartInfo() → logs version, URLs, envInfo (no config needed)
2. "Ready in X" ← reflects actual framework startup time
3. getRequestHandlers() → loadConfig (once)
4. logExperimentalInfo() → logs experimental features
```

**Changes:**

- Split `logStartInfo` into two functions:
- `logStartInfo()` - basic info (version, URLs, env) - no config needed
  - `logExperimentalInfo()` - experimental features and cacheComponents
- Removed `getStartServerInfo()` which was loading config unnecessarily
- Added `experimentalFeatures` and `cacheComponents` to
`ServerInitResult` so they can be passed back after config loads
- In build, added `reportExperimentalFeatures` callback to the existing
`loadConfig` call instead of loading config twice

---------

Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
2026-01-08 19:09:50 +01:00

85 lines
2.5 KiB
TypeScript

import { isNextDev, nextTestSetup } from 'e2e-utils'
import { getPrerenderOutput } from './utils'
import { retry } from 'next-test-utils'
describe('Cache Components Errors', () => {
const { next, isTurbopack, isNextStart, skipped } = nextTestSetup({
files: __dirname + '/fixtures/console-patch',
skipDeployment: true,
skipStart: !isNextDev,
env: {
NODE_OPTIONS: '--require ./patch-console.js',
},
})
if (skipped) {
return
}
let cliOutputLength: number
beforeEach(async () => {
cliOutputLength = next.cliOutput.length
})
afterEach(async () => {
if (isNextStart) {
await next.stop()
}
})
describe('Sync IO in console methods', () => {
describe('Console Patching', () => {
if (isNextDev) {
it('does not warn about sync IO if console.log is patched to call new Date() internally', async () => {
await next.fetch('/404')
// Wait for after 404 is rendered to the console.
await retry(async () => {
expect(next.cliOutput).toContain('GET /404 404')
})
const from = next.cliOutput.length
await next.browser('/')
// trim off any logs after the HTTP request finished
const output = next.cliOutput.slice(from)
expect(output).toContain('GET / 200')
const snapshot = output.slice(0, output.indexOf('GET / 200')).trim()
expect(snapshot).toMatchInlineSnapshot(
`"[<timestamp>] This is a console log from a server component page"`
)
})
} else {
it('does not fail the build for Sync IO if console.log is patched to call new Date() internally', async () => {
try {
await next.build()
} catch {}
const output = getPrerenderOutput(
next.cliOutput.slice(cliOutputLength),
{ isMinified: true }
)
if (isTurbopack) {
expect(output).toMatchInlineSnapshot(`
"[<timestamp>] This is a console log from a server component page
[<timestamp>] This is a console log from a server component page
[<timestamp>]"
`)
} else {
expect(output).toMatchInlineSnapshot(`
"[<timestamp>] This is a console log from a server component page
[<timestamp>] This is a console log from a server component page
[<timestamp>] Collecting build traces ...
[<timestamp>]"
`)
}
})
}
})
})
})