perf: optimize CSS-in-JS performance with build-time Tailwind pre-gen… - #548
Merged
Merged
Conversation
…eration and canonical cn utility
|
@Unclebaffa Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Unclebaffa
force-pushed
the
perf/css-in-js-performance
branch
from
August 26, 2026 18:49
df49f36 to
d207aa7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[Performance] CSS-in-JS Optimization & Build-Time Tailwind Pre-generation
📌 Summary of Changes
This PR addresses the interaction jank, layout thrashing, and visible frame drops caused by runtime CSS/class generation and dynamic style evaluations across the StellarAid web application.
Although the application relies on Tailwind CSS rather than a runtime CSS-in-JS engine (e.g., Emotion / Styled Components), performance bottlenecks were identified stemming from:
twMergeconflict resolution, allowing conflicting utility classes to compound in the DOM and cause recalculation overhead.style={{}}object allocations for static gradients, backgrounds, and meter bars.contentpaths risking class purging and un-purged CSS fallbacks.package.json(@tailwindcss/postcssv4 dependency colliding with Tailwind v3 configuration).All styling has now been migrated to build-time pre-generated Tailwind classes with a centralized
cn()utility (clsx+tailwind-merge), and automated CI gates have been instituted.🛠️ Detailed Implementation Breakdown
1. Canonical Class-Name Merging Utility (
lib/cn.ts)clsxfor conditional boolean logic withtailwind-mergefor conflict resolution (e.g., ensuring dynamicclassNameprops override base utilities cleanly).2. Tailwind Configuration & Build-Time Optimization
contentarray:hooks/,stores/,lib/,utils/,constants/, andtypes/to prevent premature purging of utilities.@tailwindcss/postcss(Tailwind v4) dependency to eliminate version discrepancies with Tailwind v3.3.0.3. Elimination of Runtime Inline Style Objects
.hero-mesh-gradientand.hero-grid-texture.style={{ background: ... }}andstyle={{ backgroundImage: ... }}with.hero-mesh-gradientand.hero-grid-texture.4. Refactoring
PasswordStrengthIndicatorto Tailwindstyle={{ backgroundColor: color, ... }}) to static Tailwind color mapping (STRENGTH_BAR_CLASSES,STRENGTH_TEXT_CLASSES).role="meter"and ARIA labels.5. Component Class Composition Standardization (
cn())Replaced ad-hoc string concatenation, template literals, and
clsx()calls across 16 core UI and layout components:app/components/ui/Button.tsxapp/components/ui/Input.tsxapp/components/ui/Skeleton.tsxapp/components/ui/Breadcrumb.tsxapp/components/common/ButtonSpinner.tsxapp/components/common/Modal.tsxapp/components/common/Lightbox.tsxapp/components/common/Spinner.tsxapp/components/common/ErrorMessage.tsxcomponents/common/VerifiedBadge.tsxapp/components/layout/Header.tsxapp/components/layout/Navbar.tsxapp/components/layout/NotificationBell.tsxapp/explore/components/ExploreProjects.tsxcomponents/landing/HowItWorks.tsxcomponents/landing/CategoriesShowcase.tsx6. TypeScript & Build Configuration Fixes
"types": ["node"]to prevent the TS compiler/IDE from attempting to auto-discover ambient type definitions from transitive testing packages (@types/sinonjs__fake-timers,@types/sizzle).Window.freighterdeclarations and updated Freighter SDK calls for v6 compatibility.pool: 'threads'for deterministic cross-platform test runs.7. CI Pipeline (
.github/workflows/ci.yml)npm run type-check(tsc --noEmit)npm run lint(next lint)npm run format:check(prettier --check)npm run test(vitest run)npm run build(next build)🧪 Verification & Test Results
All 5 quality and performance gates passed with zero errors:
npm run type-checknpm run lintnpm run format:checknpm testnpm run build📂 Key Files Modified / Added
lib/cn.ts(new)lib/__tests__/cn.test.ts(new).github/workflows/ci.yml(new)app/globals.csstailwind.config.tspackage.jsontsconfig.jsonvitest.config.tsapp/components/common/PasswordStrengthIndicator.tsxapp/components/common/ButtonSpinner.tsxapp/components/common/ErrorMessage.tsxapp/components/common/Lightbox.tsxapp/components/common/Modal.tsxapp/components/common/Spinner.tsxapp/components/landing/Hero.tsxapp/components/layout/Header.tsxapp/components/layout/Navbar.tsxapp/components/layout/NotificationBell.tsxapp/components/ui/Breadcrumb.tsxapp/components/ui/Button.tsxapp/components/ui/Input.tsxapp/components/ui/Skeleton.tsxapp/explore/components/ExploreProjects.tsxcomponents/common/VerifiedBadge.tsxcomponents/landing/CategoriesShowcase.tsxcomponents/landing/HowItWorks.tsxCloses #522