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

Postcss-Merge-Rules Unsafe Merge With Font Shorthand Breaks Line-Height Cascade

Next.js 16.2.10's production CSS minification (cssnano-simple/postcss-merge-rules) extracts shared `line-height: 22px` from `.a` and `.b` into a merged rule placed before `.b`. Because `.b` still contains the `font: inherit` shorthand later, that shorthand resets line-height to normal, breaking the original cascade priority and causing incorrect rendering.

highConfidence 85%Next.jsAffected V16.2.10

Origin Analysis

The built-in postcss-merge-rules plugin merges identical declarations without checking whether one of the source rules includes a CSS shorthand that can reset the merged longhand. In this case, the `font: inherit` shorthand in `.b` resets `line-height` after the merged rule is applied, so the extracted declaration is overridden.
1. Create `.a { line-height: 22px; }` and `.b { font: inherit; font-size: 14px; line-height: 22px; }` in a global CSS file. 2. Run `pnpm build` with next@16.2.10. 3. Open the generated CSS in `.next/static/css/*.css`. 4. Observe `.a, .b { line-height: 22px; }` appears before `.b`'s `font` shorthand, causing `.b`'s line-height to be reset to normal.

Fixing Code Block

Edge Case Audit

This hotfix changes the built-in CSS minification pipeline. It may slightly increase CSS output size because safe rule merging is disabled. The internal import path `next/dist/compiled/css-minimizer-webpack-plugin` may change in future Next.js releases, so test after upgrades. Rollback by removing the webpack override from next.config.js. Also verify that no other CSS minification expectations are broken.

Ecosystem Topology