question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Customizing the CSS identifiers (scope, hash etc)

See original GitHub issue

Feature 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:closed
  • Created 4 years ago
  • Reactions:12
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
Timercommented, Jan 2, 2020

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:

  • Single Character Class Names: Using single-character class names are a suggested practice that produce smaller application output (all considered, JS bundles and CSS files, Gzip, etc).
  • Deduping of Styles: If multiple classes define common sets of attributes, we may hoist those attributes out into a new class and then transparently compose the emitted classes (think Atomic CSS).

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:

0reactions
morganfeeneycommented, Jan 8, 2020

tl;dr: To set expectations, we’re probably not going to ship with this ability by default. Read on for testing alternatives.

@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:

image

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found