fix(frontend): resolve set-state-in-effect in useUnsavedChanges (#1063)#1070
Merged
ericsocrat merged 1 commit intomainfrom May 1, 2026
Merged
fix(frontend): resolve set-state-in-effect in useUnsavedChanges (#1063)#1070ericsocrat merged 1 commit intomainfrom
ericsocrat merged 1 commit intomainfrom
Conversation
Replaces a useEffect that synced isDirty into both a ref and a state reset with the canonical 'adjust state during render' pattern for the state portion. The ref sync remains in its own effect (no setState involved). Behaviour is identical: when the form transitions back to clean, any pending navigation is cleared.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Bundle Size Report
✅ Bundle size is within acceptable limits. |
There was a problem hiding this comment.
Pull request overview
Updates the useUnsavedChanges hook to eliminate a react-compiler/set-state-in-effect lint violation while preserving the existing navigation-guard behavior for dirty forms.
Changes:
- Removes
setPendingHref(null)from theuseEffectthat mirrorsisDirtyinto a ref. - Introduces a render-phase “adjust state during render” pattern using
prevIsDirtyto clearpendingHrefonly when transitioning from dirty → clean. - Keeps the ref-sync effect so event handlers observe the latest
isDirtywithout capturing stale values.
This was referenced May 1, 2026
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 2 of #1063 — second of 19
react-hooks/set-state-in-effectviolations.Change
In
useUnsavedChanges, the effect that mirroredisDirtyinto a ref also resetpendingHrefwhenever the form went from dirty to clean. ThesetPendingHref(null)call inside the effect is the violation.Replaced the state-reset half with the canonical adjust-state-during-render pattern, comparing
isDirtyagainst a previous-value state. The ref-sync effect is kept (nosetStateinvolved).Behaviour is unchanged: when the form transitions back to clean, any pending navigation is cleared.
Verification
eslint src/hooks/use-unsaved-changes.ts— cleanvitest run src/hooks/use-unsaved-changes.test.ts— 15/15 passtsc --noEmit— cleanProgress