Skip to content

Commit 6bbaaed

Browse files
fix(ui): image selected twice on invocation complete
Selecting a board selects the image, and then we were selecting it again afterwards. So we programmatically select the newly generated image twice. This can cause a race condition if the user changes image selection between when the two programmatic image selection actions. Their selection will be quickly overridden by the second programmatic selection action.
1 parent de809ec commit 6bbaaed

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

invokeai/frontend/web/src/services/events/onInvocationComplete.tsx

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export const buildOnInvocationComplete = (getState: () => RootState, dispatch: A
3434
// update the total images for the board
3535
dispatch(
3636
boardsApi.util.updateQueryData('getBoardImagesTotal', imageDTO.board_id ?? 'none', (draft) => {
37-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
3837
draft.total += 1;
3938
})
4039
);
@@ -52,36 +51,33 @@ export const buildOnInvocationComplete = (getState: () => RootState, dispatch: A
5251
])
5352
);
5453

55-
const { shouldAutoSwitch, galleryView, selectedBoardId } = getState().gallery;
54+
const { shouldAutoSwitch, selectedBoardId } = getState().gallery;
5655

5756
// If auto-switch is enabled, select the new image
5857
if (shouldAutoSwitch) {
59-
// if auto-add is enabled, switch the gallery view and board if needed as the image comes in
60-
if (galleryView !== 'images') {
61-
dispatch(galleryViewChanged('images'));
62-
}
63-
58+
// If the image is from a different board, switch to that board - this will also select the image
6459
if (imageDTO.board_id && imageDTO.board_id !== selectedBoardId) {
6560
dispatch(
6661
boardIdSelected({
6762
boardId: imageDTO.board_id,
6863
selectedImageName: imageDTO.image_name,
6964
})
7065
);
71-
}
72-
73-
dispatch(offsetChanged({ offset: 0 }));
74-
75-
if (!imageDTO.board_id && selectedBoardId !== 'none') {
66+
} else if (!imageDTO.board_id && selectedBoardId !== 'none') {
7667
dispatch(
7768
boardIdSelected({
7869
boardId: 'none',
7970
selectedImageName: imageDTO.image_name,
8071
})
8172
);
73+
} else {
74+
// Else just select the image
75+
dispatch(imageSelected(imageDTO));
8276
}
8377

84-
dispatch(imageSelected(imageDTO));
78+
// We also need to update the gallery view to images and reset the offset to 0
79+
dispatch(galleryViewChanged('images'));
80+
dispatch(offsetChanged({ offset: 0 }));
8581
}
8682
};
8783

0 commit comments

Comments
 (0)