Performance: CSS Modules
CSS Modules impact how styles are scoped and loaded, affecting CSS bundle size and render blocking during page load.
// Button.module.css
.button { padding: 1rem; background: blue; }
// Button.jsx
import styles from './Button.module.css';
<button className={styles.button}>Click</button>/* global.css */ .button { padding: 1rem; background: blue; } // In multiple components, .button class is reused globally
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Global CSS with many unused styles | Low | Low | High due to large CSS | [X] Bad |
| CSS Modules scoped per component | Low | Low | Low due to smaller CSS | [OK] Good |
CSS Modules in a Remix app?.module.css to enable local scoping.import styles from "./Button.module.css";
export default function Button() {
return <button className={styles.primary}>Click Me</button>;
}Button.module.css contains:.primary {
background-color: blue;
color: white;
}Button.module.css and applies styles.primary as className.background-color: blue; and color: white;, so the button background is blue.import styles from "./Card.module.css";
export default function Card() {
return <div className="styles.card">Content</div>;
}className="styles.card" which treats it as a string literal, not a variable.className={styles.card} without quotes to use the imported object.PrimaryButton.module.css and SecondaryButton.module.css. How do you ensure styles do not conflict and are applied correctly?Pass the test and this pattern moves unknown