Skip to content

Migrate batch 1 components from BEM to CSS Modules#2014

Merged
umputun merged 2 commits intomasterfrom
bem-to-css-modules-batch1
Mar 25, 2026
Merged

Migrate batch 1 components from BEM to CSS Modules#2014
umputun merged 2 commits intomasterfrom
bem-to-css-modules-batch1

Conversation

@paskal
Copy link
Copy Markdown
Collaborator

@paskal paskal commented Feb 24, 2026

Summary

  • Migrate 8 frontend components from BEM to CSS Modules: button, dropdown, thread, auth-panel, dropdown-item, list-comments, subscribe-by-rss, settings
  • Consolidate 19 BEM CSS files into 8 CSS Module files
  • Replace bem-react-helper b() calls with clsx for conditional class composition
  • Remove 12 index.ts barrel re-export files that are no longer needed
  • Update CLAUDE.md CSS guideline to reflect migration status
  • Fix deprecated -moz-touch-enabled media queries in new CSS Module files (incorporating cleanup from Clean up deprecated CSS and fix silent CSS bugs in frontend #2012)

Visual regression verification

Built artefacts compared between master and this branch:

File Master Branch Delta
remark.css 43,779 B 43,299 B -480 B
last-comments.css 18,792 B 18,776 B -16 B
remark.js 256,709 B 304,837 B +48 KB (expected: classname maps in JS)
last-comments.js 121,726 B 168,615 B +47 KB (same reason)

Pixel-level screenshot comparison:

  • Dark theme: zero pixel difference
  • Light theme: zero remark42 widget difference (0.21% diff is the native demo page "Toggle theme" button, not any widget element)

@paskal paskal requested a review from umputun as a code owner February 24, 2026 20:00
@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 24, 2026

size-limit report 📦

Path Size
public/embed.mjs 2.02 KB (0%)
public/remark.mjs 73.47 KB (-0.4% 🔽)
public/remark.css 7.67 KB (-5.8% 🔽)
public/last-comments.mjs 35.95 KB (-0.64% 🔽)
public/last-comments.css 3.41 KB (-8.2% 🔽)
public/deleteme.mjs 12.42 KB (0%)
public/counter.mjs 747 B (0%)

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.03%. Comparing base (b888a53) to head (bd450ad).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2014      +/-   ##
==========================================
- Coverage   62.16%   62.03%   -0.14%     
==========================================
  Files         132      132              
  Lines        3037     3037              
  Branches      728      745      +17     
==========================================
- Hits         1888     1884       -4     
- Misses       1145     1149       +4     
  Partials        4        4              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

umputun
umputun previously approved these changes Mar 25, 2026
Copy link
Copy Markdown
Owner

@umputun umputun left a comment

Choose a reason for hiding this comment

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

lgtm, thx

@paskal paskal marked this pull request as draft March 25, 2026 21:44
paskal added 2 commits March 25, 2026 21:47
Migrate 8 components from BEM to CSS Modules:
- button (7 BEM files -> 1 module)
- dropdown (7 BEM files -> 1 module)
- thread (3 BEM files -> 1 module)
- auth-panel (2 BEM files -> 1 module)
- dropdown-item, list-comments, subscribe-by-rss, settings (from batch 0 PR #2013)

Consolidates 19 BEM CSS files into 8 CSS Module files. Uses clsx for
conditional class composition, replacing bem-react-helper's b() calls.
Class naming follows the established convention: BEM block = .root,
elements = camelCase, modifiers = camelCase.

Visual regression verification on built artefacts:
- remark.css: 43,779 -> 43,299 bytes (480 bytes smaller)
- last-comments.css: 18,792 -> 18,776 bytes (16 bytes smaller)
- remark.js: 256,709 -> 304,837 bytes (48KB larger, expected: CSS Module
  classname mappings now live in JS instead of plain strings)
- Dark theme: pixel-identical (zero difference)
- Light theme: pixel-identical (0.21% diff is the native demo page
  "Toggle theme" button, not any remark42 widget element)

Also updates CLAUDE.md CSS guideline to reflect the migration status.
Migrate the last 4 BEM components to CSS Modules, completing the
migration and removing bem-react-helper from the project entirely.

Components migrated:
- subscribe-by-email (1 BEM CSS file -> 1 module)
- comment-form + markdown-toolbar (20 BEM CSS files -> 2 modules)
- comment (19 BEM CSS files -> expanded existing module)
- root (10 BEM CSS files -> expanded existing module)

Consolidates ~50 BEM CSS files into 4 new + 2 expanded CSS Module files.
Removes bem-react-helper dependency — all components now use clsx for
conditional class composition.

Dead CSS cleanup during migration:
- Orphaned comment-actions selectors in comment theme CSS (already migrated)
- Dead BEM modifiers: comment_disabled, comment_pinned, comment_guest
- Dead element: comment__user-id (CSS existed but never used in TSX)
- Dead button type classes: comment-form__button_type_preview/_send
- Dead mix values: auth-email-login-form__back-button, comment-form__email-dropdown

Key implementation details:
- comment_highlighting stays global via :global() (imperatively added by classList)
- Bare .dark/.light theme class preserved on root wrapper (8+ modules depend on it)
- raw-content.css kept as global utility CSS (syntax highlighting)

Visual regression verification on built artefacts:
- remark.css: 43,779 -> 36,106 bytes (-17.5%)
- last-comments.css: 18,792 -> 13,955 bytes (-25.7%)
- remark.js: 256,709 -> 253,637 bytes (-1.2%)
- last-comments.js: 121,726 -> 120,795 bytes (-0.8%)
- Total: 441,006 -> 424,493 bytes (-3.7%)
- Screenshot comparison: pixel-identical across light/dark themes
@paskal paskal force-pushed the bem-to-css-modules-batch1 branch from d3c5cbc to bd450ad Compare March 25, 2026 21:50
@paskal paskal marked this pull request as ready for review March 25, 2026 21:51
@umputun umputun merged commit 06436ff into master Mar 25, 2026
9 of 10 checks passed
@umputun umputun deleted the bem-to-css-modules-batch1 branch March 25, 2026 21:53
@paskal paskal added this to the v1.16.0 milestone Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants