css icon indicating copy to clipboard operation
css copied to clipboard

🐞 `font-color:$(variable)` not working with scoped variables

Open gammx opened this issue 2 years ago • 5 comments

Description

I want to use a CSS variable defined outside :root, eg:

:root {
    --gyan-100: #00FF75;
}

.theme-dark {
    --text-tertiary: #8B98AC;
}

It works if I use a global variable:

<p className="font-color:$(gyan-100)">...</p>

generated-class1 But not with this one:

<p className="font-color:$(text-tertiary)">...</p> // Fail!

generated-class

.theme-dark is correctly applied btw, and changing the value through developer tools returns the expected color.

html

Any ideas of what is happening? (:

Reproduction

No response

System Informations

Browser: Microsoft Edge (Chromium) 103.0.1264.51 OS: Zorin OS (x64) Node.js: 18.5.0 Package Manager: npm 8.12.1

gammx avatar Aug 24 '22 23:08 gammx

@gammx What's your Master CSS version now? It works for me.

Generated CSS

Screen Shot 2022-08-25 at 10 31 14 PM

JIT in console

Screen Shot 2022-08-25 at 10 32 27 PM

1aron avatar Aug 25 '22 14:08 1aron

@1Aron I'm using the latest version, I'm also using the manual/hybrid rendering setup with Next.js (https://docs.master.co/css/setup/nextjs#hybrid-rendering), Here are some things I've noticed:

  • If I use Next.js with SCSS and declare the scoped variable in a .scss file it doesn't work, but it works with a .css file
  • If I refresh the page, the class is generated but it's using the color as variable --#F9F9F9:
<style id="master-css">
    .font-color\:\$\(text-primary\){color:var(--#F9F9F9)}
</style>
  • If I remove the manual initialization/hybrid rendering declared in my _document.tsx file, it works with both .scss and .css but it's weird because the style tag gets empty:
<style id="master-css"></style>

So I guess it's something with the Next.js setup... maybe?

gammx avatar Aug 25 '22 16:08 gammx

Ok I managed to get it working removing some conflicts with other classes, but it works only if I remove hybrid rendering, I get this with the https://docs.master.co/css/setup/nextjs#hybrid-rendering setup:

<style id="master-css">
    .font-color\:\$\(text-primary\){color:var(--#F9F9F9)} /*instead of var(--text-primary)*/
</style>

And it works if I remove the hybrid rendering code, but the style tag gets empty:

css

gammx avatar Aug 25 '22 17:08 gammx

If it is JIT, Master CSS will use the native style.sheet API to manipulate CSS rules. You can't see it through inspect, but you can use console.log.

1aron avatar Aug 26 '22 02:08 1aron

Nice, well, I removed the hybrid rendering setup to stop getting the color:var(--#F9F9F9) thing, thanks:)

gammx avatar Aug 26 '22 06:08 gammx