From 141a575a3a93734e134c3406c1598edd24f2000d Mon Sep 17 00:00:00 2001 From: harehare Date: Sun, 12 Apr 2026 19:38:17 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(playground):=20fix=20theme?= =?UTF-8?q?=20switching=20not=20working=20in=20production=20build?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lightningcss transforms light-dark() into a @media (prefers-color-scheme) polyfill using --lightningcss-light/dark variables. Setting colorScheme via JS had no effect on these variables in the production build. - Update --lightningcss-light/dark CSS variables when switching themes - Remove duplicate :root block with hardcoded hex values to prevent CSS variable override conflicts during minification - Replace hardcoded hex colors with CSS variables using light-dark() - Fix h1 inline style using hardcoded #67b8e3 instead of CSS variable --- packages/mq-playground/src/Playground.tsx | 24 ++++++++++++++++---- packages/mq-playground/src/index.css | 27 +++++++++-------------- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/packages/mq-playground/src/Playground.tsx b/packages/mq-playground/src/Playground.tsx index 462b10e4c..836359374 100644 --- a/packages/mq-playground/src/Playground.tsx +++ b/packages/mq-playground/src/Playground.tsx @@ -371,8 +371,16 @@ export const Playground = () => { const themeParam = urlParams.get("theme"); if (themeParam) { - document.documentElement.style.colorScheme = - themeParam === "dark" ? "dark" : "light"; + const isDark = themeParam === "dark"; + document.documentElement.style.colorScheme = isDark ? "dark" : "light"; + document.documentElement.style.setProperty( + "--lightningcss-light", + isDark ? " " : "initial" + ); + document.documentElement.style.setProperty( + "--lightningcss-dark", + isDark ? "initial" : " " + ); } // Update sidebar visibility from URL parameter if present @@ -1004,8 +1012,16 @@ export const Playground = () => { if (theme === "system") { document.documentElement.style.colorScheme = ""; + document.documentElement.style.removeProperty("--lightningcss-light"); + document.documentElement.style.removeProperty("--lightningcss-dark"); + } else if (theme === "dark") { + document.documentElement.style.colorScheme = "dark"; + document.documentElement.style.setProperty("--lightningcss-light", " "); + document.documentElement.style.setProperty("--lightningcss-dark", "initial"); } else { - document.documentElement.style.colorScheme = theme; + document.documentElement.style.colorScheme = "light"; + document.documentElement.style.setProperty("--lightningcss-light", "initial"); + document.documentElement.style.setProperty("--lightningcss-dark", " "); } }, [ vimModeEnabled, @@ -1519,7 +1535,7 @@ export const Playground = () => { > -

mq

+

mq