You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The last component of the value, the hash 1CwiK, is a hash generated based on the relative path of CSS Module file i.e. src/components/Footer/Footer.module.scss.
The bug occurs when 2 different components, in to 2 different packages, have a CSS Module with the same relative path. For example, we have a component we use to display ads on the site, and an Ad has a Footer. This is not the same Footer component as above, but one local to the Ad component. The Ad package has files at src/components/Footer/Footer.jsx and src/components/Footer/Footer.module.scss.
This results in 2 CSS rules on the page for .Footer_Footer__1CwiK, which means Ad styles leak in to the Footer and vice versa.
Would you consider updating the hashing approach to be globally unique? There's lots to discuss in terms of options, so far the ideas we've kicked around are:
Use the absolute path
Include the package name [and version] in the hash
We use a fork of create-react-app internally; backpack-react-scripts. Our last resort would be to update the getCSSModuleLocalIdent function there. So far our fork only contains changes to the react-scripts package; changing that function would require us to fork react-dev-utils as well. In an ideal world we'd like an upstream change because it will allow others to benefit from it, but also because we'd like to move away from our fork and use react-scripts directly, so we're reluctant to diverge from it further.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hi! I work at Skyscanner. We build our UIs with React, and use
react-scriptsto build our micro-frontends and our component library Backpack.Recently we've seen a few bugs related to the way CSS Module
classNames are generated.As an example, we have a React component we use to display the footer at the bottom of every page on the site:
This results in the following HTML for the footer:
The value of the
classproperty is generated by thisgetCSSModuleLocalIdentfunction, following this formula:The last component of the value, the hash
1CwiK, is a hash generated based on the relative path of CSS Module file i.e.src/components/Footer/Footer.module.scss.The bug occurs when 2 different components, in to 2 different packages, have a CSS Module with the same relative path. For example, we have a component we use to display ads on the site, and an
Adhas aFooter. This is not the sameFootercomponent as above, but one local to theAdcomponent. The Ad package has files atsrc/components/Footer/Footer.jsxandsrc/components/Footer/Footer.module.scss.This results in 2 CSS rules on the page for
.Footer_Footer__1CwiK, which meansAdstyles leak in to theFooterand vice versa.The
getCSSModuleLocalIdentfunction states that the hashes it produces "will be unique across a project, and close to globally unique.". For us, it's not close enough to globally unique! 😄Would you consider updating the hashing approach to be globally unique? There's lots to discuss in terms of options, so far the ideas we've kicked around are:
contenthashWe use a fork of
create-react-appinternally;backpack-react-scripts. Our last resort would be to update thegetCSSModuleLocalIdentfunction there. So far our fork only contains changes to thereact-scriptspackage; changing that function would require us to forkreact-dev-utilsas well. In an ideal world we'd like an upstream change because it will allow others to benefit from it, but also because we'd like to move away from our fork and usereact-scriptsdirectly, so we're reluctant to diverge from it further.If you've gotten this far, thanks for reading!
Mike
Beta Was this translation helpful? Give feedback.
All reactions