Skip to content

Commit 3ace17a

Browse files
gantoineclaude
andcommitted
fix(v2): snapshot delete-dialog state before awaiting
The delete handler re-read the dialog refs (roms, platform, exclude flag) after the request resolved. Because the dialog is a singleton, a fresh showDeleteRomDialog event arriving mid-request could swap those refs, so the completed request would prune the new dialog's IDs instead of the ones it processed. Snapshot the state at entry and act on the snapshot. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 2591051 commit 3ace17a

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

frontend/src/v2/components/Dialogs/DeleteRomDialog.vue

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,27 @@ async function deleteRoms() {
7575
if (deleting.value) return;
7676
deleting.value = true;
7777
78+
// Snapshot the dialog state up front: the dialog is a singleton, so a
79+
// fresh `showDeleteRomDialog` event could replace these refs while the
80+
// request is in flight. Acting on the snapshot keeps the response tied
81+
// to the ROMs it actually processed.
82+
const targetRoms = roms.value;
83+
const targetPlatformId = platformId.value;
84+
const deleteFromFs = romsToDeleteFromFs.value;
85+
const exclude = excludeOnDelete.value;
86+
7887
try {
7988
const response = await romApi.deleteRoms({
80-
roms: roms.value,
81-
deleteFromFs: romsToDeleteFromFs.value,
89+
roms: targetRoms,
90+
deleteFromFs,
8291
});
8392
// The backend deletes per-ROM and can partially fail; only prune the
8493
// ROMs it actually removed so a failed subset stays visible and
8594
// selected for the user to retry.
8695
const failedIds = new Set(response.data.failed_ids);
87-
const deletedRoms = roms.value.filter((rom) => !failedIds.has(rom.id));
96+
const deletedRoms = targetRoms.filter((rom) => !failedIds.has(rom.id));
8897
snackbar.success(
89-
fsCount.value > 0
98+
deleteFromFs.length > 0
9099
? t("rom.deleted-from-filesystem", {
91100
count: response.data.successful_items,
92101
})
@@ -95,7 +104,7 @@ async function deleteRoms() {
95104
}),
96105
{ icon: "mdi-check-bold" },
97106
);
98-
if (excludeOnDelete.value) {
107+
if (exclude) {
99108
for (const rom of deletedRoms) {
100109
const type = rom.has_simple_single_file
101110
? "EXCLUDED_SINGLE_FILES"
@@ -131,7 +140,7 @@ async function deleteRoms() {
131140
if (route.name === "rom" && deletedRoms.length > 0) {
132141
router.push({
133142
name: ROUTES.PLATFORM,
134-
params: { platform: platformId.value },
143+
params: { platform: targetPlatformId },
135144
});
136145
}
137146
} catch (error: unknown) {

0 commit comments

Comments
 (0)