Skip to content

fix(frontend): resolve set-state-in-effect in NutritionSettingsPage (#1063)#1075

Merged
ericsocrat merged 1 commit intomainfrom
chore/react-compiler-nutrition-page
May 1, 2026
Merged

fix(frontend): resolve set-state-in-effect in NutritionSettingsPage (#1063)#1075
ericsocrat merged 1 commit intomainfrom
chore/react-compiler-nutrition-page

Conversation

@ericsocrat
Copy link
Copy Markdown
Owner

Phase 2 of #1063 - seventh PR, eighth violation of 19. Resolves src/app/app/settings/nutrition/page.tsx:48.

Change

Replaces a useEffect that synced 5 form fields (diet, allergens, strictDiet, strictAllergen, treatMayContain) from a useQuery prefs result with the React 19 'adjust state during render' pattern (https://react.dev/learn/you-might-not-need-an-effect#adjusting-some-state-when-a-prop-changes).

A prevPrefs state variable tracks the last seen query result; when the prefs reference changes, the new values are written before render completes.

The useEffect import is removed since the file no longer uses it.

Behaviour is unchanged - the form still populates after the query resolves and after refetches.

Verification

  • eslint - clean
  • vitest run src/app/app/settings/nutrition/page.test.tsx - 16/16 pass
  • tsc --noEmit - clean

Progress

…1063)

Replaces useEffect that synced 5 form fields (diet, allergens, strictDiet, strictAllergen, treatMayContain) from useQuery prefs result with React 19 'adjust state during render' pattern. A prevPrefs state tracks last seen query result; new values written before render completes when prefs identity changes. useEffect import removed as no longer used. Behaviour unchanged.
Copilot AI review requested due to automatic review settings May 1, 2026 11:17
@ericsocrat ericsocrat enabled auto-merge (squash) May 1, 2026 11:17
@vercel
Copy link
Copy Markdown

vercel Bot commented May 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
tryvit Ready Ready Preview, Comment May 1, 2026 11:18am

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

📸 PR Screenshots

Captured 2 screenshots (1 mobile, 1 desktop) for 1 changed page(s):

  • settings

📥 Download screenshots from workflow artifacts.

Captured by PR Screenshots workflow • 2026-05-01

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the Nutrition settings page to eliminate a React Compiler react-hooks/set-state-in-effect warning by replacing an effect-driven “sync query result into local form state” flow with React’s “adjust state during render” pattern.

Changes:

  • Removed useEffect usage/import and introduced a prevPrefs sentinel state to detect upstream prefs changes.
  • Hydrates 5 local form states (diet/allergens/strict flags) during render when the prefs query result reference changes.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

Bundle Size Report

Metric Value
Main baseline 0 KB
This PR 0 KB
Delta +0 KB (+0%)
JS chunks 0
Hard limit 4000 KB

✅ Bundle size is within acceptable limits.

@ericsocrat ericsocrat merged commit 0c32275 into main May 1, 2026
22 checks passed
@ericsocrat ericsocrat deleted the chore/react-compiler-nutrition-page branch May 1, 2026 11:22
ericsocrat added a commit that referenced this pull request May 1, 2026
…) (#1077)

Phase 2 of #1063 -- resolves 2 of 19 violations (running total: 12/19 across 9 PRs).

Two react-hooks/set-state-in-effect warnings in SearchAutocomplete.tsx resolved by adjusting state during render:

1. Refresh recent-searches list on dropdown open: replaced the show-dep useEffect with a prevShow render-phase tracker. Added a lazy initial-state initializer so the list is hydrated on mount when show is already true (preserves existing test contract).

2. Reset activeIndex when suggestions/query change: replaced the multi-dep useEffect with a composite resetKey + prevResetKey render-phase tracker.

Pattern: https://react.dev/learn/you-might-not-need-an-effect#adjusting-some-state-when-a-prop-changes

Behaviour unchanged. 32/32 vitest pass, eslint and tsc clean.

Cross-references: #1067, #1069, #1070, #1071, #1072, #1073, #1074, #1075, #1076.

Co-authored-by: ericsocrat <ericsocrat@users.noreply.github.com>
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.

2 participants