Skip to content

Fix the light and dark toggle problem by updating index.js#1635

Merged
omroy07 merged 2 commits intoomroy07:mainfrom
Amit-dev-zone:toggle
Feb 22, 2026
Merged

Fix the light and dark toggle problem by updating index.js#1635
omroy07 merged 2 commits intoomroy07:mainfrom
Amit-dev-zone:toggle

Conversation

@Amit-dev-zone
Copy link
Copy Markdown
Contributor

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.

Screenshot 2026-02-22 152223 Screenshot 2026-02-22 152234

@vercel
Copy link
Copy Markdown

vercel bot commented Feb 22, 2026

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

@github-actions
Copy link
Copy Markdown

Thanks for creating a PR for your Issue! ☺️

We'll review it as soon as possible.
In the meantime, please double-check the file changes and ensure that all commits are accurate.

If there are any unresolved review comments, feel free to resolve them. 🙌🏼

@omroy07 omroy07 merged commit a244df6 into omroy07:main Feb 22, 2026
2 of 5 checks passed
@github-actions
Copy link
Copy Markdown

🎉 Congrats @Amit-dev-zone on getting your PR merged! 🙌
Thanks for the contribution — looking forward to more from you 🚀

SatyamPandey-07 added a commit to SatyamPandey-07/AgriTech that referenced this pull request Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Dark Mode toggle in sidebar does not apply theme change

2 participants