generated from cording12/next-fast-turbo
-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Labels
bugSomething isn't workingSomething isn't workingfrontendgood first issueGood for newcomersGood for newcomers
Description
Description
In use-search-source-connectors.ts, the createConnector, updateConnector, deleteConnector, and indexConnector functions all close over the connectors state variable. Since these are async functions that await network requests, if two operations run concurrently the second will use a stale snapshot of connectors, potentially losing the first operation's update.
Vercel React Best Practices Rule: rerender-functional-setstate (5.9)
File to change
surfsense_web/hooks/use-search-source-connectors.ts
What to do
Replace each direct state reference with a functional updater:
createConnector (lines 187-190):
const newConnector = await response.json();
setConnectors(prev => {
const updated = [...prev, newConnector];
updateConnectorSourceItems(updated);
return updated;
});
return newConnector;updateConnector (lines 221-226):
const updatedConnector = await response.json();
setConnectors(prev => {
const updated = prev.map(c => c.id === connectorId ? updatedConnector : c);
updateConnectorSourceItems(updated);
return updated;
});
return updatedConnector;deleteConnector (lines 251-253):
setConnectors(prev => {
const updated = prev.filter(c => c.id !== connectorId);
updateConnectorSourceItems(updated);
return updated;
});indexConnector (lines 297-306):
setConnectors(prev =>
prev.map(c => c.id === connectorId
? { ...c, last_indexed_at: new Date().toISOString() }
: c
)
);Acceptance criteria
- No function in the hook directly references
connectorsstate variable (only usesprevinside the updater) - Creating, updating, deleting, and indexing connectors still work correctly
- Rapid sequential operations (e.g., delete two connectors quickly) don't lose data
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingfrontendgood first issueGood for newcomersGood for newcomers