Customizing the CSS identifiers (scope, hash etc)
See original GitHub issueFeature request
Problem
Our Selenium tests rely on a specific naming of class names in the HTML. E.g. class="Header__link", where Header is the name of a component, and link is a class in the component’s CSS module).
With the current experimental CSS support in Next.js, there’s no apparent way to customize the outputted CSS identifiers.
With next-css, we used to simply override the Webpack config with our own css-loader options localIdentName and getLocalIdent).
Proposed solution
Please allow to override the Webpack config like it was the case with next-css.
Thanks!
Related to #8626.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:12
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Attribute selectors - CSS: Cascading Style Sheets | MDN
The CSS attribute selector matches elements based on the presence or value of a given attribute.
Read more >A Complete Guide to CSS Cascade Layers
This is your complete guide to CSS cascade layers, a CSS feature that allows us to define explicit contained layers of specificity.
Read more >The End of Global CSS - Medium
CSS selectors all exist within the same global scope. Anyone who has worked with CSS long ... By default, css-loader transforms our identifiers...
Read more >Selectors Level 4 - W3C
This document was published by the CSS Working Group as a Working Draft using the Recommendation track. Publication as a Working Draft does...
Read more >css-loader | webpack - JS.ORG
Using local value requires you to specify :global classes. Using global value requires you to specify :local classes. Using pure value requires selectors...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

tl;dr: To set expectations, we’re probably not going to ship with this ability by default. Read on for testing alternatives.
Customizing the emitted CSS identifiers is a footgun, as uniqueness is no longer guaranteed and we may optimize them in the future.
For example, we may explore these optimizations:
Our new CSS support is extremely focused on correctness — allowing this option may undermine that correctness and our flexibility to innovate in the future.
We can reconsider this when it’s released stable if there’s significant demand. IMO, there’s better options here:
identity-obj-proxyto get stable class names. The emitted class name is an implementation detail that shouldn’t be tested.getComputedStyle()— not class names.@Timer when you say not ship with the ability to do this, are you referring to what has been requested in this issue, or the ability to turn on the experimental CSS features (which would Customize the CSS identifiers)?
I’m using BEM and next-css and well… this is a big change, I’m using a well documented system for creating components (BEM), and I’m concerned that the new CSS features are going to mean that we’ll end up having to re-invent the wheel by creating something that works with a CSS module based approach. The ability to change the ident structure would be useful, as it would enable me to possibly get around changing the file structure:
I could maybe do this:
[exportName]__[hash]for more uniqueness, or if forced, do this:[exportName]to allow me to carry on doing what I’m currently doing, but then you’d wonder why the ident name would be better as an option to turn off/on to allow some flexibility?