Replies: 3 comments
-
|
I prefer Biome's take on this because redundant dependencies obscure dependecies that actually matter, so they hinder understanding dynamics of hook, which is sometimes really tricky to get right. I would prefer to eliminate all useless dependencies. I disliked about the official rule that it doesn't care whether a redundant dependency is included or not instead of teaching people that setState and dispatch don't change. Some juniors don't know this, and it's a useful thing to know. But I understand wanting to align Biome with the official rule. |
Beta Was this translation helpful? Give feedback.
-
|
I voted for creating an option for this, and I would suggest the default behaviour to stay as it is. This way, it's not a breaking change for Biome users, we also improve the situation for new users that prefer strictness/tidyness (as we do today), yet we also give users that really want to cling to ESLint's way of doing things the option to disable the behaviour. |
Beta Was this translation helpful? Give feedback.
-
|
Correct me if I'm wrong here but |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Biome's
useExhaustiveDependenciescurrently reports a diagnostic when a "stable" value (e.g. auseStatesetter or auseRefresult) is included in a hook's dependency array. The official ESLintreact-hooks/exhaustive-depsrule does not report this — it silently accepts stable values in the dependency array. This RFC proposes aligning Biome's behavior with the ESLint rule by no longer treating the presence of stable dependencies as a diagnostic-worthy issue.Motivation
Current behavior comparison
exhaustive-depsuseExhaustiveDependenciessetState) included in arrayThe inconsistency
When a developer writes:
Biome flags
setNameas an unnecessary dependency and suggests removing it. The ESLintreact-hooks/exhaustive-depsrule, however, does not report this. It recognizessetNameas stable and simply doesn't require it — but it also doesn't complain if the developer chooses to include it.Why the ESLint behavior is more correct
Including stable dependencies is not wrong. React's documentation states that stable values like
useStatesetters,useReducerdispatch, anduseRefrefs maintain the same identity across renders. Including them in the dependency array is harmless — it doesn't cause unnecessary re-renders or stale closures. It's simply redundant.It's a matter of developer intent and code style. Some developers and teams prefer to explicitly list all values used inside the callback, including stable ones, for readability and to make dependencies self-documenting. Others prefer a minimal array. Neither approach is incorrect.
The current diagnostic is misleading. Biome's message says "Specifying more dependencies than required can lead to unnecessary re-rendering and degraded performance" — but this is not true for stable dependencies. Since their identity never changes, including them has zero performance impact. The diagnostic implies a problem that doesn't exist.
It creates friction when migrating from ESLint. Users migrating from ESLint to Biome encounter new diagnostics on code that was previously considered valid. This is a common pain point reported by the community (see #630).
The official ESLint rule is the de facto standard. The
eslint-plugin-react-hookspackage is maintained by the React team itself. Aligning with its behavior reduces surprise and increases trust in Biome as a drop-in replacement.What "stable" means
Both Biome and the ESLint rule understand the concept of stable return values. The ESLint rule knows that certain hooks produce values that never change:
useStatesetter (second element)useReducerdispatch (second element)useRefreturn valueuseTransitionstartTransition(second element)Biome has the same built-in knowledge and also allows configuring custom hooks via the
stableResultoption. The difference is only in what happens when a stable value appears in the dependency array.Proposal
Stop emitting a diagnostic when a known-stable dependency is included in the dependency array.
Specifically:
setNameas unnecessary in[name, setName]whensetNamecomes fromuseState.refas unnecessary in[ref]whenrefcomes fromuseRef.stableResulthook option.Biome should continue to report:
the team prefers a more conservative approach, an alternative would be to change the default of
reportUnnecessaryDependenciestofalse— but this would also suppress diagnostics for genuinely unused dependencies, which is less desirable.Alternatives considered
1. Add a separate option for stable dependency reporting
A new option like
reportStableDependencies: false(defaulting tofalse) could be introduced. This is viable but adds configuration surface for what is arguably just a bug fix in alignment with the upstream rule.2. Keep current behavior
The current behavior is intentional and could be seen as a stricter, more opinionated stance: if a dependency is known to never change, listing it is noise. Teams that prefer minimal dependency arrays may actually appreciate this diagnostic. Biome doesn't have to match ESLint 1:1 on every decision — it's a separate tool with its own philosophy.
3. Split into two rules (that can be too complicated to maintain)
Issue #630 proposed splitting
useExhaustiveDependenciesinto two separate rules: one for missing dependencies and one for unnecessary dependencies. While this would give users more granular control, it adds a lot of complexity.Migration / breaking change considerations
This is a diagnostic reduction — code that currently triggers a warning would no longer trigger one. No previously-valid code would start being flagged. This means:
--error-on-warningswould see fewer failures, not more.biome-ignorecomments for stable dependency warnings would become unnecessary (but harmless).reportUnnecessaryDependenciesoption would remain useful for controlling diagnostics about genuinely unused dependencies.This could be considered a minor behavioral change suitable for a patch or minor release, not a breaking change.
References
useExhaustiveDependenciesdocumentationreact-hooks/exhaustive-depsdocumentationuseExhaustiveDependenciesinto two rulesreportUnnecessaryDependencies)49 votes ·
Beta Was this translation helpful? Give feedback.
All reactions