Fix the light and dark toggle problem by updating index.js#1635
Merged
omroy07 merged 2 commits intoomroy07:mainfrom Feb 22, 2026
Merged
Fix the light and dark toggle problem by updating index.js#1635omroy07 merged 2 commits intoomroy07:mainfrom
omroy07 merged 2 commits intoomroy07:mainfrom
Conversation
|
@Amit-dev-zone is attempting to deploy a commit to the Om Roy's projects Team on Vercel. A member of the Team first needs to authorize it. |
Thanks for creating a PR for your Issue!
|
|
🎉 Congrats @Amit-dev-zone on getting your PR merged! 🙌 |
SatyamPandey-07
added a commit
to SatyamPandey-07/AgriTech
that referenced
this pull request
Feb 25, 2026
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.
Which issue does this PR close?
Rationale for this change
The light/dark mode toggle in index.js was experiencing inconsistencies (e.g., state not persisting on reload or failing to toggle classes correctly). This PR ensures a seamless transition between themes and improves the overall user experience by stabilizing the theme switching logic.
What changes are included in this PR?
Logic Update: Refactored the event listener in index.js to correctly identify the current theme state.
Persistence: Added/Updated localStorage functionality to ensure the user's theme preference is saved across sessions.
Class Refinement: Cleaned up the DOM manipulation logic to ensure the correct CSS classes are applied to the body or root element without conflicts.
Are these changes tested?
Yes, I have manually tested these changes:
Toggle Functionality: Verified that clicking the toggle switches between light and dark modes instantly.
Persistence Test: Set the theme to "Dark," refreshed the page, and confirmed the "Dark" theme remained active.
Cross-Browser Check: Verified the toggle works as expected on Chrome and Firefox.
Are there any user-facing changes?
Yes. Users will now experience a bug-free theme toggle. The website will also "remember" their chosen theme (Light or Dark) the next time they visit, preventing the common "flash" of the default theme during page load.