Skip to content

Fix stale disc file ID in localStorage causing 404 on ROM play after rescan#3374

Merged
gantoine merged 2 commits into
masterfrom
copilot/fix-file-id-issue-api-call
May 15, 2026
Merged

Fix stale disc file ID in localStorage causing 404 on ROM play after rescan#3374
gantoine merged 2 commits into
masterfrom
copilot/fix-file-id-issue-api-call

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 14, 2026

After rescanning ROMs (e.g. when changing the library path), RomFile records are recreated with new IDs. The previously persisted disc selection in localStorage (player:{romId}:disc) becomes stale, causing the player to pass an invalid ?file_ids= to /api/roms/{id}/content/{name} — resulting in a 404.

Changes

  • views/Player/EmulatorJS/Base.vue — Validate the stored disc ID against the ROM's actual file list before using it. If stale, remove the key from localStorage and fall back to the first available file.
  • console/views/Play.vue — Same validation before constructing EJS_gameUrl. Clears playerStorage.disc if the stored ID no longer maps to a real file.
// Before: blindly trusted localStorage
const discId = playerStorage.disc.value ? parseInt(playerStorage.disc.value) : null;

// After: validate against actual files
const storedDiscId = playerStorage.disc.value ? parseInt(playerStorage.disc.value) : null;
const validDiscId =
  storedDiscId && rom.files.some((f) => f.id === storedDiscId) ? storedDiscId : null;
if (storedDiscId && !validDiscId) playerStorage.disc.value = null;

When a ROM is rescanned and its file IDs change, disc IDs stored in
localStorage become stale. This caused file_ids query params with invalid
IDs to be sent to /api/roms/{id}/content/{name}, resulting in 404 errors.

Validate the stored disc ID against the actual ROM files before use. If
stale, clear localStorage and fall back to the first available file.

Agent-Logs-Url: https://github.com/rommapp/romm/sessions/3579d577-13ff-4288-9a9c-909b6f891c9e

Co-authored-by: gantoine <3247106+gantoine@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix file_id returning as rom_id on API call Fix stale disc file ID in localStorage causing 404 on ROM play after rescan May 14, 2026
Copilot AI requested a review from gantoine May 14, 2026 18:39
@gantoine gantoine marked this pull request as ready for review May 15, 2026 00:25
Copilot AI review requested due to automatic review settings May 15, 2026 00:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Validates persisted disc selections in localStorage against the ROM's current file list before use, preventing 404 errors when stale IDs remain after a rescan recreates RomFile records.

Changes:

  • Validate stored disc ID in EmulatorJS Base.vue and clear it from localStorage if no longer valid.
  • Apply the same validation and cleanup in console/views/Play.vue before constructing EJS_gameUrl.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
frontend/src/views/Player/EmulatorJS/Base.vue Falls back to first file and removes stale localStorage key when stored disc ID is not in rom.files.
frontend/src/console/views/Play.vue Computes a validDiscId and clears playerStorage.disc when the stored ID is stale.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@gantoine gantoine merged commit 32cdfb1 into master May 15, 2026
10 checks passed
@gantoine gantoine deleted the copilot/fix-file-id-issue-api-call branch May 15, 2026 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] file_id returning as rom_id on /roms/rom_id/content/name/file_id API call

3 participants