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

Absolute resourcePath used in getCSSModuleLocalIdent #6875

Closed
vg-stan opened this issue Apr 23, 2019 · 3 comments · Fixed by #6876
Closed

Absolute resourcePath used in getCSSModuleLocalIdent #6875

vg-stan opened this issue Apr 23, 2019 · 3 comments · Fixed by #6876

Comments

@vg-stan
Copy link
Contributor

vg-stan commented Apr 23, 2019

I recently upgraded to create-react-app 2.1.8 and noticed the hashes used in css modules classnames are different in different build environments. I did some debugging and saw that 'react-dev-utils/getCSSModuleLocalIdent' uses 'context.resourcePath + localName' for the hash generation and that context.resourcePath was an absolute path. The original discussion (#3965) indicated we wanted the full path for uniqueness and that we also wanted to preserve keep the classnames deterministic for automated testing. It seems like trimming the context.resourcePath of context.rootContext would preserve uniqueness within the project and allow users to write tests against the classnames locally and have it work on different machines regardless of the project path.

Example of the issue, the classnames for css modules in the below two repo locations will hash to different values in the current code:
/Users/person1/projectrepo/
/Users/person2/projectrepo/

If in getCSSModuleLocalIdent we change the code to something like the below, the hashes will be the same

const hash = loaderUtils.getHashDigest(
    context.resourcePath.replace(context.rootContext, "") + localName
    'md5',
    'base64',
    5
  );

I'd be happy to submit a PR if this makes sense and I didn't miss something obvious. Thank you!

@ianschmitz
Copy link
Contributor

This sounds reasonable. Want to start a PR and we can go from there?

@vg-stan
Copy link
Contributor Author

vg-stan commented Apr 27, 2019

Thanks @ianschmitz, the PR has been submitted: #6876

@gaearon
Copy link
Contributor

gaearon commented Apr 28, 2019

While not exactly the same issue, I’ve seen a report that our CSS sourcemaps include absolute paths. Is this related?

@lock lock bot locked and limited conversation to collaborators May 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants