Summary
The AgentDashboardPanel component has a few optimization opportunities, including a bug where editForm state doesn't sync when the site prop changes.
File: frontend/src/pages/AgentDashboardPanel.tsx
Issues
1. Bug: editForm doesn't sync when site prop updates
If the site prop changes while not in editing mode, editForm retains stale values from the initial render. This could cause the user to save outdated config if they click Edit after the site data updates.
Current:
const [editForm, setEditForm] = useState({
autonomy_level: site.autonomy_level ?? 'readonly',
cache_policy: site.cache_policy ?? 'minimal',
conflict_resolution: site.conflict_resolution ?? 'central_wins',
})
Fix:
useEffect(() => {
if (!editing) {
setEditForm({
autonomy_level: site.autonomy_level ?? 'readonly',
cache_policy: site.cache_policy ?? 'minimal',
conflict_resolution: site.conflict_resolution ?? 'central_wins',
})
}
}, [site, editing])
2. Optimization: Lazy state initialization
Avoid creating object on every initial render:
const [editForm, setEditForm] = useState(() => ({
autonomy_level: site.autonomy_level ?? 'readonly',
// ...
}))
3. Optional: memo wrapper
If parent re-renders frequently, wrap component with memo:
export const AgentDashboardPanel = memo(function AgentDashboardPanel({ site, health }) {
// ...
})
Priority
Summary
The
AgentDashboardPanelcomponent has a few optimization opportunities, including a bug whereeditFormstate doesn't sync when thesiteprop changes.File:
frontend/src/pages/AgentDashboardPanel.tsxIssues
1. Bug: editForm doesn't sync when site prop updates
If the
siteprop changes while not in editing mode,editFormretains stale values from the initial render. This could cause the user to save outdated config if they click Edit after the site data updates.Current:
Fix:
2. Optimization: Lazy state initialization
Avoid creating object on every initial render:
3. Optional: memo wrapper
If parent re-renders frequently, wrap component with
memo:Priority