✦ Continue with Google
AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Missing Preload Hint For CSS Chunks In Next.Js App Router

Next.js App Router emits <link rel="stylesheet"> without a companion <link rel="preload"> for CSS chunks, hurting performance metrics such as Lighthouse network dependency tree.

mediumConfidence 72%Next.jsAffected V13.4.0 - 16.2.4

Origin Analysis

The getLinkAndScriptTags function in app-render.tsx only generates stylesheet links for CSS assets; it lacks logic to emit preload hints, which are essential for early resource discovery.
1. Create a Next.js App Router project with multiple CSS files. 2. Run `next build && next start`. 3. Inspect page HTML head. 4. Observe only stylesheet links without preload.

Fixing Code Block

// packages/next/src/server/app-render/app-render.tsx // Inside getLinkAndScriptTags function, replace the styles array push for css files with: const href = `${assetPrefix}/_next/${file}`; styles.push( <link rel="preload" href={href} as="style" key={`preload-${file}`} />, <link rel="stylesheet" href={href} data-precedence="next" key={file} /> );
Preload hints tell the browser to fetch CSS earlier without blocking render, reducing critical request chain length.

Edge Case Audit

Applying this patch modifies internal HTML output; ensure existing tests that assert exact link order are updated. If performance regressions occur due to duplicate requests (unlikely as preload is cacheable), revert the patch immediately. Works only for App Router, not Pages Router.

Ecosystem Topology