Issue 193
tech-debt: Fix the 9 places that break the React Compiler lint rules, then turn them on
Back to our planOpen
frontendtech-debtpriority: medium
Type
tech-debt
Summary
Next 16's ESLint config adds three React rules: react-hooks/set-state-in-effect, react-hooks/refs and react-hooks/purity. They come from eslint-plugin-react-hooks 7, the React Compiler rules. Nine places in today's code break them. The Next 16 upgrade (#120) turns the three rules off so it stays a pure upgrade. This issue fixes those nine places and turns the rules back on as errors.
Problem
The nine places:
| File | Line | Rule |
|---|---|---|
src/Header/Component.client.tsx | 36, 41 | set-state-in-effect |
src/blocks/Form/Component.tsx | 174 | refs |
src/components/Card/index.tsx | 49, 98 | refs |
src/components/VersionCheck/index.tsx | 14 | purity (Date.now during render) |
src/components/VersionCheck/index.tsx | 77 | set-state-in-effect |
src/providers/Theme/ThemeSelector/index.tsx | 33 | set-state-in-effect |
src/providers/Theme/index.tsx | 38 | set-state-in-effect |
Setting state directly in an effect causes an extra render. Reading refs or calling Date.now during render makes the output unpredictable. See https://react.dev/learn/you-might-not-need-an-effect, opens in a new tab.
Proposed fix
- Fix each place the way the rule suggests:
- derive the value during render, or use a lazy
useStateinitializer; - read refs in effects or event handlers only;
- move
Date.nowinto an effect or an event.
- derive the value during render, or use a lazy
- Turn the three rules back on in
eslint.config.mjs(remove theofflines added by #120). - Run a visual check of the header, theme selector, cards and forms. These components render on every page.
Acceptance criteria
- Not done:
npx eslint .reports none of the three rules, with them set toerror. - Not done: The header, theme switch, cards, form and version check behave as before, checked at 375 and 1280 px in light and dark.
Depends on
#120 (Next 16).
Area
frontend
Priority
priority: medium
Generated by Claude Code, opens in a new tab