Deprecate Rule typescript:S6481 (“unstable Context value object”) now that React has a compiler

Hello SonarQube team,

I’d like to propose deprecating rule typescript:S6481 (which warns that:

“The value object passed as the value prop to the Context provider changes every render. To fix this consider wrapping it in a useMemo 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

  1. Mark typescript:S6481 as deprecated in the next SonarQube TypeScript plugin release.
  2. Remove it from the default “bug” or “perf” rule sets.
  3. (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,

1 Like

Hello @Jan078,

thanks for your feedback and all the detailed explanation. I agree this rule needs to be adapted, but not sure about deprecating it unless the majority of codebases have migrated to React 18+ and using RC. However I agree that in the meantime the rule message needs to be adapted, probably even suggesting disabling the rule if React Compiler is being used.

I created a ticket to handle this.

Thanks again!
Victor