AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

App Router Incorrectly Bundles Unused CSS Modules Into Unrelated Routes

Next.js App Router with Turbopack/Webpack incorrectly includes CSS modules from components that are only used in specific routes (e.g., Button on home and not-found) into the bundle of all routes (e.g., dashboard and dashboard/users), causing render-blocking CSS and significant performance degradation.

highConfidence 85%Next.jsTurbopackPages RouterAffected V16.1.6

Origin Analysis

The CSS module import in a client component is being treated as a global side-effect instead of being scoped to the component's chunk. This likely stems from a missing dependency graph analysis in the bundler (Turbopack/Webpack) that fails to tree-shake unused CSS when the component is not imported by a route. The CSS may be hoisted into a shared chunk or incorrectly added to the flight manifest as required for all routes.
1. Clone reproduction repo: https://github.com/t18n/next-js-app-router-css-bundle-repro/tree/main 2. Run `pnpm install` 3. Run `pnpm build:analyzer` 4. Open analyzer at http://localhost:4000/ 5. Inspect the bundles for dashboard and dashboard/users routes; observe that Button.module.scss is included and loaded even though Button is not used on those routes.

Fixing Code Block

Edge Case Audit

This workaround adds a network request for the Button chunk when first rendered, which may slightly delay component appearance. If Button is above-the-fold or critical for LCP, this could impact initial paint. All usage sites must be updated to use dynamic import; missing one will reintroduce the unused CSS. Rollback: remove the dynamic import and restore static import once Next.js provides an official fix. Also, dynamic import may affect server-side rendering if not configured with ssr: true, so ensure ssr is set appropriately.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state