Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(vibe-tests): prevent lightningcss from mangling light-dark() in previews (#735)

Cindy Zhang5f6adfd62756
diff --git a/internal/vibe-tests/app/vite.config.preview.ts b/internal/vibe-tests/app/vite.config.preview.ts
index 4f4c538fb1..6bf67d8d32 100644
--- a/internal/vibe-tests/app/vite.config.preview.ts
+++ b/internal/vibe-tests/app/vite.config.preview.ts
@@ -31,7 +31,12 @@ const lightningcssTargets = {
*/
export default defineConfig({
root: __dirname,
- build: {},
+ build: {
+ // Don't use lightningcss for minification — it lowers light-dark()
+ // into --lightningcss-light/--lightningcss-dark polyfill variables
+ // which breaks theming. The StyleX plugin handles its own CSS.
+ cssMinify: false,
+ },
plugins: [
stylex.vite({
dev: process.env.NODE_ENV === 'development',
diff --git a/internal/vibe-tests/app/vite.config.report.ts b/internal/vibe-tests/app/vite.config.report.ts
index 5035a450e9..97a9d8f7f7 100644
--- a/internal/vibe-tests/app/vite.config.report.ts
+++ b/internal/vibe-tests/app/vite.config.report.ts
@@ -39,6 +39,18 @@ export default defineConfig({
rollupOptions: {
input: path.resolve(__dirname, 'index.report.html'),
},
+ // Don't use lightningcss for minification — it lowers light-dark()
+ // into --lightningcss-light/--lightningcss-dark polyfill variables
+ // which breaks theming. The pre-compiled CSS is already minified.
+ cssMinify: false,
+ },
+ css: {
+ // Set Vite's own CSS transformer targets so any CSS processing
+ // (including dev server) preserves native light-dark().
+ transformer: 'lightningcss',
+ lightningcss: {
+ targets: lightningcssTargets,
+ },
},
resolve: {
alias: [
diff --git a/internal/vibe-tests/app/vite.config.ts b/internal/vibe-tests/app/vite.config.ts
index c07cadcd5e..7e4a90d13e 100644
--- a/internal/vibe-tests/app/vite.config.ts
+++ b/internal/vibe-tests/app/vite.config.ts
@@ -23,7 +23,12 @@ const lightningcssTargets = {
};
export default defineConfig({
- build: {},
+ build: {
+ // Don't use lightningcss for minification — it lowers light-dark()
+ // into --lightningcss-light/--lightningcss-dark polyfill variables
+ // which breaks theming. The StyleX plugin handles its own CSS.
+ cssMinify: false,
+ },
plugins: [
stylex.vite({
dev: process.env.NODE_ENV === 'development',
diff --git a/internal/vibe-tests/src/build-previews.ts b/internal/vibe-tests/src/build-previews.ts
index ae5945d8aa..d38e7fe6b8 100644
--- a/internal/vibe-tests/src/build-previews.ts
+++ b/internal/vibe-tests/src/build-previews.ts
@@ -21,6 +21,21 @@ const VIBE_DIR = path.resolve(__dirname, '..');
const _APP_DIR = path.join(VIBE_DIR, 'app');
const REPO_ROOT = path.resolve(VIBE_DIR, '../..');
+/**
+ * Browser targets for lightningcss.
+ * Prevents lowering native light-dark() into --lightningcss-light/--lightningcss-dark
+ * polyfill variables. XDS tokens use native light-dark() which is baseline 2024:
+ * Chrome 123+, Firefox 120+, Safari 17.5+
+ *
+ * Must match the targets in apps/storybook/.storybook/main.ts and
+ * internal/vibe-tests/app/vite.config.*.ts
+ */
+const LIGHTNINGCSS_TARGETS_JS = `{
+ chrome: 123 << 16,
+ firefox: 120 << 16,
+ safari: (17 << 16) | (5 << 8),
+}`;
+
interface PreviewManifest {
[promptId: string]: {
[target: string]: string; // relative path to preview HTML
@@ -279,6 +294,9 @@ function createViteConfig(tmpDir: string, target: string): string {
.resolve(REPO_ROOT, 'packages/core/src/theme/tokens.stylex.ts')
.replace(/\\/g, '/')}',
},
+ lightningcssOptions: {
+ targets: ${LIGHTNINGCSS_TARGETS_JS},
+ },
}),
react(),
viteSingleFile(),`
@@ -348,6 +366,10 @@ export default defineConfig({
build: {
outDir: 'dist',
emptyOutDir: true,
+ // Don't use lightningcss for minification — it lowers light-dark()
+ // into --lightningcss-light/--lightningcss-dark polyfill variables
+ // which breaks XDS theming.
+ cssMinify: false,
},
logLevel: 'warn',
});