close
The Wayback Machine - https://web.archive.org/web/20210901203556/https://github.com/twbs/bootstrap/issues/34756
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated .bg-* and .text-* utilities break when CSS variables are not enabled in v5.1.0 #34756

Open
dgsiegel opened this issue Aug 16, 2021 · 9 comments
Labels

Comments

@dgsiegel
Copy link

@dgsiegel dgsiegel commented Aug 16, 2021

In one of my projects I include the needed Bootstrap SCSS files manually and specifically exclude bootstrap/scss/root, first because I don't rely on most of the CSS variables and secondly because adding all CSS variables increases the CSS file size by about 50-60kb (uncompressed).

With v5.1.0 all .bg-* and .text-* utilities break, as the needed CSS variables are missing, e.g.

.text-white {
    --bs-text-opacity: 1;
    color: rgba(var(--bs-white-rgb), var(--bs-text-opacity)) !important; // --bs-white-rgb is not set
}

Is there a simple way to disable CSS variables generation or to reduce the number of CSS variables? The only way forward right now would be to revert the utility sets back to $theme-colors, but that still leaves an additional --bs-text-opacity: 1; and does not take care of --bs-body-color and the like:

$utilities-text-colors: $theme-colors;
$utilities-bg-colors: $theme-colors;
@WinterSilence
Copy link
Contributor

@WinterSilence WinterSilence commented Aug 17, 2021

bootstrap/scss/root required, this variables uses in many files.

@iatek
Copy link
Contributor

@iatek iatek commented Aug 17, 2021

The whole bg-, text- update in 5.1.0 has seemingly complicated the entire process of adding a new theme-color. The only way I could find to get the bg- and text- classes regenerated for the new "custom" theme color is....

@import "functions";
@import "variables";
@import "mixins";

$custom: #df711b;

$custom-theme-colors: (
  "custom": $custom
);

$theme-colors: map-merge($theme-colors, $custom-theme-colors);
$theme-colors-rgb: map-loop($theme-colors, to-rgb, "$value");
$utilities-colors: map-merge($utilities-colors, $theme-colors-rgb);
$utilities-text-colors: map-loop($utilities-colors, rgba-css-var, "$key", "text");
$utilities-bg-colors: map-loop($utilities-colors, rgba-css-var, "$key", "bg");

@import "bootstrap";

I discovered this on an SO question and here's the working code demo


Whereas in 5.0.2 one could simply follow the example in the docs...

@import "functions";
@import "variables";
@import "mixins";

$custom-colors: (
  "custom-color": #df711b
);

$theme-colors: map-merge($theme-colors, $custom-colors);

@Kopyov
Copy link
Contributor

@Kopyov Kopyov commented Aug 18, 2021

In addition to that, the suggested way of extending color utility classes generates HEX color values instead of RGBA and still keeps useless --bs-text-opacity: 1; in every custom color class

@Pythagus
Copy link

@Pythagus Pythagus commented Aug 19, 2021

The whole bg-, text- update in 5.1.0 has seemingly complicated the entire process of adding a new theme-color. The only way I could find to get the bg- and text- classes regenerated for the new "custom" theme color is....

@import "functions";
@import "variables";
@import "mixins";

Thanks!
This really needs to be written in the official documentation!

@gigadie
Copy link

@gigadie gigadie commented Aug 24, 2021

I consider this either a regression or a lack in documentation.
Thanks @iatek for the above! Unfortunately it didn't work for me.
What finally worked for me was moving mixins after the merge-map and map-loop, like this:

// CUSTOM COLOURS
@import './variables';

// Configuration
@import "node_modules/bootstrap/scss/functions";
@import "node_modules/bootstrap/scss/variables";

$theme-colors: map-merge($theme-colors, $custom-colours);
$theme-colors-rgb: map-loop($theme-colors, to-rgb, "$value");
$utilities-colors: map-merge($utilities-colors, $theme-colors-rgb);
$utilities-text-colors: map-loop($utilities-colors, rgba-css-var, "$key", "text");
$utilities-bg-colors: map-loop($utilities-colors, rgba-css-var, "$key", "bg");

@import "node_modules/bootstrap/scss/mixins";
@import "node_modules/bootstrap/scss/utilities";
// ... and the rest of boostrap

@gigadie
Copy link

@gigadie gigadie commented Aug 24, 2021

Oh, and btw the same is true if you need to add spacing classes:

@import "node_modules/bootstrap/scss/functions";
@import "node_modules/bootstrap/scss/variables";

// Extend the spacings
$spacers: map-merge(
  $spacers, (
    6: ($spacer * 6)
  )
);

@WilliamStam
Copy link

@WilliamStam WilliamStam commented Aug 24, 2021

arrrggghhhh add +1 to frustration of note. this change has had me tearing my hair out.

i sort of got it working with

_variables.scss (my custom variables)

@import "../../../../../node_modules/bootstrap/scss/functions";
@import "../../../../../node_modules/bootstrap/scss/variables";
@import "../../../../../node_modules/bootstrap/scss/mixins";

$colors: (
...
);
$theme-colors: (
...
);
$theme-colors-rgb: map-loop($theme-colors, to-rgb, "$value");
$utilities-colors: map-merge($utilities-colors, $theme-colors-rgb);
$utilities-text-colors: map-loop($utilities-colors, rgba-css-var, "$key", "text");
$utilities-bg-colors: map-loop($utilities-colors, rgba-css-var, "$key", "bg");

....

styles.scss (main style)

@import "./variables";
@import "../../../../../node_modules/bootstrap/scss/bootstrap.scss";
...

at the devs, its changes like this that might actually drive people away tho. would suggest you consider "ability and ease of extending bootstrap" as a core just like getting the code working right. i know people might disagree with this, but this change for instance has some what had me questioning if bootstrap and me remain in a loving relationship or not). 12k lines of css :( last i looked it was around 8 or so

@mdo
Copy link
Member

@mdo mdo commented Aug 24, 2021

Sorry we've been slow to investigate and identify a path forward. We'll need a little more time to experiment and validate the issues identified here. Definitely not in our interest to be causing headaches for folks :).

@WilliamStam
Copy link

@WilliamStam WilliamStam commented Aug 24, 2021

Hehe thanks mdo. I think the 5.1 update took a few people by surprise. Some "breaking" things like this but on the face of it it looks like 5.0 but it's still a big update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
8 participants