Performance: Scoped styles by default
MEDIUM IMPACT
This affects rendering speed and visual stability by limiting CSS scope to components, reducing style recalculations and layout shifts.
<style>
button {
color: red;
}
</style>
<script>
// component code
</script>
<button>Click me</button><style>
:global(.button) { color: red; }
</style>
<script>
// component code
</script>
<button class="button">Click me</button>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Global CSS styles | Affects all matching elements in DOM | Multiple reflows if styles change globally | High paint cost due to broad style recalculation | [X] Bad |
| Scoped styles by default | Affects only component subtree | Single reflow limited to component | Lower paint cost due to isolated style recalculation | [OK] Good |