fix: remove optimistic UI updates in external actions to prevent race condition (#4711)

When adding/deleting external actions, the UI would sometimes show
duplicated or cloned rows due to a race condition between:
1. The optimistic setActions() call updating local state
2. The save() callback updating externalActions in context
3. The useEffect syncing actions from externalActions

This fix removes the optimistic updates and lets the server response
be the single source of truth, updating the UI only after the context
is updated via the save() success callback.

Fixes #4347
This commit is contained in:
John Costa
2026-01-17 14:44:33 -08:00
committed by GitHub
parent 9f169ce96e
commit 1cdbde58f5
+7 -3
View File
@@ -274,8 +274,10 @@ const Actions = () => {
actionsData.splice(index, 1);
try {
setActions(actionsData);
save(actionsData);
// Don't optimistically update local state - let the server response
// update externalActions in context, which will then update actions
// via useEffect. This prevents race conditions causing visual glitches.
await save(actionsData);
} catch (error) {
console.error(error);
}
@@ -312,7 +314,9 @@ const Actions = () => {
actionsData.push(newAction);
}
setActions(actionsData);
// Don't optimistically update local state - let the server response
// update externalActions in context, which will then update actions
// via useEffect. This prevents race conditions causing visual glitches.
await save(actionsData);
} catch (error) {
console.error(error);