Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • C create-react-app
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1,547
    • Issues 1,547
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 417
    • Merge requests 417
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Meta
  • create-react-app
  • Issues
  • #6875
Closed
Open
Issue created Apr 23, 2019 by Administrator@rootContributor

Absolute resourcePath used in getCSSModuleLocalIdent

Created by: vg-stan

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 (https://github.com/facebook/create-react-app/pull/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!

Assignee
Assign to
Time tracking