Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(postcss): disable cssnano calc optimization to prevent incorrect CSS simplification#34367

Open
lllomh wants to merge 1 commit intonuxt:mainfrom
lllomh:fix/cssnano-calc-optimization-34366
Open

fix(postcss): disable cssnano calc optimization to prevent incorrect CSS simplification#34367
lllomh wants to merge 1 commit intonuxt:mainfrom
lllomh:fix/cssnano-calc-optimization-34366

Conversation

@lllomh
Copy link
Contributor

@lllomh lllomh commented Feb 22, 2026

Summary

Fixes #34366

cssnano's default preset includes postcss-calc, which aggressively simplifies nested calc() expressions using algebraic reduction. This causes calc(100vh - calc(100vh - 100%)) to be incorrectly reduced to 100% in production builds.

While a - (a - b) = b is mathematically correct, it is semantically incorrect in CSS — 100vh and 100% are not equivalent on mobile browsers where 100vh includes the browser chrome (address bar), making this a common technique for handling mobile viewport heights.

Changes

  • Set cssnano's default preset to ['default', { calc: false }] in packages/schema/src/config/postcss.ts
  • All other CSSNano optimisations remain enabled
  • User-defined CSSNano configuration is not affected (existing override check is preserved)

Before / After

Before (production build output):

.test { height: 100% }

After (production build output):

.test { height: calc(100vh - calc(100vh - 100%)) }

@lllomh lllomh requested a review from danielroe as a code owner February 22, 2026 17:16
@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 22, 2026

Open in StackBlitz

@nuxt/kit

npm i https://pkg.pr.new/@nuxt/kit@34367

@nuxt/nitro-server

npm i https://pkg.pr.new/@nuxt/nitro-server@34367

nuxt

npm i https://pkg.pr.new/nuxt@34367

@nuxt/rspack-builder

npm i https://pkg.pr.new/@nuxt/rspack-builder@34367

@nuxt/schema

npm i https://pkg.pr.new/@nuxt/schema@34367

@nuxt/vite-builder

npm i https://pkg.pr.new/@nuxt/vite-builder@34367

@nuxt/webpack-builder

npm i https://pkg.pr.new/@nuxt/webpack-builder@34367

commit: e18baff

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 22, 2026

Walkthrough

The change modifies the default cssnano plugin configuration in postcss.ts. When cssnano is used in production builds without explicit user configuration and not in development mode, the default return value changed from an empty object to { preset: ['default', { calc: false }] }. This configures cssnano to use its default preset while explicitly disabling calc optimizations. The change preserves existing behavior for explicit user configurations and development mode.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: disabling cssnano's calc optimization in the default PostCSS configuration to prevent incorrect CSS simplification.
Description check ✅ Passed The description clearly explains the issue, the root cause, the solution, and provides before/after examples demonstrating the fix.
Linked Issues check ✅ Passed The code changes directly address issue #34366 by disabling cssnano's calc optimization in the default configuration, preserving user-defined settings.
Out of Scope Changes check ✅ Passed Changes are limited to the postcss.ts configuration file and are directly related to the stated objective of fixing the cssnano calc optimization issue.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/schema/src/config/postcss.ts (1)

49-51: Add a brief comment explaining why calc is disabled.

The reason for calc: false is non-obvious — future maintainers won't immediately know whether it was a deliberate semantic decision (preventing unsafe algebraic reduction of nested calc() for viewport units on mobile) or an oversight. Per project guidelines, non-obvious logic should carry an explanatory comment.

💬 Suggested comment
+          // Disable postcss-calc to prevent incorrect algebraic simplification of
+          // nested calc() expressions (e.g. calc(100vh - calc(100vh - 100%)) → 100%),
+          // which is mathematically valid but semantically wrong for mobile viewport units.
          return {
            preset: ['default', { calc: false }],
          }

As per coding guidelines, "Add comments only to explain complex logic or non-obvious implementations."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/schema/src/config/postcss.ts` around lines 49 - 51, Add a short,
one-line comment above the returned postcss preset configuration explaining why
calc is disabled (the object that returns preset: ['default', { calc: false }]);
state the intent (e.g., avoiding unsafe/algebraic reduction of nested calc()
with viewport units on mobile or whatever the real rationale is) so future
maintainers understand this non-obvious choice.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/schema/src/config/postcss.ts`:
- Around line 49-51: Add a short, one-line comment above the returned postcss
preset configuration explaining why calc is disabled (the object that returns
preset: ['default', { calc: false }]); state the intent (e.g., avoiding
unsafe/algebraic reduction of nested calc() with viewport units on mobile or
whatever the real rationale is) so future maintainers understand this
non-obvious choice.

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 22, 2026

Merging this PR will not alter performance

✅ 21 untouched benchmarks


Comparing lllomh:fix/cssnano-calc-optimization-34366 (e18baff) with main (e16c835)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (ba5a7a5) during the generation of this report, so e16c835 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@huang-julien
Copy link
Member

huang-julien commented Feb 23, 2026

This is a bug of post-css - cssnano, I don't think we should handle this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Production build breaks calc(100vh - calc(100vh - 100%)) due to aggressive cssnano optimization

2 participants