effect-antipattern-scan
Review PR diffs that add or modify `useEffect` for the systemic React effect antipatterns
- License 许可
- MIT
- 最近更新
- 2026-11-15
- Stars
- ★ 81
- Forks
- 17
01 前言 Front Matter
- name
- effect-antipattern-scan
- maturity
- experimental
- description
- Review PR diffs that add or modify `useEffect` for the systemic React effect antipatterns
02 资源文件 5
- 许可证LICENSE1.0 KB
- 参考文档repos/metamask-extension.md894 B
- 参考文档repos/metamask-mobile.md1012 B
- 参考文档SOURCE.md378 B
- 参考文档TRUST.auto.yaml2.1 KB
03 SKILL.md 正文
Effect Anti-Pattern Review
Scope: Pre-merge review of PRs that add or modify useEffect calls. The workflow is a grep-driven checklist against the patterns catalogued in the effect-antipatterns knowledge file, which is the single source for their definitions and fixes (installed alongside this skill under knowledge/).
Applies to both metamask-extension and metamask-mobile. See overlays for repo-specific paths.
When To Use
- Reviewing a PR that adds or modifies a
useEffectcall - Reviewing a PR that adds
setInterval,setTimeout,fetch, oraddEventListenerinside a component - Investigating a "Can't perform a React state update on an unmounted component" warning
Do Not Use When
- Reviewing selector or render-cascade issues (use
selector-antipattern-scan) - Reviewing non-React code (background scripts, workers, test utilities)
- Reviewing an effect that is intentionally one-shot with no async work or timers (check patterns below anyway, but most do not apply)
Workflow
- List changed files with
useEffect.git diff --name-only origin/main...HEAD | xargs grep -l 'useEffect' - Run the grep checklist against the changed files.
- For each hit, map to a pattern in
effect-antipatternsand apply the fix from the knowledge file. - Block on unstable dependency identity, unless it is a
JSON.stringifyon a cold path with a small object. Do not merge otherwise. - Block on a timer without cleanup. Any
setInterval/setTimeoutwithout a matchingclearInterval/clearTimeoutin the cleanup function is blocking. - Require cancellation for async effects. Any
fetch/ network call insideuseEffectmust guard against a stale response, with a cancelled flag orAbortController.
Grep Checklist
Pattern (effect-antipatterns §) |
Detection |
|---|---|
| §1 Unstable dependency identity | grep -rnE 'useEffect.*\[.*JSON\.stringify' <source-dir>, plus inline {/[ literals in the dep position |
| §2 Wrong dependencies | Hand review — empty deps that read state (stale closure), deps that read nothing, or an effect dependency the effect never reads |
| §3 Derived state via effect + setState | Hand review — useEffect that calls setX from other state/props; §3a for chains of them |
| §4 Missing timer cleanup | grep -rnE 'setInterval|setTimeout' <source-dir> then check each effect returns a cleanup |
| §5 Uncancelled async work | grep -rnB2 -A10 'fetch\(' <source-dir> within useEffect blocks |
See the repo overlay for the concrete <source-dir> path.
Common Pitfalls
| Mistake | Correct approach |
|---|---|
Accept JSON.stringify in deps because "the effect needs to rerun when X changes" |
Destructure to primitives or useMemo the object on a hot path. A cold path with a small object can stringify |
| Accept a state-mirror effect because "the computation is expensive" | Use useMemo for expensive derivations. Effects are for side effects, not state derivation |
Let setInterval ship without cleanup because "the component rarely unmounts" |
Cleanup is non-negotiable — unmount frequency doesn't matter, correctness does |
| Treat "can't perform state update on unmounted component" as a cosmetic warning | It is a data race. An old response can overwrite a new one |
Add a lint rule disable on react-hooks/exhaustive-deps |
Almost always wrong. Destructure or memoize instead |
Refactor toward useEffect + setState because it "feels like state" |
You probably do not need an effect. See You Might Not Need an Effect |
04 同仓库更多 Skills
troves
Deposit and withdraw from Troves DeFi yield vault strategies on Starknet. View available strategies, check positions, and manage vault deposits. Use this skill when the user mentions Troves, vault, yield vault, DeFi vault, strategy, yield farming, vault deposit, vault withdraw, earning yield through vaults, passive yield strategies, or wants to deposit into or withdraw from a yield strategy — even if they don't say "Troves" explicitly.
trade
Swap tokens on Starknet via Fibrous DEX aggregator. Supports per-provider selection (avnu, ekubo, or auto to race all). Use this skill when the user wants to swap, exchange, trade, convert, buy, or sell one token for another on Starknet. Also use when the user asks about token prices, exchange rates, DEX routing, best swap route, or wants to check how much they would receive for a given amount — even if they don't explicitly say "swap".
staking
Stake, unstake, claim, and compound rewards for STRK, WBTC, tBTC, SolvBTC, and LBTC on Starknet. View validators, pools, and staking positions. Use this skill when the user mentions staking, delegating, validators, staking pools, rewards, compounding, unstaking, earning yield, passive income on crypto, or wants to earn on their STRK or BTC tokens — even if they don't say "stake" explicitly.
send
Send STRK, ETH, or any ERC-20 token to a Starknet address. Supports simulation (dry-run) before execution. Use this skill when the user wants to send, transfer, pay, tip, or move tokens to another wallet address on Starknet. Also trigger when the user mentions sending funds to someone, making a payment, transferring assets, or moving crypto to a specific address — even if they just say "pay 10 STRK to 0x...".
portfolio
View a comprehensive DeFi portfolio dashboard and optimize portfolio allocation via automated rebalancing. Use this skill when the user wants an overview, summary, dashboard, total value, net worth, portfolio rebalancing, target allocation, or wants to see all their DeFi positions across Starknet at once. Also trigger when the user asks "what do I have", "show me everything", "how much am I worth", "my positions", "my investments", "rebalance my portfolio", "I want 50% ETH", "optimize my holdings", or any request for a holistic view of their Starknet holdings — even if they don't explicitly say "portfolio".
multi-swap
Execute multiple token swaps in a single Starknet transaction via Fibrous (default). Supports per-provider selection (avnu, ekubo, or auto to race all). Supports 2-3 swap pairs bundled into one multicall. Use this skill when the user wants to swap multiple token pairs at once, do batch swaps, execute several trades simultaneously, perform parallel swaps, or do bulk trading in one transaction. Also trigger when the user mentions "two swaps", "three swaps", "swap X and Y at the same time", or wants to convert multiple tokens in a single call.