Skip to content
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

Modify Check for System Dark Mode Matching #211

Closed
wants to merge 1 commit into from

Conversation

trevorwhealy
Copy link

I believe the code has an issue but it is typically not encountered because a fallback condition saves it.

The code here is written as:

m=window.matchMedia(t);if(m.media===t||m.matches) { ...

If we format it differently it would look something like this:

m = window.matchMedia(t);

if (
   m.media === t || 
   m.matches
) { ...

If we convert this into better named variables:

prefersDarkMode = window.matchMedia("(prefers-color-scheme: dark)");

if (
   prefersDarkMode.media !== "(prefers-color-scheme: dark)" ||
   prefersDarkMode.matches
) { ...

This catches my eye since I assume that we actually want to find where m.media does equal "(prefers-color-scheme: dark)". However, since m.matches is likely to be true, the condition succeeds.

I could be missing the original motivation for why there are two checks versus just one. Perhaps .matches is good enough since I don't see how the first condition will be true.

@vercel
Copy link

vercel bot commented Aug 29, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
next-themes-basic ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 29, 2023 5:06am
next-themes-tailwind ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 29, 2023 5:06am
next-themes-with-app-dir ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 29, 2023 5:06am

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.

None yet

1 participant