AGENT SKILL

effect-antipattern-scan

Review PR diffs that add or modify `useEffect` for the systemic React effect antipatterns

License 许可
MIT
所属仓库
MetaMask/skills
最近更新
2026-11-14
Stars
★ 25
Forks
11

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 资源文件 2

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 useEffect call
  • Reviewing a PR that adds setInterval, setTimeout, fetch, or addEventListener inside 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

  1. List changed files with useEffect. git diff --name-only origin/main...HEAD | xargs grep -l 'useEffect'
  2. Run the grep checklist against the changed files.
  3. For each hit, map to a pattern in effect-antipatterns and apply the fix from the knowledge file.
  4. Block on unstable dependency identity, unless it is a JSON.stringify on a cold path with a small object. Do not merge otherwise.
  5. Block on a timer without cleanup. Any setInterval / setTimeout without a matching clearInterval / clearTimeout in the cleanup function is blocking.
  6. Require cancellation for async effects. Any fetch / network call inside useEffect must guard against a stale response, with a cancelled flag or AbortController.

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

MetaMask
MetaMask/skills

recipe-plan-and-dispatch

Plan a ticket with the engineer before a recipe fix-bug or dev run. Agree the acceptance criteria and an implementation plan, write it as an approved plan file, and print the prompt that starts the run with any agent and model. Never edits product code or starts the run.

★ 25
MetaMask
MetaMask/skills

recipe-library-audit

Run every recipe of a team recipe library on one client with mm-harness, classify each result with the failing node and exact error, and review naming and composability. Produces a per-client table; changes nothing.

★ 25
MetaMask
MetaMask/skills

recipe-performance

Diagnose a specific MetaMask user flow's real-app performance and Sentry critical-user-flow telemetry with deterministic mm-harness recipes. Use for CUF boundaries, cold/warm/background-resume behavior, latency regressions, lifecycle tags, duplicate or blocking network requests, long tasks, layout/paint cost, screen redraws, React rerenders, or browser trace analysis where tests alone cannot prove the real app.

★ 25
MetaMask
MetaMask/skills

x402-payments

Build x402 payment flows using MetaMask Smart Accounts Kit, machine to machine payments over HTTP with ERC-7710 delegations and ERC-7715 Advanced Permissions

★ 25
MetaMask
MetaMask/skills

smart-accounts-kit

Build dApps with MetaMask Smart Accounts Kit — ERC-4337 smart accounts, delegations, and Advanced Permissions (ERC-7715)

★ 25
MetaMask
MetaMask/skills

oh-my-opencode

Multi-agent orchestration plugin for OpenCode. Use when the user wants to install, configure, or operate oh-my-opencode — including agent delegation, ultrawork mode, Prometheus planning, background tasks, category-based task routing, model resolution, tmux integration, or any oh-my-opencode feature. Covers installation, configuration, all agents (Sisyphus, Oracle, Librarian, Explore, Atlas, Prometheus, Metis, Momus), all categories, slash commands, hooks, skills, MCPs, and troubleshooting.

★ 25