lightningcss icon indicating copy to clipboard operation
lightningcss copied to clipboard

Stylesheet visitor fails when using custom properties in 1.30.2

Open Hansjv opened this issue 2 months ago • 4 comments

Issue

CSS:

.foo {
  color: var(--color-red);
}

Visitor:

{
  StyleSheet(stylesheet) {
    return stylesheet;
  }
}

Expected

.foo{color:var(--color-red)}

Current behaviour

/* ERROR: failed to deserialize; expected an object-like struct named Specifier, found () */

Reproduction

Playground example Set version to 1.30.2 to reproduce the issue

Works from 1.18.0 to 1.30.1.

Hansjv avatar Oct 04 '25 04:10 Hansjv

Hi guys!

Hope you are doing well.

I have the same issue with my plugin from the 1.30.2.

It's pretty hard to spot from where come the issue from but it fail when it has to call a registered "rule" like this:

.my-element {
   @s-transition(fast);
}

and my rule is registered like so:

{
   Rule: {
      unknown(rule) {
        try {
          switch (true) {
            case rule.name === `s-transition`:
              return __transitionRule(rule, finalSettings);
          }
        } catch (e) {
          console.error(e);
        }
      },
    },
}

All my plugin documentation is available here: https://sugarcss.blackbyte.space

Hope this is not a deep issue...

obuzzbrothers avatar Oct 06 '25 13:10 obuzzbrothers

I also have this on projects when using custom visitors and drafts. If i remove both of these the issue disappears

lightningcss: {
	drafts: { customMedia: true },
	visitor: composeVisitors([
		breakpoints({
			mobile: 640,
			tablet: 1024,
			laptop: 1280,
			desktop: 1440
		}),
		fluid({ vmax: 1600 }),
		size
	])
}

visitors in use are here https://github.com/mattpilott/kitto/tree/main/src/lib/lightningcss

mattpilott avatar Oct 07 '25 10:10 mattpilott

Same issue in #1071

alijvhr avatar Oct 10 '25 13:10 alijvhr

For me it is the same. The newest rolldown-vite installs automatically version 1.30.2 then I could make the smallest reproducable visitor:

Link

{
  Function: {
    '--Foo': (args) => {
      return {
        type: 'var',
        value: {
          name: { ident: '--foo', from: null },
          fallback: null,
        },
      };
    },
  }
}

gejgalis avatar Oct 21 '25 13:10 gejgalis