Challenge 2: Why CSS's Global-Scope Problem Is Even Worse Than JS's — Possible Solution ==================================================================== THE SPECIFIC PROBLEM CSS MODULES SOLVE ------------------------------ Per this chapter's own explanation, every CSS selector is global across an entire page by default — a class named .button defined in one CSS file will collide with, and be overridden by (or override), any other .button class defined anywhere else in the entire project, regardless of which component or file each one was intended for. CSS Modules solve this by automatically rewriting each class name at build time into something guaranteed globally unique (like Button_button__x7f3a), so two components can both use a class simply named .button in their own source files without their compiled output ever actually colliding. WHY THIS IS DESCRIBED AS WORSE THAN JAVASCRIPT'S OWN PROBLEM ------------------------------ Per this chapter's own comparison to build-tooling1-1, JavaScript's pre-ESM global-scope problem was real, but JavaScript at least had SOME scoping mechanisms available even before ES Modules existed — function scope and (with let/const) block scope could contain variables so they weren't automatically visible everywhere. A developer disciplined about wrapping code in functions had at least a partial, if easy to gloss over, workaround. CSS has no equivalent AT ALL. Per this chapter's own wording, there is "no built-in scoping mechanism at all — not even the function/block scope JavaScript at least had." Every single CSS selector, no matter how or where it's written, is automatically global the moment it's loaded on a page — there is no CSS-native construct comparable to a function or block that could contain a selector's own reach. This is exactly why the chapter frames CSS's version of the problem as more severe: JavaScript had an imperfect but real partial defense before ESM ever arrived; CSS has none. WHY THIS WORKS AS AN ANSWER ------------------------------ It explains precisely how CSS Modules solve the global-scope problem (build-time class-name rewriting to guarantee uniqueness), and explains the "even more severe" comparison specifically by naming what partial scoping mechanism JavaScript at least had available (function/block scope) that CSS has no equivalent of whatsoever.