Fix theme toggle button not working due to SSR hydration mismatch#208
Merged
amansrivastava merged 3 commits intomainfrom Aug 16, 2025
Merged
Fix theme toggle button not working due to SSR hydration mismatch#208amansrivastava merged 3 commits intomainfrom
amansrivastava merged 3 commits intomainfrom
Conversation
Co-authored-by: credevator <2756303+credevator@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] [Frontend Bug]:
Fix theme toggle button not working due to SSR hydration mismatch
Aug 16, 2025
amansrivastava
previously approved these changes
Aug 16, 2025
amansrivastava
approved these changes
Aug 16, 2025
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.
The theme mode toggle button in the header dropdown was not working due to a Next.js server-side rendering (SSR) hydration mismatch in the ThemeContext component.
Problem
The ThemeContext was accessing
localStorageduring the initial render without checking if it was running on the client side. This caused hydration mismatches between what the server rendered and what the client expected, preventing the theme toggle functionality from working properly.Solution
Updated the ThemeContext to properly handle SSR by:
localStorageaccess withtypeof window !== 'undefined'checksmountedstate to prevent theme application until the component has hydrated on the clientChanges
Testing
The fix has been verified to work correctly:
Screenshots
Light Mode:

Dark Mode:

The theme mode button in the header dropdown now works as expected for all authenticated users, allowing seamless switching between light and dark themes.
Fixes #207.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.