babel-plugin-styled-components icon indicating copy to clipboard operation
babel-plugin-styled-components copied to clipboard

Question: What is namespace used for?

Open luanraithz opened this issue 5 years ago • 14 comments

The documentation suggests: this setting is handy when you are working with micro frontends where class name collision can occur It suggests that this feature would replace this such as https://github.com/QuickBase/babel-plugin-styled-components-css-namespace, but they only make the debugging experience better.

Here is a code sandbox to illustrate my point. The class name is right, but I can't see the point if the css is attached to the simple hash: image

image

If styles were attached to the longest generated (src__Div-my-app__adb5uh-0 in the example), this problem would be fixed.

luanraithz avatar Aug 20 '20 19:08 luanraithz

@rajzik am I getting anything wrong here?

luanraithz avatar Aug 20 '20 19:08 luanraithz

@luanraithz I have had issue with css-namespace-plugin, it didn't work with a parcel for example.

generated output of namespace setting

I am not sure why there is the only hash. but my generated components have only long className.

I will check tomorrow if I can replicate it.

rajzik avatar Aug 20 '20 20:08 rajzik

Ok, thanks! You can check the code sandbox I provided in the description, there is a very simple scenario there.

luanraithz avatar Aug 20 '20 20:08 luanraithz

@luanraithz I have checked my local env and it works as intended. I don't have that short hash class name.

rajzik avatar Aug 24 '20 07:08 rajzik

@rajzik Can you upload your local test to github? I want to see what I've done wrong.

luanraithz avatar Aug 24 '20 13:08 luanraithz

@luanraithz There might be an issue, after all, I have checked the wrong plugin, there has to be some PR which negates my changes. Will take a look.

rajzik avatar Aug 24 '20 20:08 rajzik

Ok, thanks a lot!

luanraithz avatar Aug 26 '20 13:08 luanraithz

@rajzik Any news?

luanraithz avatar Sep 01 '20 19:09 luanraithz

Sorry, not yet I didn't had any time.

rajzik avatar Sep 01 '20 20:09 rajzik

@luanraithz today I have had some time to take a look, and it looks like there is an issue with some change in styled-components. Because right now injection of the stylesheet to the HTML will create hashed className and it doesn't really care about component id at all.

https://github.com/styled-components/styled-components/blob/d4b9ee8a3c1514cac57e22209bcd6102e10f79b1/packages/styled-components/src/models/ComponentStyle.js#L52

I have created an issue/question on styled-components.

rajzik avatar Sep 03 '20 19:09 rajzik

Damn, I have no words, really nice investigation! Thank you for that @rajzik!

luanraithz avatar Sep 03 '20 23:09 luanraithz

@luanraithz no problem sorry that it took so long.

rajzik avatar Sep 04 '20 05:09 rajzik

i submitted a pull request https://github.com/styled-components/styled-components/pull/3225 because i did not see that the namespaces work... and we really need that feature to work, please 🙏

justnewbee avatar Dec 21 '20 09:12 justnewbee

@justnewbee if you want something that work you could use https://github.com/QuickBase/babel-plugin-styled-components-css-namespace. I'm using it in production, so far so good.

luanraithz avatar Dec 21 '20 12:12 luanraithz