Skip to content

Commit 121a6fd

Browse files
committed
fix(todos): use addDismissedTodo thunk to prevent stale closure on dismiss
dismissTodo was closing over dismissedTodos from the last render. When the parent component did not re-render after the first dismiss, the second dismiss called setDismissedTodos with only the new id, overwriting the previously dismissed one and causing it to reappear stuck with the is-dismissing class.
1 parent 5fb96c4 commit 121a6fd

1 file changed

Lines changed: 2 additions & 7 deletions

File tree

  • modules/ppcp-settings/resources/js/data/todos

modules/ppcp-settings/resources/js/data/todos/hooks.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const useStoreData = () => {
3838

3939
const useHooks = () => {
4040
const { dispatch, select } = useStoreData();
41-
const { fetchTodos, setDismissedTodos, setCompletedTodos } = dispatch;
41+
const { fetchTodos, addDismissedTodo, setCompletedTodos } = dispatch;
4242

4343
// Get todos data from store
4444
const todos = select.getTodos();
@@ -47,12 +47,7 @@ const useHooks = () => {
4747

4848
const dismissedSet = new Set( dismissedTodos );
4949

50-
const dismissTodo = async ( todoId ) => {
51-
if ( ! dismissedSet.has( todoId ) ) {
52-
const newDismissedTodos = [ ...dismissedTodos, todoId ];
53-
await setDismissedTodos( newDismissedTodos );
54-
}
55-
};
50+
const dismissTodo = ( todoId ) => addDismissedTodo( todoId );
5651

5752
const setTodoCompleted = async ( todoId, isCompleted ) => {
5853
let newCompletedTodos;

0 commit comments

Comments
 (0)