Files
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

90 lines
2.1 KiB
TypeScript

// @ts-check
// @ts-ignore
import { nextTestSetup } from 'e2e-utils'
import cheerio from 'cheerio'
import { retry } from 'next-test-utils'
const { i18n } = require('./next.config')
const urls = [
// Include the app page without a locale.
...(global.isNextDeploy
? []
: [
// TODO: enable for deploy mode when behavior is corrected
{
pathname: '/blog/first-post',
expected: {
pathname: '/blog/first-post',
page: '/app/blog/[slug]/page.js',
},
},
]),
// Include the app pages with locales (should not resolve).
...i18n.locales.map((locale) => ({
pathname: `/${locale}/blog/first-post`,
expected: null,
})),
// Include the pages page without a locale (should default to the default
// locale).
{
pathname: '/about',
expected: {
pathname: `/${i18n.defaultLocale}/about`,
page: '/pages/about.js',
},
},
// Include the locale prefixed urls for the pages page (should resolve).
...i18n.locales.map((locale) => ({
pathname: `/${locale}/about`,
expected: {
pathname: `/${locale}/about`,
page: '/pages/about.js',
},
})),
]
describe('i18n-hybrid', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it('should warn about i18n in app dir', async () => {
await retry(async () => {
expect(next.cliOutput).toContain(
'i18n configuration in next.config.js is unsupported in App Router.'
)
})
})
it.each(urls.filter((url) => !url.expected))(
'does not resolve $pathname',
async (url) => {
const res = await next.fetch(url.pathname, {
redirect: 'manual',
})
expect(res.status).toBe(404)
}
)
it.each(urls.filter((url) => url.expected))(
'does resolve $pathname',
async (url) => {
const res = await next.fetch(url.pathname, {
redirect: 'manual',
})
expect(res.status).toBe(200)
const $ = cheerio.load(await res.text())
const debug = JSON.parse($('#debug').text())
expect(debug).toEqual(url.expected)
}
)
})