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

The hash of css class names packaged on different platform systems is inconsistent #5136

Closed
1 task
J-env opened this issue Oct 21, 2022 · 6 comments
Closed
1 task
Assignees
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)

Comments

@J-env
Copy link

J-env commented Oct 21, 2022

What version of astro are you using?

1.5.2

Are you using an SSR adapter? If so, which one?

None

What package manager are you using?

npm

What operating system are you using?

Mac

Describe the Bug

The hash of the css class name is inconsistent, resulting in a change in the hash of the packaged file.

// example.astro
<style>
.example { 
  font-size: 34px;
}
</style>

Mac output file: [name].f6446fc8.css

.example:where(.astro-6YSHC6AL){font-size:34px}

Windows output: [name].12333479.css

.example:where(.astro-CVKMEFR4){font-size:34px}

Link to Minimal Reproducible Example

none

Participation

  • I am willing to submit a pull request for this issue.
@bluwy
Copy link
Member

bluwy commented Oct 21, 2022

Looks like the Astro compiler builds the hash based on the content and file name since withastro/compiler#513. Maybe we should use a project-root-relative path to compute the hash? cc @matthewp

@bluwy bluwy added the - P3: minor bug An edge case that only affects very specific usage (priority) label Oct 21, 2022
@J-env
Copy link
Author

J-env commented Oct 21, 2022

@bluwy

import path from 'node:path';
import slash from 'slash';

// project root
const root = __dirname
// current filepath
const src = ''

const slashSrc = slash(path.normalize(path.relative(root, src)));

const hash = createHash(slashSrc)
// const hash = createHash(slashSrc + `${code}`)

@matthewp matthewp self-assigned this Nov 4, 2022
@matthewp
Copy link
Contributor

Yes we should! I plan on fixing this. @J-env this happens inside of our (Go-based) compiler. But I think we have all of the information to make this root-relative.

@matthewp
Copy link
Contributor

Looking into it, we don't actually pass in the moduleId so it is just based on the source. I wonder if the source is what is different between platforms, probably because of the different line endings?

@malcolm-kee
Copy link

malcolm-kee commented Apr 17, 2023

In my case this issue seems to be causing certain CSS modules rules works in dev but missing in prod.

  • in JS: _element_17ddh_2
  • in CSS: _element_d3dod_1

I'll try roll back few Astro versions to see when it starts breaking.

Update: I can confirm that for my case, [email protected] is the version that introduces the regression. It was fine before that.

Update 2: I tried to create a minimal reproduction but not able to. Wish I can be more helpful :(

@bluwy
Copy link
Member

bluwy commented Apr 17, 2023

I think this is already fixed but forgot to closed. We are now deriving a root-relative normalized path to generate the hash, so something like /src/pages/index.astro. I'll close this for now.

@malcolm-kee if you can reproduce this, feel free to open a new issue. Thanks!

@bluwy bluwy closed this as completed Apr 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

No branches or pull requests

4 participants