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

[Bug]: CSS variable accessed from JavaScript is removed #998

Open
1 task done
2-5 opened this issue Sep 19, 2022 · 0 comments
Open
1 task done

[Bug]: CSS variable accessed from JavaScript is removed #998

2-5 opened this issue Sep 19, 2022 · 0 comments
Labels

Comments

@2-5
Copy link

2-5 commented Sep 19, 2022

Describe the bug

CSS variables which are accessed only from JavaScript are removed.

To Reproduce

/* test.css */

:root {
  --test-used: green;
  --test-unused: red;
  --test-used-from-js: blue;
}

.test-used {
  --test-used-from-js: yellow;
  color: var(--test-used);
}

.test-unused {
  color: var(--test-unused);
}
// test.js

const el = document.createElement("div")
el.classList.add("test-used")

const color = window.getComputedStyle(el).getPropertyValue("--test-used-from-js")
purgecss --variables --css test.css --content test.js
/* output */

:root {
  --test-used: green;
}

.test-used {
  color: var(--test-used);
}

Expected Behavior

CSS variables used from JavaScript are safe-listed and not removed.

Environment

purgecss 4.1.3

Add any other context about the problem here

I encountered this problem using Bootstrap 5.2.1, which accesses a CSS variable from JavaScript in it's dropdown implementation:

https://github.com/twbs/bootstrap/blob/23e50829f958ea1d741d63e2781716be037e4644/dist/css/bootstrap.css#L3304-L3306

.dropdown-menu-end {
  --bs-position: end;
}

https://github.com/twbs/bootstrap/blob/23e50829f958ea1d741d63e2781716be037e4644/js/src/dropdown.js#L265

const isEnd = getComputedStyle(this._menu).getPropertyValue('--bs-position').trim() === 'end'

Code of Conduct

  • I agree to follow this project's Code of Conduct
@2-5 2-5 added the bug label Sep 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant