Bug report
Describe the bug
In development mode, when a page imports styles from a .module.css file ( import styles from "./home.module.css" ) and then imports another component after that ( import { Container } from "../components/Container" ), and passes the imported styles to the component like <Container className={styles.blue}>, these styles get overriden by the imported component. This component has it's own styles and passes the className prop to a DOM element:
import styles from "./Container.module.css";
function classes(...classNames) {
const joined = classNames.join(' ');
return joined;
}
export const Container = ({
children,
className= "",
}) => {
return (
<div className={classes(styles.container, className)}>
{children}
</div>
);
};
The Container has the following style:
.container {
background-color: yellow;
}
But the page provides the following style:
.blue {
background-color: blue;
}
In development, the styles are injected into the head as follows:
<style>
.index_blue__3Iu-s {
background-color: blue;
}
</style>
<style>
.Container_container__1UmhU {
background-color: yellow;
}
</style>
In production, these styles are combined into one stylesheet:
.Container_container__1UmhU {
background-color: #ff0
}
.index_blue__3Iu-s {
background-color: #00f
}
As you can see, there is a difference in order. This causes the inconsistency across environments with CSS ( yellow in development, blue in production ).
I believe that the production result is the correct one, as you should be able to override the component styles.
I'd be happy to try to contribute to a fix. However, I am a beginner developer so I might need some guidance.
To Reproduce
Clone my reproduction repository and run npm run dev to see the styles applied incorrectly, and run npm run build; npm run start to see that the styles work as intended.
Expected behavior
I would expect that in both development and production mode the classes get defined in the same order so that the styles are applied correctly.
System information
- OS: Windows 10
- Browser: Chrome 81.0.4044.138
- Version of Next.js: 9.4.1
- Version of Node.js: 12.16.1
More information
The style tags are injected by the code in this file. It uses style-loader in development and the MiniCssExtractPlugin in production. What is the reason as to why it isn't used in development mode?
NEXT-1386
Bug report
Describe the bug
In development mode, when a page imports styles from a
.module.cssfile (import styles from "./home.module.css") and then imports another component after that (import { Container } from "../components/Container"), and passes the imported styles to the component like<Container className={styles.blue}>, these styles get overriden by the imported component. This component has it's own styles and passes theclassNameprop to a DOM element:The
Containerhas the following style:But the page provides the following style:
In development, the styles are injected into the head as follows:
In production, these styles are combined into one stylesheet:
As you can see, there is a difference in order. This causes the inconsistency across environments with CSS ( yellow in development, blue in production ).
I believe that the production result is the correct one, as you should be able to override the component styles.
I'd be happy to try to contribute to a fix. However, I am a beginner developer so I might need some guidance.
To Reproduce
Clone my reproduction repository and run
npm run devto see the styles applied incorrectly, and runnpm run build; npm run startto see that the styles work as intended.Expected behavior
I would expect that in both development and production mode the classes get defined in the same order so that the styles are applied correctly.
System information
More information
The style tags are injected by the code in this file. It uses
style-loaderin development and theMiniCssExtractPluginin production. What is the reason as to why it isn't used in development mode?NEXT-1386