[Suggestion]: Runtime Development Warning for Stale Closures in useEffect, useCallback, and useMemo
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 11.8k
- Forks
- 7.9k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 11
Description
Summary
Make the waring for Stale Closures in useEffect, useCallback, and useMemo more detailed
Page
No response
Details
React hooks that accept dependency arrays (useEffect, useCallback, useMemo) rely on developers to manually list all reactive values that the hook's closure depends on. When a value is omitted from the dependencies array, the hook's closure continues to reference an outdated value from a previous render—a "stale closure". This leads to subtle, difficult‑to‑debug bugs such as:
Event handlers or effects reading old state/props.
Effects that should run on state changes never re‑executing.
Callbacks that always operate on stale data.
Currently, the eslint-plugin-react-hooks provides a static analysis rule (exhaustive‑deps) that warns about missing dependencies. However, this rule:
Cannot catch all cases (e.g., dynamic values, complex control flow, or custom hooks that obscure dependencies).
Only runs at lint time; developers may ignore or disable the warning.
Does not warn about actual runtime behavior—it cannot tell if a stale closure actually read an outdated value during a particular render.
As a result, developers often spend hours chasing down stale‑closure bugs, especially in larger codebases or when integrating third‑party hooks.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Begin with the behavior described for useEffect, useCallback, and useMemo, and compare it with eslint-plugin-react-hooks' exhaustive-deps rule. Define a concrete runtime-warning scope and acceptance cases for omitted dependencies, dynamic values, and custom hooks; the issue is done when the warning behavior and validation approach are specified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- eslint, javascript, react
- Domain
- developer-experience, frontend, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100