You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## React components and hooks should have unit tests
47
+
48
+
**Urgency:** suggestion
49
+
50
+
### Category
51
+
52
+
Maintainability
53
+
54
+
### Confidence Threshold
55
+
56
+
Flag new or significantly modified components/hooks lacking Jest tests when they contain logic (state, effects, event handlers, conditional rendering). Simple presentational components rendering static JSX may defer testing. Existing untested code not modified in the PR should not be flagged.
57
+
58
+
### Exceptions / False Positives
59
+
60
+
- Do not flag demo-only, internal layout wrappers, or placeholder components.
61
+
- Do not flag when tests exist in a different location (e.g., shared test suite) if verifiable.
62
+
- Do not flag existing untested code outside the PR scope.
63
+
64
+
### Description
65
+
66
+
Components with state, effects, event handlers, or conditional logic need Jest tests. Test what should always be covered: `useState`/`useReducer`, event handlers, conditional rendering, custom hooks with logic, permission-gated rendering. Layout-only components are optional.
1. Check for `.test.tsx`/`.test.ts` file corresponding to modified component.
112
+
2. If missing, flag if component has: hooks, event handlers, or conditional logic.
113
+
3. If tests exist, verify they assert on behavior (not just render existence).
114
+
115
+
## Large JSX/TSX blocks should be extracted into separate components
116
+
117
+
**Urgency:** suggestion
118
+
119
+
### Category
120
+
121
+
Maintainability
122
+
123
+
### Confidence Threshold
124
+
125
+
Flag JSX return statements >25 lines or those with multiple conditional branches (3+ `{condition && <...>}` or ternary operators). Simple single-element returns or small layout wrappers are exempt.
126
+
127
+
### Exceptions / False Positives
128
+
129
+
- Do not flag simple, single-element returns or small layout wrappers.
130
+
131
+
### Description
132
+
133
+
Large JSX blocks reduce readability, increase cognitive load, and make testing harder. Red flags: multiple conditional rendering branches, repeated patterns (like tab buttons with similar structure), deeply nested element hierarchies, and components managing multiple independent concerns.
134
+
135
+
### Anti-patterns to Flag
136
+
137
+
```tsx
138
+
// ❌ Return block with multiple conditional branches and repeated patterns
2.**Repeated patterns:** Similar button/input groups with duplicated props (e.g., `role="tab"`, `aria-selected`, `onClick`) → extract into component.
236
+
3.**Multiple state sections:** Component with separate state for tabs/panels (e.g., `const [tab, setTab]` and `const [panel, setPanel]`) often signals multiple concerns.
## React components and hooks should have unit tests
240
+
241
+
**Urgency:** suggestion
242
+
243
+
### Category
244
+
245
+
Maintainability
246
+
247
+
### Confidence Threshold
248
+
249
+
Flag new or significantly modified components/hooks lacking Jest tests when they contain logic (state, effects, event handlers, conditional rendering). Simple presentational components rendering static JSX may defer testing. Existing untested code not modified in the PR should not be flagged.
250
+
251
+
### Exceptions / False Positives
252
+
253
+
- Do not flag demo-only, internal layout wrappers, or placeholder components.
254
+
- Do not flag when tests exist in a different location (e.g., shared test suite) if verifiable.
255
+
- Do not flag existing untested code outside the PR scope.
256
+
257
+
### Description
258
+
259
+
Components with state, effects, event handlers, or conditional logic need Jest tests. Test what should always be covered: `useState`/`useReducer`, event handlers, conditional rendering, custom hooks with logic, permission-gated rendering. Layout-only components are optional.
Copy file name to clipboardExpand all lines: .agents/review-checklists/react/performance.md
+50Lines changed: 50 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,56 @@
2
2
3
3
> **Prerequisite:** Review and apply the common guidelines in [`common.md`](../common.md) before using this checklist.
4
4
5
+
## Event handlers should be memoized with `useCallback`
6
+
7
+
**Urgency:** urgent
8
+
9
+
### Category
10
+
11
+
Performance
12
+
13
+
### Confidence Threshold
14
+
15
+
Flag any event handler prop (`onClick`, `onChange`, `onSubmit`, etc.) that is an inline arrow function or a named function in the component body without `useCallback`. Do not flag handlers defined at module scope — they are already stable references.
16
+
17
+
### Exceptions / False Positives
18
+
19
+
- Do not flag event handlers defined at module scope.
20
+
- Do not suggest `useCallback` for handlers with no component-scope dependencies — hoisting to module scope is preferable (a true constant reference with no Hook overhead).
21
+
22
+
### Description
23
+
24
+
All event handlers in a component body should be wrapped with `useCallback`, including those on native DOM elements. The overhead is negligible; omitting it has caused real performance issues and creates audit work whenever a future refactor forwards the handler to a memoized child.
25
+
26
+
Watch for the factory anti-pattern: `useCallback` wrapping a function that itself returns a function. The outer reference is stable, but invoking it still produces a new function reference on every render.
1. Search for `onClick={`, `onChange={`, etc. where the value is an inline arrow or an identifier not assigned via `useCallback(...)`.
51
+
2. For existing `useCallback` calls, check if the wrapped function returns another function — if so, verify that returned function is not being passed directly as a prop.
Copy file name to clipboardExpand all lines: CLAUDE.md
+8Lines changed: 8 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -83,6 +83,14 @@ We keep local copies of the `@labkey` packages in the `clientAPIs/` directory. Y
83
83
84
84
The local copies of the packages may contain changes related to the current branches in any of the modules that have an NPM build. For example there may be changes to the `@labkey/components` package that affect the package in the `server/modules/platform/core` module. These packages are not required to be present to build the project, so they may not be available. If they are not present, you can assume that there are no changes in those packages relevant to the current branch. If you suspect an issue is with one of the packages, but it is not present you may prompt the user to check out a local copy of the relevant package.
85
85
86
+
### React Conventions
87
+
- We are using React 18
88
+
-**Component typing:** Use `FC<Props>` (or `FC` for no-prop components) for proper components used as `<Component />`. Use `ReactNode` as the return type for render helpers — functions that return JSX but are not used as components (typically named with a lowercase letter or a `render` prefix). Do **not** annotate with `JSX.Element` or `ReactElement`.
89
+
-**React type imports:** Always import React types directly from `react` rather than accessing them via the `React.*` namespace. For example: `import { FC, ReactNode } from 'react'`, never `React.FC` or `React.ReactNode`.
90
+
-**displayName:** Set `ComponentName.displayName = 'ComponentName'` immediately after each `React.FC` definition so it appears correctly in React DevTools and error boundaries.
91
+
-**Props interfaces:** Declare a separate named `interface ComponentNameProps` for any component with two or more props. Do not inline the type in the `FC<>` generic.
92
+
-**Event handlers:** Wrap all event handlers defined in a component body with `useCallback`, including those passed to native DOM elements. Do not use inline arrow functions in JSX (e.g., `onClick={() => doX()}`); extract and memoize them instead. Be aware that `useCallback` on a factory function (one that itself returns a new function) does not memoize the result — each invocation still produces a new reference.
93
+
86
94
### Distributions
87
95
88
96
The `distributions/` directory defines 60+ distribution configurations that select which modules to package. Distributions inherit from each other (most inherit from `:distributions:base`). Distribution directory names must not collide with module names.
0 commit comments