@baselane/packs 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/dist/aliases.js +1 -0
  2. package/package.json +2 -2
  3. package/packs/database-review/pack.json +75 -9
  4. package/packs/database-review/rendered/.claude/agents/database-reviewer.md +75 -2
  5. package/packs/database-review/rendered/.claude/commands/migration-review.md +6 -0
  6. package/packs/database-review/rendered/.claude/settings.json +11 -0
  7. package/packs/database-review/rendered/.claude/skills/database-migrations/SKILL.md +431 -0
  8. package/packs/database-review/rendered/.claude/skills/mysql-patterns/SKILL.md +414 -0
  9. package/packs/database-review/rendered/.claude/skills/postgres-patterns/SKILL.md +149 -0
  10. package/packs/database-review/rendered/.github/copilot-instructions.md +1096 -14
  11. package/packs/database-review/rendered/AGENTS.md +45 -16
  12. package/packs/database-review/rendered/CLAUDE.md +4 -0
  13. package/packs/database-review/rendered/GEMINI.md +987 -0
  14. package/packs/go-rules/pack.json +65 -9
  15. package/packs/go-rules/rendered/.claude/agents/go-build-resolver.md +90 -0
  16. package/packs/go-rules/rendered/.claude/agents/go-reviewer.md +72 -2
  17. package/packs/go-rules/rendered/.claude/commands/go-build.md +6 -0
  18. package/packs/go-rules/rendered/.claude/commands/go-review.md +1 -1
  19. package/packs/go-rules/rendered/.claude/commands/go-test.md +6 -0
  20. package/packs/go-rules/rendered/.claude/settings.json +9 -0
  21. package/packs/go-rules/rendered/.claude/skills/golang-patterns/SKILL.md +673 -0
  22. package/packs/go-rules/rendered/.claude/skills/golang-testing/SKILL.md +719 -0
  23. package/packs/go-rules/rendered/.github/copilot-instructions.md +1783 -7
  24. package/packs/go-rules/rendered/AGENTS.md +244 -8
  25. package/packs/go-rules/rendered/CLAUDE.md +5 -0
  26. package/packs/go-rules/rendered/GEMINI.md +1394 -0
  27. package/packs/python-rules/pack.json +87 -10
  28. package/packs/python-rules/rendered/.claude/agents/django-reviewer.md +159 -0
  29. package/packs/python-rules/rendered/.claude/agents/fastapi-reviewer.md +70 -0
  30. package/packs/python-rules/rendered/.claude/agents/python-reviewer.md +92 -2
  31. package/packs/python-rules/rendered/.claude/commands/django-review.md +6 -0
  32. package/packs/python-rules/rendered/.claude/commands/fastapi-review.md +6 -0
  33. package/packs/python-rules/rendered/.claude/commands/python-review.md +1 -1
  34. package/packs/python-rules/rendered/.claude/settings.json +1 -1
  35. package/packs/python-rules/rendered/.claude/skills/django-security/SKILL.md +642 -0
  36. package/packs/python-rules/rendered/.claude/skills/django-tdd/SKILL.md +728 -0
  37. package/packs/python-rules/rendered/.claude/skills/fastapi-patterns/SKILL.md +512 -0
  38. package/packs/python-rules/rendered/.claude/skills/python-patterns/SKILL.md +749 -0
  39. package/packs/python-rules/rendered/.claude/skills/python-testing/SKILL.md +815 -0
  40. package/packs/python-rules/rendered/.github/copilot-instructions.md +3815 -12
  41. package/packs/python-rules/rendered/AGENTS.md +73 -13
  42. package/packs/python-rules/rendered/CLAUDE.md +9 -0
  43. package/packs/python-rules/rendered/GEMINI.md +3448 -0
  44. package/packs/security-review/pack.json +51 -7
  45. package/packs/security-review/rendered/.claude/agents/security-reviewer.md +29 -2
  46. package/packs/security-review/rendered/.claude/settings.json +11 -0
  47. package/packs/security-review/rendered/.claude/skills/security-review/SKILL.md +302 -0
  48. package/packs/security-review/rendered/.claude/skills/security-review/cloud-infrastructure-security.md +171 -0
  49. package/packs/security-review/rendered/.claude/skills/security-scan-config/SKILL.md +56 -0
  50. package/packs/security-review/rendered/.github/copilot-instructions.md +658 -15
  51. package/packs/security-review/rendered/AGENTS.md +283 -17
  52. package/packs/security-review/rendered/CLAUDE.md +2 -0
  53. package/packs/security-review/rendered/GEMINI.md +352 -0
  54. package/packs/software-engineer-harness/pack.json +249 -13
  55. package/packs/software-engineer-harness/rendered/.claude/agents/build-error-resolver.md +15 -0
  56. package/packs/software-engineer-harness/rendered/.claude/agents/code-explorer.md +67 -0
  57. package/packs/software-engineer-harness/rendered/.claude/agents/performance-optimizer.md +444 -0
  58. package/packs/software-engineer-harness/rendered/.claude/agents/pr-test-analyzer.md +43 -0
  59. package/packs/software-engineer-harness/rendered/.claude/agents/refactor-cleaner.md +12 -0
  60. package/packs/software-engineer-harness/rendered/.claude/agents/silent-failure-hunter.md +16 -0
  61. package/packs/software-engineer-harness/rendered/.claude/agents/tdd-guide.md +16 -0
  62. package/packs/software-engineer-harness/rendered/.claude/commands/feature-dev.md +6 -0
  63. package/packs/software-engineer-harness/rendered/.claude/commands/fix-build.md +6 -0
  64. package/packs/software-engineer-harness/rendered/.claude/commands/hunt-silent-failures.md +6 -0
  65. package/packs/software-engineer-harness/rendered/.claude/commands/tdd.md +6 -0
  66. package/packs/software-engineer-harness/rendered/.claude/settings.json +29 -0
  67. package/packs/software-engineer-harness/rendered/.claude/skills/api-design/SKILL.md +522 -0
  68. package/packs/software-engineer-harness/rendered/.claude/skills/architecture-decision-records/SKILL.md +178 -0
  69. package/packs/software-engineer-harness/rendered/.claude/skills/backend-patterns/SKILL.md +560 -0
  70. package/packs/software-engineer-harness/rendered/.claude/skills/codebase-onboarding/SKILL.md +232 -0
  71. package/packs/software-engineer-harness/rendered/.claude/skills/deployment-patterns/SKILL.md +426 -0
  72. package/packs/software-engineer-harness/rendered/.claude/skills/docker-patterns/SKILL.md +363 -0
  73. package/packs/software-engineer-harness/rendered/.claude/skills/e2e-testing/SKILL.md +325 -0
  74. package/packs/software-engineer-harness/rendered/.claude/skills/tdd-red-green-refactor/SKILL.md +20 -0
  75. package/packs/software-engineer-harness/rendered/.claude/skills/tdd-workflow/SKILL.md +580 -0
  76. package/packs/software-engineer-harness/rendered/.github/copilot-instructions.md +3948 -2
  77. package/packs/software-engineer-harness/rendered/AGENTS.md +194 -4
  78. package/packs/software-engineer-harness/rendered/CLAUDE.md +20 -0
  79. package/packs/software-engineer-harness/rendered/GEMINI.md +3208 -0
  80. package/packs/typescript-rules/pack.json +68 -5
  81. package/packs/typescript-rules/rendered/.claude/agents/react-reviewer.md +165 -0
  82. package/packs/typescript-rules/rendered/.claude/agents/type-design-analyzer.md +48 -0
  83. package/packs/typescript-rules/rendered/.claude/commands/react-review.md +6 -0
  84. package/packs/typescript-rules/rendered/.claude/settings.json +9 -0
  85. package/packs/typescript-rules/rendered/.claude/skills/react-patterns/SKILL.md +340 -0
  86. package/packs/typescript-rules/rendered/.claude/skills/react-performance/SKILL.md +573 -0
  87. package/packs/typescript-rules/rendered/.claude/skills/react-testing/SKILL.md +422 -0
  88. package/packs/typescript-rules/rendered/.github/copilot-instructions.md +2459 -53
  89. package/packs/typescript-rules/rendered/AGENTS.md +893 -17
  90. package/packs/typescript-rules/rendered/CLAUDE.md +6 -0
  91. package/packs/typescript-rules/rendered/GEMINI.md +1335 -0
