Skip to content

LightningCSS minify issues #16354

@predaytor

Description

@predaytor

Describe the bug

I noticed an unnecessary duplication of @supports rules when using the Lightning CSS minification, which also differs from the LightningCSS playground output.

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import browserslist from 'browserslist';
import { browserslistToTargets } from 'lightningcss';

// https://vitejs.dev/config/
export default defineConfig({
  css: {
    transformer: 'lightningcss',
    lightningcss: {
      targets: browserslistToTargets(browserslist('>= 0.25%')),
      drafts: {
        customMedia: true,
      },
    },
  },
  build: {
    cssMinify: 'lightningcss',
    // cssMinify: true,
  },
  plugins: [react()],
});

1st test (OKLCH):

Input:

.x {
  --x: oklch(61% 0.016 277.7);
}

Result:

.x {
	--x: #81828d;
}
@supports (color: lab(0% 0 0)) {
	.x {
		--x: #81828d;
	}
	@supports (color: color(display-p3 0 0 0)) {
		.x {
			--x: color(display-p3 0.50541 0.511328 0.549274);
		}
	}
	@supports (color: lab(0% 0 0)) {
		.x {
			--x: lab(54.6419% 0.899702 -5.96);
		}
	}
}

Expected result (LightningCSS playground):

.x {
	--x: #81828d;
}
@supports (color: lab(0% 0 0)) {
	.x {
		--x: lab(54.6419% 0.899702 -5.96);
	}
}

///

2nd case (display-p3):

Input:

.x {
  --x: color(display-p3 0.004 0.278 0.933 / 0.173);
}

Result:

.x {
	--x: #0051e52c;
}
@supports (color: color(display-p3 0 0 0)) {
	.x {
		--x: #0051e52c;
	}
	@supports (color: color(display-p3 0 0 0)) {
		.x {
			--x: color(display-p3 0.004 0.278 0.933/.173);
		}
	}
}

Expected result (LightningCSS playground):

.x {
	--x: rgba(0, 81, 229, 0.173);
}
@supports (color: color(display-p3 0 0 0)) {
	.x {
		--x: color(display-p3 0.004 0.278 0.933/.173);
	}
}

Reproduction

https://stackblitz.com/edit/vitejs-vite-wdjgbn?file=src%2FApp.css,vite.config.ts

Steps to reproduce

Run pnpm build to inspect /dist folder for CSS output

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.18.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.3 - /usr/local/bin/pnpm
  npmPackages:
    @vitejs/plugin-react: ^4.2.1 => 4.2.1 
    vite: ^5.2.7 => 5.2.8

Used Package Manager

pnpm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug: upstreamBug in a dependency of Vitefeat: cssp3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions