Skip to content

Conversation

mh-rafi
Copy link
Contributor

@mh-rafi mh-rafi commented Dec 15, 2020

Variables($background, $border, $color) in @each loop pollutes global scopes.
And don't let define new variables with these names in custom SCSS file.

@mh-rafi mh-rafi requested a review from a team as a code owner December 15, 2020 11:05
Copy link
Member

@ffoodd ffoodd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me; @twbs/css-review any thoughts? Should this be documented somewhere?

@mdo
Copy link
Member

mdo commented Dec 16, 2020

Does this count as a breaking change?

@ffoodd
Copy link
Member

ffoodd commented Dec 16, 2020

This is an internal loop, declaring a mixin: I don't see what could break since $theme-colors doesn't change nor the mixins. I may miss something but this looks pretty straightforward to me. Maybe @MartijnCuppens would help? He's usually the best at preventing BCs!

Copy link
Member

@MartijnCuppens MartijnCuppens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, I didn't know global variables were overwritten within these loops, but I can confirm this is the case:
https://www.sassmeister.com/gist/fc876c989dbc0920e2d4373aa262ec85?token=203daf3221af119f9e7a6898b97e14608c077727&scope=gist,read:user

I double checked if the $state & $value variables were overridden, but it turns out that's a new scope, meaning we don't have to worry about

@each $color, $value in $theme-colors {
.btn-#{$color} {
@include button-variant($value, $value);
}
}
@each $color, $value in $theme-colors {
.btn-outline-#{$color} {
@include button-outline-variant($value);
}
}

It's not a BC and there's no reason to document this, since these are variables set in a loop. We could move the alert variables inside the selector to prevent them becoming global. But for the list groups, we still need global variables, so prefixing is fine!

@XhmikosR XhmikosR merged commit b424650 into twbs:main Dec 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants