Skip to content

fix(dialogs): move open-reset effects into onOpenChange handlers#1268

Merged
MODSetter merged 1 commit intoMODSetter:devfrom
aaron-seq:fix/move-open-reset-effects-to-onOpenChange
Apr 21, 2026
Merged

fix(dialogs): move open-reset effects into onOpenChange handlers#1268
MODSetter merged 1 commit intoMODSetter:devfrom
aaron-seq:fix/move-open-reset-effects-to-onOpenChange

Conversation

@aaron-seq
Copy link
Copy Markdown

@aaron-seq aaron-seq commented Apr 19, 2026

Fixes #1251

Problem

Three components used useEffect(() => { if (open) {...} }, [open]) to reset form state and focus inputs when dialogs/popovers open. Per React's "you might not need an effect" guidance, logic triggered by a user action belongs in the event handler, not a useEffect.

Changes

Replaced the useEffect block in each file with a handleOpenChange = useCallback(...) wrapper that resets state when next === true, then forwards to the parent's onOpenChange/setOpen:

  • CreateFolderDialog.tsx — clears folder name input + focuses it
  • FolderPickerDialog.tsx — resets selected folder + collapsed state
  • free-model-selector.tsx — clears search query + resets focus index + focuses search input

Removed useEffect from the React import in the two files that no longer use it. The model-fetch useEffect in free-model-selector.tsx is preserved.

What is NOT changed

  • No behavioral changes — fields still clear on open, focus still moves, dialogs still close on submit/cancel
  • No new dependencies
  • No other files modified
  • The nested button in FolderPickerDialog is intentionally left as-is (out of scope)

How to verify

  1. pnpm build — passes with no TypeScript errors
  2. Open each dialog/popover in the app:
    • Create Folder dialog: name input should be empty and focused on open
    • Folder Picker dialog: selection and expansion should reset on open
    • Free model selector: search should be empty and focused on open

High-level PR Summary

This PR refactors three dialog components to follow React best practices by moving state reset and focus logic from useEffect hooks into onOpenChange event handlers. When dialogs open, the same initialization behavior (clearing input fields, resetting selection state, and focusing inputs) now happens directly in response to the user action rather than as a side effect of the open state changing.

⏱️ Estimated Review Time: 5-15 minutes

💡 Review Order Suggestion
Order File Path
1 surfsense_web/components/documents/CreateFolderDialog.tsx
2 surfsense_web/components/documents/FolderPickerDialog.tsx
3 surfsense_web/components/free-chat/free-model-selector.tsx

Need help? Join our Discord

Analyze latest changes

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 19, 2026

Someone 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.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 19, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f8c5c554-14a0-4568-b9bd-0489e1bd81a5

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@recurseml recurseml Bot left a comment

Choose a reason for hiding this comment

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

Review by RecurseML

🔍 Review performed on 2b2453e..2d4adce

✨ No bugs found, your code is sparkling clean

✅ Files analyzed, no issues (3)

surfsense_web/components/documents/CreateFolderDialog.tsx
surfsense_web/components/documents/FolderPickerDialog.tsx
surfsense_web/components/free-chat/free-model-selector.tsx

@MODSetter MODSetter merged commit 6bd4ffb into MODSetter:dev Apr 21, 2026
2 of 3 checks passed
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