Skip to content

Commit 3edbd01

Browse files
committed
chore(FR-2616): scope memoization rule via paths frontmatter
Align the new react-compiler-memoization rule with Claude Code's official rules schema (docs.claude.com): add a paths field so the rule only loads when React files are in scope, matching sibling rules antd-v6-props.md and use-effect-event.md. Without paths scoping, the rule would load unconditionally every session and consume context even for backend or docs work. Also trim the Why section from five bullets to three to save context when the rule is active.
1 parent 24e8783 commit 3edbd01

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

.claude/rules/react-compiler-memoization.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
---
2-
description: When writing or editing React components and hooks that need memoization
2+
description: Rely on the React Compiler (`'use memo'`) instead of manual `useMemo` / `useCallback`
3+
paths:
4+
- "react/**/*.{tsx,ts}"
5+
- "packages/backend.ai-ui/**/*.{tsx,ts}"
36
---
47

58
# React Compiler Memoization Rule
69

7-
This project runs **React 19.2** with **`babel-plugin-react-compiler` in annotation mode**. Memoization is the React Compiler's job, not the developer's. Do not reach for `useMemo` / `useCallback` as a first instinct — add the `'use memo'` directive to the component or hook body instead, and write plain values and plain functions.
10+
This project runs **React 19.2** with **`babel-plugin-react-compiler` in annotation mode**. The compiler owns memoization. Add the `'use memo'` directive to each component and hook body, and write plain values and plain functions.
811

912
## Why
1013

11-
1. The compiler analyzes dependencies and inserts caching automatically, including cases that are hard or impossible to express with manual `useMemo` / `useCallback` dependency arrays (e.g., stable references across conditional code paths, partial memoization of branches).
12-
2. Manual dependency arrays drift out of sync as code evolves — the compiler's view is always up to date with the code it compiles.
13-
3. `useCallback` cascades: wrapping one function in `useCallback` forces every caller that depends on its identity (child components, other hooks) to also memoize. The compiler breaks this cascade.
14-
4. Inline arrow functions passed to JSX (`onClick`, `action`, etc.) are already memoized by the compiler under `'use memo'`; wrapping them is noise.
15-
5. Consistent adoption across the codebase keeps the memoization story legible — reviewers don't have to decide case-by-case whether a given `useCallback` is load-bearing or ceremonial.
14+
- Manual `useMemo` / `useCallback` dependency arrays drift out of sync as code evolves; the compiler's view is always current with the code it compiles.
15+
- `useCallback` forces every identity-sensitive caller (child components, other hooks) to also memoize. The compiler short-circuits this cascade.
16+
- Consistent adoption keeps the memoization story legible across the codebase — reviewers don't decide case-by-case whether a given `useCallback` is load-bearing or ceremonial.
1617

1718
## Rules
1819

.specs/draft-stoken-login-boundary/metadata.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@
5454
{
5555
"key": "FR-2634",
5656
"title": "[1.7] CI grep rule forbidding URL APIs in STokenLoginBoundary",
57-
"prNumber": 6854,
58-
"prUrl": "https://github.com/lablup/backend.ai-webui/pull/6854"
57+
"prNumber": null,
58+
"prUrl": null,
59+
"status": "wont-do",
60+
"note": "Closed as redundant. URL-free invariant enforced by FR-2633 test assertion."
5961
},
6062
{
6163
"key": "FR-2635",
@@ -147,5 +149,5 @@
147149
},
148150
"sourceIssues": [],
149151
"createdAt": "2026-04-21T00:00:00Z",
150-
"notes": "Epic FR-2616 filed. Spec Task FR-2618 created as sub-issue under the Epic. Spec PR #6828 resolves FR-2618. Dev plan landed on same PR stack. Story 1 implementation PRs #6850-#6856 submitted (FR-2628-FR-2634 + test). FR-2635 closed as investigation-only (comment on issue). Directory still uses draft- prefix; rename to FR-2616-stoken-login-boundary as a follow-up."
152+
"notes": "Epic FR-2616 filed. Spec Task FR-2618 created. Story 1 implementation: PRs #6850-#6853, #6855-#6857 submitted (FR-2628, FR-2629, FR-2630, FR-2631, FR-2632, FR-2633, refactor). FR-2634 closed as Not Planned (duplicate of FR-2633 test assertion). FR-2635 closed as investigation-only (Jira comment). Directory still uses draft- prefix; rename to FR-2616-stoken-login-boundary as a follow-up."
151153
}

0 commit comments

Comments
 (0)