@@ -0,0 +1,573 @@
1
+ ---
2
+ name: react-performance
3
+ description: Use when writing, reviewing, or refactoring React/Next.js code for performance — 70+ rules across waterfalls, bundle size, server-side performance, client fetching, re-renders, rendering, JS micro-perf, and advanced patterns, adapted from Vercel Engineering's React Best Practices.
4
+ ---
5
+
6
+ # React Performance
7
+
8
+ Performance optimization patterns for React 18/19 and Next.js, adapted from [Vercel Labs `react-best-practices`](https://github.com/vercel-labs/agent-skills/tree/main/skills/react-best-practices) (MIT, v1.0.0). This skill organizes rules by priority and provides decision-tree guidance for active code review and refactoring.
9
+
10
+ ## When to Activate
11
+
12
+ - Writing or reviewing React/Next.js code for performance
13
+ - Diagnosing slow page loads, slow interactions, or high CPU on the client
14
+ - Auditing bundle size or Lighthouse Core Web Vitals regressions
15
+ - Removing waterfalls in Server Components / API routes
16
+ - Reducing client-side re-renders
17
+ - Optimizing long lists, animations, or hydration
18
+ - Auditing optimization choices in PRs touching `app/`, `pages/`, `components/`, or data layers
19
+
20
+ ## Priority Index
21
+
22
+ | Priority | Category | Prefix | When it matters |
23
+ |---|---|---|---|
24
+ | 1 — CRITICAL | Eliminating Waterfalls | `async-` | Anytime `await` is followed by independent `await` |
25
+ | 2 — CRITICAL | Bundle Size Optimization | `bundle-` | First-load JS, route-level imports, third-party libs |
26
+ | 3 — HIGH | Server-Side Performance | `server-` | RSC, Server Actions, API routes, SSR |
27
+ | 4 — MEDIUM-HIGH | Client-Side Data Fetching | `client-` | SWR / TanStack Query / raw `fetch` in hooks |
28
+ | 5 — MEDIUM | Re-render Optimization | `rerender-` | High-frequency state updates, parent-child fan-out |
29
+ | 6 — MEDIUM | Rendering Performance | `rendering-` | Long lists, animations, hydration |
30
+ | 7 — LOW-MEDIUM | JavaScript Performance | `js-` | Hot loops, frequent allocations |
31
+ | 8 — LOW | Advanced Patterns | `advanced-` | Effect-event integration, stable refs |
32
+
33
+ ## 1. Eliminating Waterfalls (CRITICAL)
34
+
35
+ > "Waterfalls are the #1 performance killer" — every sequential `await` adds full network latency.
36
+
37
+ ### Cheap conditions before await
38
+
39
+ Check sync conditions (props, env, hardcoded flags) before awaiting remote data.
40
+
41
+ ```ts
42
+ // INCORRECT
43
+ async function Page({ id }: { id: string }) {
44
+ const flag = await getFlag("show-page");
45
+ if (!flag || !id) return null;
46
+ const data = await getData(id);
47
+ // ...
48
+ }
49
+
50
+ // CORRECT — short-circuit on cheap sync condition first
51
+ async function Page({ id }: { id: string }) {
52
+ if (!id) return null;
53
+ const flag = await getFlag("show-page");
54
+ if (!flag) return null;
55
+ const data = await getData(id);
56
+ }
57
+ ```
58
+
59
+ ### Defer awaits until used
60
+
61
+ Move `await` into the branch that uses it.
62
+
63
+ ```ts
64
+ // INCORRECT — awaits before deciding it needs the data
65
+ const user = await getUser(id);
66
+ if (mode === "guest") return renderGuest();
67
+ return renderUser(user);
68
+
69
+ // CORRECT
70
+ if (mode === "guest") return renderGuest();
71
+ const user = await getUser(id);
72
+ return renderUser(user);
73
+ ```
74
+
75
+ ### Promise.all for independent work
76
+
77
+ ```ts
78
+ // INCORRECT — sequential
79
+ const user = await getUser(id);
80
+ const posts = await getPosts(id);
81
+ const followers = await getFollowers(id);
82
+
83
+ // CORRECT — parallel
84
+ const [user, posts, followers] = await Promise.all([
85
+ getUser(id),
86
+ getPosts(id),
87
+ getFollowers(id),
88
+ ]);
89
+ ```
90
+
91
+ ### Partial dependencies — start early, await late
92
+
93
+ ```ts
94
+ // CORRECT — kick off all promises, await only when each result is needed
95
+ const userP = getUser(id);
96
+ const postsP = getPosts(id);
97
+ const profile = await getProfile(id);
98
+ if (profile.private) return null;
99
+ const [user, posts] = await Promise.all([userP, postsP]);
100
+ ```
101
+
102
+ ### Suspense for streaming
103
+
104
+ Push `<Suspense>` boundaries close to the data so the page paints what it can while slower sub-trees stream in. The trade-off: layout shift when content arrives — reserve space (skeleton or `min-height`).
105
+
106
+ ### Server Components: parallel through composition
107
+
108
+ ```tsx
109
+ // INCORRECT — sibling awaits run sequentially inside one component
110
+ export default async function Page() {
111
+ const user = await getUser();
112
+ const cart = await getCart();
113
+ return <View user={user} cart={cart} />;
114
+ }
115
+
116
+ // CORRECT — split into children, React runs them in parallel
117
+ export default async function Page() {
118
+ return (
119
+ <View>
120
+ <UserSection />
121
+ <CartSection />
122
+ </View>
123
+ );
124
+ }
125
+ ```
126
+
127
+ ## 2. Bundle Size Optimization (CRITICAL)
128
+
129
+ ### Direct imports, not barrels
130
+
131
+ Barrel `index.ts` files force the bundler to walk the entire module graph even when tree-shaking removes most of it. Direct imports save 200-800ms of first-load JS in many real-world apps.
132
+
133
+ ```ts
134
+ // INCORRECT
135
+ import { Button, Card, Modal } from "@/components";
136
+
137
+ // CORRECT
138
+ import { Button } from "@/components/Button";
139
+ import { Card } from "@/components/Card";
140
+ import { Modal } from "@/components/Modal";
141
+ ```
142
+
143
+ Next.js 13.5+ has [Optimize Package Imports](https://nextjs.org/docs/app/api-reference/next-config-js/optimizePackageImports) that automates this for listed packages — use it; manual direct imports still required for non-listed libs.
144
+
145
+ ### Statically analyzable paths
146
+
147
+ ```ts
148
+ // INCORRECT — defeats bundler/trace analysis
149
+ const mod = await import(`./pages/${name}`);
150
+
151
+ // CORRECT — explicit per branch
152
+ const mod = name === "home" ? await import("./pages/home") : await import("./pages/about");
153
+ ```
154
+
155
+ ### Dynamic imports for heavy components
156
+
157
+ ```tsx
158
+ import dynamic from "next/dynamic";
159
+
160
+ const HeavyChart = dynamic(() => import("./HeavyChart"), {
161
+ loading: () => <Skeleton />,
162
+ ssr: false, // when client-only
163
+ });
164
+ ```
165
+
166
+ ### Defer third-party scripts
167
+
168
+ Load analytics, logging, support widgets AFTER hydration. Use `next/script` with `strategy="afterInteractive"` (default) or `"lazyOnload"`.
169
+
170
+ ### Conditional module loading
171
+
172
+ ```tsx
173
+ if (user.role === "admin") {
174
+ const { AdminPanel } = await import("./admin/AdminPanel");
175
+ // ...
176
+ }
177
+ ```
178
+
179
+ ### Preload on hover/focus
180
+
181
+ Trigger `<link rel="preload">` or `import()` on hover so the bundle is in cache by the time the user clicks.
182
+
183
+ ## 3. Server-Side Performance (HIGH)
184
+
185
+ ### Authenticate Server Actions like API routes
186
+
187
+ Every `"use server"` function is a public endpoint. Authenticate AND authorize inside the action — never rely on the calling Client Component's gating.
188
+
189
+ ```ts
190
+ "use server";
191
+ export async function deleteUser(formData: FormData) {
192
+ const session = await getSession();
193
+ if (!session?.user) throw new Error("Unauthorized");
194
+ const targetId = String(formData.get("id"));
195
+ if (session.user.role !== "admin" && session.user.id !== targetId) {
196
+ throw new Error("Forbidden");
197
+ }
198
+ await db.user.delete({ where: { id: targetId } });
199
+ }
200
+ ```
201
+
202
+ ### `React.cache()` for per-request deduplication
203
+
204
+ ```ts
205
+ import { cache } from "react";
206
+
207
+ export const getUser = cache(async (id: string) => {
208
+ return db.user.findUnique({ where: { id } });
209
+ });
210
+ ```
211
+
212
+ `React.cache` dedupes within a single request. Calling `getUser("1")` from three Server Components in the same render = one DB query.
213
+
214
+ ### LRU cache for cross-request data
215
+
216
+ For data that does NOT change per request (config, lookup tables), cache outside React with an LRU cache or `unstable_cache`.
217
+
218
+ ### Avoid duplicate serialization in RSC props
219
+
220
+ When a Server Component renders the same data into multiple Client Components, the data is serialized once per consumer. Lift the Client Component up and pass children.
221
+
222
+ ### Hoist static I/O to module scope
223
+
224
+ ```ts
225
+ // CORRECT — runs once at module load
226
+ const fontData = readFileSync(fontPath);
227
+
228
+ export async function Page() {
229
+ return <Banner font={fontData} />;
230
+ }
231
+ ```
232
+
233
+ ### No mutable module-level state in RSC/SSR
234
+
235
+ Module state on the server is shared across all requests — a race condition between users. Use request-scoped storage (`headers()`, `cookies()`, async context) instead.
236
+
237
+ ### Minimize data passed to Client Components
238
+
239
+ Only serialize what the Client needs. Strip fields, paginate, project columns at the DB layer.
240
+
241
+ ### Parallelize nested fetches with Promise.all per item
242
+
243
+ ```ts
244
+ const users = await getUsers();
245
+ const enriched = await Promise.all(
246
+ users.map(async (u) => ({ ...u, posts: await getPostsFor(u.id) })),
247
+ );
248
+ ```
249
+
250
+ ### Use `after()` for non-blocking work
251
+
252
+ Next.js 15 `after()` runs work after the response is sent — logging, cache warming, analytics.
253
+
254
+ ```ts
255
+ import { after } from "next/server";
256
+ export async function GET() {
257
+ const data = await getData();
258
+ after(() => logAnalytics(data));
259
+ return Response.json(data);
260
+ }
261
+ ```
262
+
263
+ ## 4. Client-Side Data Fetching (MEDIUM-HIGH)
264
+
265
+ ### SWR / TanStack Query for deduplication
266
+
267
+ Multiple components calling `useUser(id)` should share one network request and one cache entry. Use SWR or TanStack Query — never roll your own `useEffect` + `fetch` for shared data.
268
+
269
+ ### Deduplicate global event listeners
270
+
271
+ ```tsx
272
+ // INCORRECT — every component adds its own
273
+ useEffect(() => {
274
+ window.addEventListener("scroll", handler);
275
+ return () => window.removeEventListener("scroll", handler);
276
+ }, []);
277
+
278
+ // CORRECT — single shared listener via a hook + global subject
279
+ const useScroll = createScrollHook(); // singleton subject under the hood
280
+ ```
281
+
282
+ ### Passive listeners for scroll
283
+
284
+ ```ts
285
+ window.addEventListener("scroll", handler, { passive: true });
286
+ ```
287
+
288
+ Improves scrolling smoothness; the listener cannot `preventDefault()`.
289
+
290
+ ### localStorage: version + minimize
291
+
292
+ - Always store a `version` field; bump on schema change and migrate or discard old data
293
+ - Keep payloads small — `localStorage` is synchronous and blocks main thread
294
+
295
+ ## 5. Re-render Optimization (MEDIUM)
296
+
297
+ ### Don't subscribe to state used only in callbacks
298
+
299
+ ```tsx
300
+ // INCORRECT — re-renders every time count changes
301
+ const count = useStore((s) => s.count);
302
+ const handler = () => doSomething(count);
303
+
304
+ // CORRECT — read once on call
305
+ const handler = () => {
306
+ const count = useStore.getState().count;
307
+ doSomething(count);
308
+ };
309
+ ```
310
+
311
+ ### Extract expensive work into memoized components
312
+
313
+ ```tsx
314
+ // CORRECT — child re-renders only when `items` changes
315
+ const Heavy = memo(function Heavy({ items }: { items: Item[] }) {
316
+ return <Chart data={transform(items)} />;
317
+ });
318
+ ```
319
+
320
+ ### Hoist default non-primitive props
321
+
322
+ ```tsx
323
+ // INCORRECT — new array each render breaks memo
324
+ <List items={items ?? []} />
325
+
326
+ // CORRECT
327
+ const EMPTY: Item[] = [];
328
+ <List items={items ?? EMPTY} />
329
+ ```
330
+
331
+ ### Primitive dependencies in effects
332
+
333
+ ```tsx
334
+ // INCORRECT — new object identity every render
335
+ useEffect(() => {}, [{ id, name }]);
336
+
337
+ // CORRECT — primitives
338
+ useEffect(() => {}, [id, name]);
339
+ ```
340
+
341
+ ### Subscribe to derived booleans, not raw values
342
+
343
+ ```tsx
344
+ // INCORRECT — re-renders for any cart change
345
+ const cart = useStore((s) => s.cart);
346
+ const hasItems = cart.length > 0;
347
+
348
+ // CORRECT — re-renders only when emptiness flips
349
+ const hasItems = useStore((s) => s.cart.length > 0);
350
+ ```
351
+
352
+ ### Derive during render, never via `useEffect`
353
+
354
+ ```tsx
355
+ // INCORRECT
356
+ const [full, setFull] = useState("");
357
+ useEffect(() => setFull(`${first} ${last}`), [first, last]);
358
+
359
+ // CORRECT
360
+ const full = `${first} ${last}`;
361
+ ```
362
+
363
+ ### Functional `setState` for stable callbacks
364
+
365
+ ```tsx
366
+ // CORRECT
367
+ const increment = useCallback(() => setCount((c) => c + 1), []);
368
+ ```
369
+
370
+ ### Lazy state initializer for expensive values
371
+
372
+ ```tsx
373
+ const [tree] = useState(() => parseTree(largeInput));
374
+ ```
375
+
376
+ ### Avoid memo for simple primitives
377
+
378
+ `useMemo(() => x + 1, [x])` is overhead. Memo earns its keep on object identity and expensive computation.
379
+
380
+ ### Split hooks with independent deps
381
+
382
+ ```tsx
383
+ // INCORRECT — both selectors re-run if either source changes
384
+ const { a, b } = useSomething(source1, source2);
385
+
386
+ // CORRECT
387
+ const a = useA(source1);
388
+ const b = useB(source2);
389
+ ```
390
+
391
+ ### Move interaction logic into event handlers
392
+
393
+ Event handlers run only on the user action — `useEffect` re-runs whenever deps change.
394
+
395
+ ### `startTransition` for non-urgent updates
396
+
397
+ ```tsx
398
+ const [pending, startTransition] = useTransition();
399
+ startTransition(() => setFilters(newFilters));
400
+ ```
401
+
402
+ ### `useDeferredValue` for expensive renders
403
+
404
+ ```tsx
405
+ const deferredQuery = useDeferredValue(query);
406
+ const results = useMemo(() => expensiveSearch(deferredQuery), [deferredQuery]);
407
+ ```
408
+
409
+ ### `useRef` for transient frequent values
410
+
411
+ For values that change often but should not trigger re-render (timestamps, last-key, accumulators).
412
+
413
+ ### Don't define components inside components
414
+
415
+ ```tsx
416
+ // INCORRECT — Inner is a new component on every Outer render
417
+ function Outer() {
418
+ const Inner = () => <span />;
419
+ return <Inner />;
420
+ }
421
+ ```
422
+
423
+ Each render makes a new `Inner` type, defeating reconciliation and unmounting children.
424
+
425
+ ## 6. Rendering Performance (MEDIUM)
426
+
427
+ ### Animate the wrapper, not the SVG
428
+
429
+ Transforming a `<div>` wrapper around an SVG is GPU-accelerated; transforming the SVG itself triggers paint.
430
+
431
+ ### `content-visibility: auto` for long lists
432
+
433
+ ```css
434
+ .row { content-visibility: auto; contain-intrinsic-size: auto 80px; }
435
+ ```
436
+
437
+ Browser skips offscreen rendering — major win for lists with hundreds of rows.
438
+
439
+ ### Hoist static JSX
440
+
441
+ ```tsx
442
+ const STATIC_HEADER = <h1>Title</h1>;
443
+ function Page() {
444
+ return <>{STATIC_HEADER}<Body /></>;
445
+ }
446
+ ```
447
+
448
+ ### SVG: reduce coordinate precision
449
+
450
+ `d="M10.123456,20.654321"` → `d="M10.12,20.65"`. Each digit costs bytes; the visual difference is sub-pixel.
451
+
452
+ ### Hydration no-flicker via inline script
453
+
454
+ For values needed before hydration (theme, locale), inline a `<script>` that sets `document.documentElement.dataset.*` before React mounts.
455
+
456
+ ### Suppress expected hydration mismatches narrowly
457
+
458
+ ```tsx
459
+ <time suppressHydrationWarning>{new Date().toLocaleString()}</time>
460
+ ```
461
+
462
+ Use ONLY for known-divergent leaf nodes — never on a tree containing other children.
463
+
464
+ ### `<Activity>` for show/hide instead of mount/unmount
465
+
466
+ React 19 `<Activity mode="visible|hidden">` keeps tree state and effects mounted but hides — cheaper than unmount/remount for tabs and accordions.
467
+
468
+ ### Ternary over `&&` for conditional render
469
+
470
+ ```tsx
471
+ // INCORRECT — `0` renders as text node
472
+ {count && <Badge>{count}</Badge>}
473
+
474
+ // CORRECT
475
+ {count > 0 ? <Badge>{count}</Badge> : null}
476
+ ```
477
+
478
+ ### `useTransition` for loading states
479
+
480
+ Pair `startTransition` with the action; React shows the previous UI as `isPending` while the next state computes.
481
+
482
+ ### React DOM resource hints
483
+
484
+ ```tsx
485
+ import { preload, preconnect } from "react-dom";
486
+ preload("/api/critical", { as: "fetch" });
487
+ preconnect("https://api.example.com");
488
+ ```
489
+
490
+ ### `defer` / `async` on `<script>` tags
491
+
492
+ `defer` for ordered execution after DOMContentLoaded; `async` for fire-and-forget.
493
+
494
+ ## 7. JavaScript Performance (LOW-MEDIUM)
495
+
496
+ - **Batch DOM/CSS changes** — apply via class swap or `cssText`, not property-by-property
497
+ - **`Map` for repeated lookups** — `O(1)` vs `O(n)` linear scan
498
+ - **Cache property access in loops** — `const len = arr.length`
499
+ - **Memoize pure functions** — module-level `Map<key, result>`
500
+ - **Cache `localStorage` reads** — sync API; one read per render
501
+ - **Combine `filter().map()` into one pass** — `flatMap` or single `for`
502
+ - **Check array length first** before expensive comparisons
503
+ - **Early return** from functions
504
+ - **Hoist RegExp** out of loops — compilation is not free
505
+ - **Loop for min/max** instead of `sort()` — `O(n)` vs `O(n log n)`
506
+ - **`Set`/`Map` for membership** — `O(1)` vs `Array.includes` `O(n)`
507
+ - **`toSorted()` over mutation** when immutability matters
508
+ - **`flatMap` to map and filter in one pass**
509
+ - **`requestIdleCallback`** for non-critical work
510
+
511
+ ## 8. Advanced Patterns (LOW)
512
+
513
+ ### `useEffectEvent` deps
514
+
515
+ Values from `useEffectEvent` are stable — do NOT add them to effect deps.
516
+
517
+ ### Event handler refs
518
+
519
+ For stable callbacks passed to memoized children:
520
+
521
+ ```tsx
522
+ const handlerRef = useRef(handler);
523
+ useEffect(() => { handlerRef.current = handler; });
524
+ const stable = useCallback((arg) => handlerRef.current(arg), []);
525
+ ```
526
+
527
+ ### Init once per app load
528
+
529
+ For module-level singletons (telemetry, logger), guard with a module-scope flag — not `useEffect`.
530
+
531
+ ### `useLatest` for stable callback refs
532
+
533
+ ```tsx
534
+ function useLatest<T>(value: T) {
535
+ const ref = useRef(value);
536
+ ref.current = value;
537
+ return ref;
538
+ }
539
+ ```
540
+
541
+ ## Automated Tools
542
+
543
+ Many of these rules are now automated:
544
+
545
+ - **Next.js 13.5+ Optimize Package Imports** — barrel import optimization
546
+ - **React Compiler** (RFC, in canary) — auto-memoization
547
+ - **Turbopack** — faster builds, better tree-shaking
548
+ - **Bundle Analyzer** (`@next/bundle-analyzer`) — visualize first-load JS
549
+
550
+ When the project ships React Compiler, demote `rerender-*` manual memoization rules to "review-only" — the compiler handles them. Manual `useMemo`/`useCallback` becomes unnecessary noise.
551
+
552
+ ## Lighthouse / Web Vitals Mapping
553
+
554
+ | Metric | Most relevant categories |
555
+ |---|---|
556
+ | **LCP** (Largest Contentful Paint) | Waterfalls, Bundle Size, Resource Hints |
557
+ | **INP** (Interaction to Next Paint) | Re-render, Rendering, JavaScript |
558
+ | **CLS** (Cumulative Layout Shift) | Rendering (Suspense placement, image dimensions) |
559
+ | **TBT** (Total Blocking Time) | Bundle Size, JavaScript, Defer Third-Party |
560
+ | **FID** (legacy) | Bundle Size, Hydration |
561
+
562
+ ## Related
563
+
564
+ - Skills: [react-patterns](../react-patterns/SKILL.md), [react-testing](../react-testing/SKILL.md), [frontend-patterns](../frontend-patterns/SKILL.md), [accessibility](../accessibility/SKILL.md), [nextjs-turbopack](../nextjs-turbopack/SKILL.md)
565
+ - Rules: [rules/react/](../../rules/react/)
566
+ - Agents: `react-reviewer` enforces these rules in code review; `react-build-resolver` handles related build failures
567
+ - Commands: `/react-review`, `/react-build`, `/react-test`
568
+
569
+ ## Attribution
570
+
571
+ Adapted from Vercel Labs `react-best-practices` skill (MIT License, copyright Vercel Engineering, v1.0.0 January 2026). Source: [https://github.com/vercel-labs/agent-skills/tree/main/skills/react-best-practices](https://github.com/vercel-labs/agent-skills/tree/main/skills/react-best-practices).
572
+
573
+ This skill restructures and adapts the original 70-rule catalog into a single navigable reference. For the full original ruleset with extended examples, see the upstream repository.