Hello SonarQube team,
I’d like to propose deprecating rule typescript:S6481
(which warns that:
“The
value
object passed as thevalue
prop to the Context provider changes every render. To fix this consider wrapping it in auseMemo
hook.”)
Background
When this rule was introduced, it helped catch anti‑patterns where inline object literals would cause every consumer of a React Context to re‑render on each parent render. Wrapping the value
prop in a useMemo
was the recommended workaround.
Why it’s no longer needed
As of React 18 (and the new “React Compiler” / automatic JSX runtime), the build step now performs sufficient static analysis such that:
- Inline object literals passed to
<Context.Provider>
are automatically hoisted or otherwise recognized as stable values when they have no dynamic dependencies. - In practice, this means developers no longer need to sprinkle
useMemo
around every context provider to avoid spurious re‑renders. - Over‑eager enforcement of
useMemo
can actually harm readability without delivering any meaningful performance gain in modern React apps.
Proposal
- Mark
typescript:S6481
as deprecated in the next SonarQube TypeScript plugin release. - Remove it from the default “bug” or “perf” rule sets.
- (Optionally) Replace it with a lightweight advisory note, e.g. “If you’re targeting React <18 or not using the automatic compiler, consider memoizing complex
value
objects.”
Deprecating this rule will reduce noise in codebases that have already migrated to React 18+ and are leveraging the new compiler optimizations. Please let me know if you need any additional details or examples!
Thanks for your consideration,