Skip to content

fix(cssnano-preset): disable CSS counter minification#11487

Merged
slorber merged 2 commits intofacebook:mainfrom
YDKK:fix/codeblock-line-number
Oct 16, 2025
Merged

fix(cssnano-preset): disable CSS counter minification#11487
slorber merged 2 commits intofacebook:mainfrom
YDKK:fix/codeblock-line-number

Conversation

@YDKK
Copy link
Contributor

@YDKK YDKK commented Oct 16, 2025

Pre-flight checklist

  • I have read the Contributing Guidelines on pull requests.
  • If this is a code change: I have written unit tests and/or added dogfooding pages to fully verify the new behavior.
  • If this is a new API or substantial change: the PR has an accompanying issue (closes #0000) and the maintainers have approved on my working plan.

Motivation

In sites generated with the default classic template, the CSS variable that counts line numbers is minified by cssnano during deployment. As a result, the feature that continues line numbering from a specific value using showLineNumbers=X does not work correctly.
This PR fixes the issue by adding a configuration to the cssnano-preset that prevents CSS counters from being minified.

Test Plan

I added a sample of this feature to the dogfooding page.

Since the /website deployment uses Rspack instead of Webpack, the following steps are required to reproduce the issue:

  1. Comment out all feature->experimental_faster lines in /website/docusaurus.config.ts.
  2. Run yarn build --locale en.
    • Note: The issue cannot be reproduced with yarn start because CSS minification does not occur in that mode.
  3. Run npx serve website/build/.
  4. Visit http://localhost:3000/tests/pages/code-block-tests#code-blocks-with-line-numbering-tests and check the line numbers.

Screenshots

Before After
image image

Test links

Deploy preview: https://deploy-preview-11487--docusaurus-2.netlify.app/

Related issues/PRs

@meta-cla meta-cla bot added the CLA Signed Signed Facebook CLA label Oct 16, 2025
@netlify
Copy link

netlify bot commented Oct 16, 2025

[V2]

Name Link
🔨 Latest commit 9020237
🔍 Latest deploy log https://app.netlify.com/projects/docusaurus-2/deploys/68f10c4c5c52430008f4044e
😎 Deploy Preview https://deploy-preview-11487--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@slorber slorber added the pr: bug fix This PR fixes a bug in a past release. label Oct 16, 2025
@slorber
Copy link
Collaborator

slorber commented Oct 16, 2025

Thanks

I can confirm this is a bug and can reproduced with DOCUSAURUS_SLOWER=true yarn build:website:fast && yarn serve:website

This is because only the CSS counter ident is renamed, but the inline style ident is not:

CleanShot 2025-10-16 at 17 17 19

@slorber slorber merged commit 5423a77 into facebook:main Oct 16, 2025
41 of 42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Signed Facebook CLA pr: bug fix This PR fixes a bug in a past release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants