Skip to content

Narrow useEffect dependencies from objects to primitive properties in settings components #1008

@MODSetter

Description

@MODSetter

Description

Several useEffect hooks use whole objects (like searchSpace or preferences) as dependencies, but only access specific properties inside the effect body. This causes the effect to re-run whenever TanStack Query returns a new object reference, even if the relevant properties haven't changed.

Vercel React Best Practices Rule: rerender-dependencies (5.6)

Files to change

  • surfsense_web/components/settings/general-settings-manager.tsx
  • surfsense_web/components/settings/prompt-config-manager.tsx
  • surfsense_web/components/settings/llm-role-manager.tsx

What to do

In general-settings-manager.tsx (line 51):

The init effect uses searchSpace.name and searchSpace.description, but depends on [searchSpace]:

// Before
}, [searchSpace]);
// After
}, [searchSpace?.name, searchSpace?.description]);

In prompt-config-manager.tsx (line 43):

The init effect uses searchSpace.qna_custom_instructions, but depends on [searchSpace]:

// Before
}, [searchSpace]);
// After
}, [searchSpace?.qna_custom_instructions]);

In llm-role-manager.tsx (line 132):

The sync effect uses three specific preference IDs, but depends on [preferences]:

// Before
}, [preferences]);
// After
}, [preferences?.agent_llm_id, preferences?.document_summary_llm_id, preferences?.image_generation_config_id]);

Acceptance criteria

  • Effects only re-run when the specific properties they use actually change
  • Settings forms still initialize correctly when data loads
  • No ESLint react-hooks/exhaustive-deps warnings

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions