Skip to content

fix: resolve react-hooks lint warnings — exhaustive-deps and React Compiler (#159 #160)#161

Merged
ChristopherRotnes merged 1 commit intomasterfrom
fix/lint-159-160
May 10, 2026
Merged

fix: resolve react-hooks lint warnings — exhaustive-deps and React Compiler (#159 #160)#161
ChristopherRotnes merged 1 commit intomasterfrom
fix/lint-159-160

Conversation

@ChristopherRotnes
Copy link
Copy Markdown
Owner

@ChristopherRotnes ChristopherRotnes commented May 10, 2026

Summary

Changes per file

File What changed
History.jsx loadSession moved before its mount effect (fixes forward-reference); initialDate captured in a ref so the empty-dep array is correct; auto-expand logic moved into loadSession (sets expandedIds right after setDaySessions) — eliminates a cascading setState
MuscleMap.jsx setUseTodayDate effect removed; call added at the two dispatch sites that enter confirm (ANALYZE_SUCCESS in analyze() and the template-preload effect); onTemplatePreloadConsumed dep suppressed with comment
Report.jsx Cache-lookup useEffect relocated below muscleCounts / sessionCount / untrainedMuscles declarations — fixes three "variable accessed before declaration" warnings; onPrefillConsumed dep suppressed (mount-only callback); setLoading(true) suppressed (standard pre-async loading-state init)
Home.jsx weekStripRef.current removed from JSX render path; maxLeft now stored in tooltip state when set by event handlers (onMouseEnter, onFocus)
Bibliotek.jsx setExVisible(20) suppressed — standard "reset pagination on filter change" pattern
Planlegger.jsx loadPlan() suppressed — async data fetch; setState happens inside async callbacks, not synchronously

Test plan

This PR touches hook execution order and setState timing in History, MuscleMap, Report, Home, Bibliotek, and Planlegger. The logic is unchanged — the refactors move setState calls to equivalent points in the render cycle. Verify the following golden paths on the SWA preview:

  • Upload flow: photograph a whiteboard → confirm step auto-resets date to today → save session
  • Template use flow: pick a template via Planlegger or Bibliotek → confirm step opens with today's date pre-selected
  • History: click a date with one session → session auto-expands; click a date with multiple sessions → none auto-expand
  • History: navigate from Home weekly strip to a date → correct date pre-selected
  • Report: change period filter → loading spinner appears then results update; cache-restored recs appear on mount
  • Report: navigate from History with a prefill (weekday/session type) → filters applied on mount
  • Home: hover a day bar with sessions → tooltip appears clamped within the strip; no console errors
  • Bibliotek: type in exercise search → visible list resets to 20 items
  • Planlegger: navigate between weeks → plan loads correctly for each week

🤖 Generated with Claude Code

…ings (#159 #160)

Real refactors (no eslint-disable):
- History: move auto-expand out of useEffect into loadSession, eliminating a
  cascading setState; capture initialDate in a ref for mount-only effect
- MuscleMap: move setUseTodayDate(true) to the two dispatch sites (ANALYZE_SUCCESS
  and template preload) that enter the confirm step; removes the step-watching effect
- Report: relocate cache-lookup useEffect below the useMemo declarations it reads
  (muscleCounts, sessionCount, untrainedMuscles), fixing forward-reference warnings
- Home: store maxLeft in tooltip state at event-handler time instead of reading
  weekStripRef.current during render

Targeted eslint-disable (with justification comments) for patterns that are
correct but unfixable without large refactors:
- Bibliotek: setExVisible(20) reset on filter change (standard pagination pattern)
- Planlegger: loadPlan() in useEffect (async data fetch, setState in callbacks only)
- Report: setLoading(true) before async fetch (standard loading-state init)
- MuscleMap: setUseTodayDate in template preload effect
- MuscleMap/Report: intentionally excluded callback deps (onTemplatePreloadConsumed,
  onPrefillConsumed) to prevent infinite re-runs

npm run lint: 0 in-scope warnings (9 react-refresh/only-export-components remain,
intentional multi-export architecture per issue scope)
npm test: 82/82 passing

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

Azure Static Web Apps: Your stage site is ready! Visit it here: https://white-island-090dfd003-161.westeurope.7.azurestaticapps.net

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant