Skip to content

Commit 3211079

Browse files
committed
update copilot instructions
1 parent 02d9f6d commit 3211079

File tree

1 file changed

+70
-1
lines changed

1 file changed

+70
-1
lines changed

.github/instructions/css.instructions.md

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,73 @@ If the file ends with `*.module.css`, it is a CSS Module.
1010

1111
## General Conventions
1212

13-
- After making a change to a file, use `npx stylelint -q --rd --fix` with a path to the file changed to make sure the code lints
13+
- After making a change to a file, use `npx stylelint -q --rd --fix` with a path to the file changed to make sure the code lints.
14+
15+
## Performance and Web Vitals Analysis (Required)
16+
17+
When creating or modifying CSS, you must **explicitly analyze and account for impact on Core Web Vitals**. Treat this as a first-class requirement, not an afterthought.
18+
19+
### Metrics to Consider
20+
21+
Evaluate changes against the following metrics and call out any risks:
22+
23+
- **LCP (Largest Contentful Paint)**
24+
25+
- Risk factors: render-blocking styles, large above-the-fold background images, heavy font usage, complex selectors on critical elements.
26+
27+
- **CLS (Cumulative Layout Shift)**
28+
29+
- Risk factors: late-loading fonts, size-less images/media, conditional styles that affect layout after initial render, JS-driven class toggles that change dimensions.
30+
31+
- **INP (Interaction to Next Paint)**
32+
33+
- Risk factors: expensive selector matching, `:has()` on large subtrees, frequent style recalculation triggers, deep descendant selectors on interactive paths.
34+
35+
### Required Analysis Checklist
36+
37+
For each meaningful CSS change, reason through and validate the following:
38+
39+
- **Selector Cost**
40+
41+
- Prefer class selectors over tag or attribute selectors.
42+
- Avoid deep descendant chains (`.a .b .c .d`) in large or frequently updated subtrees.
43+
- Use `:has()` only when strictly necessary; assume worst-case cost on large DOMs and justify usage.
44+
45+
- **Style Recalculation Scope**
46+
47+
- Consider which DOM nodes are affected when classes or attributes change.
48+
- Avoid selectors that match large portions of the tree when toggling state (e.g., `[data-*] .child`).
49+
50+
- **Layout and Paint Stability**
51+
52+
- Do not introduce layout-affecting properties (`width`, `height`, `margin`, `padding`, `display`) that may change after hydration or user interaction unless explicitly intended.
53+
- Prefer transform/opacity for interaction-driven effects.
54+
- Ensure predictable sizing for media, containers, and dynamic content to prevent CLS.
55+
56+
- **Critical Rendering Path**
57+
58+
- Avoid adding styles that block first paint or LCP for above-the-fold content.
59+
- Be cautious with large background images, filters, and shadows on critical elements.
60+
61+
### CSS Modules–Specific Guidance
62+
63+
- Assume CSS Modules may be used across multiple React roots and hydration boundaries.
64+
- Avoid styles that depend on global cascade ordering or implicit inheritance from non-module CSS.
65+
- Do not rely on runtime-injected styles to correct layout shifts introduced by base styles.
66+
67+
### Documentation Requirement
68+
69+
When a change has **any non-trivial performance implication**, include a brief inline comment or PR description that states:
70+
71+
- Which Web Vital(s) may be affected.
72+
- Why the change is safe, or what tradeoff is being made.
73+
- Any assumptions about DOM size, interaction frequency, or rendering phase (SSR vs client).
74+
75+
### Examples of High-Risk Patterns (Avoid Unless Justified)
76+
77+
- `:has()` selectors applied to containers with large or frequently changing subtrees.
78+
- Attribute selectors used as global state flags on high-level containers.
79+
- Layout changes driven by hover, focus, or JS state on large components.
80+
- Font or image-dependent sizing without explicit fallbacks.
81+
82+
Performance regressions are considered correctness issues. If a change cannot be justified as Web Vitals–safe, it should not be merged without explicit sign-off.

0 commit comments

Comments
 (0)