Commit ad4f5ce5 authored by Jude Gao's avatar Jude Gao

improve ux

parent 961fb0ae
......@@ -187,8 +187,8 @@ program
'Comma-separated glob patterns or explicit paths for selective builds. Examples: "app/*", "app/page.tsx", "app/**/page.tsx"'
)
.option(
'--profiler',
'Creates a profiler build with source maps enabled, no minification, and React profiling.'
'--insights',
'Creates an insights build with source maps enabled, no minification, and React profiling.'
)
.action((directory: string, options: NextBuildOptions) => {
if (options.experimentalNextConfigStripTypes) {
......
......@@ -96,5 +96,5 @@ export const NextBuildContext: Partial<{
isCompileMode?: boolean
debugPrerender: boolean
analyze: boolean
profiler: boolean
insights: boolean
}> = {}
......@@ -345,7 +345,7 @@ export function getDefineEnv({
config.experimental.reactDebugChannel ?? false,
'process.env.__NEXT_TRANSITION_INDICATOR':
config.experimental.transitionIndicator ?? false,
'process.env.__NEXT_PROFILER_BUILD': config.profiler ?? false,
'process.env.__NEXT_INSIGHTS_BUILD': config.insights ?? false,
}
const userDefines = config.compiler?.define ?? {}
......
......@@ -891,7 +891,7 @@ export default async function build(
traceUploadUrl: string | undefined,
debugBuildAppPaths?: string[],
debugBuildPagePaths?: string[],
profiler = false
insights = false
): Promise<void> {
const isCompileMode = experimentalBuildMode === 'compile'
const isGenerateMode = experimentalBuildMode === 'generate'
......@@ -914,7 +914,7 @@ export default async function build(
NextBuildContext.reactProductionProfiling = reactProductionProfiling
NextBuildContext.noMangling = noMangling
NextBuildContext.debugPrerender = debugPrerender
NextBuildContext.profiler = profiler
NextBuildContext.insights = insights
await nextBuildSpan.traceAsyncFn(async () => {
// attempt to load global env values so they are available in next.config.js
......@@ -934,7 +934,7 @@ export default async function build(
silent: false,
reactProductionProfiling,
debugPrerender,
profiler,
insights,
}),
turborepoAccessTraceResult
)
......
......@@ -230,7 +230,7 @@ export async function workerMain(workerData: {
{
debugPrerender: NextBuildContext.debugPrerender,
reactProductionProfiling: NextBuildContext.reactProductionProfiling,
profiler: NextBuildContext.profiler,
insights: NextBuildContext.insights,
}
))
// Matches handling in build/index.ts
......
......@@ -390,7 +390,7 @@ export async function workerMain(workerData: {
{
debugPrerender: NextBuildContext.debugPrerender,
reactProductionProfiling: NextBuildContext.reactProductionProfiling,
profiler: NextBuildContext.profiler,
insights: NextBuildContext.insights,
}
))
await installBindings(config.experimental?.useWasmBinary)
......
......@@ -394,8 +394,8 @@ export default async function getBaseWebpackConfig(
const hasAppDir = !!appDir
const disableOptimizedLoading = true
// Combine reactProductionProfiling with profiler flag for React profiling builds
const enableReactProfiling = reactProductionProfiling || config.profiler
// Combine reactProductionProfiling with insights flag for React profiling builds
const enableReactProfiling = reactProductionProfiling || config.insights
const bundledReactChannel = needsExperimentalReact(config)
? '-experimental'
: ''
......
......@@ -21,7 +21,7 @@ export type NextBuildOptions = {
debug?: boolean
debugPrerender?: boolean
profile?: boolean
profiler?: boolean
insights?: boolean
mangling: boolean
turbo?: boolean
turbopack?: boolean
......@@ -45,7 +45,7 @@ const nextBuild = async (options: NextBuildOptions, directory?: string) => {
debugPrerender,
experimentalDebugMemoryUsage,
profile,
profiler,
insights,
mangling,
experimentalAppOnly,
experimentalBuildMode,
......@@ -86,9 +86,9 @@ const nextBuild = async (options: NextBuildOptions, directory?: string) => {
)
}
if (profiler) {
if (insights) {
warn(
`Profiler build is enabled. ${italic(
`Insights build is enabled. ${italic(
'Note: Source maps are enabled and minification is disabled. This build is not suitable for production.'
)}`
)
......@@ -139,7 +139,7 @@ const nextBuild = async (options: NextBuildOptions, directory?: string) => {
traceUploadUrl,
resolvedAppPaths,
resolvedPagePaths,
profiler
insights
)
.catch((err) => {
if (experimentalDebugMemoryUsage) {
......
......@@ -15,11 +15,11 @@ window.next = {
appDir: true,
}
// Log profiler build info at startup
if (process.env.__NEXT_PROFILER_BUILD) {
// Log insights build info at startup
if (process.env.__NEXT_INSIGHTS_BUILD) {
console.log('')
console.log(
'%c[Next.js Profiler Build]',
'%c[Next.js Insights Build]',
'background: #0070f3; color: white; padding: 2px 6px; border-radius: 3px;',
'\n• Source maps: enabled',
'\n• Minification: disabled',
......
......@@ -50,11 +50,11 @@ import { isNextRouterError } from './components/is-next-router-error'
/// <reference types="react-dom/experimental" />
// Log profiler build info at startup
if (process.env.__NEXT_PROFILER_BUILD) {
// Log insights build info at startup
if (process.env.__NEXT_INSIGHTS_BUILD) {
console.log('')
console.log(
'%c[Next.js Profiler Build]',
'%c[Next.js Insights Build]',
'background: #0070f3; color: white; padding: 2px 6px; border-radius: 3px;',
'\n• Source maps: enabled',
'\n• Minification: disabled',
......
......@@ -8,7 +8,7 @@
// Initialize waterfall detector FIRST (before any other code runs)
// This must happen before the instrumentation client is loaded to patch fetch early
let disableWaterfallDetector: (() => void) | null = null
if (process.env.__NEXT_PROFILER_BUILD) {
if (process.env.__NEXT_INSIGHTS_BUILD) {
const waterfallDetector =
require('../client/waterfall-detector') as typeof import('../client/waterfall-detector')
waterfallDetector.initWaterfallDetector()
......
......@@ -1141,11 +1141,11 @@ export interface NextConfig {
reactProductionProfiling?: boolean
/**
* Enable profiler build with source maps and no minification.
* This is set automatically when using `next build --profiler`.
* Enable insights build with source maps and no minification.
* This is set automatically when using `next build --insights`.
* @internal
*/
profiler?: boolean
insights?: boolean
/**
* The Next.js runtime is Strict Mode-compliant.
......@@ -1429,7 +1429,7 @@ export const defaultConfig = Object.freeze({
productionBrowserSourceMaps: false,
excludeDefaultMomentLocales: true,
reactProductionProfiling: false,
profiler: false,
insights: false,
reactStrictMode: null,
reactMaxHeadersLength: 6000,
httpAgentOptions: {
......@@ -1632,7 +1632,7 @@ export interface NextConfigRuntime {
skipProxyUrlNormalize: NextConfigComplete['skipProxyUrlNormalize']
pageExtensions: NextConfigComplete['pageExtensions']
useFileSystemPublicRoutes: NextConfigComplete['useFileSystemPublicRoutes']
profiler?: NextConfigComplete['profiler']
insights?: NextConfigComplete['insights']
experimental: Pick<
NextConfigComplete['experimental'],
......@@ -1762,7 +1762,7 @@ export function getNextConfigRuntime(
skipProxyUrlNormalize: config.skipProxyUrlNormalize,
pageExtensions: config.pageExtensions,
useFileSystemPublicRoutes: config.useFileSystemPublicRoutes,
profiler: config.profiler,
insights: config.insights,
experimental,
}
......
......@@ -1415,7 +1415,7 @@ function getCacheKey(
customConfig?: object | null,
reactProductionProfiling?: boolean,
debugPrerender?: boolean,
profiler?: boolean,
insights?: boolean,
pid?: number
): string {
// The next.config.js is unique per project, so we can use the dir as the major key
......@@ -1426,7 +1426,7 @@ function getCacheKey(
hasCustomConfig: Boolean(customConfig),
reactProductionProfiling: Boolean(reactProductionProfiling),
debugPrerender: Boolean(debugPrerender),
profiler: Boolean(profiler),
insights: Boolean(insights),
pid: pid || 0,
})
......@@ -1442,7 +1442,7 @@ type LoadConfigOptions = {
) => void
reactProductionProfiling?: boolean
debugPrerender?: boolean
profiler?: boolean
insights?: boolean
}
export default async function loadConfig(
......@@ -1471,7 +1471,7 @@ export default async function loadConfig(
reportExperimentalFeatures,
reactProductionProfiling,
debugPrerender,
profiler,
insights,
}: LoadConfigOptions = {}
): Promise<NextConfigComplete> {
// Generate cache key based on parameters that affect config output
......@@ -1482,7 +1482,7 @@ export default async function loadConfig(
customConfig,
reactProductionProfiling,
debugPrerender,
profiler,
insights,
process.pid
)
......@@ -1723,7 +1723,7 @@ export default async function loadConfig(
isDefaultConfig: false,
configuredExperimentalFeatures,
debugPrerender,
profiler,
insights,
phase,
})
......@@ -1782,7 +1782,7 @@ export default async function loadConfig(
isDefaultConfig: true,
configuredExperimentalFeatures,
debugPrerender,
profiler,
insights,
phase,
})
......@@ -1825,14 +1825,14 @@ function enforceExperimentalFeatures(
isDefaultConfig: boolean
configuredExperimentalFeatures: ConfiguredExperimentalFeature[] | undefined
debugPrerender: boolean | undefined
profiler: boolean | undefined
insights: boolean | undefined
phase: PHASE_TYPE
}
) {
const {
configuredExperimentalFeatures,
debugPrerender,
profiler,
insights,
isDefaultConfig,
phase,
} = options
......@@ -1868,9 +1868,9 @@ function enforceExperimentalFeatures(
)
}
// Profiler build: enable source maps (client + server) and disable minification
// Insights build: enable source maps (client + server) and disable minification
if (
profiler &&
insights &&
(phase === PHASE_PRODUCTION_BUILD || phase === PHASE_EXPORT)
) {
// Enable client-side source maps
......@@ -1901,8 +1901,8 @@ function enforceExperimentalFeatures(
configuredExperimentalFeatures
)
// Mark this as a profiler build in config for runtime detection
config.profiler = true
// Mark this as a insights build in config for runtime detection
config.insights = true
}
// TODO: Remove this once we've made Cache Components the default.
......
......@@ -16,6 +16,7 @@ export function logStartInfo({
experimentalFeatures,
logBundler,
cacheComponents,
insights,
}: {
networkUrl: string | null
appUrl: string | null
......@@ -23,6 +24,7 @@ export function logStartInfo({
experimentalFeatures?: ConfiguredExperimentalFeature[]
logBundler: boolean
cacheComponents?: boolean
insights?: boolean
}) {
let versionSuffix = ''
const parts = []
......@@ -41,6 +43,10 @@ export function logStartInfo({
parts.push('Cache Components')
}
if (insights) {
parts.push('Insights')
}
if (parts.length > 0) {
versionSuffix = ` (${parts.join(', ')})`
}
......@@ -114,9 +120,11 @@ export async function getStartServerInfo({
envInfo?: string[]
experimentalFeatures?: ConfiguredExperimentalFeature[]
cacheComponents?: boolean
insights?: boolean
}> {
let experimentalFeatures: ConfiguredExperimentalFeature[] = []
let cacheComponents = false
let insights = false
const config = await loadConfig(
dev ? PHASE_DEVELOPMENT_SERVER : PHASE_PRODUCTION_BUILD,
dir,
......@@ -132,6 +140,7 @@ export async function getStartServerInfo({
)
cacheComponents = !!config.cacheComponents
insights = !!config.insights
// we need to reset env if we are going to create
// the worker process with the esm loader so that the
......@@ -146,5 +155,6 @@ export async function getStartServerInfo({
envInfo,
experimentalFeatures,
cacheComponents,
insights,
}
}
......@@ -355,15 +355,22 @@ export async function startServer(
}
// Only load env and config in dev to for logging purposes
// For production, we still need to check for insights mode
let envInfo: string[] | undefined
let experimentalFeatures: ConfiguredExperimentalFeature[] | undefined
let cacheComponents: boolean | undefined
let insights: boolean | undefined
try {
if (isDev) {
const startServerInfo = await getStartServerInfo({ dir, dev: isDev })
envInfo = startServerInfo.envInfo
cacheComponents = startServerInfo.cacheComponents
experimentalFeatures = startServerInfo.experimentalFeatures
insights = startServerInfo.insights
} else {
// For production, check if this is an insights build
const startServerInfo = await getStartServerInfo({ dir, dev: false })
insights = startServerInfo.insights
}
logStartInfo({
networkUrl,
......@@ -371,6 +378,7 @@ export async function startServer(
envInfo,
experimentalFeatures,
cacheComponents,
insights,
logBundler: isDev,
})
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment