Skip to content

fix(react): wrap loader in styledscope for consistent styling#174

Merged
chakrihacker merged 6 commits intomainfrom
fix/loading-spinner
Mar 24, 2026
Merged

fix(react): wrap loader in styledscope for consistent styling#174
chakrihacker merged 6 commits intomainfrom
fix/loading-spinner

Conversation

@chakrihacker
Copy link
Copy Markdown
Contributor

@chakrihacker chakrihacker commented Mar 17, 2026

Problem

In Next.js with SSR, the server always rendered components with the default light theme, while the client-side React hydration would immediately switch to dark mode based on OS preference (prefers-color-scheme). This caused a hydration mismatch and a visible flash of incorrectly themed content on page load.

The root cause: the server has no access to window.matchMedia, so it cannot know the user's preferred color scheme at render time.

Solution

A cookie-based approach is used to bridge the server/client theme preference gap. The user's preferred theme is persisted to a theme-mode cookie, which the server can read on the next request to pre-render with the correct theme, eliminating the mismatch.

Before

Screenshot 2026-03-16 at 2 17 08 PM

After

Screenshot 2026-03-18 at 4 35 57 PM

Checklist

Copy link
Copy Markdown
Contributor

@rax7389 rax7389 left a comment

Choose a reason for hiding this comment

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

Unit test Checks are failing in also the PR doesn't describe before and after fix

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.65%. Comparing base (20a6bc3) to head (e4ee495).

Additional details and impacted files
@@           Coverage Diff            @@
##             main     #174    +/-   ##
========================================
  Coverage   88.64%   88.65%            
========================================
  Files         154      154            
  Lines       13134    13140     +6     
  Branches     1716     1406   -310     
========================================
+ Hits        11643    11649     +6     
  Misses       1491     1491            

☔ 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.

Comment thread packages/react/src/providers/proxy-provider.tsx Outdated
@chakrihacker chakrihacker self-assigned this Mar 19, 2026
Comment thread examples/next-rwa/src/hooks/use-dark-mode.ts
Comment thread examples/next-rwa/src/hooks/use-dark-mode.ts
Comment thread examples/next-rwa/src/hooks/use-dark-mode.ts Outdated
Comment thread examples/next-rwa/src/hooks/use-dark-mode.ts
@chakrihacker chakrihacker merged commit 7795ce1 into main Mar 24, 2026
6 checks passed
@chakrihacker chakrihacker deleted the fix/loading-spinner branch March 24, 2026 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants