Skip to content

fix: resolve CodeMirror dark mode and theme switching issues #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 8, 2025

Conversation

nullcoder
Copy link
Owner

Summary

This PR fixes critical theme detection and switching issues in the CodeMirror editor on the create page. The editor now properly respects system dark mode and responds correctly to manual theme changes.

Issues Fixed

🌙 System Dark Mode Detection

  • Problem: CodeMirror editor didn't match system dark mode on initial load
  • Solution: Use resolvedTheme from next-themes instead of systemTheme for proper theme resolution
  • Result: Editor now correctly starts in dark mode when system is in dark mode

🔄 Theme Switching

  • Problem: Editor didn't switch themes when user toggled light/dark mode manually
  • Solution: Remove competing theme update effects that were interfering with each other
  • Result: Editor now immediately switches themes when theme toggle button is clicked

Technical Changes

Improved Theme Resolution

  • Switch from systemTheme to resolvedTheme for better theme detection
  • Add fallback to window.matchMedia('(prefers-color-scheme: dark)') during initialization
  • Handle SSR and hydration edge cases properly

Fixed Theme Switching Logic

  • Remove duplicate theme update effects that were conflicting
  • Ensure single source of truth for theme updates via activeTheme
  • Maintain proper effect dependencies for reliable updates

Test Plan

  • Editor starts with correct theme based on system preferences
  • Editor switches themes when manual toggle is used
  • Theme switching works in both directions (light ↔ dark)
  • System theme changes are detected and applied
  • No theme flickering or delays during switches
  • Works correctly during SSR/hydration

Code Quality

  • No linting errors
  • Proper TypeScript types
  • Clean effect dependencies
  • Removed unused variables
  • Follows existing code patterns

This ensures a consistent and responsive theme experience across the entire application.

🤖 Generated with Claude Code

nullcoder and others added 4 commits June 7, 2025 22:57
…pport

- Use resolvedTheme from next-themes for better theme resolution
- Add fallback to system preference detection during initialization
- Add dedicated effect to handle initial theme resolution
- Remove duplicate theme update logic
- Fix theme switching when system mode changes

This ensures the code editor properly matches the system dark mode
and responds correctly to theme changes.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <claude@ghostpaste.dev>
Remove duplicate theme update effect that was interfering with
proper theme switching. Now the editor correctly responds to
manual theme changes while still supporting system theme detection.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <claude@ghostpaste.dev>
…pport

- Use resolvedTheme from next-themes for better theme resolution
- Add fallback to system preference detection during initialization
- Add dedicated effect to handle initial theme resolution
- Remove duplicate theme update logic
- Fix theme switching when system mode changes

This ensures the code editor properly matches the system dark mode
and responds correctly to theme changes.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <claude@ghostpaste.dev>
Remove duplicate theme update effect that was interfering with
proper theme switching. Now the editor correctly responds to
manual theme changes while still supporting system theme detection.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <claude@ghostpaste.dev>
Copy link

cloudflare-workers-and-pages bot commented Jun 8, 2025

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
ghostpaste 19cd94d Visit preview Jun 08 2025, 06:02 AM

@nullcoder nullcoder merged commit 3bceaf7 into main Jun 8, 2025
1 check was pending
@nullcoder nullcoder deleted the fix/codemirror-dark-mode-theme-switching branch June 8, 2025 06:00
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.

1 participant