-
Notifications
You must be signed in to change notification settings - Fork 27.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scoping imported CSS w/ styled-components #3281
Comments
I think the reason it works with Consider this: You have a Those styles now get nested as such:
When in reality, they should be this (note the
So this is why the |
thanks @pruhstal. I don't believe the There's an example in the repo I set up in OP demonstrating this, but here's a webpack bin with styled-components affecting a deeply nested div in a nested component with no https://www.webpackbin.com/bins/-KywGV9ZD4mUavFIORe9 Here's code:
|
FWIW it appears some are experiencing similar challenges w/ |
I'm expecting this to be solved now that there's universal webpack and otherwise it sounds like more of a styled-components / babel plugins issue 🤔 |
I'm using
babel-plugin-inline-import
toimport
built css files forantd
components. I import the CSS as strings & insert it via tagged template literal into astyled-component
. This is to avoid requiring the entire CSS file on every page.Expected Behavior
When importing CSS as a string and passing it to a styled component, the imported styles should affect components in the proper scope.
Here's my
.babelrc
:Current Behavior
When I wrap the component in the regular
styled
function fromstyled-components
, the styles are injected into the<head>
and the component is given the correct classnames. However, no styles are applied.Such an implementation looks like this:
^^ Note that this implementation works in non-nextjs projects, at least in my experience.
Now, when I use
styled-components
injectGlobal
, though, it works fine:Using classnames to style descendants work fine in Styled Components/next in regular use cases, like this:
It seems the only broken case is when I'm importing the css.
Steps to Reproduce (for bugs)
I setup a small example repo based on the
with-styled-components
example in next's repo:https://github.com/brandonmp/styled-components-next-scope
Context
I'm trying to port over a project from Gatsby, and I'd rather not pollute global with all of antd's styles.
Your Environment
The text was updated successfully, but these errors were encountered: