fix: guard SiblingBadge against missing sibling_roms

The `scan:scanning_rom` socket emit strips `sibling_roms` from the rom
payload, so a freshly-scanned rom can reach SiblingBadge with the field
undefined (despite the schema typing it as required). Reading
`.length`/`.map` then threw `TypeError: Cannot read properties of
undefined (reading 'length')`, crashing the gallery during a scan while
"Group ROMs" was enabled.

Default `sibling_roms` to an empty list (a `siblings` computed). REST
payloads always include it (possibly empty), so only the socket path was
affected.

Closes #3567

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
androosio
2026-06-21 14:48:55 +02:00
parent 28e2ebe780
commit b96a1dda2a

View File

@@ -42,11 +42,18 @@ const { groupRoms } = useUISettings();
// "pinned" pattern GameActionBtn uses for `more` / `status` menus).
const menuOpen = ref(false);
// The scan socket (`scan:scanning_rom`) emits roms with `sibling_roms`
// stripped from the payload, so it can be undefined here even though the
// type marks it required. Default to an empty list — otherwise reading
// `.length`/`.map` throws while a scan streams roms and `groupRoms` is on.
// REST payloads always include it (possibly empty).
const siblings = computed(() => props.rom.sibling_roms ?? []);
const visible = computed(
() => groupRoms.value === true && props.rom.sibling_roms.length > 0,
() => groupRoms.value === true && siblings.value.length > 0,
);
const totalCount = computed(() => props.rom.sibling_roms.length + 1);
const totalCount = computed(() => siblings.value.length + 1);
const tooltipText = computed(() =>
t("rom.versions-count", { n: totalCount.value }),
@@ -65,7 +72,7 @@ const versions = computed(() => [
current: true,
main: props.rom.rom_user?.is_main_sibling === true,
},
...props.rom.sibling_roms.map((s) => ({
...siblings.value.map((s) => ({
id: s.id,
label: s.fs_name_no_ext,
current: false,