Fix note image duplication on navigate #1047
Merged
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.
This merge request fixes an issue where images were being duplicated when navigating indefinitely. This I think is down to how React reconciles elements that do not have unique keys.
The fix is to use the note image id for the map keys so that the uniqueness required, exists. I have also added additional code to ensure that when seeding the database, a note is not created using the same image multiple times. The second bit might be beyond the scope of this so I am happy to remove it, I've included it as a nice to have (in my opinion).
Tests have not been updated but no functionality has been lost although I don't believe this area of the code is currently covered.
Test Plan
A bit of a tedious one to test because a new project is needed with a seeded database where a note is created with the same image being used multiple times. Once you have this, you will be able to navigate back and forth and see the issue as shown in #1046
Pulling down my changes, you will see that this issue is no longer happening as we have swapped out using the objectKey for the map key in favour of the image id.
Checklist
Screenshots
Before:
Screen.Recording.2025-10-06.at.21.19.00.mp4
After:
Screen.Recording.2025-10-06.at.21.19.44.mp4
Note
Switch note image list keys to
image.idand update seeding to select unique images per note.app/routes/users+/$username_+/notes.$noteId.tsx):images.id.image.objectKeytoimage.id.prisma/seed.ts):faker.helpers.arrayElementsand create withPromise.allto avoid duplicates.Written by Cursor Bugbot for commit 670ba5f. This will update automatically on new commits. Configure here.