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
-
Hi! I work at Skyscanner. We build our UIs with React, and use
react-scripts
to build our micro-frontends and our component library Backpack.Recently we've seen a few bugs related to the way CSS Module
className
s 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
class
property is generated by thisgetCSSModuleLocalIdent
function, 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
Ad
has aFooter
. This is not the sameFooter
component as above, but one local to theAd
component. The Ad package has files atsrc/components/Footer/Footer.jsx
andsrc/components/Footer/Footer.module.scss
.This results in 2 CSS rules on the page for
.Footer_Footer__1CwiK
, which meansAd
styles leak in to theFooter
and vice versa.The
getCSSModuleLocalIdent
function 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:
contenthash
We use a fork of
create-react-app
internally;backpack-react-scripts
. Our last resort would be to update thegetCSSModuleLocalIdent
function there. So far our fork only contains changes to thereact-scripts
package; changing that function would require us to forkreact-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 usereact-scripts
directly, 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