mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
fd2bd2952e
## 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>
134 lines
5.0 KiB
TypeScript
134 lines
5.0 KiB
TypeScript
import { isNextDev, nextTestSetup } from 'e2e-utils'
|
|
|
|
describe('Cache Components Errors', () => {
|
|
const { next, skipped } = nextTestSetup({
|
|
files: __dirname + '/fixtures/dev-cache-bypass',
|
|
})
|
|
|
|
if (skipped) {
|
|
return
|
|
}
|
|
|
|
describe('Warning for Bypassing Caches in Dev', () => {
|
|
if (isNextDev) {
|
|
it('warns if you render with cache-control: no-cache in dev on initial page load', async () => {
|
|
// Wait for pages to be loaded to ensure the logging for the test page is the only thing that can be logged.
|
|
await next.fetch('/404')
|
|
const from = next.cliOutput.length
|
|
|
|
await next.fetch('/', {
|
|
headers: { 'cache-control': 'no-cache' },
|
|
})
|
|
|
|
expect(stripGetLines(next.cliOutput.slice(from)))
|
|
.toMatchInlineSnapshot(`
|
|
"Route / is rendering with server caches disabled. For this navigation, Component Metadata in React DevTools will not accurately reflect what is statically prerenderable and runtime prefetchable. See more info here: https://nextjs.org/docs/messages/cache-bypass-in-dev
|
|
"
|
|
`)
|
|
})
|
|
|
|
it('warns if you render with cache-control: no-cache in dev on client navigation', async () => {
|
|
// Wait for pages to be loaded to ensure the logging for the test page is the only thing that can be logged.
|
|
await next.fetch('/404')
|
|
const from = next.cliOutput.length
|
|
|
|
await next.fetch('/other', {
|
|
headers: { 'cache-control': 'no-cache', RSC: '1' },
|
|
})
|
|
|
|
expect(stripGetLines(next.cliOutput.slice(from)))
|
|
.toMatchInlineSnapshot(`
|
|
"Route /other is rendering with server caches disabled. For this navigation, Component Metadata in React DevTools will not accurately reflect what is statically prerenderable and runtime prefetchable. See more info here: https://nextjs.org/docs/messages/cache-bypass-in-dev
|
|
"
|
|
`)
|
|
})
|
|
|
|
it('does not warn if you render without cache-control: no-cache in dev on initial page load', async () => {
|
|
// Wait for pages to be loaded to ensure the logging for the test page is the only thing that can be logged.
|
|
await next.fetch('/404')
|
|
const from = next.cliOutput.length
|
|
|
|
await next.fetch('/')
|
|
|
|
expect(stripGetLines(next.cliOutput.slice(from))).toMatchInlineSnapshot(
|
|
`""`
|
|
)
|
|
})
|
|
|
|
it('does not warn if you render without cache-control: no-cache in dev on client navigation', async () => {
|
|
// Wait for pages to be loaded to ensure the logging for the test page is the only thing that can be logged.
|
|
await next.fetch('/404')
|
|
const from = next.cliOutput.length
|
|
|
|
await next.fetch('/', {
|
|
headers: { RSC: '1' },
|
|
})
|
|
|
|
expect(stripGetLines(next.cliOutput.slice(from))).toMatchInlineSnapshot(
|
|
`""`
|
|
)
|
|
})
|
|
} else {
|
|
it('does not warn if you render with cache-control: no-cache in dev on initial page load', async () => {
|
|
// Wait for pages to be loaded to ensure the logging for the test page is the only thing that can be logged.
|
|
await next.fetch('/404')
|
|
const from = next.cliOutput.length
|
|
|
|
await next.fetch('/', {
|
|
headers: { 'cache-control': 'no-cache' },
|
|
})
|
|
|
|
expect(stripGetLines(next.cliOutput.slice(from))).toMatchInlineSnapshot(
|
|
`""`
|
|
)
|
|
})
|
|
|
|
it('does not warn if you render with cache-control: no-cache in dev on client navigation', async () => {
|
|
// Wait for pages to be loaded to ensure the logging for the test page is the only thing that can be logged.
|
|
await next.fetch('/404')
|
|
const from = next.cliOutput.length
|
|
|
|
await next.fetch('/', {
|
|
headers: { 'cache-control': 'no-cache' },
|
|
})
|
|
|
|
expect(stripGetLines(next.cliOutput.slice(from))).toMatchInlineSnapshot(
|
|
`""`
|
|
)
|
|
})
|
|
|
|
it('does not warn if you render without cache-control: no-cache in dev on initial page load in start', async () => {
|
|
// Wait for pages to be loaded to ensure the logging for the test page is the only thing that can be logged.
|
|
await next.fetch('/404')
|
|
const from = next.cliOutput.length
|
|
|
|
await next.fetch('/')
|
|
|
|
expect(stripGetLines(next.cliOutput.slice(from))).toMatchInlineSnapshot(
|
|
`""`
|
|
)
|
|
})
|
|
|
|
it('does not warn if you render without cache-control: no-cache in dev on client navigation in start', async () => {
|
|
// Wait for pages to be loaded to ensure the logging for the test page is the only thing that can be logged.
|
|
await next.fetch('/404')
|
|
const from = next.cliOutput.length
|
|
|
|
await next.fetch('/', {
|
|
headers: { RSC: '1' },
|
|
})
|
|
|
|
expect(stripGetLines(next.cliOutput.slice(from))).toMatchInlineSnapshot(
|
|
`""`
|
|
)
|
|
})
|
|
}
|
|
})
|
|
})
|
|
|
|
function stripGetLines(input: string): string {
|
|
return input
|
|
.replace(/^\s*GET.*(?:\r?\n|$)/gm, '')
|
|
.replace(/^\s*[○✓].*(?:\r?\n|$)/gm, '')
|
|
}
|