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

Using math.random() in css module leads to a wrongly generated class names #2150

Closed
orangecoloured opened this issue Dec 21, 2023 · 1 comment

Comments

@orangecoloured
Copy link

I used create-preact to initialise my app.
It uses vite v4.3.2 and sass v1.69.5.

I have a scss module with a code that contains math.random().

.someClass {
    some-value: 100px + math.random(1000);
}

And because of the math.random() as a result the names that are assigned to the html elements are not that are being generated and loaded in the stylesheet.

With the math.random()
Screenshot 2023-12-19 at 11 18 02 PM

Without the math.random()
Screenshot 2023-12-19 at 11 17 39 PM

For clarity. When the math.random() is used the generated class name that is used for class="" has 1lzbo part in the class name, but in the injected <style> tag it's yl1g2. When the math.random() is not used, the class names are correct. Both have 1u0g5 in their name.

The css property name that is using math.random() does not matter. The behaviour is consistent per file which contains math.random() while npm run dev.

I tried reproducing it, but no success. The minimal version works correctly.
https://stackblitz.com/edit/vitejs-vite-dtieff?file=style.module.scss

Haven't yet tried upgrading vite to the latest version.

What could be wrong? Which part could be failing here? And how can I try to fix this? Apart from not using math.random().

@nex3
Copy link
Contributor

nex3 commented Dec 27, 2023

This seems like an issue you should file with Vite. Sass has no part in generating your HTML. If you can find a case where a specific Sass input file is creating output you think is invalid, feel free to update this issue, but otherwise I don't think there's anything we can do to help you.

@nex3 nex3 closed this as not planned Won't fix, can't repro, duplicate, stale Dec 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants