fix(hitl-edit-panel): move duplicate-tag check into functional setTags (#1248)#1281
Conversation
Fixes MODSetter#1248 handleAddTag had tags in its useCallback dependency array only so the closure-level duplicate check could read it, which forced the callback to re-create on every tag mutation and compared new additions against a potentially-stale closure value. Collapse the duplicate check into the functional setTags updater so the check always runs against the latest state, and drop tags from the dependency array - the callback is stable for the component's lifetime and downstream memoization won't get invalidated on every keystroke.
|
@mvanhorn is attempting to deploy a commit to the Rohan Verma's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Review by RecurseML
🔍 Review performed on 3f30b12..7f0a5cd
✨ No bugs found, your code is sparkling clean
✅ Files analyzed, no issues (1)
• surfsense_web/components/hitl-edit-panel/hitl-edit-panel.tsx
|
Thanks for the merge, @MODSetter. Functional setTags is the right home for that check. |
Summary
Fixes #1248
handleAddTaginEmailsTagField(surfsense_web/components/hitl-edit-panel/hitl-edit-panel.tsx) listedtagsin itsuseCallbackdependency array only so the closure-level duplicate check could read it. That had two side effects the issue calls out:tags, not the latest state, so rapid adds could race.Change
Move the duplicate check inside the functional
setTagsupdater so it always sees the latest state, and droptagsfrom the dependency array. The callback is now stable for the component's lifetime.Testing
pnpm biome check components/hitl-edit-panel/hitl-edit-panel.tsx- cleanpnpm biome lint components/hitl-edit-panel/hitl-edit-panel.tsx- cleanPre-existing tsc errors in
app/(home)/blog/[slug]/page.tsxare unrelated to this change.High-level PR Summary
This PR fixes a React hooks optimization issue in the
EmailsTagFieldcomponent by moving the duplicate-tag check from the closure scope into the functional state updater. This eliminates unnecessary callback re-creation on every tag mutation and prevents race conditions when adding tags rapidly, ensuring the duplicate check always sees the latest state while maintaining a stable callback reference.⏱️ Estimated Review Time: 5-15 minutes
💡 Review Order Suggestion
surfsense_web/components/hitl-edit-panel/hitl-edit-panel.tsx