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.

[IDEA] => CSS Modules => Ability to pass identifier names to methods

See original GitHub issue

Hello, thank you for all the work you have done.

Goal

  • To further optimize the processed CSS after importing it as a module. Example:
    • .mdc-button becomes .b_0

Story

Webpack along with css-loader using css-modules allow us to import necessary for a developer component and then call it in the following way, assuming we import object named styles:

  • styles.mdcButton

Problem

The problem is with the JavaScript architecture that is currently in use. The methods should accept classes (identifiers using css-modules) as parameters, instead you are returning constants. See example @material/ripple/constants

In the end, we have huge nonsense in production classnames like mdc-ripple-upgraded--foreground-activation, when we instead could pass it as a generated CSS local identifier such as b_0

Suggested solution

The function should accept an object parameter, default = false, with the classnames generated from the local identifiers of the processed component. Instead of returning constants after interacting with elements like Ripple that become no longer valid, since the classnames change based on the local identifiers.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
amsheehancommented, Dec 15, 2017

Keep in mind with regard to framework specific UI libraries that some frameworks require wrappers because they interact with the DOM in different ways. This is exactly why MDC Web is architected the way it is—so specific frameworks can implement all of their DOM interactions in the way required by a specific framework.

I see nothing wrong with having enthusiasts with domain specific expertise maintain framework specific wrappers in lock step with MDC Web. We found it’s a better use of everyone’s time and results in a better MDC Web, and better framework specific wrapper libraries.

As for spending time building UI—while it may not be a goal of your project to spend engineering time on the front end, that doesn’t mean that a library like MDC Web shouldn’t provide for, and recommend the work of other highly skilled front end engineers.

In terms of suggesting things to address your specific request. It is my opinion that css renaming (shortening) should not even really be the responsibility of a UI library like MDC Web, and that something in your build chain should do does this. What Lynn suggested is to reimplement the adapter methods in the components that add or remove classes to use shorter custom names in place of the default MDC classes. I think that’s a valid suggestion and is supplemented with a code snippet.

0reactions
jamesmfriedmancommented, Jun 10, 2018

This came up with RMWC. I’m curious to know what the total reduction in CSS size would be. Other than that, I’m not aware of the length of class names helping or hurting runtime performance.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What are CSS Modules and why do we need them?
CSS files in which all class names and animation names are scoped locally by default. So CSS Modules is not an official spec...
Read more >
How to use composition in elements without className? #33
I'm re-writing the page/docs for Minigrid and I'm using markdown-loader for generate content for both. I can use my own markdownLoader to ...
Read more >
CSS Modules with React: The Complete Guide | by Suraj KC
CSS module makes CSS classes local for every component declared within by adding hashes in class names which are unique to each component, ......
Read more >
A complete guide to CSS Modules in React (Part-2) - codeburst
A quick recap: we know that when CSS is applied as modular CSS, the class names are changed at the compile-time and are...
Read more >
CSS Modules - referencing classes from other modules
I can't find a valid method to work with a CSS class within a CSS modules environment when this class should work in...
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