fix : copy the wrong game PGN after a deletion - #98
Open
mateuskb wants to merge 2 commits into
Open
Conversation
added 2 commits
August 21, 2026 18:11
The DataGrid is fed `rows={games}` with no `getRowId`, so it derives row ids
from `Game.id`, which is the IndexedDB auto-increment key. `handleCopyGameRow`
treated that key as an array index (`games[id - 1]`).
Keys stay dense only until a game is deleted. After that they go sparse
(1, 2, 4, 5...) while the array stays contiguous, so copying a game whose id
sits past the gap yields another game's PGN, or throws on `undefined.pgn` for
the last row.
Look the game up by key instead, matching what `handleDeleteGameRow` already
does with the same value.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On
/database, the games grid is rendered withrows={games}and nogetRowId, so MUI DataGrid derives each row id fromGame.id— the IndexedDB auto-increment key.handleCopyGameRowtreats that key as an array index:Keys are only dense until a game is deleted. Afterwards they go sparse (
1, 2, 4, 5) whilegamesstays contiguous, so the two stop lining up.Steps to reproduce
1, 2, 3.2, 3;gameshas length 2.3.games[2]isundefined, so it throws onundefined.pgn. With more games saved it silently copies a different game's PGN instead, which is the worse outcome since there is no visible error.Fix
Look the game up by key rather than by position — the same value
handleDeleteGameRowalready passes straight todeleteGame(id):The second commit drops an unrelated
console.log(games)that was firing on every render of the same page. Happy to split that out if you would rather keep the PR to a single concern.npm run lintpasses.