question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CSS variable with built-in color name replaced with color code on build

See original GitHub issue

Bug report

Describe the bug

I have added some css variable using scss map in global css with naming like below:

$colorPalette: (
	red: #ff0000,
	red1: #fa5e56,
	red2: #DA291C,
	red3: #d0021b,
	red4: #4C191B,
        black: #000000
)
:root {
  @each $color, $value in $colorPalette {
    --#{$color}: #{$value};
  }  
}

After building the project, I see variable becomes like below but in dev it works fine:

--red: #ff0000;
--red1: #fa5e56;
--red2: #DA291C;
--red3: #d0021b;
--red4: #4C191B;
--#000: #000;

To Reproduce

Just add a css variable with any builtin color name and build the project.

Expected behavior

After project building variables should remain like below:

--red: #ff0000;
--red1: #fa5e56;
--red2: #DA291C;
--red3: #d0021b;
--red4: #4C191B;
--black: #000;

System information

  • OS: Ubuntu 20,4
  • Browser (if applies) Any browser
  • Version of Next.js: 9.4.4
  • Version of Node.js: 12.16.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
panteliselefcommented, Jun 4, 2022

I believe this has been resolved

$colorPalette: (
        red: #ff0000,
        red1: #fa5e56,
        red2: #DA291C,
        red3: #d0021b,
        red4: #4C191B,
        black: #000000
);

:root {
  @each $color, $value in $colorPalette {
    --#{$color}: #{$value};
  }
}

my package.json

  "dependencies": {
    "next": "12.1.6",
    "react": "18.0.0",
    "react-dom": "18.0.0",
    "sass": "^1.49.9",
  },
  "devDependencies": {
    "@types/node": "17.0.39",
    "@types/react": "18.0.0",
    "@types/react-dom": "^18.0.0",
    "typescript": "^4.6.2"
  }
0reactions
github-actions[bot]commented, Jul 16, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using CSS custom properties (variables) - MDN Web Docs
They are set using custom property notation (e.g., --main-color: black; ) and are accessed using the var() function (e.g., color: var(--main- ...
Read more >
Common CSS Color Variables and Properties in Theming
An effort to collect, categorize, and summarize some of the common CSS custom properties that are being used to maintain colors in modern ......
Read more >
How to combine SASS color functions and CSS Variables
A new method, supported in all browsers, to store your colors in CSS Variables and modify them using SASS functions.
Read more >
What do you name color variables?
I first give a name to all the colors I use using that tool, for example “$color-cornflower-blue: #6195ED;” and then I create variables...
Read more >
Why can't update css variable name to apply a different ...
I think what you are trying to do, can not be done. SCSS is a CSS preprocessor which runs on the server-side. It...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found